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