File ivyfile;
if (line.hasOption("dependency")) {
String[] dep = line.getOptionValues("dependency");
ivyfile = File.createTempFile("ivy", ".xml");
ivyfile.deleteOnExit();
DefaultModuleDescriptor md = DefaultModuleDescriptor
.newDefaultInstance(ModuleRevisionId.newInstance(dep[0],
dep[1] + "-caller", "working"));
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md,
ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true);
for (int i = 0; i < confs.length; i++) {
dd.addDependencyConfiguration("default", confs[i]);
}
md.addDependency(dd);
XmlModuleDescriptorWriter.write(md, ivyfile);
confs = new String[] {"default"};
} else {
ivyfile = new File(settings.substitute(line.getOptionValue("ivy", "ivy.xml")));
if (!ivyfile.exists()) {
error("ivy file not found: " + ivyfile);
} else if (ivyfile.isDirectory()) {
error("ivy file is not a file: " + ivyfile);
}
}
if (line.hasOption("useOrigin")) {
ivy.getSettings().useDeprecatedUseOrigin();
}
ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs)
.setValidate(validate);
if (line.hasOption("refresh")) {
resolveOptions.setRefresh(true);
}
ResolveReport report = ivy.resolve(ivyfile.toURI().toURL(), resolveOptions);
if (report.hasError()) {
System.exit(1);
}
ModuleDescriptor md = report.getModuleDescriptor();
if (confs.length == 1 && "*".equals(confs[0])) {
confs = md.getConfigurationsNames();
}
if (line.hasOption("retrieve")) {
String retrievePattern = settings.substitute(line.getOptionValue("retrieve"));
if (retrievePattern.indexOf("[") == -1) {
retrievePattern = retrievePattern + "/lib/[conf]/[artifact].[ext]";
}
ivy.retrieve(md.getModuleRevisionId(), retrievePattern, new RetrieveOptions()
.setConfs(confs).setSync(line.hasOption("sync"))
.setUseOrigin(line.hasOption("useOrigin")));
}
if (line.hasOption("cachepath")) {
outputCachePath(ivy, cache, md, confs, line.getOptionValue("cachepath",
"ivycachepath.txt"));
}
if (line.hasOption("revision")) {
ivy.deliver(md.getResolvedModuleRevisionId(), settings.substitute(line
.getOptionValue("revision")), settings.substitute(line.getOptionValue(
"deliverto", "ivy-[revision].xml")), DeliverOptions.newInstance(settings)
.setStatus(settings.substitute(line.getOptionValue("status", "release")))
.setValidate(validate));
if (line.hasOption("publish")) {
ivy.publish(md.getResolvedModuleRevisionId(), Collections.singleton(settings
.substitute(line.getOptionValue("publishpattern",
"distrib/[type]s/[artifact]-[revision].[ext]"))), line
.getOptionValue("publish"), new PublishOptions()
.setPubrevision(settings.substitute(line.getOptionValue("revision")))
.setValidate(validate).setSrcIvyPattern(