001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.core.resolve;
019:
020: import java.util.Date;
021:
022: import org.apache.ivy.core.LogOptions;
023: import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
024: import org.apache.ivy.core.module.id.ModuleId;
025: import org.apache.ivy.util.ConfigurationUtils;
026: import org.apache.ivy.util.filter.Filter;
027: import org.apache.ivy.util.filter.FilterHelper;
028:
029: /**
030: * A set of options used during resolve related tasks
031: *
032: * @see ResolveEngine
033: */
034: public class ResolveOptions extends LogOptions {
035:
036: /**
037: * an array of configuration names to resolve - must not be null nor empty
038: */
039: private String[] confs = new String[] { "*" };
040:
041: /**
042: * the revision of the module for which dependencies should be resolved. This revision is
043: * considered as the resolved revision of the module, unless it is null. If it is null, then a
044: * default revision is given if necessary (no revision found in ivy file)
045: */
046: private String revision = null;
047:
048: /**
049: * the date for which the dependencies should be resolved. All obtained artifacts should have a
050: * publication date which is before or equal to the given date. The date can be null, in which
051: * case all artifacts will be considered
052: */
053: private Date date = null;
054:
055: /**
056: * True if validation of module descriptors should done, false otherwise
057: */
058: private boolean validate = true;
059:
060: /**
061: * True if only the cache should be used for resolve, false if a real resolve with dependency
062: * resolvers should be done
063: */
064: private boolean useCacheOnly = false;
065:
066: /**
067: * True if the dependencies should be resolved transitively, false if only direct dependencies
068: * should be resolved
069: */
070: private boolean transitive = true;
071:
072: /**
073: * True if the resolve should also download artifacts, false if only dependency resolution with
074: * module descriptors should be done
075: */
076: private boolean download = true;
077:
078: /**
079: * True if a report of the resolve process should be output at the end of the process, false
080: * otherwise
081: */
082: private boolean outputReport = true;
083:
084: /**
085: * A filter to use to avoid downloading all artifacts.
086: */
087: private Filter artifactFilter = FilterHelper.NO_FILTER;
088:
089: /**
090: * The id used to store the resolve information.
091: */
092: private String resolveId;
093:
094: private boolean refresh;
095:
096: public ResolveOptions() {
097: }
098:
099: public ResolveOptions(ResolveOptions options) {
100: super (options);
101: confs = options.confs;
102: revision = options.revision;
103: date = options.date;
104: validate = options.validate;
105: refresh = options.refresh;
106: useCacheOnly = options.useCacheOnly;
107: transitive = options.transitive;
108: download = options.download;
109: outputReport = options.outputReport;
110: artifactFilter = options.artifactFilter;
111: resolveId = options.resolveId;
112: }
113:
114: public Filter getArtifactFilter() {
115: return artifactFilter;
116: }
117:
118: public ResolveOptions setArtifactFilter(Filter artifactFilter) {
119: this .artifactFilter = artifactFilter;
120: return this ;
121: }
122:
123: /**
124: * Indicates if the configurations use a special configuration
125: * * , *(private) or *(public).
126: * When special configurations are used, you must have the module
127: * descriptor in order to get the list of configurations.
128: * @see #getConfs()
129: * @see #getConfs(ModuleDescriptor)
130: */
131: public boolean useSpecialConfs() {
132: for (int i = 0; confs != null && i < confs.length; i++) {
133: if (confs[0].startsWith("*")) {
134: return true;
135: }
136: }
137: return false;
138: }
139:
140: /**
141: * @pre can only be called if useSpecialConfs()==false. When it is true,
142: * you have to provide a module desciptor so that configurations can be resolved.
143: * @see #getConfs(ModuleDescriptor)
144: */
145: public String[] getConfs() {
146: if (useSpecialConfs()) {
147: throw new AssertionError("ResolveOptions.getConfs() "
148: + "can not be used for options used special confs.");
149: }
150: return confs;
151: }
152:
153: /**
154: * Get the aksed confs. Special confs (like *) use the moduleDescriptor to find the values *
155: * @param md Used to get the exact values for special confs.
156: * */
157: public String[] getConfs(ModuleDescriptor md) {
158: //TODO add isInline, in that case, replace * by *(public).
159: return ConfigurationUtils.replaceWildcards(confs, md);
160: }
161:
162: public ResolveOptions setConfs(String[] confs) {
163: this .confs = confs;
164: return this ;
165: }
166:
167: public Date getDate() {
168: return date;
169: }
170:
171: public ResolveOptions setDate(Date date) {
172: this .date = date;
173: return this ;
174: }
175:
176: public boolean isDownload() {
177: return download;
178: }
179:
180: public ResolveOptions setDownload(boolean download) {
181: this .download = download;
182: return this ;
183: }
184:
185: public boolean isOutputReport() {
186: return outputReport;
187: }
188:
189: public ResolveOptions setOutputReport(boolean outputReport) {
190: this .outputReport = outputReport;
191: return this ;
192: }
193:
194: public boolean isTransitive() {
195: return transitive;
196: }
197:
198: public ResolveOptions setTransitive(boolean transitive) {
199: this .transitive = transitive;
200: return this ;
201: }
202:
203: public boolean isUseCacheOnly() {
204: return useCacheOnly;
205: }
206:
207: public ResolveOptions setUseCacheOnly(boolean useCacheOnly) {
208: this .useCacheOnly = useCacheOnly;
209: return this ;
210: }
211:
212: public boolean isValidate() {
213: return validate;
214: }
215:
216: public ResolveOptions setValidate(boolean validate) {
217: this .validate = validate;
218: return this ;
219: }
220:
221: public String getRevision() {
222: return revision;
223: }
224:
225: public ResolveOptions setRevision(String revision) {
226: this .revision = revision;
227: return this ;
228: }
229:
230: public String getResolveId() {
231: return resolveId;
232: }
233:
234: public ResolveOptions setResolveId(String resolveId) {
235: this .resolveId = resolveId;
236: return this ;
237: }
238:
239: public ResolveOptions setRefresh(boolean refresh) {
240: this .refresh = refresh;
241: return this ;
242: }
243:
244: public boolean isRefresh() {
245: return refresh;
246: }
247:
248: public static String getDefaultResolveId(ModuleDescriptor md) {
249: ModuleId module = md.getModuleRevisionId().getModuleId();
250: return getDefaultResolveId(module);
251: }
252:
253: public static String getDefaultResolveId(ModuleId moduleId) {
254: return moduleId.getOrganisation() + "-" + moduleId.getName();
255: }
256:
257: }
|