View Javadoc
1   /*******************************************************************************
2    * Copyright (c) 2010, 2012 Sonatype, Inc.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *    Sonatype, Inc. - initial API and implementation
10   *******************************************************************************/
11  package org.eclipse.aether.deployment;
12  
13  import java.util.ArrayList;
14  import java.util.Collection;
15  import java.util.Collections;
16  
17  import org.eclipse.aether.RepositorySystem;
18  import org.eclipse.aether.RepositorySystemSession;
19  import org.eclipse.aether.artifact.Artifact;
20  import org.eclipse.aether.metadata.Metadata;
21  
22  /**
23   * The result of deploying artifacts and their accompanying metadata into the a remote repository.
24   * 
25   * @see RepositorySystem#deploy(RepositorySystemSession, DeployRequest)
26   */
27  public final class DeployResult
28  {
29  
30      private final DeployRequest request;
31  
32      private Collection<Artifact> artifacts;
33  
34      private Collection<Metadata> metadata;
35  
36      /**
37       * Creates a new result for the specified request.
38       * 
39       * @param request The deployment request, must not be {@code null}.
40       */
41      public DeployResult( DeployRequest request )
42      {
43          if ( request == null )
44          {
45              throw new IllegalArgumentException( "deploy request has not been specified" );
46          }
47          this.request = request;
48          artifacts = Collections.emptyList();
49          metadata = Collections.emptyList();
50      }
51  
52      /**
53       * Gets the deploy request that was made.
54       * 
55       * @return The deploy request, never {@code null}.
56       */
57      public DeployRequest getRequest()
58      {
59          return request;
60      }
61  
62      /**
63       * Gets the artifacts that got deployed.
64       * 
65       * @return The deployed artifacts, never {@code null}.
66       */
67      public Collection<Artifact> getArtifacts()
68      {
69          return artifacts;
70      }
71  
72      /**
73       * Sets the artifacts that got deployed.
74       * 
75       * @param artifacts The deployed artifacts, may be {@code null}.
76       * @return This result for chaining, never {@code null}.
77       */
78      public DeployResult setArtifacts( Collection<Artifact> artifacts )
79      {
80          if ( artifacts == null )
81          {
82              this.artifacts = Collections.emptyList();
83          }
84          else
85          {
86              this.artifacts = artifacts;
87          }
88          return this;
89      }
90  
91      /**
92       * Adds the specified artifacts to the result.
93       * 
94       * @param artifact The deployed artifact to add, may be {@code null}.
95       * @return This result for chaining, never {@code null}.
96       */
97      public DeployResult addArtifact( Artifact artifact )
98      {
99          if ( artifact != null )
100         {
101             if ( artifacts.isEmpty() )
102             {
103                 artifacts = new ArrayList<Artifact>();
104             }
105             artifacts.add( artifact );
106         }
107         return this;
108     }
109 
110     /**
111      * Gets the metadata that got deployed. Note that due to automatically generated metadata, there might have been
112      * more metadata deployed than originally specified in the deploy request.
113      * 
114      * @return The deployed metadata, never {@code null}.
115      */
116     public Collection<Metadata> getMetadata()
117     {
118         return metadata;
119     }
120 
121     /**
122      * Sets the metadata that got deployed.
123      * 
124      * @param metadata The deployed metadata, may be {@code null}.
125      * @return This result for chaining, never {@code null}.
126      */
127     public DeployResult setMetadata( Collection<Metadata> metadata )
128     {
129         if ( metadata == null )
130         {
131             this.metadata = Collections.emptyList();
132         }
133         else
134         {
135             this.metadata = metadata;
136         }
137         return this;
138     }
139 
140     /**
141      * Adds the specified metadata to this result.
142      * 
143      * @param metadata The deployed metadata to add, may be {@code null}.
144      * @return This result for chaining, never {@code null}.
145      */
146     public DeployResult addMetadata( Metadata metadata )
147     {
148         if ( metadata != null )
149         {
150             if ( this.metadata.isEmpty() )
151             {
152                 this.metadata = new ArrayList<Metadata>();
153             }
154             this.metadata.add( metadata );
155         }
156         return this;
157     }
158 
159     @Override
160     public String toString()
161     {
162         return getArtifacts() + ", " + getMetadata();
163     }
164 
165 }