]> git.argeo.org Git - gpl/argeo-jcr.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/resolution/ArtifactRequest.java
Prepare next development cycle
[gpl/argeo-jcr.git] / org.argeo.slc.repo / src / org / eclipse / aether / resolution / ArtifactRequest.java
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.resolution;
12
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.List;
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.graph.DependencyNode;
22 import org.eclipse.aether.repository.RemoteRepository;
23
24 /**
25 * A request to resolve an artifact.
26 *
27 * @see RepositorySystem#resolveArtifacts(RepositorySystemSession, java.util.Collection)
28 * @see Artifact#getFile()
29 */
30 public final class ArtifactRequest
31 {
32
33 private Artifact artifact;
34
35 private DependencyNode node;
36
37 private List<RemoteRepository> repositories = Collections.emptyList();
38
39 private String context = "";
40
41 private RequestTrace trace;
42
43 /**
44 * Creates an uninitialized request.
45 */
46 public ArtifactRequest()
47 {
48 // enables default constructor
49 }
50
51 /**
52 * Creates a request with the specified properties.
53 *
54 * @param artifact The artifact to resolve, may be {@code null}.
55 * @param repositories The repositories to resolve the artifact from, may be {@code null}.
56 * @param context The context in which this request is made, may be {@code null}.
57 */
58 public ArtifactRequest( Artifact artifact, List<RemoteRepository> repositories, String context )
59 {
60 setArtifact( artifact );
61 setRepositories( repositories );
62 setRequestContext( context );
63 }
64
65 /**
66 * Creates a request from the specified dependency node.
67 *
68 * @param node The dependency node to resolve, may be {@code null}.
69 */
70 public ArtifactRequest( DependencyNode node )
71 {
72 setDependencyNode( node );
73 setRepositories( node.getRepositories() );
74 setRequestContext( node.getRequestContext() );
75 }
76
77 /**
78 * Gets the artifact to resolve.
79 *
80 * @return The artifact to resolve or {@code null}.
81 */
82 public Artifact getArtifact()
83 {
84 return artifact;
85 }
86
87 /**
88 * Sets the artifact to resolve.
89 *
90 * @param artifact The artifact to resolve, may be {@code null}.
91 * @return This request for chaining, never {@code null}.
92 */
93 public ArtifactRequest setArtifact( Artifact artifact )
94 {
95 this.artifact = artifact;
96 return this;
97 }
98
99 /**
100 * Gets the dependency node (if any) for which to resolve the artifact.
101 *
102 * @return The dependency node to resolve or {@code null} if unknown.
103 */
104 public DependencyNode getDependencyNode()
105 {
106 return node;
107 }
108
109 /**
110 * Sets the dependency node to resolve.
111 *
112 * @param node The dependency node to resolve, may be {@code null}.
113 * @return This request for chaining, never {@code null}.
114 */
115 public ArtifactRequest setDependencyNode( DependencyNode node )
116 {
117 this.node = node;
118 if ( node != null )
119 {
120 setArtifact( node.getDependency().getArtifact() );
121 }
122 return this;
123 }
124
125 /**
126 * Gets the repositories to resolve the artifact from.
127 *
128 * @return The repositories, never {@code null}.
129 */
130 public List<RemoteRepository> getRepositories()
131 {
132 return repositories;
133 }
134
135 /**
136 * Sets the repositories to resolve the artifact from.
137 *
138 * @param repositories The repositories, may be {@code null}.
139 * @return This request for chaining, never {@code null}.
140 */
141 public ArtifactRequest setRepositories( List<RemoteRepository> repositories )
142 {
143 if ( repositories == null )
144 {
145 this.repositories = Collections.emptyList();
146 }
147 else
148 {
149 this.repositories = repositories;
150 }
151 return this;
152 }
153
154 /**
155 * Adds the specified repository for the resolution.
156 *
157 * @param repository The repository to add, may be {@code null}.
158 * @return This request for chaining, never {@code null}.
159 */
160 public ArtifactRequest addRepository( RemoteRepository repository )
161 {
162 if ( repository != null )
163 {
164 if ( this.repositories.isEmpty() )
165 {
166 this.repositories = new ArrayList<RemoteRepository>();
167 }
168 this.repositories.add( repository );
169 }
170 return this;
171 }
172
173 /**
174 * Gets the context in which this request is made.
175 *
176 * @return The context, never {@code null}.
177 */
178 public String getRequestContext()
179 {
180 return context;
181 }
182
183 /**
184 * Sets the context in which this request is made.
185 *
186 * @param context The context, may be {@code null}.
187 * @return This request for chaining, never {@code null}.
188 */
189 public ArtifactRequest setRequestContext( String context )
190 {
191 this.context = ( context != null ) ? context : "";
192 return this;
193 }
194
195 /**
196 * Gets the trace information that describes the higher level request/operation in which this request is issued.
197 *
198 * @return The trace information about the higher level operation or {@code null} if none.
199 */
200 public RequestTrace getTrace()
201 {
202 return trace;
203 }
204
205 /**
206 * Sets the trace information that describes the higher level request/operation in which this request is issued.
207 *
208 * @param trace The trace information about the higher level operation, may be {@code null}.
209 * @return This request for chaining, never {@code null}.
210 */
211 public ArtifactRequest setTrace( RequestTrace trace )
212 {
213 this.trace = trace;
214 return this;
215 }
216
217 @Override
218 public String toString()
219 {
220 return getArtifact() + " < " + getRepositories();
221 }
222
223 }