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  
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 deploying artifacts and their accompanying metadata into the a remote repository.
33   * 
34   * @see RepositorySystem#deploy(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          if ( request == null )
53          {
54              throw new IllegalArgumentException( "deploy request has not been specified" );
55          }
56          this.request = request;
57          artifacts = Collections.emptyList();
58          metadata = Collections.emptyList();
59      }
60  
61      /**
62       * Gets the deploy request that was made.
63       * 
64       * @return The deploy request, never {@code null}.
65       */
66      public DeployRequest getRequest()
67      {
68          return request;
69      }
70  
71      /**
72       * Gets the artifacts that got deployed.
73       * 
74       * @return The deployed artifacts, never {@code null}.
75       */
76      public Collection<Artifact> getArtifacts()
77      {
78          return artifacts;
79      }
80  
81      /**
82       * Sets the artifacts that got deployed.
83       * 
84       * @param artifacts The deployed artifacts, may be {@code null}.
85       * @return This result for chaining, never {@code null}.
86       */
87      public DeployResult 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 deployed artifact to add, may be {@code null}.
104      * @return This result for chaining, never {@code null}.
105      */
106     public DeployResult 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 deployed. Note that due to automatically generated metadata, there might have been
121      * more metadata deployed than originally specified in the deploy request.
122      * 
123      * @return The deployed metadata, never {@code null}.
124      */
125     public Collection<Metadata> getMetadata()
126     {
127         return metadata;
128     }
129 
130     /**
131      * Sets the metadata that got deployed.
132      * 
133      * @param metadata The deployed metadata, may be {@code null}.
134      * @return This result for chaining, never {@code null}.
135      */
136     public DeployResult 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 deployed metadata to add, may be {@code null}.
153      * @return This result for chaining, never {@code null}.
154      */
155     public DeployResult 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 }