use of org.apache.ivy.core.resolve.ResolveProcessException in project ant-ivy by apache.
the class Main method run.
@SuppressWarnings("deprecation")
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;
}
use of org.apache.ivy.core.resolve.ResolveProcessException in project ant-ivy by apache.
the class LogTrigger method log.
/**
* Logs the given message.
*
* @param message
* the message to log
*/
protected void log(String message) {
if (file == null) {
Message.info(message);
} else {
Writer out = null;
try {
// we add a line separator here for consistency with Message.info which creates a
// new line each time.
// we use the system dependent line separator to ease reading the log file
message += LINE_SEPARATOR;
String filename = file.getAbsolutePath();
if (isNullOrEmpty(encoding)) {
out = new FileWriter(filename, append);
} else {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename, append), encoding));
}
out.write(message, 0, message.length());
} catch (IOException e) {
throw new ResolveProcessException(e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
throw new ResolveProcessException(e);
}
}
}
}
}
use of org.apache.ivy.core.resolve.ResolveProcessException in project ant-ivy by apache.
the class IvyResolve method doExecute.
@Override
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
try {
conf = getProperty(conf, settings, "ivy.configurations");
type = getProperty(type, settings, "ivy.resolve.default.type.filter");
String[] confs = splitToArray(conf);
boolean childs = !dependencies.isEmpty() || !excludes.isEmpty() || !conflicts.isEmpty();
ResolveReport report;
if (childs) {
if (isInline()) {
throw new BuildException("the inline mode is incompatible with child elements");
}
if (organisation != null) {
throw new BuildException("'organisation' is not allowed with child elements");
}
if (module != null) {
throw new BuildException("'module' is not allowed with child elements");
}
if (file != null) {
throw new BuildException("'file' not allowed with child elements");
}
if (!getAllowedLogOptions().contains(log)) {
throw new BuildException("invalid option for 'log': " + log + ". Available options are " + getAllowedLogOptions());
}
ModuleRevisionId mrid = ModuleRevisionId.newInstance("", "", Ivy.getWorkingRevision());
DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(mrid, null);
for (IvyDependency dep : dependencies) {
DependencyDescriptor dd = dep.asDependencyDescriptor(md, "default", settings);
md.addDependency(dd);
}
for (IvyExclude exclude : excludes) {
DefaultExcludeRule rule = exclude.asRule(settings);
rule.addConfiguration("default");
md.addExcludeRule(rule);
}
for (IvyConflict conflict : conflicts) {
conflict.addConflict(md, settings);
}
report = ivy.resolve(md, getResolveOptions(ivy, new String[] { "default" }, settings));
} else if (isInline()) {
if (organisation == null) {
throw new BuildException("'organisation' is required when using inline mode");
}
if (module == null) {
throw new BuildException("'module' is required when using inline mode");
}
if (file != null) {
throw new BuildException("'file' not allowed when using inline mode");
}
if (!getAllowedLogOptions().contains(log)) {
throw new BuildException("invalid option for 'log': " + log + ". Available options are " + getAllowedLogOptions());
}
for (int i = 0; i < confs.length; i++) {
if ("*".equals(confs[i])) {
confs[i] = "*(public)";
}
}
if (revision == null) {
revision = "latest.integration";
}
report = ivy.resolve(ModuleRevisionId.newInstance(organisation, module, branch, revision), getResolveOptions(ivy, confs, settings), changing);
} else {
if (organisation != null) {
throw new BuildException("'organisation' not allowed when not using 'org' attribute");
}
if (module != null) {
throw new BuildException("'module' not allowed when not using 'org' attribute");
}
if (file == null) {
file = getProject().resolveFile(getProperty(settings, "ivy.dep.file"));
}
report = ivy.resolve(file.toURI().toURL(), getResolveOptions(ivy, confs, settings));
}
if (report.hasError()) {
if (failureProperty != null) {
getProject().setProperty(failureProperty, "true");
}
if (isHaltonfailure()) {
throw new BuildException("resolve failed - see output for details");
}
}
setResolved(report, resolveId, isKeep());
confs = report.getConfigurations();
if (isKeep()) {
ModuleDescriptor md = report.getModuleDescriptor();
// put resolved infos in ant properties and ivy variables
// putting them in ivy variables is important to be able to change from one resolve
// call to the other
String mdOrg = md.getModuleRevisionId().getOrganisation();
String mdName = md.getModuleRevisionId().getName();
String mdRev = md.getResolvedModuleRevisionId().getRevision();
getProject().setProperty("ivy.organisation", mdOrg);
settings.setVariable("ivy.organisation", mdOrg);
getProject().setProperty("ivy.module", mdName);
settings.setVariable("ivy.module", mdName);
getProject().setProperty("ivy.revision", mdRev);
settings.setVariable("ivy.revision", mdRev);
List<ExtendsDescriptor> parents = Arrays.asList(md.getInheritedDescriptors());
for (ExtendsDescriptor parent : parents) {
int i = parents.indexOf(parent);
String parentOrg = parent.getResolvedParentRevisionId().getOrganisation();
String parentModule = parent.getResolvedParentRevisionId().getName();
String parentRevision = parent.getResolvedParentRevisionId().getRevision();
String parentBranch = parent.getResolvedParentRevisionId().getBranch();
getProject().setProperty("ivy.parent[" + i + "].organisation", parentOrg);
settings.setVariable("ivy.parent[" + i + "].organisation", parentOrg);
getProject().setProperty("ivy.parent[" + i + "].module", parentModule);
settings.setVariable("ivy.parent[" + i + "].module", parentModule);
getProject().setProperty("ivy.parent[" + i + "].revision", parentRevision);
settings.setVariable("ivy.parent[" + i + "].revision", parentRevision);
if (parentBranch != null) {
getProject().setProperty("ivy.parent[" + i + "].branch", parentBranch);
settings.setVariable("ivy.parent[" + i + "].branch", parentBranch);
}
}
getProject().setProperty("ivy.parents.count", String.valueOf(md.getInheritedDescriptors().length));
settings.setVariable("ivy.parents.count", String.valueOf(md.getInheritedDescriptors().length));
Boolean hasChanged = null;
if (getCheckIfChanged()) {
hasChanged = report.hasChanged();
getProject().setProperty("ivy.deps.changed", hasChanged.toString());
settings.setVariable("ivy.deps.changed", hasChanged.toString());
}
getProject().setProperty("ivy.resolved.configurations", mergeConfs(confs));
settings.setVariable("ivy.resolved.configurations", mergeConfs(confs));
if (file != null) {
getProject().setProperty("ivy.resolved.file", file.getAbsolutePath());
settings.setVariable("ivy.resolved.file", file.getAbsolutePath());
}
if (resolveId != null) {
getProject().setProperty("ivy.organisation." + resolveId, mdOrg);
settings.setVariable("ivy.organisation." + resolveId, mdOrg);
getProject().setProperty("ivy.module." + resolveId, mdName);
settings.setVariable("ivy.module." + resolveId, mdName);
getProject().setProperty("ivy.revision." + resolveId, mdRev);
settings.setVariable("ivy.revision." + resolveId, mdRev);
if (getCheckIfChanged()) {
// hasChanged has already been set earlier
getProject().setProperty("ivy.deps.changed." + resolveId, hasChanged.toString());
settings.setVariable("ivy.deps.changed." + resolveId, hasChanged.toString());
}
getProject().setProperty("ivy.resolved.configurations." + resolveId, mergeConfs(confs));
settings.setVariable("ivy.resolved.configurations." + resolveId, mergeConfs(confs));
if (file != null) {
getProject().setProperty("ivy.resolved.file." + resolveId, file.getAbsolutePath());
settings.setVariable("ivy.resolved.file." + resolveId, file.getAbsolutePath());
}
}
}
} catch (MalformedURLException e) {
throw new BuildException("unable to convert given ivy file to url: " + file + ": " + e, e);
} catch (ParseException e) {
log(e.getMessage(), Project.MSG_ERR);
throw new BuildException("syntax errors in ivy file: " + e, e);
} catch (ResolveProcessException e) {
throw new BuildException("impossible to resolve dependencies:\n\t" + e.getMessage(), e);
} catch (Exception e) {
throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
}
}
Aggregations