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;
019:
020: import java.io.File;
021: import java.io.IOException;
022: import java.net.URL;
023: import java.text.ParseException;
024: import java.util.Collection;
025: import java.util.Collections;
026: import java.util.Date;
027: import java.util.List;
028: import java.util.Map;
029:
030: import org.apache.ivy.core.cache.DefaultResolutionCacheManager;
031: import org.apache.ivy.core.deliver.DeliverOptions;
032: import org.apache.ivy.core.deliver.PublishingDependencyRevisionResolver;
033: import org.apache.ivy.core.module.descriptor.Artifact;
034: import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
035: import org.apache.ivy.core.module.id.ModuleId;
036: import org.apache.ivy.core.module.id.ModuleRevisionId;
037: import org.apache.ivy.core.publish.PublishOptions;
038: import org.apache.ivy.core.report.ArtifactDownloadReport;
039: import org.apache.ivy.core.report.ResolveReport;
040: import org.apache.ivy.core.resolve.DownloadOptions;
041: import org.apache.ivy.core.resolve.IvyNode;
042: import org.apache.ivy.core.resolve.ResolveOptions;
043: import org.apache.ivy.core.resolve.ResolvedModuleRevision;
044: import org.apache.ivy.core.retrieve.RetrieveOptions;
045: import org.apache.ivy.core.search.ModuleEntry;
046: import org.apache.ivy.core.search.OrganisationEntry;
047: import org.apache.ivy.core.search.RevisionEntry;
048: import org.apache.ivy.core.sort.SilentNonMatchingVersionReporter;
049: import org.apache.ivy.plugins.matcher.PatternMatcher;
050: import org.apache.ivy.plugins.resolver.DependencyResolver;
051: import org.apache.ivy.util.Message;
052: import org.apache.ivy.util.filter.Filter;
053: import org.apache.ivy.util.filter.FilterHelper;
054:
055: /**
056: * This class can be used for easy migration from Ivy 1.4 API.
057: * <p>
058: * Indeed, Ivy 2.0 API has changed substantially, so it can take time to migrate existing code using
059: * Ivy 1.4 API to the new API. Using this class it's really easy: replace your instance of Ivy by an
060: * instance of this class.
061: * <p>
062: * For instance, where you were doing:
063: *
064: * <pre>
065: * Ivy ivy = new Ivy();
066: * </pre>
067: *
068: * do instead:
069: *
070: * <pre>
071: * Ivy14 ivy = new Ivy14();
072: * </pre>
073: *
074: * And that should be enough in most cases!
075: */
076: public class Ivy14 {
077: //CheckStyle:ParameterNumberCheck OFF
078: // don't check parameter numbers, since this class is here for backward compatibility
079:
080: private Ivy ivy;
081:
082: public Ivy14() {
083: this (Ivy.newInstance());
084: }
085:
086: public Ivy14(Ivy ivy) {
087: this .ivy = ivy;
088: }
089:
090: public boolean check(URL ivyFile, String resolvername) {
091: return ivy.check(ivyFile, resolvername);
092: }
093:
094: public void configure(File settingsFile) throws ParseException,
095: IOException {
096: ivy.configure(settingsFile);
097: }
098:
099: public void configure(URL settingsURL) throws ParseException,
100: IOException {
101: ivy.configure(settingsURL);
102: }
103:
104: public void configureDefault() throws ParseException, IOException {
105: ivy.configureDefault();
106: }
107:
108: public void deliver(ModuleRevisionId mrid, String revision,
109: File cache, String destIvyPattern, String status,
110: Date pubdate,
111: PublishingDependencyRevisionResolver pdrResolver,
112: boolean validate, boolean resolveDynamicRevisions)
113: throws IOException, ParseException {
114: ivy.deliver(mrid, revision, destIvyPattern, new DeliverOptions(
115: status, pubdate, pdrResolver, validate,
116: resolveDynamicRevisions, null));
117: }
118:
119: public void deliver(ModuleRevisionId mrid, String revision,
120: File cache, String destIvyPattern, String status,
121: Date pubdate,
122: PublishingDependencyRevisionResolver pdrResolver,
123: boolean validate) throws IOException, ParseException {
124: deliver(mrid, revision, cache, destIvyPattern, status, pubdate,
125: pdrResolver, validate, true);
126: }
127:
128: public Map determineArtifactsToCopy(ModuleId moduleId,
129: String[] confs, File cache, String destFilePattern,
130: String destIvyPattern, Filter artifactFilter)
131: throws ParseException, IOException {
132: return ivy.getRetrieveEngine()
133: .determineArtifactsToCopy(
134: new ModuleRevisionId(moduleId, Ivy
135: .getWorkingRevision()),
136: destFilePattern,
137: new RetrieveOptions().setConfs(confs)
138: .setDestIvyPattern(destIvyPattern)
139: .setArtifactFilter(artifactFilter));
140: }
141:
142: public Map determineArtifactsToCopy(ModuleId moduleId,
143: String[] confs, File cache, String destFilePattern,
144: String destIvyPattern) throws ParseException, IOException {
145: return ivy.getRetrieveEngine()
146: .determineArtifactsToCopy(
147: new ModuleRevisionId(moduleId, Ivy
148: .getWorkingRevision()),
149: destFilePattern,
150: new RetrieveOptions().setConfs(confs)
151: .setDestIvyPattern(destIvyPattern));
152: }
153:
154: public ArtifactDownloadReport download(Artifact artifact,
155: File cache, boolean useOrigin) {
156: Message
157: .deprecated("using cache and useOrigin when calling download is not supported anymore");
158: return ivy.getResolveEngine().download(artifact,
159: new DownloadOptions());
160: }
161:
162: public ResolvedModuleRevision findModule(ModuleRevisionId id) {
163: ResolveOptions options = new ResolveOptions();
164: options.setValidate(false);
165: return ivy.getResolveEngine().findModule(id, options);
166: }
167:
168: public IvyNode[] getDependencies(ModuleDescriptor md,
169: String[] confs, File cache, Date date,
170: ResolveReport report, boolean validate, boolean transitive) {
171: return ivy.getResolveEngine().getDependencies(
172: md,
173: newResolveOptions(confs, null, cache, date, validate,
174: false, transitive, false, true, true,
175: FilterHelper.NO_FILTER), report);
176: }
177:
178: public IvyNode[] getDependencies(ModuleDescriptor md,
179: String[] confs, File cache, Date date,
180: ResolveReport report, boolean validate) {
181: return ivy.getResolveEngine().getDependencies(
182: md,
183: newResolveOptions(confs, null, cache, date, validate,
184: false, true, false, true, true,
185: FilterHelper.NO_FILTER), report);
186: }
187:
188: public IvyNode[] getDependencies(URL ivySource, String[] confs,
189: File cache, Date date, boolean validate)
190: throws ParseException, IOException {
191: return ivy.getResolveEngine().getDependencies(
192: ivySource,
193: newResolveOptions(confs, null, cache, date, validate,
194: false, true, false, true, true,
195: FilterHelper.NO_FILTER));
196: }
197:
198: public String getVariable(String name) {
199: return ivy.getVariable(name);
200: }
201:
202: public ResolveReport install(ModuleRevisionId mrid, String from,
203: String to, boolean transitive, boolean validate,
204: boolean overwrite, Filter artifactFilter, File cache,
205: String matcherName) throws IOException {
206: return ivy.install(mrid, from, to, transitive, validate,
207: overwrite, artifactFilter, matcherName);
208: }
209:
210: public void interrupt() {
211: ivy.interrupt();
212: }
213:
214: public void interrupt(Thread operatingThread) {
215: ivy.interrupt(operatingThread);
216: }
217:
218: public boolean isInterrupted() {
219: return ivy.isInterrupted();
220: }
221:
222: public ModuleEntry[] listModuleEntries(OrganisationEntry org) {
223: return ivy.listModuleEntries(org);
224: }
225:
226: public ModuleId[] listModules(ModuleId criteria,
227: PatternMatcher matcher) {
228: return ivy.listModules(criteria, matcher);
229: }
230:
231: public ModuleRevisionId[] listModules(ModuleRevisionId criteria,
232: PatternMatcher matcher) {
233: return ivy.listModules(criteria, matcher);
234: }
235:
236: public String[] listModules(String org) {
237: return ivy.listModules(org);
238: }
239:
240: public OrganisationEntry[] listOrganisationEntries() {
241: return ivy.listOrganisationEntries();
242: }
243:
244: public String[] listOrganisations() {
245: return ivy.listOrganisations();
246: }
247:
248: public RevisionEntry[] listRevisionEntries(ModuleEntry module) {
249: return ivy.listRevisionEntries(module);
250: }
251:
252: public String[] listRevisions(String org, String module) {
253: return ivy.listRevisions(org, module);
254: }
255:
256: public String[] listTokenValues(String token, Map otherTokenValues) {
257: return ivy.listTokenValues(token, otherTokenValues);
258: }
259:
260: public Collection publish(ModuleDescriptor md,
261: DependencyResolver resolver, Collection srcArtifactPattern,
262: String srcIvyPattern, Artifact[] extraArtifacts,
263: boolean overwrite, String conf) throws IOException {
264: return ivy.getPublishEngine().publish(
265: md,
266: srcArtifactPattern,
267: resolver,
268: new PublishOptions().setSrcIvyPattern(srcIvyPattern)
269: .setExtraArtifacts(extraArtifacts)
270: .setOverwrite(overwrite).setConfs(
271: splitConfs(conf)));
272: }
273:
274: public Collection publish(ModuleRevisionId mrid,
275: String pubrevision, File cache,
276: Collection srcArtifactPattern, String resolverName,
277: String srcIvyPattern, String status, Date pubdate,
278: Artifact[] extraArtifacts, boolean validate,
279: boolean overwrite, boolean update, String conf)
280: throws IOException {
281: return ivy.publish(mrid, srcArtifactPattern, resolverName,
282: new PublishOptions().setStatus(status).setPubdate(
283: pubdate).setPubrevision(pubrevision)
284: .setSrcIvyPattern(srcIvyPattern)
285: .setExtraArtifacts(extraArtifacts).setUpdate(
286: update).setValidate(validate)
287: .setOverwrite(overwrite).setConfs(
288: splitConfs(conf)));
289: }
290:
291: public Collection publish(ModuleRevisionId mrid,
292: String pubrevision, File cache, String srcArtifactPattern,
293: String resolverName, String srcIvyPattern,
294: boolean validate, boolean overwrite) throws IOException {
295: return ivy.publish(mrid, Collections
296: .singleton(srcArtifactPattern), resolverName,
297: new PublishOptions().setPubrevision(pubrevision)
298: .setSrcIvyPattern(srcIvyPattern).setValidate(
299: validate).setOverwrite(overwrite));
300: }
301:
302: public Collection publish(ModuleRevisionId mrid,
303: String pubrevision, File cache, String srcArtifactPattern,
304: String resolverName, String srcIvyPattern, boolean validate)
305: throws IOException {
306: return ivy.publish(mrid, Collections
307: .singleton(srcArtifactPattern), resolverName,
308: new PublishOptions().setPubrevision(pubrevision)
309: .setSrcIvyPattern(srcIvyPattern).setValidate(
310: validate));
311: }
312:
313: public Collection publish(ModuleRevisionId mrid,
314: String pubrevision, File cache, String srcArtifactPattern,
315: String resolverName, String srcIvyPattern, String status,
316: Date pubdate, Artifact[] extraArtifacts, boolean validate,
317: boolean overwrite, boolean update, String conf)
318: throws IOException {
319: return ivy.publish(mrid, Collections
320: .singleton(srcArtifactPattern), resolverName,
321: new PublishOptions().setStatus(status).setPubdate(
322: pubdate).setPubrevision(pubrevision)
323: .setSrcIvyPattern(srcIvyPattern)
324: .setExtraArtifacts(extraArtifacts).setUpdate(
325: update).setValidate(validate)
326: .setOverwrite(overwrite).setConfs(
327: splitConfs(conf)));
328: }
329:
330: public ResolveReport resolve(File ivySource) throws ParseException,
331: IOException {
332: return ivy.resolve(ivySource);
333: }
334:
335: public ResolveReport resolve(ModuleDescriptor md, String[] confs,
336: File cache, Date date, boolean validate,
337: boolean useCacheOnly, boolean transitive,
338: boolean useOrigin, boolean download, boolean outputReport,
339: Filter artifactFilter) throws ParseException, IOException {
340: return ivy.resolve(md, newResolveOptions(confs, null, cache,
341: date, validate, useCacheOnly, transitive, useOrigin,
342: download, outputReport, artifactFilter));
343: }
344:
345: private ResolveOptions newResolveOptions(String[] confs,
346: String revision, File cache, Date date, boolean validate,
347: boolean useCacheOnly, boolean transitive,
348: boolean useOrigin, boolean download, boolean outputReport,
349: Filter artifactFilter) {
350: if (useOrigin) {
351: ivy.getSettings().useDeprecatedUseOrigin();
352: }
353: return new ResolveOptions().setConfs(confs).setRevision(
354: revision).setValidate(validate).setUseCacheOnly(
355: useCacheOnly).setTransitive(transitive).setDownload(
356: download).setOutputReport(outputReport)
357: .setArtifactFilter(artifactFilter);
358: }
359:
360: public ResolveReport resolve(ModuleDescriptor md, String[] confs,
361: File cache, Date date, boolean validate,
362: boolean useCacheOnly, boolean transitive, boolean download,
363: boolean outputReport, Filter artifactFilter)
364: throws ParseException, IOException {
365: return ivy.resolve(md, newResolveOptions(confs, null, cache,
366: date, validate, useCacheOnly, transitive, false,
367: download, outputReport, artifactFilter));
368: }
369:
370: public ResolveReport resolve(ModuleDescriptor md, String[] confs,
371: File cache, Date date, boolean validate,
372: boolean useCacheOnly, boolean transitive,
373: Filter artifactFilter) throws ParseException, IOException {
374: return ivy.resolve(md, newResolveOptions(confs, null, cache,
375: date, validate, useCacheOnly, transitive, false, true,
376: true, artifactFilter));
377: }
378:
379: public ResolveReport resolve(ModuleDescriptor md, String[] confs,
380: File cache, Date date, boolean validate,
381: boolean useCacheOnly, Filter artifactFilter)
382: throws ParseException, IOException {
383: return ivy.resolve(md, newResolveOptions(confs, null, cache,
384: date, validate, useCacheOnly, true, false, true, true,
385: artifactFilter));
386: }
387:
388: public ResolveReport resolve(ModuleRevisionId mrid, String[] confs,
389: boolean transitive, boolean changing, File cache,
390: Date date, boolean validate, boolean useCacheOnly,
391: boolean useOrigin, Filter artifactFilter)
392: throws ParseException, IOException {
393: return ivy.resolve(mrid, newResolveOptions(confs, null, cache,
394: date, validate, useCacheOnly, transitive, useOrigin,
395: true, true, artifactFilter), changing);
396: }
397:
398: public ResolveReport resolve(ModuleRevisionId mrid, String[] confs,
399: boolean transitive, boolean changing, File cache,
400: Date date, boolean validate, boolean useCacheOnly,
401: Filter artifactFilter) throws ParseException, IOException {
402: return ivy.resolve(mrid, newResolveOptions(confs, null, cache,
403: date, validate, useCacheOnly, transitive, false, true,
404: true, artifactFilter), changing);
405: }
406:
407: public ResolveReport resolve(ModuleRevisionId mrid, String[] confs)
408: throws ParseException, IOException {
409: return ivy
410: .resolve(mrid, newResolveOptions(confs, null, ivy
411: .getSettings().getDefaultCache(), null, true,
412: false, true, false, true, true,
413: FilterHelper.NO_FILTER), false);
414: }
415:
416: public ResolveReport resolve(URL ivySource, String revision,
417: String[] confs, File cache, Date date, boolean validate,
418: boolean useCacheOnly, boolean transitive,
419: boolean useOrigin, Filter artifactFilter)
420: throws ParseException, IOException {
421: return ivy.resolve(ivySource, newResolveOptions(confs,
422: revision, cache, date, validate, useCacheOnly,
423: transitive, useOrigin, true, true, artifactFilter));
424: }
425:
426: public ResolveReport resolve(URL ivySource, String revision,
427: String[] confs, File cache, Date date, boolean validate,
428: boolean useCacheOnly, boolean transitive,
429: Filter artifactFilter) throws ParseException, IOException {
430: return ivy.resolve(ivySource, newResolveOptions(confs,
431: revision, cache, date, validate, useCacheOnly,
432: transitive, false, true, true, artifactFilter));
433: }
434:
435: public ResolveReport resolve(URL ivySource, String revision,
436: String[] confs, File cache, Date date, boolean validate,
437: boolean useCacheOnly, Filter artifactFilter)
438: throws ParseException, IOException {
439: return ivy.resolve(ivySource, newResolveOptions(confs,
440: revision, cache, date, validate, useCacheOnly, true,
441: false, true, true, artifactFilter));
442: }
443:
444: public ResolveReport resolve(URL ivySource, String revision,
445: String[] confs, File cache, Date date, boolean validate,
446: boolean useCacheOnly) throws ParseException, IOException {
447: return ivy.resolve(ivySource, newResolveOptions(confs,
448: revision, cache, date, validate, useCacheOnly, true,
449: false, true, true, FilterHelper.NO_FILTER));
450: }
451:
452: public ResolveReport resolve(URL ivySource, String revision,
453: String[] confs, File cache, Date date, boolean validate)
454: throws ParseException, IOException {
455: return ivy.resolve(ivySource, newResolveOptions(confs,
456: revision, cache, date, validate, false, true, false,
457: true, true, FilterHelper.NO_FILTER));
458: }
459:
460: public ResolveReport resolve(URL ivySource) throws ParseException,
461: IOException {
462: return ivy.resolve(ivySource);
463: }
464:
465: public int retrieve(ModuleId moduleId, String[] confs, File cache,
466: String destFilePattern, String destIvyPattern,
467: Filter artifactFilter, boolean sync, boolean useOrigin,
468: boolean makeSymlinks) {
469: try {
470: return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy
471: .getWorkingRevision()), destFilePattern,
472: new RetrieveOptions().setConfs(confs)
473: .setDestIvyPattern(destIvyPattern)
474: .setArtifactFilter(artifactFilter).setSync(
475: sync).setUseOrigin(useOrigin)
476: .setMakeSymlinks(makeSymlinks));
477: } catch (IOException e) {
478: throw new RuntimeException(e);
479: }
480: }
481:
482: public int retrieve(ModuleId moduleId, String[] confs, File cache,
483: String destFilePattern, String destIvyPattern,
484: Filter artifactFilter, boolean sync, boolean useOrigin) {
485: try {
486: return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy
487: .getWorkingRevision()), destFilePattern,
488: new RetrieveOptions().setConfs(confs)
489: .setDestIvyPattern(destIvyPattern)
490: .setArtifactFilter(artifactFilter).setSync(
491: sync).setUseOrigin(useOrigin));
492: } catch (IOException e) {
493: throw new RuntimeException(e);
494: }
495: }
496:
497: public int retrieve(ModuleId moduleId, String[] confs, File cache,
498: String destFilePattern, String destIvyPattern,
499: Filter artifactFilter) {
500: try {
501: return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy
502: .getWorkingRevision()), destFilePattern,
503: new RetrieveOptions().setConfs(confs)
504: .setDestIvyPattern(destIvyPattern)
505: .setArtifactFilter(artifactFilter));
506: } catch (IOException e) {
507: throw new RuntimeException(e);
508: }
509: }
510:
511: public int retrieve(ModuleId moduleId, String[] confs, File cache,
512: String destFilePattern, String destIvyPattern) {
513: try {
514: return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy
515: .getWorkingRevision()), destFilePattern,
516: new RetrieveOptions().setConfs(confs)
517: .setDestIvyPattern(destIvyPattern));
518: } catch (IOException e) {
519: throw new RuntimeException(e);
520: }
521: }
522:
523: public int retrieve(ModuleId moduleId, String[] confs, File cache,
524: String destFilePattern) {
525: try {
526: return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy
527: .getWorkingRevision()), destFilePattern,
528: new RetrieveOptions().setConfs(confs));
529: } catch (IOException e) {
530: throw new RuntimeException(e);
531: }
532: }
533:
534: public void setVariable(String varName, String value) {
535: ivy.setVariable(varName, value);
536: }
537:
538: public List sortModuleDescriptors(Collection moduleDescriptors) {
539: return ivy.sortModuleDescriptors(moduleDescriptors,
540: new SilentNonMatchingVersionReporter());
541: }
542:
543: public List sortNodes(Collection nodes) {
544: return ivy.sortNodes(nodes);
545: }
546:
547: public String substitute(String str) {
548: return ivy.substitute(str);
549: }
550:
551: private String[] splitConfs(String conf) {
552: if (conf == null || "".equals(conf)) {
553: return null;
554: }
555: String[] confs = conf.split(",");
556: for (int i = 0; i < confs.length; i++) {
557: confs[i] = confs[i].trim();
558: }
559: return confs;
560: }
561:
562: //CheckStyle:ParameterNumberCheck ON
563: }
|