001/*
002 * Extra Bnd Repository Plugins
003 * Copyright (C) 2019-2021  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.api.Revision;
023import aQute.maven.provider.MavenBackingRepository;
024
025/**
026 * An {@link Archive} with a reference to the maven repository
027 * in which it was found.
028 * 
029 * @see BoundRevision 
030 */
031public class BoundArchive extends Archive {
032
033    private final MavenBackingRepository mavenBackingRepository;
034
035    /**
036     * Instantiates a new bound archive.
037     *
038     * @param mavenBackingRepository the maven backing repository
039     * @param unbound the unbound archive
040     */
041    public BoundArchive(MavenBackingRepository mavenBackingRepository,
042            Archive unbound) {
043        super(unbound.revision, unbound.snapshot, unbound.extension,
044            unbound.classifier);
045        this.mavenBackingRepository = mavenBackingRepository;
046    }
047
048    /**
049     * Instantiates a new bound archive.
050     *
051     * @param mavenBackingRepository the maven backing repository
052     * @param revision the revision
053     * @param snapshot the snapshot
054     * @param extension the extension
055     * @param classifier the classifier
056     */
057    public BoundArchive(MavenBackingRepository mavenBackingRepository,
058            Revision revision, MavenVersion snapshot, String extension,
059            String classifier) {
060        super(revision, snapshot == null ? null : snapshot.asBndMavenVersion(),
061            extension, classifier);
062        this.mavenBackingRepository = mavenBackingRepository;
063    }
064
065    /**
066     * Gets the maven backing repository.
067     *
068     * @return the mavenBackingRepository
069     */
070    public MavenBackingRepository mavenBackingRepository() {
071        return mavenBackingRepository;
072    }
073
074    /**
075     * Return the archive's revision, bound to its backing repository.
076     *
077     * @return the bound revision
078     */
079    public BoundRevision revision() {
080        return new BoundRevision(mavenBackingRepository, revision);
081    }
082
083}