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