Search in sources :

Example 1 with ManifestHeaderElement

use of org.apache.ivy.osgi.core.ManifestHeaderElement 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);
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ManifestHeaderValue(org.apache.ivy.osgi.core.ManifestHeaderValue) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DefaultWorkspaceModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultWorkspaceModuleDescriptor) WorkspaceModuleDescriptor(org.apache.ivy.core.module.descriptor.WorkspaceModuleDescriptor) ModuleId(org.apache.ivy.core.module.id.ModuleId) ManifestHeaderElement(org.apache.ivy.osgi.core.ManifestHeaderElement) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) ParseException(java.text.ParseException) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact)

Aggregations

ParseException (java.text.ParseException)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)1 DefaultWorkspaceModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultWorkspaceModuleDescriptor)1 WorkspaceModuleDescriptor (org.apache.ivy.core.module.descriptor.WorkspaceModuleDescriptor)1 ModuleId (org.apache.ivy.core.module.id.ModuleId)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)1 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)1 ManifestHeaderElement (org.apache.ivy.osgi.core.ManifestHeaderElement)1 ManifestHeaderValue (org.apache.ivy.osgi.core.ManifestHeaderValue)1 VersionMatcher (org.apache.ivy.plugins.version.VersionMatcher)1