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