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.installation;
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.RequestTrace;
20  import org.eclipse.aether.artifact.Artifact;
21  import org.eclipse.aether.metadata.Metadata;
22  
23  /**
24   * A request to install artifacts and their accompanying metadata into the local repository.
25   * 
26   * @see RepositorySystem#install(RepositorySystemSession, InstallRequest)
27   */
28  public final class InstallRequest
29  {
30  
31      private Collection<Artifact> artifacts = Collections.emptyList();
32  
33      private Collection<Metadata> metadata = Collections.emptyList();
34  
35      private RequestTrace trace;
36  
37      /**
38       * Creates an uninitialized request.
39       */
40      public InstallRequest()
41      {
42      }
43  
44      /**
45       * Gets the artifact to install.
46       * 
47       * @return The artifacts to install, never {@code null}.
48       */
49      public Collection<Artifact> getArtifacts()
50      {
51          return artifacts;
52      }
53  
54      /**
55       * Sets the artifacts to install.
56       * 
57       * @param artifacts The artifacts to install, may be {@code null}.
58       * @return This request for chaining, never {@code null}.
59       */
60      public InstallRequest setArtifacts( Collection<Artifact> artifacts )
61      {
62          if ( artifacts == null )
63          {
64              this.artifacts = Collections.emptyList();
65          }
66          else
67          {
68              this.artifacts = artifacts;
69          }
70          return this;
71      }
72  
73      /**
74       * Adds the specified artifacts for installation.
75       * 
76       * @param artifact The artifact to add, may be {@code null}.
77       * @return This request for chaining, never {@code null}.
78       */
79      public InstallRequest addArtifact( Artifact artifact )
80      {
81          if ( artifact != null )
82          {
83              if ( artifacts.isEmpty() )
84              {
85                  artifacts = new ArrayList<Artifact>();
86              }
87              artifacts.add( artifact );
88          }
89          return this;
90      }
91  
92      /**
93       * Gets the metadata to install.
94       * 
95       * @return The metadata to install, never {@code null}.
96       */
97      public Collection<Metadata> getMetadata()
98      {
99          return metadata;
100     }
101 
102     /**
103      * Sets the metadata to install.
104      * 
105      * @param metadata The metadata to install.
106      * @return This request for chaining, never {@code null}.
107      */
108     public InstallRequest setMetadata( Collection<Metadata> metadata )
109     {
110         if ( metadata == null )
111         {
112             this.metadata = Collections.emptyList();
113         }
114         else
115         {
116             this.metadata = metadata;
117         }
118         return this;
119     }
120 
121     /**
122      * Adds the specified metadata for installation.
123      * 
124      * @param metadata The metadata to add, may be {@code null}.
125      * @return This request for chaining, never {@code null}.
126      */
127     public InstallRequest addMetadata( Metadata metadata )
128     {
129         if ( metadata != null )
130         {
131             if ( this.metadata.isEmpty() )
132             {
133                 this.metadata = new ArrayList<Metadata>();
134             }
135             this.metadata.add( metadata );
136         }
137         return this;
138     }
139 
140     /**
141      * Gets the trace information that describes the higher level request/operation in which this request is issued.
142      * 
143      * @return The trace information about the higher level operation or {@code null} if none.
144      */
145     public RequestTrace getTrace()
146     {
147         return trace;
148     }
149 
150     /**
151      * Sets the trace information that describes the higher level request/operation in which this request is issued.
152      * 
153      * @param trace The trace information about the higher level operation, may be {@code null}.
154      * @return This request for chaining, never {@code null}.
155      */
156     public InstallRequest setTrace( RequestTrace trace )
157     {
158         this.trace = trace;
159         return this;
160     }
161 
162     @Override
163     public String toString()
164     {
165         return getArtifacts() + ", " + getMetadata();
166     }
167 
168 }