Java 类org.osgi.framework.namespace.IdentityNamespace 实例源码

项目:sbt-osgi-manager    文件:BndrunResolveContext.java   
private void constructInputRequirements() {
    List<Requirement> requires = runModel.getRunRequires();
    if (requires == null || requires.isEmpty()) {
        inputRequirementsResource = null;
    } else {
        ResourceBuilder resBuilder = new ResourceBuilder();
        CapReqBuilder identity = new CapReqBuilder(
                IdentityNamespace.IDENTITY_NAMESPACE).addAttribute(
                IdentityNamespace.IDENTITY_NAMESPACE,
                IDENTITY_INITIAL_RESOURCE);
        resBuilder.addCapability(identity);

        for (Requirement req : requires) {
            resBuilder.addRequirement(req);
        }

        inputRequirementsResource = resBuilder.build();
    }
}
项目:sbt-osgi-manager    文件:Utils.java   
static Version findIdentityVersion(Resource resource) {
    List<Capability> idCaps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
    if (idCaps == null || idCaps.isEmpty())
        throw new IllegalArgumentException("Resource has no identity capability.");
    if (idCaps.size() > 1)
        throw new IllegalArgumentException("Resource has more than one identity capability.");

    Object versionObj = idCaps.get(0).getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
    if (versionObj == null)
        return Version.emptyVersion;

    if (versionObj instanceof Version)
        return (Version) versionObj;

    if (versionObj instanceof String)
        return Version.parseVersion((String) versionObj);

    throw new IllegalArgumentException("Unable to convert type for version attribute: " + versionObj.getClass());
}
项目:osc-core    文件:PluginResolveContext.java   
private static String getIdentity(Resource resource) {
    List<Capability> caps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
    if (caps == null || caps.isEmpty()) {
           return "<unknown>";
       }

    Object idObj = caps.get(0).getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
    if (!(idObj instanceof String)) {
           return "<unknown>";
       }

    return (String) idObj;
}
项目:osc-core    文件:ResourceImpl.java   
@Override
public String toString() {
    String name = "<unknown>";
    List<Capability> idCaps = getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
    if (idCaps != null && !idCaps.isEmpty()) {
        Object nameObj = idCaps.get(0).getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
        if (nameObj instanceof String) {
               name = (String) nameObj;
           }
    }
    return name;
}
项目:osc-core    文件:DeploymentInstaller.java   
private static String getIdentity(Capability identityCap) {
    Object idObj = identityCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
    if (!(idObj instanceof String)) {
        throw new IllegalArgumentException("Missing identity capability on resource, or incorrect type");
    }

    return (String) idObj;
}
项目:osc-core    文件:DeploymentInstaller.java   
private static String getVersion(Capability identityCap) {
    Object versionObj = identityCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
    if (versionObj == null) {
        return Version.emptyVersion.toString();
    }
    if (versionObj instanceof Version) {
        return ((Version) versionObj).toString();
    }
    if (versionObj instanceof String) {
        return Version.parseVersion((String) versionObj).toString();
    }
    throw new IllegalArgumentException("Incorrect type on identity version");
}
项目:osc-core    文件:DeploymentInstaller.java   
private static Capability getIdentityCapability(Resource resource) {
    List<Capability> caps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
    if (caps == null || caps.isEmpty()) {
        throw new IllegalArgumentException("Missing identity capability on resource");
    }
    return caps.get(0);
}
项目:sbt-osgi-manager    文件:BndrunResolveContext.java   
private boolean isPermitted(Resource resource) {
    // OSGi frameworks cannot be selected as ordinary resources
    Capability fwkCap = findFrameworkContractCapability(resource);
    if (fwkCap != null) {
        return false;
    }

    // Remove osgi.core and any ee JAR
    List<Capability> idCaps = resource
            .getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
    if (idCaps == null || idCaps.isEmpty()) {
        log.log(LogService.LOG_ERROR,
                "Resource is missing an identity capability (osgi.identity).");
        return false;
    }
    if (idCaps.size() > 1) {
        log.log(LogService.LOG_ERROR,
                "Resource has more than one identity capability (osgi.identity).");
        return false;
    }
    String identity = (String) idCaps.get(0).getAttributes()
            .get(IdentityNamespace.IDENTITY_NAMESPACE);
    if (identity == null) {
        log.log(LogService.LOG_ERROR,
                "Resource is missing an identity capability (osgi.identity).");
        return false;
    }

    if ("osgi.core".equals(identity))
        return false;

    if (identity.startsWith("ee."))
        return false;

    return true;
}
项目:osc-core    文件:PluginResolveContext.java   
private static CapabilityImpl createIdentityCap(Resource resource, String identity) {
    Map<String, Object> idCapAttrs = new HashMap<>();
    idCapAttrs.put(IdentityNamespace.IDENTITY_NAMESPACE, identity);
    CapabilityImpl idCap = new CapabilityImpl(IdentityNamespace.IDENTITY_NAMESPACE, Collections.emptyMap(), idCapAttrs, resource);
    return idCap;
}
项目:osgi-jpms-layer    文件:EquinoxJPMSSupport.java   
private ModuleRevisionBuilder createBuilder(ModuleReference ref) {
    ModuleDescriptor desc = ref.descriptor();
    ModuleRevisionBuilder builder = new ModuleRevisionBuilder();
    builder.setSymbolicName(desc.name());

    Version version = desc.version().map((v) -> {
        try {
            return Version.valueOf(v.toString());
        } catch (IllegalArgumentException e) {
            return Version.emptyVersion;
        }
    }).orElse(Version.emptyVersion);
    builder.setVersion(version);

    // add bundle and identity capabilities, do not create host capability for JPMS
    builder.addCapability(
            BundleNamespace.BUNDLE_NAMESPACE,
            Map.of(),
            Map.of(
                    BundleNamespace.BUNDLE_NAMESPACE, desc.name(),
                    BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, version));
    builder.addCapability(
            IdentityNamespace.IDENTITY_NAMESPACE,
            Map.of(),
            Map.of(
                    IdentityNamespace.IDENTITY_NAMESPACE, desc.name(),
                    IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version));

    for(Exports exports : desc.exports()) {
        // TODO map targets to x-friends directive.
        builder.addCapability(
                PackageNamespace.PACKAGE_NAMESPACE,
                Map.of(),
                Map.of(PackageNamespace.PACKAGE_NAMESPACE, exports.source()));
    }

    for(Provides provides : desc.provides()) {
        builder.addCapability(
                JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE,
                Map.of(),
                Map.of(
                        JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE, provides.service(),
                        JpmsServiceNamespace.CAPABILITY_PROVIDES_WITH, provides.providers()));
    }

    for (Requires requires : desc.requires()) {
        Map<String, String> directives = new HashMap<>();

        // determine the resolution value based on the STATIC modifier
        String resolution = requires.modifiers().contains(Requires.Modifier.STATIC) ? Namespace.RESOLUTION_OPTIONAL : Namespace.RESOLUTION_MANDATORY;
        directives.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, resolution);
        // determine the visibility value based on the TRANSITIVE modifier
        String visibility = requires.modifiers().contains(Requires.Modifier.TRANSITIVE) ? BundleNamespace.VISIBILITY_REEXPORT : BundleNamespace.VISIBILITY_PRIVATE;
        directives.put(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE, visibility);
        // create a bundle filter based on the requires name 
        directives.put(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + BundleNamespace.BUNDLE_NAMESPACE + "=" + requires.name() + ")");

        builder.addRequirement(BundleNamespace.BUNDLE_NAMESPACE, directives, Collections.emptyMap());
    }

    for(String uses : desc.uses()) {
        builder.addRequirement(JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE,
                Map.of(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL,
                        Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE + "=" + uses + ")"),
                Map.of(JpmsServiceNamespace.JPMS_SERVICE_NAMESPACE, uses));
    }
    return builder;
}
项目:sbt-osgi-manager    文件:BndrunResolveContext.java   
private void findFramework() {
    String header = runModel.getRunFw();
    if (header == null)
        return;

    // Get the identity and version of the requested JAR
    Parameters params = new Parameters(header);
    if (params.size() > 1)
        throw new IllegalArgumentException(
                "Cannot specify more than one OSGi Framework.");
    Entry<String, Attrs> entry = params.entrySet().iterator().next();
    String identity = entry.getKey();

    String versionStr = entry.getValue().get("version");

    // Construct a filter & requirement to find matches
    Filter filter = new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE,
            identity);
    if (versionStr != null)
        filter = new AndFilter().addChild(filter).addChild(
                new LiteralFilter(Filters.fromVersionRange(versionStr)));
    Requirement frameworkReq = new CapReqBuilder(
            IdentityNamespace.IDENTITY_NAMESPACE).addDirective(
            Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString())
            .buildSyntheticRequirement();

    // Iterate over repos looking for matches
    for (Repository repo : repos) {
        Map<Requirement, Collection<Capability>> providers = repo
                .findProviders(Collections.singletonList(frameworkReq));
        Collection<Capability> frameworkCaps = providers.get(frameworkReq);
        if (frameworkCaps != null) {
            for (Capability frameworkCap : frameworkCaps) {
                if (findFrameworkContractCapability(frameworkCap
                        .getResource()) != null) {
                    Version foundVersion = toVersion(frameworkCap
                            .getAttributes()
                            .get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE));
                    if (foundVersion != null) {
                        if (frameworkResourceVersion == null
                                || (foundVersion
                                        .compareTo(frameworkResourceVersion) > 0)) {
                            frameworkResource = frameworkCap.getResource();
                            frameworkResourceVersion = foundVersion;
                            frameworkResourceRepo = new FrameworkResourceRepository(
                                    frameworkResource, ee, sysPkgsExtra,
                                    sysCapsExtraParams);
                        }
                    }
                }
            }
        }
    }
}
项目:sbt-osgi-manager    文件:BndrunResolveContext.java   
public static boolean isInputRequirementResource(Resource resource) {
    Capability id = resource.getCapabilities(
            IdentityNamespace.IDENTITY_NAMESPACE).get(0);
    return IDENTITY_INITIAL_RESOURCE.equals(id.getAttributes().get(
            IdentityNamespace.IDENTITY_NAMESPACE));
}