use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.
the class BasicResolver method findResource.
/**
* When the resolver has many choices, this function helps choosing one
*
* @param rress
* the list of resolved resource which the resolver found to fit the requirement
* @param rmdparser
* the parser of module descriptor
* @param mrid
* the module being resolved
* @param date
* the current date
* @return the selected resource
*/
public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser, ModuleRevisionId mrid, Date date) {
String name = getName();
VersionMatcher versionMatcher = getSettings().getVersionMatcher();
ResolvedResource found = null;
List<ArtifactInfo> sorted = getLatestStrategy().sort(rress);
List<String> rejected = new ArrayList<>();
List<ModuleRevisionId> foundBlacklisted = new ArrayList<>();
IvyContext context = IvyContext.getContext();
ListIterator<ArtifactInfo> iter = sorted.listIterator(sorted.size());
while (iter.hasPrevious()) {
ResolvedResource rres = (ResolvedResource) iter.previous();
// name, blacklisting and first level version matching
if (filterNames(new ArrayList<>(Collections.singleton(rres.getRevision()))).isEmpty()) {
Message.debug("\t" + name + ": filtered by name: " + rres);
continue;
}
ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision());
ResolveData data = context.getResolveData();
if (data != null && data.getReport() != null && data.isBlacklisted(data.getReport().getConfiguration(), foundMrid)) {
Message.debug("\t" + name + ": blacklisted: " + rres);
rejected.add(rres.getRevision() + " (blacklisted)");
foundBlacklisted.add(foundMrid);
continue;
}
if (!versionMatcher.accept(mrid, foundMrid)) {
Message.debug("\t" + name + ": rejected by version matcher: " + rres);
rejected.add(rres.getRevision());
continue;
}
if (rres.getResource() != null && !rres.getResource().exists()) {
Message.debug("\t" + name + ": unreachable: " + rres + "; res=" + rres.getResource());
rejected.add(rres.getRevision() + " (unreachable)");
continue;
}
if (date != null && rres.getLastModified() > date.getTime()) {
Message.verbose("\t" + name + ": too young: " + rres);
rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")");
continue;
}
if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) {
ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision());
if (r == null) {
Message.debug("\t" + name + ": impossible to get module descriptor resource: " + rres);
rejected.add(rres.getRevision() + " (no or bad MD)");
continue;
}
ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision().getDescriptor();
if (md.isDefault()) {
Message.debug("\t" + name + ": default md rejected by version matcher" + "requiring module descriptor: " + rres);
rejected.add(rres.getRevision() + " (MD)");
continue;
}
if (!versionMatcher.accept(mrid, md)) {
Message.debug("\t" + name + ": md rejected by version matcher: " + rres);
rejected.add(rres.getRevision() + " (MD)");
continue;
}
found = r;
} else {
found = rres;
}
if (found != null) {
break;
}
}
if (found == null && !rejected.isEmpty()) {
logAttempt(rejected.toString());
}
if (found == null && !foundBlacklisted.isEmpty()) {
// all acceptable versions have been blacklisted, this means that an unsolvable conflict
// has been found
DependencyDescriptor dd = context.getDependencyDescriptor();
IvyNode parentNode = context.getResolveData().getNode(dd.getParentRevisionId());
ConflictManager cm = parentNode.getConflictManager(mrid.getModuleId());
cm.handleAllBlacklistedRevisions(dd, foundBlacklisted);
}
return found;
}
use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.
the class BasicResolver method getDependency.
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
IvyContext context = IvyContext.pushNewCopyContext();
try {
ResolvedModuleRevision mr = data.getCurrentResolvedModuleRevision();
if (mr != null && shouldReturnResolvedModule(dd, mr)) {
return mr;
}
if (isForce()) {
dd = dd.clone(ModuleRevisionId.newInstance(dd.getDependencyRevisionId(), "latest.integration"));
}
DependencyDescriptor systemDd = dd;
DependencyDescriptor nsDd = fromSystem(dd);
context.setDependencyDescriptor(systemDd);
context.setResolveData(data);
clearIvyAttempts();
clearArtifactAttempts();
ModuleRevisionId systemMrid = systemDd.getDependencyRevisionId();
ModuleRevisionId nsMrid = nsDd.getDependencyRevisionId();
checkRevision(systemMrid);
boolean isDynamic = getAndCheckIsDynamic(systemMrid);
// we first search for the dependency in cache
ResolvedModuleRevision rmr = findModuleInCache(systemDd, data);
if (rmr != null) {
if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
Message.verbose("\t" + getName() + ": found revision in cache: " + systemMrid + " (resolved by " + rmr.getResolver().getName() + "): but it's a default one, maybe we can find a better one");
} else if (isForce() && rmr.getResolver() != this) {
Message.verbose("\t" + getName() + ": found revision in cache: " + systemMrid + " (resolved by " + rmr.getResolver().getName() + "): but we are in force mode, let's try to find one ourselves");
} else {
Message.verbose("\t" + getName() + ": revision in cache: " + systemMrid);
return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
}
}
if (data.getOptions().isUseCacheOnly()) {
throw new UnresolvedDependencyException("\t" + getName() + " (useCacheOnly) : no ivy file found for " + systemMrid, false);
}
checkInterrupted();
ResolvedResource ivyRef = findIvyFileRef(nsDd, data);
checkInterrupted();
// get module descriptor
ModuleDescriptor nsMd;
ModuleDescriptor systemMd = null;
if (ivyRef == null) {
if (!isAllownomd()) {
throw new UnresolvedDependencyException("\t" + getName() + ": no ivy file found for " + systemMrid, false);
}
nsMd = DefaultModuleDescriptor.newDefaultInstance(nsMrid, nsDd.getAllDependencyArtifacts());
ResolvedResource artifactRef = findFirstArtifactRef(nsMd, nsDd, data);
checkInterrupted();
if (artifactRef == null) {
throw new UnresolvedDependencyException("\t" + getName() + ": no ivy file nor artifact found for " + systemMrid, false);
}
long lastModified = artifactRef.getLastModified();
if (lastModified != 0 && nsMd instanceof DefaultModuleDescriptor) {
((DefaultModuleDescriptor) nsMd).setLastModified(lastModified);
}
Message.verbose("\t" + getName() + ": no ivy file found for " + systemMrid + ": using default data");
if (isDynamic) {
nsMd.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(nsMrid, artifactRef.getRevision()));
}
systemMd = toSystem(nsMd);
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(systemMd.getMetadataArtifact());
madr.setDownloadStatus(DownloadStatus.NO);
madr.setSearched(true);
rmr = new ResolvedModuleRevision(this, this, systemMd, madr, isForce());
getRepositoryCacheManager().cacheModuleDescriptor(this, artifactRef, toSystem(dd), systemMd.getAllArtifacts()[0], null, getCacheOptions(data));
} else {
if (ivyRef instanceof MDResolvedResource) {
rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
}
if (rmr == null) {
rmr = parse(ivyRef, systemDd, data);
if (rmr == null) {
throw new UnresolvedDependencyException();
}
}
if (!rmr.getReport().isDownloaded() && rmr.getReport().getLocalFile() != null) {
return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
}
nsMd = rmr.getDescriptor();
// check descriptor data is in sync with resource revision and names
systemMd = toSystem(nsMd);
if (isCheckconsistency()) {
checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
} else {
if (systemMd instanceof DefaultModuleDescriptor) {
DefaultModuleDescriptor defaultMd = (DefaultModuleDescriptor) systemMd;
ModuleRevisionId revision = getRevision(ivyRef, systemMrid, systemMd);
defaultMd.setModuleRevisionId(revision);
defaultMd.setResolvedModuleRevisionId(revision);
} else {
Message.warn("consistency disabled with instance of non DefaultModuleDescriptor... module info can't be updated, so consistency check will be done");
checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
}
}
rmr = new ResolvedModuleRevision(this, this, systemMd, toSystem(rmr.getReport()), isForce());
}
resolveAndCheckRevision(systemMd, systemMrid, ivyRef, isDynamic);
resolveAndCheckPublicationDate(systemDd, systemMd, systemMrid, data);
checkNotConvertedExclusionRule(systemMd, ivyRef, data);
if (ivyRef == null || ivyRef.getResource() != null) {
cacheModuleDescriptor(systemMd, systemMrid, ivyRef, rmr);
}
return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
} catch (UnresolvedDependencyException ex) {
if (!ex.getMessage().isEmpty()) {
if (ex.isError()) {
Message.error(ex.getMessage());
} else {
Message.verbose(ex.getMessage());
}
}
return data.getCurrentResolvedModuleRevision();
} finally {
IvyContext.popContext();
}
}
use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.
the class BasicResolver method getDefaultRMDParser.
protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) {
return new ResourceMDParser() {
public MDResolvedResource parse(Resource resource, String rev) {
DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(new ModuleRevisionId(mid, rev));
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
madr.setDownloadStatus(DownloadStatus.NO);
madr.setSearched(true);
return new MDResolvedResource(resource, rev, new ResolvedModuleRevision(BasicResolver.this, BasicResolver.this, md, madr, isForce()));
}
};
}
use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.
the class AbstractOSGiResolver method buildResolvedCapabilityMd.
private MDResolvedResource buildResolvedCapabilityMd(DependencyDescriptor dd, ModuleDescriptor md) {
String org = dd.getDependencyRevisionId().getOrganisation();
String name = dd.getDependencyRevisionId().getName();
String rev = md.getExtraInfoContentByTagName(BundleInfoAdapter.EXTRA_INFO_EXPORT_PREFIX + name);
ModuleRevisionId capabilityRev = ModuleRevisionId.newInstance(org, name, rev, Collections.singletonMap(CAPABILITY_EXTRA_ATTR, md.getModuleRevisionId().toString()));
DefaultModuleDescriptor capabilityMd = new DefaultModuleDescriptor(capabilityRev, getSettings().getStatusManager().getDefaultStatus(), new Date());
String useConf = BundleInfoAdapter.CONF_USE_PREFIX + dd.getDependencyRevisionId().getName();
capabilityMd.addConfiguration(BundleInfoAdapter.CONF_DEFAULT);
capabilityMd.addConfiguration(BundleInfoAdapter.CONF_OPTIONAL);
capabilityMd.addConfiguration(BundleInfoAdapter.CONF_TRANSITIVE_OPTIONAL);
capabilityMd.addConfiguration(new Configuration(useConf));
DefaultDependencyDescriptor capabilityDD = new DefaultDependencyDescriptor(md.getModuleRevisionId(), false);
capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_DEFAULT, BundleInfoAdapter.CONF_NAME_DEFAULT);
capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_OPTIONAL, BundleInfoAdapter.CONF_NAME_OPTIONAL);
capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL, BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL);
capabilityDD.addDependencyConfiguration(useConf, useConf);
capabilityMd.addDependency(capabilityDD);
MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
report.setDownloadStatus(DownloadStatus.NO);
report.setSearched(true);
ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, capabilityMd, report);
return new MDResolvedResource(null, capabilityMd.getRevision(), rmr);
}
use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.
the class AbstractOSGiResolver method findBundle.
public ResolvedResource[] findBundle(DependencyDescriptor dd, ResolveData data, Collection<ModuleDescriptor> mds) {
ResolvedResource[] ret = new ResolvedResource[mds.size()];
int i = 0;
for (ModuleDescriptor md : mds) {
MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
report.setDownloadStatus(DownloadStatus.NO);
report.setSearched(true);
ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, md, report);
MDResolvedResource mdrr = new MDResolvedResource(null, md.getRevision(), rmr);
ret[i++] = mdrr;
}
return ret;
}
Aggregations