use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method doFindModuleInCache.
private ResolvedModuleRevision doFindModuleInCache(ModuleRevisionId mrid, CacheMetadataOptions options, String expectedResolver) {
if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
return null;
}
boolean unlock = true;
try {
if (settings.getVersionMatcher().isDynamic(mrid)) {
String resolvedRevision = getResolvedRevision(expectedResolver, mrid, options);
if (resolvedRevision == null) {
return null;
}
Message.verbose("found resolved revision in cache: " + mrid + " => " + resolvedRevision);
// we have found another module in the cache, make sure we unlock
// the original module
unlockMetadataArtifact(mrid);
mrid = ModuleRevisionId.newInstance(mrid, resolvedRevision);
// don't forget to request a lock on the new module!
if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
// we couldn't lock the new module, so no need to unlock it
unlock = false;
return null;
}
}
File ivyFile = getIvyFileInCache(mrid);
if (ivyFile.exists()) {
// found in cache !
try {
ModuleDescriptorParser parser = getModuleDescriptorParser(ivyFile);
ModuleDescriptor depMD = getMdFromCache(parser, options, ivyFile);
String resolverName = getSavedResolverName(depMD);
String artResolverName = getSavedArtResolverName(depMD);
DependencyResolver resolver = settings.getResolver(resolverName);
if (resolver == null) {
Message.debug("\tresolver not found: " + resolverName + " => trying to use the one configured for " + mrid);
resolver = settings.getResolver(depMD.getResolvedModuleRevisionId());
if (resolver != null) {
Message.debug("\tconfigured resolver found for " + depMD.getResolvedModuleRevisionId() + ": " + resolver.getName() + ": saving this data");
saveResolver(depMD, resolver.getName());
}
}
DependencyResolver artResolver = settings.getResolver(artResolverName);
if (artResolver == null) {
artResolver = resolver;
}
if (resolver != null) {
Message.debug("\tfound ivy file in cache for " + mrid + " (resolved by " + resolver.getName() + "): " + ivyFile);
if (expectedResolver == null || expectedResolver.equals(resolver.getName())) {
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(depMD.getMetadataArtifact());
madr.setDownloadStatus(DownloadStatus.NO);
madr.setSearched(false);
madr.setLocalFile(ivyFile);
madr.setSize(ivyFile.length());
madr.setArtifactOrigin(getSavedArtifactOrigin(depMD.getMetadataArtifact()));
if (madr.getArtifactOrigin().isExists()) {
if (madr.getArtifactOrigin().isLocal() && madr.getArtifactOrigin().getArtifact().getUrl() != null) {
madr.setOriginalLocalFile(new File(madr.getArtifactOrigin().getArtifact().getUrl().toURI()));
} else {
// find locally cached file
madr.setOriginalLocalFile(getArchiveFileInCache(madr.getArtifactOrigin().getArtifact()));
}
}
return new ResolvedModuleRevision(resolver, artResolver, depMD, madr);
}
Message.debug("found module in cache but with a different resolver: " + "discarding: " + mrid + "; expected resolver=" + expectedResolver + "; resolver=" + resolver.getName());
} else {
Message.debug("\tresolver not found: " + resolverName + " => cannot use cached ivy file for " + mrid);
}
} catch (Exception e) {
// will try with resolver
Message.debug("\tproblem while parsing cached ivy file for: " + mrid, e);
}
} else {
Message.debug("\tno ivy file in cache for " + mrid + ": tried " + ivyFile);
}
} finally {
if (unlock) {
unlockMetadataArtifact(mrid);
}
}
return null;
}
use of org.apache.ivy.plugins.resolver.DependencyResolver 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.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class IvyConfigureTest method testDefault.
@Test
public void testDefault() {
// by default settings look in the current directory for an ivysettings.xml file...
// but Ivy itself has one, and we don't want to use it
configure.getProject().setProperty("ivy.settings.file", "no/settings/will/use/default.xml");
configure.execute();
IvySettings settings = getIvyInstance().getSettings();
assertNotNull(settings.getDefaultResolver());
DependencyResolver publicResolver = settings.getResolver("public");
assertNotNull(publicResolver);
assertTrue(publicResolver instanceof IBiblioResolver);
IBiblioResolver ibiblio = (IBiblioResolver) publicResolver;
assertTrue(ibiblio.isM2compatible());
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class IvyConfigureTest method testDefault14.
@Test
public void testDefault14() {
// by default settings look in the current directory for an ivysettings.xml file...
// but Ivy itself has one, and we don't want to use it
configure.getProject().setProperty("ivy.settings.file", "no/settings/will/use/default.xml");
configure.getProject().setProperty("ivy.14.compatible", "true");
configure.execute();
IvySettings settings = getIvyInstance().getSettings();
assertNotNull(settings.getDefaultResolver());
DependencyResolver publicResolver = settings.getResolver("public");
assertTrue(publicResolver instanceof IvyRepResolver);
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class BuildOBRTask method doExecute.
public void doExecute() throws BuildException {
if (file == null) {
throw new BuildException("No output file specified: use the attribute 'out'");
}
Iterable<ManifestAndLocation> it;
if (resolverName != null) {
if (baseDir != null) {
throw new BuildException("specify only one of 'resolver' or 'baseDir'");
}
if (cacheName != null) {
throw new BuildException("specify only one of 'resolver' or 'cache'");
}
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
DependencyResolver resolver = settings.getResolver(resolverName);
if (resolver == null) {
throw new BuildException("the resolver '" + resolverName + "' was not found");
}
if (!(resolver instanceof BasicResolver)) {
throw new BuildException("the type of resolver '" + resolver.getClass().getName() + "' is not supported.");
}
it = new ResolverManifestIterable((BasicResolver) resolver);
} else if (baseDir != null) {
if (cacheName != null) {
throw new BuildException("specify only one of 'baseDir' or 'cache'");
}
if (!baseDir.isDirectory()) {
throw new BuildException(baseDir + " is not a directory");
}
it = new FSManifestIterable(baseDir);
} else if (cacheName != null) {
Ivy ivy = getIvyInstance();
RepositoryCacheManager cacheManager = ivy.getSettings().getRepositoryCacheManager(cacheName);
if (!(cacheManager instanceof DefaultRepositoryCacheManager)) {
throw new BuildException("the type of cache '" + cacheManager.getClass().getName() + "' is not supported.");
}
File basedir = ((DefaultRepositoryCacheManager) cacheManager).getBasedir();
it = new FSManifestIterable(basedir);
} else {
prepareAndCheck();
try {
it = new ArtifactReportManifestIterable(getArtifactReports(), sourceTypes);
} catch (ParseException e) {
throw new BuildException("Impossible to parse the artifact reports: " + e.getMessage(), e);
}
}
OutputStream out;
try {
out = new FileOutputStream(file);
} catch (FileNotFoundException e) {
throw new BuildException(file + " was not found", e);
}
ContentHandler hd;
try {
hd = OBRXMLWriter.newHandler(out, encoding, indent);
} catch (TransformerConfigurationException e) {
throw new BuildException("Sax configuration error: " + e.getMessage(), e);
}
class AntMessageLogger2 extends AntMessageLogger {
AntMessageLogger2() {
super(BuildOBRTask.this);
}
}
IvyContext.getContext().getMessageLogger();
Message.setDefaultLogger(new AntMessageLogger2());
try {
OBRXMLWriter.writeManifests(it, hd, quiet);
} catch (SAXException e) {
throw new BuildException("Sax serialisation error: " + e.getMessage(), e);
}
try {
out.flush();
out.close();
} catch (IOException e) {
// don't care
}
Message.sumupProblems();
}
Aggregations