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