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