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.artifact.Artifact;
26  
27  /**
28   * A request to register an artifact within the local repository. Certain local repository implementations can refuse to
29   * serve physically present artifacts if those haven't been previously registered to them.
30   * 
31   * @see LocalRepositoryManager#add(org.eclipse.aether.RepositorySystemSession, LocalArtifactRegistration)
32   */
33  public final class LocalArtifactRegistration
34  {
35  
36      private Artifact artifact;
37  
38      private RemoteRepository repository;
39  
40      private Collection<String> contexts = Collections.emptyList();
41  
42      /**
43       * Creates an uninitialized registration.
44       */
45      public LocalArtifactRegistration()
46      {
47          // enables default constructor
48      }
49  
50      /**
51       * Creates a registration request for the specified (locally installed) artifact.
52       * 
53       * @param artifact The artifact to register, may be {@code null}.
54       */
55      public LocalArtifactRegistration( Artifact artifact )
56      {
57          setArtifact( artifact );
58      }
59  
60      /**
61       * Creates a registration request for the specified artifact.
62       * 
63       * @param artifact The artifact to register, may be {@code null}.
64       * @param repository The remote repository from which the artifact was resolved or {@code null} if the artifact was
65       *            locally installed.
66       * @param contexts The resolution contexts, may be {@code null}.
67       */
68      public LocalArtifactRegistration( Artifact artifact, RemoteRepository repository, Collection<String> contexts )
69      {
70          setArtifact( artifact );
71          setRepository( repository );
72          setContexts( contexts );
73      }
74  
75      /**
76       * Gets the artifact to register.
77       * 
78       * @return The artifact or {@code null} if not set.
79       */
80      public Artifact getArtifact()
81      {
82          return artifact;
83      }
84  
85      /**
86       * Sets the artifact to register.
87       * 
88       * @param artifact The artifact, may be {@code null}.
89       * @return This request for chaining, never {@code null}.
90       */
91      public LocalArtifactRegistration setArtifact( Artifact artifact )
92      {
93          this.artifact = artifact;
94          return this;
95      }
96  
97      /**
98       * Gets the remote repository from which the artifact was resolved.
99       * 
100      * @return The remote repository or {@code null} if the artifact was locally installed.
101      */
102     public RemoteRepository getRepository()
103     {
104         return repository;
105     }
106 
107     /**
108      * Sets the remote repository from which the artifact was resolved.
109      * 
110      * @param repository The remote repository or {@code null} if the artifact was locally installed.
111      * @return This request for chaining, never {@code null}.
112      */
113     public LocalArtifactRegistration setRepository( RemoteRepository repository )
114     {
115         this.repository = repository;
116         return this;
117     }
118 
119     /**
120      * Gets the resolution contexts in which the artifact is available.
121      * 
122      * @return The resolution contexts in which the artifact is available, never {@code null}.
123      */
124     public Collection<String> getContexts()
125     {
126         return contexts;
127     }
128 
129     /**
130      * Sets the resolution contexts in which the artifact is available.
131      * 
132      * @param contexts The resolution contexts, may be {@code null}.
133      * @return This request for chaining, never {@code null}.
134      */
135     public LocalArtifactRegistration setContexts( Collection<String> contexts )
136     {
137         if ( contexts != null )
138         {
139             this.contexts = contexts;
140         }
141         else
142         {
143             this.contexts = Collections.emptyList();
144         }
145         return this;
146     }
147 
148 }