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 import static java.util.Objects.requireNonNull;
26
27 import org.eclipse.aether.RepositorySystem;
28 import org.eclipse.aether.RepositorySystemSession;
29 import org.eclipse.aether.artifact.Artifact;
30 import org.eclipse.aether.metadata.Metadata;
31
32 /**
33 * The result of deploying artifacts and their accompanying metadata into the a remote repository.
34 *
35 * @see RepositorySystem#deploy(RepositorySystemSession, DeployRequest)
36 */
37 public final class DeployResult
38 {
39
40 private final DeployRequest request;
41
42 private Collection<Artifact> artifacts;
43
44 private Collection<Metadata> metadata;
45
46 /**
47 * Creates a new result for the specified request.
48 *
49 * @param request The deployment request, must not be {@code null}.
50 */
51 public DeployResult( DeployRequest request )
52 {
53 this.request = requireNonNull( request, "deploy request cannot be null" );
54 artifacts = Collections.emptyList();
55 metadata = Collections.emptyList();
56 }
57
58 /**
59 * Gets the deploy request that was made.
60 *
61 * @return The deploy request, never {@code null}.
62 */
63 public DeployRequest getRequest()
64 {
65 return request;
66 }
67
68 /**
69 * Gets the artifacts that got deployed.
70 *
71 * @return The deployed artifacts, never {@code null}.
72 */
73 public Collection<Artifact> getArtifacts()
74 {
75 return artifacts;
76 }
77
78 /**
79 * Sets the artifacts that got deployed.
80 *
81 * @param artifacts The deployed artifacts, may be {@code null}.
82 * @return This result for chaining, never {@code null}.
83 */
84 public DeployResult setArtifacts( Collection<Artifact> artifacts )
85 {
86 if ( artifacts == null )
87 {
88 this.artifacts = Collections.emptyList();
89 }
90 else
91 {
92 this.artifacts = artifacts;
93 }
94 return this;
95 }
96
97 /**
98 * Adds the specified artifacts to the result.
99 *
100 * @param artifact The deployed artifact to add, may be {@code null}.
101 * @return This result for chaining, never {@code null}.
102 */
103 public DeployResult addArtifact( Artifact artifact )
104 {
105 if ( artifact != null )
106 {
107 if ( artifacts.isEmpty() )
108 {
109 artifacts = new ArrayList<Artifact>();
110 }
111 artifacts.add( artifact );
112 }
113 return this;
114 }
115
116 /**
117 * Gets the metadata that got deployed. Note that due to automatically generated metadata, there might have been
118 * more metadata deployed than originally specified in the deploy request.
119 *
120 * @return The deployed metadata, never {@code null}.
121 */
122 public Collection<Metadata> getMetadata()
123 {
124 return metadata;
125 }
126
127 /**
128 * Sets the metadata that got deployed.
129 *
130 * @param metadata The deployed metadata, may be {@code null}.
131 * @return This result for chaining, never {@code null}.
132 */
133 public DeployResult setMetadata( Collection<Metadata> metadata )
134 {
135 if ( metadata == null )
136 {
137 this.metadata = Collections.emptyList();
138 }
139 else
140 {
141 this.metadata = metadata;
142 }
143 return this;
144 }
145
146 /**
147 * Adds the specified metadata to this result.
148 *
149 * @param metadata The deployed metadata to add, may be {@code null}.
150 * @return This result for chaining, never {@code null}.
151 */
152 public DeployResult addMetadata( Metadata metadata )
153 {
154 if ( metadata != null )
155 {
156 if ( this.metadata.isEmpty() )
157 {
158 this.metadata = new ArrayList<Metadata>();
159 }
160 this.metadata.add( metadata );
161 }
162 return this;
163 }
164
165 @Override
166 public String toString()
167 {
168 return getArtifacts() + ", " + getMetadata();
169 }
170
171 }