View Javadoc
1   package org.eclipse.aether.repository;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Collection;
23  import java.util.Collections;
24  
25  import org.eclipse.aether.RepositorySystemSession;
26  import org.eclipse.aether.artifact.Artifact;
27  
28  /**
29   * A request to register an artifact within the local repository. Certain local repository implementations can refuse to
30   * serve physically present artifacts if those haven't been previously registered to them.
31   * 
32   * @see LocalRepositoryManager#add(RepositorySystemSession, LocalArtifactRegistration)
33   */
34  public final class LocalArtifactRegistration
35  {
36  
37      private Artifact artifact;
38  
39      private RemoteRepository repository;
40  
41      private Collection<String> contexts = Collections.emptyList();
42  
43      /**
44       * Creates an uninitialized registration.
45       */
46      public LocalArtifactRegistration()
47      {
48          // enables default constructor
49      }
50  
51      /**
52       * Creates a registration request for the specified (locally installed) artifact.
53       * 
54       * @param artifact The artifact to register, may be {@code null}.
55       */
56      public LocalArtifactRegistration( Artifact artifact )
57      {
58          setArtifact( artifact );
59      }
60  
61      /**
62       * Creates a registration request for the specified artifact.
63       * 
64       * @param artifact The artifact to register, may be {@code null}.
65       * @param repository The remote repository from which the artifact was resolved or {@code null} if the artifact was
66       *            locally installed.
67       * @param contexts The resolution contexts, may be {@code null}.
68       */
69      public LocalArtifactRegistration( Artifact artifact, RemoteRepository repository, Collection<String> contexts )
70      {
71          setArtifact( artifact );
72          setRepository( repository );
73          setContexts( contexts );
74      }
75  
76      /**
77       * Gets the artifact to register.
78       * 
79       * @return The artifact or {@code null} if not set.
80       */
81      public Artifact getArtifact()
82      {
83          return artifact;
84      }
85  
86      /**
87       * Sets the artifact to register.
88       * 
89       * @param artifact The artifact, may be {@code null}.
90       * @return This request for chaining, never {@code null}.
91       */
92      public LocalArtifactRegistration setArtifact( Artifact artifact )
93      {
94          this.artifact = artifact;
95          return this;
96      }
97  
98      /**
99       * 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 }