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