use of org.apache.ivy.core.resolve.DownloadOptions in project ant-ivy by apache.
the class InstallEngine method install.
public ResolveReport install(ModuleRevisionId mrid, String from, String to, InstallOptions options) throws IOException {
DependencyResolver fromResolver = settings.getResolver(from);
DependencyResolver toResolver = settings.getResolver(to);
if (fromResolver == null) {
throw new IllegalArgumentException("unknown resolver " + from + ". Available resolvers are: " + settings.getResolverNames());
}
if (toResolver == null) {
throw new IllegalArgumentException("unknown resolver " + to + ". Available resolvers are: " + settings.getResolverNames());
}
PatternMatcher matcher = settings.getMatcher(options.getMatcherName());
if (matcher == null) {
throw new IllegalArgumentException("unknown matcher " + options.getMatcherName() + ". Available matchers are: " + settings.getMatcherNames());
}
// build module file declaring the dependency
Message.info(":: installing " + mrid + " ::");
DependencyResolver oldDictator = resolveEngine.getDictatorResolver();
boolean log = settings.logNotConvertedExclusionRule();
try {
settings.setLogNotConvertedExclusionRule(true);
resolveEngine.setDictatorResolver(fromResolver);
DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("apache", "ivy-install", "1.0"), settings.getStatusManager().getDefaultStatus(), new Date());
String resolveId = ResolveOptions.getDefaultResolveId(md);
md.addConfiguration(new Configuration("default"));
md.addConflictManager(new ModuleId(ExactPatternMatcher.ANY_EXPRESSION, ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, new NoConflictManager());
for (String dc : options.getConfs()) {
final String depConf = dc.trim();
if (MatcherHelper.isExact(matcher, mrid)) {
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, false, false, options.isTransitive());
dd.addDependencyConfiguration("default", depConf);
md.addDependency(dd);
} else {
for (ModuleRevisionId imrid : searchEngine.listModules(fromResolver, mrid, matcher)) {
Message.info("\tfound " + imrid + " to install: adding to the list");
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, imrid, false, false, options.isTransitive());
dd.addDependencyConfiguration("default", depConf);
md.addDependency(dd);
}
}
}
// resolve using appropriate resolver
ResolveReport report = new ResolveReport(md, resolveId);
Message.info(":: resolving dependencies ::");
ResolveOptions resolveOptions = new ResolveOptions().setResolveId(resolveId).setConfs(new String[] { "default" }).setValidate(options.isValidate());
IvyNode[] dependencies = resolveEngine.getDependencies(md, resolveOptions, report);
report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());
Message.info(":: downloading artifacts to cache ::");
resolveEngine.downloadArtifacts(report, options.getArtifactFilter(), new DownloadOptions());
// now that everything is in cache, we can publish all these modules
Message.info(":: installing in " + to + " ::");
for (IvyNode dependency : dependencies) {
ModuleDescriptor depmd = dependency.getDescriptor();
if (depmd != null) {
ModuleRevisionId depMrid = depmd.getModuleRevisionId();
Message.verbose("installing " + depMrid);
boolean successfullyPublished = false;
try {
toResolver.beginPublishTransaction(depMrid, options.isOverwrite());
// publish artifacts
for (ArtifactDownloadReport artifact : report.getArtifactsReports(depMrid)) {
if (artifact.getLocalFile() != null) {
toResolver.publish(artifact.getArtifact(), artifact.getLocalFile(), options.isOverwrite());
}
}
// publish metadata
MetadataArtifactDownloadReport artifactDownloadReport = dependency.getModuleRevision().getReport();
File localIvyFile = artifactDownloadReport.getLocalFile();
toResolver.publish(depmd.getMetadataArtifact(), localIvyFile, options.isOverwrite());
if (options.isInstallOriginalMetadata()) {
if (artifactDownloadReport.getArtifactOrigin() != null && artifactDownloadReport.getArtifactOrigin().isExists() && !ArtifactOrigin.isUnknown(artifactDownloadReport.getArtifactOrigin()) && artifactDownloadReport.getArtifactOrigin().getArtifact() != null && artifactDownloadReport.getArtifactOrigin().getArtifact().getType().endsWith(".original") && !artifactDownloadReport.getArtifactOrigin().getArtifact().getType().equals(depmd.getMetadataArtifact().getType() + ".original")) {
// publish original metadata artifact, too, as it has a different
// type
toResolver.publish(artifactDownloadReport.getArtifactOrigin().getArtifact(), artifactDownloadReport.getOriginalLocalFile(), options.isOverwrite());
}
}
// end module publish
toResolver.commitPublishTransaction();
successfullyPublished = true;
} finally {
if (!successfullyPublished) {
toResolver.abortPublishTransaction();
}
}
}
}
Message.info(":: install resolution report ::");
// output report
resolveEngine.outputReport(report, settings.getResolutionCacheManager(), resolveOptions);
return report;
} finally {
// IVY-834: log the problems if there were any...
Message.sumupProblems();
resolveEngine.setDictatorResolver(oldDictator);
settings.setLogNotConvertedExclusionRule(log);
}
}
use of org.apache.ivy.core.resolve.DownloadOptions in project ant-ivy by apache.
the class ChainResolverTest method testDownloadWithDual.
@Test
public void testDownloadWithDual() {
ChainResolver chain = new ChainResolver();
chain.setName("chain");
chain.setSettings(settings);
chain.setDual(true);
// first resolver has only an artifact pattern which don't lead to anything: it won't find
// the module
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("1");
resolver.setSettings(settings);
resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/nowhere/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
chain.add(resolver);
resolver = new FileSystemResolver();
resolver.setName("2");
resolver.setSettings(settings);
resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/ivys/ivy-[revision].xml");
resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
chain.add(resolver);
settings.addResolver(chain);
MockMessageLogger mockLogger = new MockMessageLogger();
IvyContext.getContext().getIvy().getLoggerEngine().setDefaultLogger(mockLogger);
DownloadReport report = chain.download(new Artifact[] { new DefaultArtifact(ModuleRevisionId.parse("org1#mod1.1;1.0"), new Date(), "mod1.1", "jar", "jar") }, new DownloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
assertEquals(DownloadStatus.SUCCESSFUL, report.getArtifactsReports()[0].getDownloadStatus());
mockLogger.assertLogDoesntContain("[FAILED ] org1#mod1.1;1.0!mod1.1.jar");
}
use of org.apache.ivy.core.resolve.DownloadOptions in project ant-ivy by apache.
the class P2DescriptorTest method testResolveSource.
@Test
public void testResolveSource() throws Exception {
settings.setDefaultResolver("p2-sources");
ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.apache.ivy", "2.2.0.final_20100923230623");
ResolvedModuleRevision rmr = p2SourceResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);
DownloadReport report = p2SourceResolver.download(rmr.getDescriptor().getAllArtifacts(), new DownloadOptions());
assertNotNull(report);
assertEquals(2, report.getArtifactsReports().length);
for (int i = 0; i < 2; i++) {
Artifact artifact = rmr.getDescriptor().getAllArtifacts()[i];
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
DownloadReport report2 = p2SourceResolver.download(new Artifact[] { artifact }, new DownloadOptions());
assertNotNull(report2);
assertEquals(1, report2.getArtifactsReports().length);
ar = report2.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
}
use of org.apache.ivy.core.resolve.DownloadOptions in project ant-ivy by apache.
the class P2DescriptorTest method testResolvePacked.
@Test
public void testResolvePacked() throws Exception {
settings.setDefaultResolver("p2-with-packed");
ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.junit", "4.10.0.v4_10_0_v20120426-0900");
ResolvedModuleRevision rmr = p2WithPackedResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
assertEquals(1, rmr.getDescriptor().getAllArtifacts().length);
DownloadOptions options = new DownloadOptions();
DownloadReport report = p2WithPackedResolver.download(rmr.getDescriptor().getAllArtifacts(), options);
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
assertNotNull(ar.getUnpackedLocalFile());
}
use of org.apache.ivy.core.resolve.DownloadOptions in project ant-ivy by apache.
the class P2DescriptorTest method testResolveNotZipped.
@Test
public void testResolveNotZipped() throws Exception {
settings.setDefaultResolver("p2-zipped");
ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.eclipse.e4.core.services", "1.0.0.v20120521-2346");
ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
assertEquals(1, rmr.getDescriptor().getAllArtifacts().length);
DownloadOptions options = new DownloadOptions();
DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(), options);
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
assertNull(ar.getUnpackedLocalFile());
}
Aggregations