use of org.apache.ivy.core.cache.ResolutionCacheManager 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.core.cache.ResolutionCacheManager 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.core.cache.ResolutionCacheManager 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);
}
}
use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.
the class IvyReport method getStylePath.
private File getStylePath(String styleResourceName) throws IOException {
// style should be a file (and not an url)
// so we have to copy it from classpath to cache
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
File style = new File(cacheMgr.getResolutionCacheRoot(), styleResourceName);
FileUtil.copy(XmlReportOutputter.class.getResourceAsStream(styleResourceName), style, null);
return style;
}
use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.
the class IvyReport method getReportStylePath.
private File getReportStylePath() throws IOException {
if (xslFile != null) {
return xslFile;
}
// style should be a file (and not an url)
// so we have to copy it from classpath to cache
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
File style = new File(cacheMgr.getResolutionCacheRoot(), "ivy-report.xsl");
if (!style.exists()) {
Message.debug("copying ivy-report.xsl to " + style.getAbsolutePath());
FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.xsl"), style, null);
}
return style;
}
Aggregations