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
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.aether
.resolution
;
13 import org
.eclipse
.aether
.RepositorySystem
;
14 import org
.eclipse
.aether
.RepositorySystemSession
;
15 import org
.eclipse
.aether
.RequestTrace
;
16 import org
.eclipse
.aether
.metadata
.Metadata
;
17 import org
.eclipse
.aether
.repository
.RemoteRepository
;
20 * A request to resolve metadata from either a remote repository or the local repository.
22 * @see RepositorySystem#resolveMetadata(RepositorySystemSession, java.util.Collection)
23 * @see Metadata#getFile()
25 public final class MetadataRequest
28 private Metadata metadata
;
30 private RemoteRepository repository
;
32 private String context
= "";
34 private boolean deleteLocalCopyIfMissing
;
36 private boolean favorLocalRepository
;
38 private RequestTrace trace
;
41 * Creates an uninitialized request.
43 public MetadataRequest()
45 // enables default constructor
49 * Creates a request to resolve the specified metadata from the local repository.
51 * @param metadata The metadata to resolve, may be {@code null}.
53 public MetadataRequest( Metadata metadata
)
55 setMetadata( metadata
);
59 * Creates a request with the specified properties.
61 * @param metadata The metadata to resolve, may be {@code null}.
62 * @param repository The repository to resolve the metadata from, may be {@code null} to resolve from the local
64 * @param context The context in which this request is made, may be {@code null}.
66 public MetadataRequest( Metadata metadata
, RemoteRepository repository
, String context
)
68 setMetadata( metadata
);
69 setRepository( repository
);
70 setRequestContext( context
);
74 * Gets the metadata to resolve.
76 * @return The metadata or {@code null} if not set.
78 public Metadata
getMetadata()
84 * Sets the metadata to resolve.
86 * @param metadata The metadata, may be {@code null}.
87 * @return This request for chaining, never {@code null}.
89 public MetadataRequest
setMetadata( Metadata metadata
)
91 this.metadata
= metadata
;
96 * Gets the repository from which the metadata should be resolved.
98 * @return The repository or {@code null} to resolve from the local repository.
100 public RemoteRepository
getRepository()
106 * Sets the repository from which the metadata should be resolved.
108 * @param repository The repository, may be {@code null} to resolve from the local repository.
109 * @return This request for chaining, never {@code null}.
111 public MetadataRequest
setRepository( RemoteRepository repository
)
113 this.repository
= repository
;
118 * Gets the context in which this request is made.
120 * @return The context, never {@code null}.
122 public String
getRequestContext()
128 * Sets the context in which this request is made.
130 * @param context The context, may be {@code null}.
131 * @return This request for chaining, never {@code null}.
133 public MetadataRequest
setRequestContext( String context
)
135 this.context
= ( context
!= null ) ? context
: "";
140 * Indicates whether the locally cached copy of the metadata should be removed if the corresponding file does not
141 * exist (any more) in the remote repository.
143 * @return {@code true} if locally cached metadata should be deleted if no corresponding remote file exists,
144 * {@code false} to keep the local copy.
146 public boolean isDeleteLocalCopyIfMissing()
148 return deleteLocalCopyIfMissing
;
152 * Controls whether the locally cached copy of the metadata should be removed if the corresponding file does not
153 * exist (any more) in the remote repository.
155 * @param deleteLocalCopyIfMissing {@code true} if locally cached metadata should be deleted if no corresponding
156 * remote file exists, {@code false} to keep the local copy.
157 * @return This request for chaining, never {@code null}.
159 public MetadataRequest
setDeleteLocalCopyIfMissing( boolean deleteLocalCopyIfMissing
)
161 this.deleteLocalCopyIfMissing
= deleteLocalCopyIfMissing
;
166 * Indicates whether the metadata resolution should be suppressed if the corresponding metadata of the local
167 * repository is up-to-date according to the update policy of the remote repository. In this case, the metadata
168 * resolution will even be suppressed if no local copy of the remote metadata exists yet.
170 * @return {@code true} to suppress resolution of remote metadata if the corresponding metadata of the local
171 * repository is up-to-date, {@code false} to resolve the remote metadata normally according to the update
174 public boolean isFavorLocalRepository()
176 return favorLocalRepository
;
180 * Controls resolution of remote metadata when already corresponding metadata of the local repository exists. In
181 * cases where the local repository's metadata is sufficient and going to be preferred, resolution of the remote
182 * metadata can be suppressed to avoid unnecessary network access.
184 * @param favorLocalRepository {@code true} to suppress resolution of remote metadata if the corresponding metadata
185 * of the local repository is up-to-date, {@code false} to resolve the remote metadata normally according
186 * to the update policy.
187 * @return This request for chaining, never {@code null}.
189 public MetadataRequest
setFavorLocalRepository( boolean favorLocalRepository
)
191 this.favorLocalRepository
= favorLocalRepository
;
196 * Gets the trace information that describes the higher level request/operation in which this request is issued.
198 * @return The trace information about the higher level operation or {@code null} if none.
200 public RequestTrace
getTrace()
206 * Sets the trace information that describes the higher level request/operation in which this request is issued.
208 * @param trace The trace information about the higher level operation, may be {@code null}.
209 * @return This request for chaining, never {@code null}.
211 public MetadataRequest
setTrace( RequestTrace trace
)
218 public String
toString()
220 return getMetadata() + " < " + getRepository();