View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.repository;
20  
21  import java.util.Collection;
22  import java.util.Collections;
23  
24  import org.eclipse.aether.metadata.Metadata;
25  
26  /**
27   * A request to register metadata within the local repository.
28   *
29   * @see LocalRepositoryManager#add(org.eclipse.aether.RepositorySystemSession, LocalMetadataRegistration)
30   */
31  public final class LocalMetadataRegistration {
32  
33      private Metadata metadata;
34  
35      private RemoteRepository repository;
36  
37      private Collection<String> contexts = Collections.emptyList();
38  
39      /**
40       * Creates an uninitialized registration.
41       */
42      public LocalMetadataRegistration() {
43          // enables default constructor
44      }
45  
46      /**
47       * Creates a registration request for the specified metadata accompanying a locally installed artifact.
48       *
49       * @param metadata The metadata to register, may be {@code null}.
50       */
51      public LocalMetadataRegistration(Metadata metadata) {
52          setMetadata(metadata);
53      }
54  
55      /**
56       * Creates a registration request for the specified metadata.
57       *
58       * @param metadata The metadata to register, may be {@code null}.
59       * @param repository The remote repository from which the metadata was resolved or {@code null} if the metadata
60       *            accompanies a locally installed artifact.
61       * @param contexts The resolution contexts, may be {@code null}.
62       */
63      public LocalMetadataRegistration(Metadata metadata, RemoteRepository repository, Collection<String> contexts) {
64          setMetadata(metadata);
65          setRepository(repository);
66          setContexts(contexts);
67      }
68  
69      /**
70       * Gets the metadata to register.
71       *
72       * @return The metadata or {@code null} if not set.
73       */
74      public Metadata getMetadata() {
75          return metadata;
76      }
77  
78      /**
79       * Sets the metadata to register.
80       *
81       * @param metadata The metadata, may be {@code null}.
82       * @return This request for chaining, never {@code null}.
83       */
84      public LocalMetadataRegistration setMetadata(Metadata metadata) {
85          this.metadata = metadata;
86          return this;
87      }
88  
89      /**
90       * Gets the remote repository from which the metadata was resolved.
91       *
92       * @return The remote repository or {@code null} if the metadata was locally installed.
93       */
94      public RemoteRepository getRepository() {
95          return repository;
96      }
97  
98      /**
99       * Sets the remote repository from which the metadata was resolved.
100      *
101      * @param repository The remote repository or {@code null} if the metadata accompanies a locally installed artifact.
102      * @return This request for chaining, never {@code null}.
103      */
104     public LocalMetadataRegistration setRepository(RemoteRepository repository) {
105         this.repository = repository;
106         return this;
107     }
108 
109     /**
110      * Gets the resolution contexts in which the metadata is available.
111      *
112      * @return The resolution contexts in which the metadata is available, never {@code null}.
113      */
114     public Collection<String> getContexts() {
115         return contexts;
116     }
117 
118     /**
119      * Sets the resolution contexts in which the metadata is available.
120      *
121      * @param contexts The resolution contexts, may be {@code null}.
122      * @return This request for chaining, never {@code null}.
123      */
124     public LocalMetadataRegistration setContexts(Collection<String> contexts) {
125         if (contexts != null) {
126             this.contexts = contexts;
127         } else {
128             this.contexts = Collections.emptyList();
129         }
130         return this;
131     }
132 }