001package org.eclipse.aether.repository;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.Collection;
023import java.util.Collections;
024
025import org.eclipse.aether.RepositorySystemSession;
026import org.eclipse.aether.artifact.Artifact;
027
028/**
029 * A request to register an artifact within the local repository. Certain local repository implementations can refuse to
030 * serve physically present artifacts if those haven't been previously registered to them.
031 * 
032 * @see LocalRepositoryManager#add(RepositorySystemSession, LocalArtifactRegistration)
033 */
034public final class LocalArtifactRegistration
035{
036
037    private Artifact artifact;
038
039    private RemoteRepository repository;
040
041    private Collection<String> contexts = Collections.emptyList();
042
043    /**
044     * Creates an uninitialized registration.
045     */
046    public LocalArtifactRegistration()
047    {
048        // enables default constructor
049    }
050
051    /**
052     * Creates a registration request for the specified (locally installed) artifact.
053     * 
054     * @param artifact The artifact to register, may be {@code null}.
055     */
056    public LocalArtifactRegistration( Artifact artifact )
057    {
058        setArtifact( artifact );
059    }
060
061    /**
062     * Creates a registration request for the specified artifact.
063     * 
064     * @param artifact The artifact to register, may be {@code null}.
065     * @param repository The remote repository from which the artifact was resolved or {@code null} if the artifact was
066     *            locally installed.
067     * @param contexts The resolution contexts, may be {@code null}.
068     */
069    public LocalArtifactRegistration( Artifact artifact, RemoteRepository repository, Collection<String> contexts )
070    {
071        setArtifact( artifact );
072        setRepository( repository );
073        setContexts( contexts );
074    }
075
076    /**
077     * Gets the artifact to register.
078     * 
079     * @return The artifact or {@code null} if not set.
080     */
081    public Artifact getArtifact()
082    {
083        return artifact;
084    }
085
086    /**
087     * Sets the artifact to register.
088     * 
089     * @param artifact The artifact, may be {@code null}.
090     * @return This request for chaining, never {@code null}.
091     */
092    public LocalArtifactRegistration setArtifact( Artifact artifact )
093    {
094        this.artifact = artifact;
095        return this;
096    }
097
098    /**
099     * Gets the remote repository from which the artifact was resolved.
100     * 
101     * @return The remote repository or {@code null} if the artifact was locally installed.
102     */
103    public RemoteRepository getRepository()
104    {
105        return repository;
106    }
107
108    /**
109     * Sets the remote repository from which the artifact was resolved.
110     * 
111     * @param repository The remote repository or {@code null} if the artifact was locally installed.
112     * @return This request for chaining, never {@code null}.
113     */
114    public LocalArtifactRegistration setRepository( RemoteRepository repository )
115    {
116        this.repository = repository;
117        return this;
118    }
119
120    /**
121     * Gets the resolution contexts in which the artifact is available.
122     * 
123     * @return The resolution contexts in which the artifact is available, never {@code null}.
124     */
125    public Collection<String> getContexts()
126    {
127        return contexts;
128    }
129
130    /**
131     * Sets the resolution contexts in which the artifact is available.
132     * 
133     * @param contexts The resolution contexts, may be {@code null}.
134     * @return This request for chaining, never {@code null}.
135     */
136    public LocalArtifactRegistration setContexts( Collection<String> contexts )
137    {
138        if ( contexts != null )
139        {
140            this.contexts = contexts;
141        }
142        else
143        {
144            this.contexts = Collections.emptyList();
145        }
146        return this;
147    }
148
149}