use of org.apache.ivy.plugins.report.XmlReportParser in project ant-ivy by apache.
the class IvyArtifactProperty method doExecute.
public void doExecute() throws BuildException {
prepareAndCheck();
try {
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
String resolveId = getResolveId();
if (resolveId == null) {
resolveId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
}
XmlReportParser parser = new XmlReportParser();
for (String conf : splitToArray(getConf())) {
File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
parser.parse(report);
for (Artifact artifact : parser.getArtifacts()) {
String name = IvyPatternHelper.substitute(getSettings().substitute(getName()), artifact, conf);
String value = IvyPatternHelper.substitute(getSettings().substitute(getValue()), artifact, conf);
setProperty(name, value);
}
}
} catch (Exception ex) {
throw new BuildException("impossible to add artifact properties: " + ex, ex);
}
}
use of org.apache.ivy.plugins.report.XmlReportParser in project ant-ivy by apache.
the class IvyCacheTask method getAllArtifactReports.
private Collection<ArtifactDownloadReport> getAllArtifactReports() throws ParseException {
String[] confs = splitToArray(getConf());
Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
ResolveReport report = getResolvedReport();
if (report != null) {
Message.debug("using internal report instance to get artifacts list");
for (String conf : confs) {
ConfigurationResolveReport configurationReport = report.getConfigurationReport(conf);
if (configurationReport == null) {
throw new BuildException("bad confs provided: " + conf + " not found among " + Arrays.asList(report.getConfigurations()));
}
for (ModuleRevisionId revId : configurationReport.getModuleRevisionIds()) {
all.addAll(Arrays.asList(configurationReport.getDownloadReports(revId)));
}
}
} else {
Message.debug("using stored report to get artifacts list");
XmlReportParser parser = new XmlReportParser();
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
String resolvedId = getResolveId();
if (resolvedId == null) {
resolvedId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
}
for (String conf : confs) {
File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolvedId, conf);
parser.parse(reportFile);
all.addAll(Arrays.asList(parser.getArtifactReports()));
}
}
return all;
}
use of org.apache.ivy.plugins.report.XmlReportParser in project ant-ivy by apache.
the class Main method invoke.
@SuppressWarnings("resource")
private static void invoke(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, List<File> fileList, String mainclass, String[] args) {
List<URL> urls = new ArrayList<>();
// Add option cp (extra classpath) urls
if (fileList != null && fileList.size() > 0) {
for (File file : fileList) {
try {
urls.add(file.toURI().toURL());
} catch (MalformedURLException e) {
// Should not happen, just ignore.
}
}
}
try {
Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
ResolutionCacheManager cacheMgr = ivy.getResolutionCacheManager();
XmlReportParser parser = new XmlReportParser();
for (String conf : confs) {
String resolveId = ResolveOptions.getDefaultResolveId(md);
File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
parser.parse(report);
all.addAll(Arrays.asList(parser.getArtifactReports()));
}
for (ArtifactDownloadReport artifact : all) {
if (artifact.getLocalFile() != null) {
urls.add(artifact.getLocalFile().toURI().toURL());
}
}
} catch (Exception ex) {
throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex);
}
URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Main.class.getClassLoader().getParent());
try {
Class<?> c = classLoader.loadClass(mainclass);
Method mainMethod = c.getMethod("main", String[].class);
Thread.currentThread().setContextClassLoader(classLoader);
mainMethod.invoke(null, new Object[] { (args == null ? new String[0] : args) });
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException("Could not find class: " + mainclass, cnfe);
} catch (SecurityException | NoSuchMethodException e) {
throw new RuntimeException("Could not find main method: " + mainclass, e);
} catch (IllegalAccessException e) {
throw new RuntimeException("No permissions to invoke main method: " + mainclass, e);
} catch (InvocationTargetException e) {
throw new RuntimeException("Unexpected exception invoking main method: " + mainclass, e);
}
}
use of org.apache.ivy.plugins.report.XmlReportParser in project ant-ivy by apache.
the class Main method outputCachePath.
private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, String outFile) {
try {
StringBuilder buf = new StringBuilder();
Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
ResolutionCacheManager cacheMgr = ivy.getResolutionCacheManager();
XmlReportParser parser = new XmlReportParser();
for (String conf : confs) {
String resolveId = ResolveOptions.getDefaultResolveId(md);
File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
parser.parse(report);
all.addAll(Arrays.asList(parser.getArtifactReports()));
}
for (ArtifactDownloadReport artifact : all) {
if (artifact.getLocalFile() != null) {
buf.append(artifact.getLocalFile().getCanonicalPath());
buf.append(File.pathSeparator);
}
}
PrintWriter writer = new PrintWriter(new FileOutputStream(outFile));
if (buf.length() > 0) {
buf.setLength(buf.length() - File.pathSeparator.length());
writer.println(buf);
}
writer.close();
System.out.println("cachepath output to " + outFile);
} catch (Exception ex) {
throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex);
}
}
Aggregations