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