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