use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class UpdateSiteLoader method readJarOrXml.
private boolean readJarOrXml(URI repoUri, String baseName, XMLInputParser reader) throws IOException, ParseException, SAXException {
// the input stream from which the xml should be read
InputStream readIn = null;
URL contentUrl = repoUri.resolve(baseName + ".jar").toURL();
URLResource res = new URLResource(contentUrl, this.timeoutConstraint);
ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, baseName, baseName, "jar", options, urlRepository);
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
// no jar file, try the xml one
contentUrl = repoUri.resolve(baseName + ".xml").toURL();
res = new URLResource(contentUrl, this.timeoutConstraint);
report = repositoryCacheManager.downloadRepositoryResource(res, baseName, baseName, "xml", options, urlRepository);
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
// no xml either
return false;
}
readIn = new FileInputStream(report.getLocalFile());
} else {
InputStream in = new FileInputStream(report.getLocalFile());
try {
// compressed, let's get the pointer on the actual xml
readIn = findEntry(in, baseName + ".xml");
if (readIn == null) {
in.close();
return false;
}
} catch (IOException e) {
in.close();
throw e;
}
}
try {
reader.parse(readIn);
} finally {
readIn.close();
}
return true;
}
use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class UpdateSiteResolver method init.
protected void init() {
if (url == null) {
throw new RuntimeException("Missing url");
}
CacheResourceOptions options = new CacheResourceOptions();
if (metadataTtl != null) {
options.setTtl(metadataTtl);
}
if (forceMetadataUpdate != null) {
options.setForce(forceMetadataUpdate);
}
final int log;
if (logLevel != null) {
if ("debug".equalsIgnoreCase(logLevel)) {
log = Message.MSG_DEBUG;
} else if ("verbose".equalsIgnoreCase(logLevel)) {
log = Message.MSG_VERBOSE;
} else if ("info".equalsIgnoreCase(logLevel)) {
log = Message.MSG_INFO;
} else if ("warn".equalsIgnoreCase(logLevel)) {
log = Message.MSG_WARN;
} else if ("error".equalsIgnoreCase(logLevel)) {
log = Message.MSG_ERR;
} else {
throw new RuntimeException("Unknown log level: " + logLevel);
}
} else {
log = Message.MSG_INFO;
}
options.setListener(new DownloadListener() {
public void startArtifactDownload(RepositoryCacheManager cache, ResolvedResource rres, Artifact artifact, ArtifactOrigin origin) {
if (log <= Message.MSG_INFO) {
Message.info("\tdownloading " + rres.getResource().getName());
}
}
public void needArtifact(RepositoryCacheManager cache, Artifact artifact) {
if (log <= Message.MSG_VERBOSE) {
Message.verbose("\ttrying to download " + artifact);
}
}
public void endArtifactDownload(RepositoryCacheManager cache, Artifact artifact, ArtifactDownloadReport adr, File archiveFile) {
if (log <= Message.MSG_VERBOSE) {
if (adr.isDownloaded()) {
Message.verbose("\tdownloaded to " + archiveFile.getAbsolutePath());
} else {
Message.verbose("\tnothing to download");
}
}
}
});
final UpdateSiteLoader loader = new UpdateSiteLoader(getRepositoryCacheManager(), getEventManager(), options, this.getTimeoutConstraint());
loader.setLogLevel(log);
RepoDescriptor repoDescriptor;
try {
repoDescriptor = loader.load(new URI(url));
} catch (IOException e) {
throw new RuntimeException("IO issue while trying to read the update site (" + e.getMessage() + ")");
} catch (ParseException e) {
throw new RuntimeException("Failed to parse the updatesite (" + e.getMessage() + ")", e);
} catch (SAXException e) {
throw new RuntimeException("Ill-formed updatesite (" + e.getMessage() + ")", e);
} catch (URISyntaxException e) {
throw new RuntimeException("Ill-formed url (" + e.getMessage() + ")", e);
}
if (repoDescriptor == null) {
setRepoDescriptor(FAILING_REPO_DESCRIPTOR);
throw new RuntimeException("No update site was found at the location: " + url);
}
setRepoDescriptor(repoDescriptor);
}
use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class IvyCacheFilesetTest method artifactDownloadReport.
private ArtifactDownloadReport artifactDownloadReport(File localFile) {
ArtifactDownloadReport report = new ArtifactDownloadReport(null);
report.setLocalFile(localFile);
return report;
}
use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.
the class IvyArtifactReport method generateXml.
private void generateXml(IvyNode[] dependencies, Map<ModuleRevisionId, Set<ArtifactDownloadReport>> moduleRevToArtifactsMap, Map<ArtifactDownloadReport, Set<String>> artifactsToCopy) {
try {
try (FileOutputStream fileOutputStream = new FileOutputStream(tofile)) {
TransformerHandler saxHandler = createTransformerHandler(fileOutputStream);
saxHandler.startDocument();
saxHandler.startElement(null, "modules", "modules", new AttributesImpl());
for (IvyNode dependency : dependencies) {
if (dependency.getModuleRevision() == null || dependency.isCompletelyEvicted()) {
continue;
}
startModule(saxHandler, dependency);
Set<ArtifactDownloadReport> artifactsOfModuleRev = moduleRevToArtifactsMap.get(dependency.getModuleRevision().getId());
if (artifactsOfModuleRev != null) {
for (ArtifactDownloadReport artifact : artifactsOfModuleRev) {
RepositoryCacheManager cache = dependency.getModuleRevision().getArtifactResolver().getRepositoryCacheManager();
startArtifact(saxHandler, artifact.getArtifact());
writeOriginLocationIfPresent(cache, saxHandler, artifact);
writeCacheLocationIfPresent(cache, saxHandler, artifact);
for (String artifactDestPath : artifactsToCopy.get(artifact)) {
writeRetrieveLocation(saxHandler, artifactDestPath);
}
saxHandler.endElement(null, "artifact", "artifact");
}
}
saxHandler.endElement(null, "module", "module");
}
saxHandler.endElement(null, "modules", "modules");
saxHandler.endDocument();
}
} catch (SAXException | IOException | TransformerConfigurationException e) {
throw new BuildException("impossible to generate report", e);
}
}
use of org.apache.ivy.core.report.ArtifactDownloadReport 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;
}
Aggregations