use of org.apache.ivy.core.module.descriptor.ModuleDescriptor 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.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class ModuleDescriptorMemoryCache method getStale.
/**
* Get the module descriptor from the mdProvider and store it into the cache.
*/
public ModuleDescriptor getStale(File ivyFile, ParserSettings ivySettings, boolean validated, ModuleDescriptorProvider mdProvider) throws ParseException, IOException {
ParserSettingsMonitor settingsMonitor = new ParserSettingsMonitor(ivySettings);
ModuleDescriptor descriptor = mdProvider.provideModule(settingsMonitor.getMonitoredSettings(), ivyFile, validated);
putInCache(ivyFile, settingsMonitor, validated, descriptor);
return descriptor;
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class IvyInfo method doExecute.
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
try {
if (organisation != null || module != null || revision != null || branch != null) {
if (organisation == null) {
throw new BuildException("no organisation provided for ivy info task");
}
if (module == null) {
throw new BuildException("no module name provided for ivy info task");
}
if (revision == null) {
throw new BuildException("no revision provided for ivy info task");
}
if (branch == null) {
settings.getDefaultBranch(new ModuleId(organisation, module));
}
ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(organisation, module, branch, revision));
if (rmr != null) {
ModuleDescriptor md = rmr.getDescriptor();
ModuleRevisionId mrid = rmr.getId();
setProperties(md, mrid);
}
} else {
if (file == null) {
file = getProject().resolveFile(getProperty(settings, "ivy.dep.file"));
}
ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(settings, file.toURI().toURL(), doValidate(settings));
ModuleRevisionId mrid = md.getModuleRevisionId();
setProperties(md, mrid);
}
} catch (MalformedURLException e) {
throw new BuildException("unable to convert given ivy file to url: " + file + ": " + e, e);
} catch (ParseException e) {
log(e.getMessage(), Project.MSG_ERR);
throw new BuildException("syntax errors in ivy file: " + e, e);
} catch (Exception e) {
throw new BuildException("impossible to resolve dependencies: " + e, e);
}
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class IvyMakePom method doExecute.
@Override
public void doExecute() throws BuildException {
try {
if (ivyFile == null) {
throw new BuildException("source ivy file is required for makepom task");
}
if (pomFile == null) {
throw new BuildException("destination pom file is required for makepom task");
}
ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(getSettings(), ivyFile.toURI().toURL(), false);
PomModuleDescriptorWriter.write(md, pomFile, getPomWriterOptions());
} catch (MalformedURLException e) {
throw new BuildException("unable to convert given ivy file to url: " + ivyFile + ": " + e, e);
} catch (ParseException e) {
log(e.getMessage(), Project.MSG_ERR);
throw new BuildException("syntax errors in ivy file " + ivyFile + ": " + e, e);
} catch (Exception e) {
throw new BuildException("impossible convert given ivy file to pom file: " + e + " from=" + ivyFile + " to=" + pomFile, e);
}
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class IvyPostResolveTask method getConfsToResolve.
protected String[] getConfsToResolve(String resolveId, String conf) {
ModuleDescriptor reference = getResolvedDescriptor(resolveId, false);
if (reference == null) {
// TODO: find a way to discover which confs were resolved by that previous resolve
if (conf == null) {
return new String[] { "*" };
}
return splitToArray(conf);
}
String[] rconfs = getProject().getReference("ivy.resolved.configurations.ref." + resolveId);
return getConfsToResolve(reference, conf, rconfs);
}
Aggregations