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