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.installation;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.Collections;
24  
25  import org.eclipse.aether.RepositorySystem;
26  import org.eclipse.aether.RequestTrace;
27  import org.eclipse.aether.artifact.Artifact;
28  import org.eclipse.aether.metadata.Metadata;
29  
30  /**
31   * A request to install artifacts and their accompanying metadata into the local repository.
32   *
33   * @see RepositorySystem#install(RepositorySystemSession, InstallRequest)
34   */
35  public final class InstallRequest {
36  
37      private Collection<Artifact> artifacts = Collections.emptyList();
38  
39      private Collection<Metadata> metadata = Collections.emptyList();
40  
41      private RequestTrace trace;
42  
43      /**
44       * Creates an uninitialized request.
45       */
46      public InstallRequest() {}
47  
48      /**
49       * Gets the artifact to install.
50       *
51       * @return The artifacts to install, never {@code null}.
52       */
53      public Collection<Artifact> getArtifacts() {
54          return artifacts;
55      }
56  
57      /**
58       * Sets the artifacts to install.
59       *
60       * @param artifacts The artifacts to install, may be {@code null}.
61       * @return This request for chaining, never {@code null}.
62       */
63      public InstallRequest setArtifacts(Collection<Artifact> artifacts) {
64          if (artifacts == null) {
65              this.artifacts = Collections.emptyList();
66          } else {
67              this.artifacts = artifacts;
68          }
69          return this;
70      }
71  
72      /**
73       * Adds the specified artifacts for installation.
74       *
75       * @param artifact The artifact to add, may be {@code null}.
76       * @return This request for chaining, never {@code null}.
77       */
78      public InstallRequest addArtifact(Artifact artifact) {
79          if (artifact != null) {
80              if (artifacts.isEmpty()) {
81                  artifacts = new ArrayList<>();
82              }
83              artifacts.add(artifact);
84          }
85          return this;
86      }
87  
88      /**
89       * Gets the metadata to install.
90       *
91       * @return The metadata to install, never {@code null}.
92       */
93      public Collection<Metadata> getMetadata() {
94          return metadata;
95      }
96  
97      /**
98       * Sets the metadata to install.
99       *
100      * @param metadata The metadata to install.
101      * @return This request for chaining, never {@code null}.
102      */
103     public InstallRequest setMetadata(Collection<Metadata> metadata) {
104         if (metadata == null) {
105             this.metadata = Collections.emptyList();
106         } else {
107             this.metadata = metadata;
108         }
109         return this;
110     }
111 
112     /**
113      * Adds the specified metadata for installation.
114      *
115      * @param metadata The metadata to add, may be {@code null}.
116      * @return This request for chaining, never {@code null}.
117      */
118     public InstallRequest addMetadata(Metadata metadata) {
119         if (metadata != null) {
120             if (this.metadata.isEmpty()) {
121                 this.metadata = new ArrayList<>();
122             }
123             this.metadata.add(metadata);
124         }
125         return this;
126     }
127 
128     /**
129      * Gets the trace information that describes the higher level request/operation in which this request is issued.
130      *
131      * @return The trace information about the higher level operation or {@code null} if none.
132      */
133     public RequestTrace getTrace() {
134         return trace;
135     }
136 
137     /**
138      * Sets the trace information that describes the higher level request/operation in which this request is issued.
139      *
140      * @param trace The trace information about the higher level operation, may be {@code null}.
141      * @return This request for chaining, never {@code null}.
142      */
143     public InstallRequest setTrace(RequestTrace trace) {
144         this.trace = trace;
145         return this;
146     }
147 
148     @Override
149     public String toString() {
150         return getArtifacts() + ", " + getMetadata();
151     }
152 }