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