001/*
002 * Extra Bnd Repository Plugins
003 * Copyright (C) 2019  Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero General Public License as published by 
007 * the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 * 
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package de.mnl.osgi.bnd.maven;
020
021import aQute.maven.api.Archive;
022import aQute.maven.provider.MavenBackingRepository;
023
024import static de.mnl.osgi.bnd.maven.MavenVersion.toBndMavenVersion;
025
026/**
027 * An {@link Archive} with a reference to the maven repository
028 * in which it was found.
029 * 
030 * @see BoundRevision 
031 */
032public class BoundArchive extends Archive {
033
034    private final BoundRevision revision;
035
036    /**
037     * Instantiates a new bound archive.
038     *
039     * @param revision the revision
040     * @param snapshot the snapshot
041     * @param extension the extension
042     * @param classifier the classifier
043     */
044    public BoundArchive(BoundRevision revision, MavenVersion snapshot,
045            String extension, String classifier) {
046        super(revision.unbound(), toBndMavenVersion(snapshot), extension,
047            classifier);
048        this.revision = revision;
049    }
050
051    /**
052     * Instantiates a new bound archive.
053     *
054     * @param revision the revision
055     * @param snapshot the snapshot
056     * @param extension the extension
057     * @param classifier the classifier
058     */
059    public BoundArchive(BoundRevision revision,
060            aQute.bnd.version.MavenVersion snapshot, String extension,
061            String classifier) {
062        super(revision.unbound(), snapshot, extension, classifier);
063        this.revision = revision;
064    }
065
066    /**
067     * Instantiates a new bound archive.
068     *
069     * @param mavenRepository the maven repository
070     * @param str the string representation
071     */
072    public BoundArchive(MavenBackingRepository mavenRepository, String str) {
073        super(str);
074        this.revision = new BoundRevision(mavenRepository, super.revision);
075    }
076
077    /**
078     * Create a {@link BoundArchive} from an (unbound) {@link Archive}.
079     *
080     * @param mavenRepository the maven repository
081     * @param archive the archive
082     * @return the bound archive
083     */
084    public static BoundArchive fromArchive(
085            MavenBackingRepository mavenRepository, Archive archive) {
086        return new BoundArchive(
087            new BoundRevision(mavenRepository, archive.revision),
088            archive.snapshot, archive.extension, archive.classifier);
089    }
090
091    /**
092     * Gets the maven backing repository.
093     *
094     * @return the mavenBackingRepository
095     */
096    public final MavenBackingRepository mavenBackingRepository() {
097        return revision.mavenBackingRepository();
098    }
099
100    /**
101     * Gets the bound revision.
102     *
103     * @return the bound revision
104     */
105    public BoundRevision getBoundRevision() {
106        return revision;
107    }
108
109}