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

项目:osgi-jpms-layer    文件:BundlePackage.java   
static BundlePackage createExportPackage(BundleCapability packageCap) {
    String name = (String) packageCap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
    if (name == null) {
        return null;
    }
    Set<String> friendsSet = Collections.emptySet();
    String friendsDir = packageCap.getDirectives().get("x-friends");
    if (friendsDir != null) {
        String[] friends = friendsDir == null ? new String[0] : friendsDir.split(",");
        for (int i = 0; i < friends.length; i++) {
            friends[i] = friends[i].trim();
        }
        // did not use Set.of(E...) because of bad meta-data that can have duplicate friends
        friendsSet = new HashSet<>(Arrays.asList(friends));
    }
    return new BundlePackage(name, friendsSet);
}
项目:sbt-osgi-manager    文件:FrameworkResourceRepository.java   
private void loadJREPackages() {
    InputStream stream = FrameworkResourceRepository.class.getResourceAsStream(ee.name() + ".properties");
    if (stream != null) {
        try {
            Properties properties = new Properties();
            properties.load(stream);

            Parameters params = new Parameters(properties.getProperty("org.osgi.framework.system.packages", ""));
            for (String packageName : params.keySet()) {
                CapReqBuilder builder = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
                builder.addAttribute(PackageNamespace.PACKAGE_NAMESPACE, packageName);
                builder.addAttribute(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, new Version(0, 0, 0));
                Capability cap = builder.setResource(framework).buildCapability();
                capIndex.addCapability(cap);
            }
        } catch (IOException e) {
            throw new IllegalStateException("Error loading JRE package properties", e);
        }
    }
}
项目: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;
}