in src/java/org/apache/ivy/Main.java [288:460]
private static ResolveReport run(CommandLine line, boolean isCli) throws Exception {
if (line.hasOption("version")) {
System.out.println("Apache Ivy " + Ivy.getIvyVersion() + " - " + Ivy.getIvyDate()
+ " :: " + Ivy.getIvyHomeURL());
return null;
}
boolean validate = !line.hasOption("novalidate");
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 (String conf : confs) {
dd.addDependencyConfiguration("default", conf);
}
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()) {
if (isCli) {
System.exit(1);
}
StringBuilder sb = new StringBuilder();
for (String problem : report.getAllProblemMessages()) {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append(problem);
}
throw new ResolveProcessException(sb.toString());
}
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.contains("[")) {
retrievePattern += "/lib/[conf]/[artifact].[ext]";
}
String ivyPattern = settings.substitute(line.getOptionValue("ivypattern"));
ivy.retrieve(
md.getModuleRevisionId(),
new RetrieveOptions()
.setConfs(confs)
.setSync(line.hasOption("sync"))
.setUseOrigin(line.hasOption("useOrigin"))
.setDestArtifactPattern(retrievePattern)
.setDestIvyPattern(ivyPattern)
.setOverwriteMode(line.getOptionValue("overwriteMode"))
.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("makepom")) {
final String pomFilePath = line.getOptionValue("makepom", "pom.xml");
final File pomFile = new File(pomFilePath);
PomModuleDescriptorWriter.write(md, pomFile, new PomWriterOptions());
Message.debug("Generated a pom file for module at " + pomFile);
}
if (line.hasOption("main")) {
// check if the option cp has been set
List<File> 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();
return report;
}