}
}
static void run(CommandLineParser parser, String[] args) throws Exception {
// parse the command line arguments
CommandLine line = parser.parse(args);
if (line.hasOption("?")) {
usage(parser, line.hasOption("deprecated"));
return;
}
if (line.hasOption("version")) {
System.out.println("Apache Ivy " + Ivy.getIvyVersion() + " - " + Ivy.getIvyDate()
+ " :: " + Ivy.getIvyHomeURL());
return;
}
boolean validate = line.hasOption("novalidate") ? false : true;
Ivy ivy = Ivy.newInstance();
initMessage(line, ivy);
IvySettings settings = initSettings(line, ivy);
ivy.pushContext();
File cache = new File(settings.substitute(line.getOptionValue("cache", settings
.getDefaultCache().getAbsolutePath())));
if (line.hasOption("cache")) {
// override default cache path with user supplied cache path
settings.setDefaultCache(cache);
}
if (!cache.exists()) {
cache.mkdirs();
} else if (!cache.isDirectory()) {
error(cache + " is not a directory");
}
String[] confs;
if (line.hasOption("confs")) {
confs = line.getOptionValues("confs");
} else {
confs = new String[] {"*"};
}
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)
.setResolveMode(line.getOptionValue("mode"))
.setArtifactFilter(
FilterHelper.getArtifactTypeFilter(line.getOptionValues("types")));
if (line.hasOption("notransitive")) {
resolveOptions.setTransitive(false);
}
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]";
}
String ivyPattern = settings.substitute(line.getOptionValue("ivypattern"));
ivy.retrieve(
md.getModuleRevisionId(),
retrievePattern,
new RetrieveOptions()
.setConfs(confs)
.setSync(line.hasOption("sync"))
.setUseOrigin(line.hasOption("useOrigin"))
.setDestIvyPattern(ivyPattern)
.setArtifactFilter(
FilterHelper.getArtifactTypeFilter(line.getOptionValues("types")))
.setMakeSymlinks(line.hasOption("symlink"))
.setMakeSymlinksInMass(line.hasOption("symlinkmass")));
}
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(
settings.substitute(line.getOptionValue("deliverto",
"ivy-[revision].xml")))
.setOverwrite(line.hasOption("overwrite")));
}
}
if (line.hasOption("main")) {
// check if the option cp has been set
List fileList = getExtraClasspathFileList(line);
// merge -args and left over args
String[] fargs = line.getOptionValues("args");
if (fargs == null) {
fargs = new String[0];
}
String[] extra = line.getLeftOverArgs();
if (extra == null) {
extra = new String[0];
}
String[] params = new String[fargs.length + extra.length];
System.arraycopy(fargs, 0, params, 0, fargs.length);
System.arraycopy(extra, 0, params, fargs.length, extra.length);
// invoke with given main class and merged params
invoke(ivy, cache, md, confs, fileList, line.getOptionValue("main"), params);
}
ivy.getLoggerEngine().popLogger();
ivy.popContext();
}