]> git.argeo.org Git - gpl/argeo-slc.git/blob - MetadataRequest.java
2f6c5f1d0fad815ebc76207d64d958facb34e3f9
[gpl/argeo-slc.git] / MetadataRequest.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 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;
18
19 /**
20 * A request to resolve metadata from either a remote repository or the local repository.
21 *
22 * @see RepositorySystem#resolveMetadata(RepositorySystemSession, java.util.Collection)
23 * @see Metadata#getFile()
24 */
25 public final class MetadataRequest
26 {
27
28 private Metadata metadata;
29
30 private RemoteRepository repository;
31
32 private String context = "";
33
34 private boolean deleteLocalCopyIfMissing;
35
36 private boolean favorLocalRepository;
37
38 private RequestTrace trace;
39
40 /**
41 * Creates an uninitialized request.
42 */
43 public MetadataRequest()
44 {
45 // enables default constructor
46 }
47
48 /**
49 * Creates a request to resolve the specified metadata from the local repository.
50 *
51 * @param metadata The metadata to resolve, may be {@code null}.
52 */
53 public MetadataRequest( Metadata metadata )
54 {
55 setMetadata( metadata );
56 }
57
58 /**
59 * Creates a request with the specified properties.
60 *
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
63 * repository.
64 * @param context The context in which this request is made, may be {@code null}.
65 */
66 public MetadataRequest( Metadata metadata, RemoteRepository repository, String context )
67 {
68 setMetadata( metadata );
69 setRepository( repository );
70 setRequestContext( context );
71 }
72
73 /**
74 * Gets the metadata to resolve.
75 *
76 * @return The metadata or {@code null} if not set.
77 */
78 public Metadata getMetadata()
79 {
80 return metadata;
81 }
82
83 /**
84 * Sets the metadata to resolve.
85 *
86 * @param metadata The metadata, may be {@code null}.
87 * @return This request for chaining, never {@code null}.
88 */
89 public MetadataRequest setMetadata( Metadata metadata )
90 {
91 this.metadata = metadata;
92 return this;
93 }
94
95 /**
96 * Gets the repository from which the metadata should be resolved.
97 *
98 * @return The repository or {@code null} to resolve from the local repository.
99 */
100 public RemoteRepository getRepository()
101 {
102 return repository;
103 }
104
105 /**
106 * Sets the repository from which the metadata should be resolved.
107 *
108 * @param repository The repository, may be {@code null} to resolve from the local repository.
109 * @return This request for chaining, never {@code null}.
110 */
111 public MetadataRequest setRepository( RemoteRepository repository )
112 {
113 this.repository = repository;
114 return this;
115 }
116
117 /**
118 * Gets the context in which this request is made.
119 *
120 * @return The context, never {@code null}.
121 */
122 public String getRequestContext()
123 {
124 return context;
125 }
126
127 /**
128 * Sets the context in which this request is made.
129 *
130 * @param context The context, may be {@code null}.
131 * @return This request for chaining, never {@code null}.
132 */
133 public MetadataRequest setRequestContext( String context )
134 {
135 this.context = ( context != null ) ? context : "";
136 return this;
137 }
138
139 /**
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.
142 *
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.
145 */
146 public boolean isDeleteLocalCopyIfMissing()
147 {
148 return deleteLocalCopyIfMissing;
149 }
150
151 /**
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.
154 *
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}.
158 */
159 public MetadataRequest setDeleteLocalCopyIfMissing( boolean deleteLocalCopyIfMissing )
160 {
161 this.deleteLocalCopyIfMissing = deleteLocalCopyIfMissing;
162 return this;
163 }
164
165 /**
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.
169 *
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
172 * policy.
173 */
174 public boolean isFavorLocalRepository()
175 {
176 return favorLocalRepository;
177 }
178
179 /**
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.
183 *
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}.
188 */
189 public MetadataRequest setFavorLocalRepository( boolean favorLocalRepository )
190 {
191 this.favorLocalRepository = favorLocalRepository;
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 MetadataRequest setTrace( RequestTrace trace )
212 {
213 this.trace = trace;
214 return this;
215 }
216
217 @Override
218 public String toString()
219 {
220 return getMetadata() + " < " + getRepository();
221 }
222
223 }