001/*
002 * JDrupes Builder
003 * Copyright (C) 2026 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.builder.mvnrepo;
020
021import java.nio.file.Path;
022import java.util.List;
023import org.eclipse.aether.repository.RemoteRepository;
024import org.jdrupes.builder.api.ResourceType;
025import org.jdrupes.builder.java.CodeContribution;
026import org.jdrupes.builder.java.DefaultJarFile;
027import org.jdrupes.builder.java.LibraryJarFile;
028import static org.jdrupes.builder.mvnrepo.MvnRepoTypes.MvnRepoResourceType;
029
030/// The default implementation of a [MvnRepoLibraryJarFile].
031///
032public class DefaultMvnRepoLibraryJarFile extends DefaultJarFile
033        implements MvnRepoLibraryJarFile {
034
035    private final List<RemoteRepository> repositories;
036    private final MvnRepoResource resource;
037    private Boolean isModular;
038
039    /// Initializes a new instance with the given values.
040    ///
041    /// @param type the type
042    /// @param repositories the repositories
043    /// @param coordinates the coordinates
044    /// @param path the path
045    ///
046    public DefaultMvnRepoLibraryJarFile(
047            ResourceType<? extends LibraryJarFile> type,
048            List<RemoteRepository> repositories, String coordinates,
049            Path path) {
050        super(type, path);
051        this.repositories = repositories;
052        resource = new DefaultMvnRepoResource(MvnRepoResourceType, coordinates);
053    }
054
055    @Override
056    public boolean isModular() {
057        if (isModular == null) {
058            isModular = CodeContribution.isModular(this);
059        }
060        return isModular;
061    }
062
063    @Override
064    public List<RemoteRepository> repositories() {
065        return repositories;
066    }
067
068    @Override
069    public MvnRepoResource reference() {
070        return resource;
071    }
072}