use of org.apache.ivy.core.module.descriptor.WorkspaceModuleDescriptor in project ant-ivy by apache.
the class AbstractWorkspaceResolver method checkCandidate.
protected ResolvedModuleRevision checkCandidate(DependencyDescriptor dd, ModuleDescriptor md, String workspaceModuleName) {
if (workspaceModuleName == null) {
workspaceModuleName = dd.getDependencyId().toString();
}
ModuleRevisionId dependencyMrid = dd.getDependencyRevisionId();
String org = dependencyMrid.getModuleId().getOrganisation();
String module = dependencyMrid.getModuleId().getName();
VersionMatcher versionMatcher = getSettings().getVersionMatcher();
ModuleRevisionId candidateMrid = md.getModuleRevisionId();
switch(org) {
case BundleInfo.BUNDLE_TYPE:
// looking for an OSGi bundle via its symbolic name
String sn = md.getExtraInfoContentByTagName("Bundle-SymbolicName");
if (sn == null || !module.equals(sn)) {
// not found, skip to next
return null;
}
break;
case BundleInfo.PACKAGE_TYPE:
// looking for an OSGi bundle via its exported package
String exportedPackages = md.getExtraInfoContentByTagName("Export-Package");
if (exportedPackages == null) {
// not found, skip to next
return null;
}
boolean found = false;
String version = null;
ManifestHeaderValue exportElements;
try {
exportElements = new ManifestHeaderValue(exportedPackages);
} catch (ParseException e) {
// wrong OSGi header: skip it
return null;
}
for (ManifestHeaderElement exportElement : exportElements.getElements()) {
if (exportElement.getValues().contains(module)) {
found = true;
version = exportElement.getAttributes().get("version");
break;
}
}
if (!found) {
// not found, skip to next
return null;
}
if (version == null) {
// no version means anything can match. Let's trick the version matcher by
// setting the exact expected version
version = dependencyMrid.getRevision();
}
md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(org, module, version));
break;
default:
if (!candidateMrid.getModuleId().equals(dependencyMrid.getModuleId())) {
// it doesn't match org#module, skip to next
return null;
}
break;
}
Message.verbose("Workspace resolver found potential matching workspace module " + workspaceModuleName + " with module " + candidateMrid + " for module " + dependencyMrid);
if (!ignoreBranch) {
ModuleId mid = dependencyMrid.getModuleId();
String defaultBranch = getSettings().getDefaultBranch(mid);
String dependencyBranch = dependencyMrid.getBranch();
String candidateBranch = candidateMrid.getBranch();
if (dependencyBranch == null) {
dependencyBranch = defaultBranch;
}
if (candidateBranch == null) {
candidateBranch = defaultBranch;
}
if (dependencyBranch != candidateBranch) {
// Both cannot be null
if (dependencyBranch == null || candidateBranch == null) {
Message.verbose("\t\trejected since branches doesn't match (one is set, the other isn't)");
return null;
}
if (!dependencyBranch.equals(candidateBranch)) {
Message.verbose("\t\trejected since branches doesn't match");
return null;
}
}
}
// Found one; check if it is for the module we need
if (!ignoreVersion && !md.getModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision()) && !versionMatcher.accept(dd.getDependencyRevisionId(), md)) {
Message.verbose("\t\treject as version didn't match");
return null;
}
if (ignoreVersion) {
Message.verbose("\t\tmatched (version are ignored)");
} else {
Message.verbose("\t\tversion matched");
}
WorkspaceModuleDescriptor workspaceMd = createWorkspaceMd(md);
Artifact mdaf = md.getMetadataArtifact();
if (mdaf == null) {
mdaf = new DefaultArtifact(md.getModuleRevisionId(), md.getPublicationDate(), workspaceModuleName, "ivy", "");
}
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(mdaf);
madr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
madr.setSearched(true);
return new ResolvedModuleRevision(this, this, workspaceMd, madr);
}
Aggregations