use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class OSGiManifestBuilderFactory method addPackageImports.
private static void addPackageImports(ModuleRevisionBuilder builder, ManifestElement[] importElements, Collection<String> importPackageNames, boolean dynamic) throws BundleException {
if (importElements == null)
return;
for (ManifestElement importElement : importElements) {
String[] packageNames = importElement.getValueComponents();
Map<String, Object> attributes = getAttributes(importElement);
Map<String, String> directives = getDirectives(importElement);
directives.remove(PackageNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE);
directives.remove(PackageNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE);
if (dynamic) {
directives.put(PackageNamespace.REQUIREMENT_RESOLUTION_DIRECTIVE, PackageNamespace.RESOLUTION_DYNAMIC);
}
String versionRangeAttr = (String) attributes.remove(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
@SuppressWarnings("deprecation") String specVersionRangeAttr = (String) attributes.remove(Constants.PACKAGE_SPECIFICATION_VERSION);
VersionRange versionRange = versionRangeAttr == null ? (specVersionRangeAttr == null ? null : new VersionRange(specVersionRangeAttr)) : new VersionRange(versionRangeAttr);
String bundleVersionRangeAttr = (String) attributes.remove(PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
VersionRange bundleVersionRange = bundleVersionRangeAttr == null ? null : new VersionRange(bundleVersionRangeAttr);
// the attribute "optional" used to be used in old versions of equinox to specify optional imports
// preserving behavior for compatibility
Object optionalAttr = attributes.remove(Namespace.RESOLUTION_OPTIONAL);
for (String packageName : packageNames) {
if (!dynamic) {
importPackageNames.add(packageName);
}
// fill in the filter directive based on the attributes
Map<String, String> packageDirectives = new HashMap<>(directives);
StringBuilder filter = new StringBuilder();
filter.append('(').append(PackageNamespace.PACKAGE_NAMESPACE).append('=').append(packageName).append(')');
int size = filter.length();
for (Map.Entry<String, Object> attribute : attributes.entrySet()) filter.append('(').append(attribute.getKey()).append('=').append(attribute.getValue()).append(')');
if (versionRange != null)
filter.append(versionRange.toFilterString(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE));
if (bundleVersionRange != null)
filter.append(bundleVersionRange.toFilterString(PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
if (size != filter.length())
// need to add (&...)
// $NON-NLS-1$
filter.insert(0, "(&").append(')');
packageDirectives.put(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
// fill in cardinality for dynamic wild cards
if (dynamic && packageName.indexOf('*') >= 0)
packageDirectives.put(PackageNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE, PackageNamespace.CARDINALITY_MULTIPLE);
// check the old optional attribute
if ("true".equals(optionalAttr) && packageDirectives.get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE) == null) {
// $NON-NLS-1$
packageDirectives.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
}
builder.addRequirement(PackageNamespace.PACKAGE_NAMESPACE, packageDirectives, new HashMap<String, Object>(0));
}
}
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class OSGiManifestBuilderFactory method getProvideCapabilities.
private static void getProvideCapabilities(ModuleRevisionBuilder builder, ManifestElement[] provideElements, boolean checkSystemCapabilities) throws BundleException {
if (provideElements == null)
return;
for (ManifestElement provideElement : provideElements) {
String[] namespaces = provideElement.getValueComponents();
Map<String, Object> attributes = getAttributes(provideElement);
Map<String, String> directives = getDirectives(provideElement);
for (String namespace : namespaces) {
if (PROHIBITED_CAPABILITIES.contains(namespace) || (checkSystemCapabilities && SYSTEM_CAPABILITIES.contains(namespace))) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new BundleException("A bundle is not allowed to define a capability in the " + namespace + " name space.", BundleException.MANIFEST_ERROR);
}
builder.addCapability(namespace, directives, attributes);
}
}
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class OSGiManifestBuilderFactory method getRequireBundle.
private static void getRequireBundle(ModuleRevisionBuilder builder, ManifestElement[] requireBundles) throws BundleException {
if (requireBundles == null)
return;
for (ManifestElement requireElement : requireBundles) {
String[] bundleNames = requireElement.getValueComponents();
Map<String, Object> attributes = getAttributes(requireElement);
Map<String, String> directives = getDirectives(requireElement);
directives.remove(BundleNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE);
directives.remove(BundleNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE);
String versionRangeAttr = (String) attributes.remove(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
VersionRange versionRange = versionRangeAttr == null ? null : new VersionRange(versionRangeAttr);
// These two attrs are used as directives in previous versions of equinox
// Preserving behavior for compatibility reasons.
Object optionalAttr = attributes.remove(Namespace.RESOLUTION_OPTIONAL);
Object reprovideAttr = attributes.remove(ATTR_OLD_REPRIVIDE);
for (String bundleName : bundleNames) {
if (bundleName.equals(builder.getSymbolicName())) {
// ignore requirements to ourself
continue;
}
// fill in the filter directive based on the attributes
Map<String, String> bundleDirectives = new HashMap<>(directives);
StringBuilder filter = new StringBuilder();
filter.append('(').append(BundleNamespace.BUNDLE_NAMESPACE).append('=').append(bundleName).append(')');
int size = filter.length();
for (Map.Entry<String, Object> attribute : attributes.entrySet()) filter.append('(').append(attribute.getKey()).append('=').append(attribute.getValue()).append(')');
if (versionRange != null)
filter.append(versionRange.toFilterString(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
if (size != filter.length())
// need to add (&...)
// $NON-NLS-1$
filter.insert(0, "(&").append(')');
bundleDirectives.put(BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
// check the old compatibility attributes
if ("true".equals(optionalAttr) && bundleDirectives.get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE) == null) {
// $NON-NLS-1$
bundleDirectives.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
}
if ("true".equals(reprovideAttr) && bundleDirectives.get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE) == null) {
// $NON-NLS-1$
bundleDirectives.put(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE, BundleNamespace.VISIBILITY_REEXPORT);
}
builder.addRequirement(BundleNamespace.BUNDLE_NAMESPACE, bundleDirectives, new HashMap<String, Object>(0));
}
}
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class OSGiManifestBuilderFactory method getFragmentHost.
private static void getFragmentHost(ModuleRevisionBuilder builder, ManifestElement[] fragmentHosts) throws BundleException {
if (fragmentHosts == null || fragmentHosts.length == 0)
return;
ManifestElement fragmentHost = fragmentHosts[0];
String hostName = fragmentHost.getValue();
Map<String, Object> attributes = getAttributes(fragmentHost);
Map<String, String> directives = getDirectives(fragmentHost);
directives.remove(HostNamespace.REQUIREMENT_CARDINALITY_DIRECTIVE);
directives.remove(HostNamespace.REQUIREMENT_EFFECTIVE_DIRECTIVE);
String versionRangeAttr = (String) attributes.remove(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
VersionRange versionRange = versionRangeAttr == null ? null : new VersionRange(versionRangeAttr);
// fill in the filter directive based on the attributes
StringBuilder filter = new StringBuilder();
filter.append('(').append(HostNamespace.HOST_NAMESPACE).append('=').append(hostName).append(')');
int size = filter.length();
for (Map.Entry<String, Object> attribute : attributes.entrySet()) filter.append('(').append(attribute.getKey()).append('=').append(attribute.getValue()).append(')');
if (versionRange != null)
filter.append(versionRange.toFilterString(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
if (size != filter.length())
// need to add (&...)
// $NON-NLS-1$
filter.insert(0, "(&").append(')');
directives.put(BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
builder.addRequirement(HostNamespace.HOST_NAMESPACE, directives, new HashMap<String, Object>(0));
// Add a fragment capability to advertise what host this resource is providing a fragment for
directives = Collections.singletonMap(EquinoxModuleDataNamespace.CAPABILITY_EFFECTIVE_DIRECTIVE, EquinoxModuleDataNamespace.EFFECTIVE_INFORMATION);
builder.addCapability(EquinoxFragmentNamespace.FRAGMENT_NAMESPACE, directives, Collections.<String, Object>singletonMap(EquinoxFragmentNamespace.FRAGMENT_NAMESPACE, hostName));
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class OSGiManifestBuilderFactory method getPackageExports.
private static void getPackageExports(ModuleRevisionBuilder builder, ManifestElement[] exportElements, Object symbolicName, Collection<Map<String, Object>> exportedPackages) throws BundleException {
if (exportElements == null)
return;
for (ManifestElement exportElement : exportElements) {
String[] packageNames = exportElement.getValueComponents();
Map<String, Object> attributes = getAttributes(exportElement);
Map<String, String> directives = getDirectives(exportElement);
directives.remove(PackageNamespace.CAPABILITY_EFFECTIVE_DIRECTIVE);
String versionAttr = (String) attributes.remove(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
@SuppressWarnings("deprecation") String specVersionAttr = (String) attributes.remove(Constants.PACKAGE_SPECIFICATION_VERSION);
Version version = versionAttr == null ? (specVersionAttr == null ? Version.emptyVersion : Version.parseVersion(specVersionAttr)) : Version.parseVersion(versionAttr);
attributes.put(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
if (symbolicName != null) {
attributes.put(PackageNamespace.CAPABILITY_BUNDLE_SYMBOLICNAME_ATTRIBUTE, symbolicName);
}
attributes.put(PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, builder.getVersion());
for (String packageName : packageNames) {
Map<String, Object> packageAttrs = new HashMap<>(attributes);
packageAttrs.put(PackageNamespace.PACKAGE_NAMESPACE, packageName);
builder.addCapability(PackageNamespace.PACKAGE_NAMESPACE, directives, packageAttrs);
exportedPackages.add(packageAttrs);
}
}
}
Aggregations