use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class ResolveTest method testUseOrigin.
@Test
public void testUseOrigin() throws Exception {
((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).setUseOrigin(true);
ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "default" }));
assertNotNull(report);
ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct.", 1, dReports.length);
assertEquals("download status not correct: should not download the artifact in useOrigin mode.", DownloadStatus.NO, dReports[0].getDownloadStatus());
Artifact artifact = dReports[0].getArtifact();
assertNotNull(artifact);
String expectedLocation = new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath();
ArtifactOrigin origin = getSavedArtifactOrigin(artifact);
File artInCache = new File(cache, getArchivePathInCache(artifact, origin));
assertFalse("should not download artifact in useOrigin mode.", artInCache.exists());
assertEquals("location for artifact not correct.", expectedLocation, getArchiveFileInCache(artifact).getAbsolutePath());
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class AggregatedOSGiResolverTest method genericTestResolveDownload.
private void genericTestResolveDownload(DependencyResolver resolver, ModuleRevisionId mrid) throws ParseException {
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
DownloadReport report = resolver.download(new Artifact[] { artifact }, new DownloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
// test to ask to download again, should use cache
report = resolver.download(new Artifact[] { artifact }, new DownloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
use of org.apache.ivy.core.module.descriptor.Artifact 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.module.descriptor.Artifact 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.core.module.descriptor.Artifact in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method unlockMetadataArtifact.
private void unlockMetadataArtifact(ModuleRevisionId mrid) {
Artifact artifact = getDefaultMetadataArtifact(mrid);
getLockStrategy().unlockArtifact(artifact, getArchiveFileInCache(artifact, getDefaultMetadataArtifactOrigin(mrid)));
}
Aggregations