1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 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
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.aether
.resolution
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collections
;
15 import java
.util
.List
;
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
.repository
.RemoteRepository
;
24 * A request to resolve a metaversion.
26 * @see RepositorySystem#resolveVersion(RepositorySystemSession, VersionRequest)
28 public final class VersionRequest
31 private Artifact artifact
;
33 private List
<RemoteRepository
> repositories
= Collections
.emptyList();
35 private String context
= "";
37 private RequestTrace trace
;
40 * Creates an uninitialized request.
42 public VersionRequest()
44 // enables default constructor
48 * Creates a request with the specified properties.
50 * @param artifact The artifact whose (meta-)version should be resolved, may be {@code null}.
51 * @param repositories The repositories to resolve the version from, may be {@code null}.
52 * @param context The context in which this request is made, may be {@code null}.
54 public VersionRequest( Artifact artifact
, List
<RemoteRepository
> repositories
, String context
)
56 setArtifact( artifact
);
57 setRepositories( repositories
);
58 setRequestContext( context
);
62 * Gets the artifact whose (meta-)version shall be resolved.
64 * @return The artifact or {@code null} if not set.
66 public Artifact
getArtifact()
72 * Sets the artifact whose (meta-)version shall be resolved.
74 * @param artifact The artifact, may be {@code null}.
75 * @return This request for chaining, never {@code null}.
77 public VersionRequest
setArtifact( Artifact artifact
)
79 this.artifact
= artifact
;
84 * Gets the repositories to resolve the version from.
86 * @return The repositories, never {@code null}.
88 public List
<RemoteRepository
> getRepositories()
94 * Sets the repositories to resolve the version from.
96 * @param repositories The repositories, may be {@code null}.
97 * @return This request for chaining, never {@code null}.
99 public VersionRequest
setRepositories( List
<RemoteRepository
> repositories
)
101 if ( repositories
== null )
103 this.repositories
= Collections
.emptyList();
107 this.repositories
= repositories
;
113 * Adds the specified repository for the resolution.
115 * @param repository The repository to add, may be {@code null}.
116 * @return This request for chaining, never {@code null}.
118 public VersionRequest
addRepository( RemoteRepository repository
)
120 if ( repository
!= null )
122 if ( this.repositories
.isEmpty() )
124 this.repositories
= new ArrayList
<RemoteRepository
>();
126 this.repositories
.add( repository
);
132 * Gets the context in which this request is made.
134 * @return The context, never {@code null}.
136 public String
getRequestContext()
142 * Sets the context in which this request is made.
144 * @param context The context, may be {@code null}.
145 * @return This request for chaining, never {@code null}.
147 public VersionRequest
setRequestContext( String context
)
149 this.context
= ( context
!= null ) ? context
: "";
154 * Gets the trace information that describes the higher level request/operation in which this request is issued.
156 * @return The trace information about the higher level operation or {@code null} if none.
158 public RequestTrace
getTrace()
164 * Sets the trace information that describes the higher level request/operation in which this request is issued.
166 * @param trace The trace information about the higher level operation, may be {@code null}.
167 * @return This request for chaining, never {@code null}.
169 public VersionRequest
setTrace( RequestTrace trace
)
176 public String
toString()
178 return getArtifact() + " < " + getRepositories();