use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class OSGiManifestBuilderFactory method getEquinoxDataCapability.
@SuppressWarnings("deprecation")
private static void getEquinoxDataCapability(ModuleRevisionBuilder builder, Map<String, String> manifest) throws BundleException {
Map<String, Object> attributes = new HashMap<>();
// Get the activation policy attributes
ManifestElement[] policyElements = ManifestElement.parseHeader(Constants.BUNDLE_ACTIVATIONPOLICY, manifest.get(Constants.BUNDLE_ACTIVATIONPOLICY));
if (policyElements != null) {
ManifestElement policy = policyElements[0];
String policyName = policy.getValue();
if (EquinoxModuleDataNamespace.CAPABILITY_ACTIVATION_POLICY_LAZY.equals(policyName)) {
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_ACTIVATION_POLICY, policyName);
String includeSpec = policy.getDirective(Constants.INCLUDE_DIRECTIVE);
if (includeSpec != null) {
// $NON-NLS-1$
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_LAZY_INCLUDE_ATTRIBUTE, convertValueWithNoWhitespace("List<String>", includeSpec));
}
String excludeSpec = policy.getDirective(Constants.EXCLUDE_DIRECTIVE);
if (excludeSpec != null) {
// $NON-NLS-1$
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_LAZY_EXCLUDE_ATTRIBUTE, convertValueWithNoWhitespace("List<String>", excludeSpec));
}
}
} else {
policyElements = ManifestElement.parseHeader(EquinoxModuleDataNamespace.LAZYSTART_HEADER, manifest.get(EquinoxModuleDataNamespace.LAZYSTART_HEADER));
if (policyElements == null) {
policyElements = ManifestElement.parseHeader(EquinoxModuleDataNamespace.AUTOSTART_HEADER, manifest.get(EquinoxModuleDataNamespace.AUTOSTART_HEADER));
}
if (policyElements != null) {
ManifestElement policy = policyElements[0];
String excludeSpec = policy.getAttribute(EquinoxModuleDataNamespace.LAZYSTART_EXCEPTIONS_ATTRIBUTE);
if ("true".equals(policy.getValue())) {
// $NON-NLS-1$
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_ACTIVATION_POLICY, EquinoxModuleDataNamespace.CAPABILITY_ACTIVATION_POLICY_LAZY);
if (excludeSpec != null) {
// $NON-NLS-1$
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_LAZY_EXCLUDE_ATTRIBUTE, convertValueWithNoWhitespace("List<String>", excludeSpec));
}
} else {
// NOTICE - the exclude list gets converted to an include list when the header is not true
if (excludeSpec != null) {
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_ACTIVATION_POLICY, EquinoxModuleDataNamespace.CAPABILITY_ACTIVATION_POLICY_LAZY);
// $NON-NLS-1$
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_LAZY_INCLUDE_ATTRIBUTE, convertValueWithNoWhitespace("List<String>", excludeSpec));
}
}
}
}
// Get the activator
String activator = manifest.get(Constants.BUNDLE_ACTIVATOR);
if (activator == null && manifest.get(Constants.FRAGMENT_HOST) != null) {
// we look for the extension activator for fragments
// probably should do this only for framework extensions, but there is no harm to check for others
// it is only acted upon for framework extension fragments
activator = manifest.get(Constants.EXTENSION_BUNDLE_ACTIVATOR);
}
if (activator != null) {
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_ACTIVATOR, activator);
}
// Get the class path
ManifestElement[] classpathElements = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, manifest.get(Constants.BUNDLE_CLASSPATH));
if (classpathElements != null) {
List<String> classpath = new ArrayList<>();
for (ManifestElement element : classpathElements) {
String[] components = element.getValueComponents();
for (String component : components) {
classpath.add(component);
}
}
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_CLASSPATH, classpath);
}
// Get the buddy policy list
ManifestElement[] buddyPolicies = ManifestElement.parseHeader(EquinoxModuleDataNamespace.BUDDY_POLICY_HEADER, manifest.get(EquinoxModuleDataNamespace.BUDDY_POLICY_HEADER));
if (buddyPolicies != null) {
List<String> policies = new ArrayList<>();
for (ManifestElement element : buddyPolicies) {
for (String component : element.getValueComponents()) {
policies.add(component);
}
}
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_BUDDY_POLICY, policies);
}
// Get the registered buddy list
ManifestElement[] registeredBuddies = ManifestElement.parseHeader(EquinoxModuleDataNamespace.REGISTERED_BUDDY_HEADER, manifest.get(EquinoxModuleDataNamespace.REGISTERED_BUDDY_HEADER));
if (registeredBuddies != null) {
List<String> buddies = new ArrayList<>();
for (ManifestElement element : registeredBuddies) {
for (String component : element.getValueComponents()) {
buddies.add(component);
}
}
attributes.put(EquinoxModuleDataNamespace.CAPABILITY_BUDDY_REGISTERED, buddies);
}
// only create the capability if the attributes is not empty
if (!attributes.isEmpty()) {
Map<String, String> directives = Collections.singletonMap(EquinoxModuleDataNamespace.CAPABILITY_EFFECTIVE_DIRECTIVE, EquinoxModuleDataNamespace.EFFECTIVE_INFORMATION);
builder.addCapability(EquinoxModuleDataNamespace.MODULE_DATA_NAMESPACE, directives, attributes);
}
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class WovenClassImpl method callHooks.
byte[] callHooks() throws Throwable {
SecurityManager sm = System.getSecurityManager();
byte[] wovenBytes = null;
List<String> newImports = null;
boolean rejected = false;
try {
if (sm == null) {
registry.notifyHooksPrivileged(this);
} else {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
public Void run() {
registry.notifyHooksPrivileged(WovenClassImpl.this);
return null;
}
});
} catch (PrivilegedActionException e) {
throw (RuntimeException) e.getException();
}
}
} finally {
if ((hookFlags & FLAG_HOOKCALLED) != 0) {
for (ClassLoaderHook classLoaderHook : container.getConfiguration().getHookRegistry().getClassLoaderHooks()) {
rejected |= classLoaderHook.rejectTransformation(className, resultBytes, classpathEntry, entry, loader.getModuleClassLoader().getClasspathManager());
}
if (!rejected) {
wovenBytes = resultBytes;
newImports = dynamicImports;
}
setHooksComplete();
// Make sure setHooksComplete() has been called. The woven class
// must be immutable in TRANSFORMED or TRANSFORMING_FAILED.
// If error is not null, a weaving hook threw an exception.
setState(error == null ? TRANSFORMED : TRANSFORMING_FAILED);
// only notify listeners if the transformation was not rejected
if (!rejected) {
notifyWovenClassListeners();
}
}
}
if (error != null)
throw error;
if (newImports != null) {
// add any new dynamic imports
for (String newImport : newImports) {
try {
ManifestElement[] importElements = ManifestElement.parseHeader(Constants.IMPORT_PACKAGE, newImport);
// Grant implied import package permissions for all dynamic
// import packages to the woven bundle.
addImpliedImportPackagePermissions(importElements);
loader.addDynamicImportPackage(importElements);
} catch (BundleException e) {
// should not have happened; checked at add.
}
}
}
return wovenBytes;
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class BundleLoader method addDynamicImportPackage.
/**
* Adds a list of DynamicImport-Package manifest elements to the dynamic
* import tables of this BundleLoader. Duplicate packages are checked and
* not added again.
* @param packages the DynamicImport-Package elements to add.
*/
public final void addDynamicImportPackage(ManifestElement[] packages) {
if (packages == null)
return;
List<String> dynamicImports = new ArrayList<>(packages.length);
StringBuilder importSpec = new StringBuilder();
for (ManifestElement dynamicImportElement : packages) {
String[] names = dynamicImportElement.getValueComponents();
for (String name : names) dynamicImports.add(name);
if (importSpec.length() > 0) {
importSpec.append(',');
}
importSpec.append(dynamicImportElement.toString());
}
if (dynamicImports.size() > 0) {
addDynamicImportPackage(dynamicImports.toArray(new String[dynamicImports.size()]));
Map<String, String> dynamicImportMap = new HashMap<>();
dynamicImportMap.put(Constants.DYNAMICIMPORT_PACKAGE, importSpec.toString());
try {
ModuleRevisionBuilder builder = OSGiManifestBuilderFactory.createBuilder(dynamicImportMap);
wiring.addDynamicImports(builder);
} catch (BundleException e) {
throw new RuntimeException(e);
}
}
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class StateObjectFactoryImpl method createBundleDescription.
public BundleDescription createBundleDescription(long id, String symbolicName, Version version, String location, BundleSpecification[] required, HostSpecification host, ImportPackageSpecification[] imports, ExportPackageDescription[] exports, String platformFilter, String[] executionEnvironments, GenericSpecification[] genericRequires, GenericDescription[] genericCapabilities, NativeCodeSpecification nativeCode) {
BundleDescriptionImpl bundle = new BundleDescriptionImpl();
bundle.setBundleId(id);
try {
ManifestElement[] symbolicNameElements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
if (symbolicNameElements != null && symbolicNameElements.length > 0) {
ManifestElement bsnElement = symbolicNameElements[0];
bundle.setSymbolicName(bsnElement.getValue());
// $NON-NLS-1$
bundle.setStateBit(BundleDescriptionImpl.SINGLETON, "true".equals(bsnElement.getDirective(Constants.SINGLETON_DIRECTIVE)));
String fragmentAttachment = bsnElement.getDirective(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE);
if (fragmentAttachment != null) {
if (fragmentAttachment.equals(Constants.FRAGMENT_ATTACHMENT_RESOLVETIME)) {
bundle.setStateBit(BundleDescriptionImpl.ATTACH_FRAGMENTS, true);
bundle.setStateBit(BundleDescriptionImpl.DYNAMIC_FRAGMENTS, false);
} else if (fragmentAttachment.equals(Constants.FRAGMENT_ATTACHMENT_NEVER)) {
bundle.setStateBit(BundleDescriptionImpl.ATTACH_FRAGMENTS, false);
bundle.setStateBit(BundleDescriptionImpl.DYNAMIC_FRAGMENTS, false);
}
}
bundle.setDirective(Constants.MANDATORY_DIRECTIVE, ManifestElement.getArrayFromList(bsnElement.getDirective(Constants.MANDATORY_DIRECTIVE)));
bundle.setAttributes(StateBuilder.getAttributes(bsnElement, StateBuilder.DEFINED_BSN_MATCHING_ATTRS));
bundle.setArbitraryDirectives(StateBuilder.getDirectives(bsnElement, StateBuilder.DEFINED_BSN_DIRECTIVES));
}
} catch (BundleException e) {
// $NON-NLS-1$
throw new IllegalArgumentException("Illegal symbolic name: " + symbolicName, e);
}
bundle.setVersion(version);
bundle.setLocation(location);
bundle.setRequiredBundles(required);
bundle.setHost(host);
bundle.setImportPackages(imports);
bundle.setExportPackages(exports);
bundle.setPlatformFilter(platformFilter);
bundle.setExecutionEnvironments(executionEnvironments);
bundle.setGenericRequires(genericRequires);
List<GenericDescription> includeIdentity = new ArrayList<>(genericCapabilities == null ? 1 : genericCapabilities.length + 1);
GenericDescription genericIdentity = StateBuilder.createOsgiIdentityCapability(bundle);
if (genericIdentity != null) {
includeIdentity.add(genericIdentity);
}
if (genericCapabilities != null) {
for (GenericDescription genericDescription : genericCapabilities) {
includeIdentity.add(genericDescription);
}
}
if (!includeIdentity.isEmpty()) {
bundle.setGenericCapabilities(includeIdentity.toArray(new GenericDescription[includeIdentity.size()]));
}
bundle.setNativeCodeSpecification(nativeCode);
return bundle;
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class StateObjectFactoryImpl method createHostSpecifications.
public List<HostSpecification> createHostSpecifications(String declaration) {
try {
ManifestElement[] elements = ManifestElement.parseHeader(Constants.FRAGMENT_HOST, declaration);
if (elements == null)
return Collections.<HostSpecification>emptyList();
List<HostSpecification> result = new ArrayList<>(elements.length);
for (ManifestElement element : elements) result.add(StateBuilder.createHostSpecification(element, null));
return result;
} catch (BundleException e) {
// $NON-NLS-1$
throw new IllegalArgumentException("Declaration is invalid: " + declaration, e);
}
}
Aggregations