use of org.eclipse.osgi.util.ManifestElement in project derby by apache.
the class DerbyUtils method launch.
// another launch mechanism
public void launch() throws CoreException {
DerbyPlugin plugin = DerbyPlugin.getDefault();
// constructs a classpath from the default JRE...
IPath systemLibs = new Path(JavaRuntime.JRE_CONTAINER);
IRuntimeClasspathEntry systemLibsEntry = JavaRuntime.newRuntimeContainerClasspathEntry(systemLibs, IRuntimeClasspathEntry.STANDARD_CLASSES);
systemLibsEntry.setClasspathProperty(IRuntimeClasspathEntry.BOOTSTRAP_CLASSES);
// include org.apache.derby.core plugin
IRuntimeClasspathEntry derbyCPEntry = null;
List classpath = new ArrayList();
classpath.add(systemLibsEntry.getMemento());
try {
ManifestElement[] elements_core, elements_ui;
elements_core = getElements(CommonNames.CORE_PATH);
elements_ui = getElements(CommonNames.UI_PATH);
Bundle bundle;
URL pluginURL, jarURL, localURL;
bundle = Platform.getBundle(CommonNames.CORE_PATH);
pluginURL = bundle.getEntry("/");
for (int i = 0; i < elements_core.length; i++) {
if (!elements_core[i].getValue().toLowerCase().endsWith("derbynet.jar")) {
jarURL = new URL(pluginURL, elements_core[i].getValue());
localURL = Platform.asLocalURL(jarURL);
derbyCPEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(localURL.getPath()));
derbyCPEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
classpath.add(derbyCPEntry.getMemento());
}
}
bundle = Platform.getBundle(CommonNames.CORE_PATH);
pluginURL = bundle.getEntry("/");
for (int i = 0; i < elements_ui.length; i++) {
if (!elements_ui[i].getValue().toLowerCase().equals("ui.jar")) {
jarURL = new URL(pluginURL, elements_ui[i].getValue());
localURL = Platform.asLocalURL(jarURL);
derbyCPEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(localURL.getPath()));
derbyCPEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
classpath.add(derbyCPEntry.getMemento());
}
}
} catch (Exception e) {
e.printStackTrace();
Logger.log("Error in launch() " + e, IStatus.ERROR);
}
}
use of org.eclipse.osgi.util.ManifestElement in project eclipse.platform.releng by eclipse.
the class EclipseTestRunner method loadSuiteClass.
/**
* Loads the class either with the system class loader or a plugin class
* loader if a plugin name was specified
*/
protected Class<?> loadSuiteClass(String suiteClassName) throws ClassNotFoundException {
if (fTestPluginName == null)
return Class.forName(suiteClassName);
Bundle bundle = Platform.getBundle(fTestPluginName);
if (bundle == null) {
throw new ClassNotFoundException(suiteClassName, new Exception("Could not find plugin \"" + fTestPluginName + "\""));
}
// is the plugin a fragment?
Dictionary<String, String> headers = bundle.getHeaders();
String hostHeader = headers.get(Constants.FRAGMENT_HOST);
if (hostHeader != null) {
// we are a fragment for sure
// we need to find which is our host
ManifestElement[] hostElement = null;
try {
hostElement = ManifestElement.parseHeader(Constants.FRAGMENT_HOST, hostHeader);
} catch (BundleException e) {
throw new RuntimeException("Could not find host for fragment:" + fTestPluginName, e);
}
Bundle host = Platform.getBundle(hostElement[0].getValue());
// we really want to get the host not the fragment
bundle = host;
}
return bundle.loadClass(suiteClassName);
}
use of org.eclipse.osgi.util.ManifestElement in project tesb-studio-se by Talend.
the class DependenciesCoreUtil method getManifestItems.
private static Collection<? extends ManifestItem> getManifestItems(Map<?, ?> map, String header) {
final Object data = map.get(header);
if (null != data) {
final Collection<ManifestItem> list = new ArrayList<ManifestItem>();
final String s = data.toString();
if (!s.isEmpty()) {
try {
for (ManifestElement me : ManifestElement.parseHeader(header, data.toString())) {
final ManifestItem item = ManifestItem.newItem(header);
item.setName(me.getValue());
item.setVersion(me.getAttribute(item.getVersionAttribute()));
item.setOptional(Constants.RESOLUTION_OPTIONAL.equals(me.getDirective(Constants.RESOLUTION_DIRECTIVE)));
item.setDescription(MessageFormat.format(Messages.DependenciesCoreUtil_userDefined, header));
list.add(item);
}
} catch (BundleException e) {
ExceptionHandler.process(e);
}
}
return list;
}
return null;
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class OSGiManifestBuilderFactory method getSymbolicNameAndVersion.
private static Object getSymbolicNameAndVersion(ModuleRevisionBuilder builder, Map<String, String> manifest, String symbolicNameAlias, int manifestVersion) throws BundleException {
boolean isFragment = manifest.get(Constants.FRAGMENT_HOST) != null;
builder.setTypes(isFragment ? BundleRevision.TYPE_FRAGMENT : 0);
String version = manifest.get(Constants.BUNDLE_VERSION);
try {
builder.setVersion((version != null) ? Version.parseVersion(version) : Version.emptyVersion);
} catch (IllegalArgumentException ex) {
if (manifestVersion >= 2) {
String message = NLS.bind(Msg.OSGiManifestBuilderFactory_InvalidManifestError, Constants.BUNDLE_VERSION, version);
throw new BundleException(message, BundleException.MANIFEST_ERROR, ex);
}
// prior to R4 the Bundle-Version header was not interpreted by the Framework;
// must not fail for old R3 style bundles
}
Object symbolicName = null;
String symbolicNameHeader = manifest.get(Constants.BUNDLE_SYMBOLICNAME);
if (symbolicNameHeader != null) {
ManifestElement[] symbolicNameElements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, symbolicNameHeader);
if (symbolicNameElements.length > 0) {
ManifestElement bsnElement = symbolicNameElements[0];
builder.setSymbolicName(bsnElement.getValue());
if (symbolicNameAlias != null) {
List<String> result = new ArrayList<>();
result.add(builder.getSymbolicName());
result.add(symbolicNameAlias);
symbolicName = result;
} else {
symbolicName = builder.getSymbolicName();
}
Map<String, String> directives = getDirectives(bsnElement);
directives.remove(BundleNamespace.CAPABILITY_USES_DIRECTIVE);
directives.remove(BundleNamespace.CAPABILITY_EFFECTIVE_DIRECTIVE);
Map<String, Object> attributes = getAttributes(bsnElement);
if (!directives.containsKey(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE)) {
// previous versions of equinox treated the singleton attribute as a directive
Object singletonAttr = attributes.get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE);
if ("true".equals(singletonAttr)) {
// $NON-NLS-1$
directives.put(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE, (String) singletonAttr);
}
}
if (!isFragment) {
// create the bundle namespace
Map<String, Object> bundleAttributes = new HashMap<>(attributes);
bundleAttributes.put(BundleNamespace.BUNDLE_NAMESPACE, symbolicName);
bundleAttributes.put(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, builder.getVersion());
builder.addCapability(BundleNamespace.BUNDLE_NAMESPACE, directives, bundleAttributes);
// only if the directive is not never
if (!HostNamespace.FRAGMENT_ATTACHMENT_NEVER.equals(directives.get(HostNamespace.CAPABILITY_FRAGMENT_ATTACHMENT_DIRECTIVE))) {
Map<String, Object> hostAttributes = new HashMap<>(attributes);
hostAttributes.put(HostNamespace.HOST_NAMESPACE, symbolicName);
hostAttributes.put(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, builder.getVersion());
builder.addCapability(HostNamespace.HOST_NAMESPACE, directives, hostAttributes);
}
}
// every bundle that has a symbolic name gets an identity;
// never use the symbolic name alias for the identity namespace
Map<String, Object> identityAttributes = new HashMap<>(attributes);
identityAttributes.put(IdentityNamespace.IDENTITY_NAMESPACE, builder.getSymbolicName());
identityAttributes.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, builder.getVersion());
identityAttributes.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, isFragment ? IdentityNamespace.TYPE_FRAGMENT : IdentityNamespace.TYPE_BUNDLE);
builder.addCapability(IdentityNamespace.IDENTITY_NAMESPACE, directives, identityAttributes);
}
}
return symbolicName == null ? symbolicNameAlias : symbolicName;
}
use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.
the class OSGiManifestBuilderFactory method getRequireCapabilities.
private static void getRequireCapabilities(ModuleRevisionBuilder builder, ManifestElement[] requireElements) throws BundleException {
if (requireElements == null)
return;
for (ManifestElement requireElement : requireElements) {
String[] namespaces = requireElement.getValueComponents();
Map<String, Object> attributes = getAttributes(requireElement);
Map<String, String> directives = getDirectives(requireElement);
for (String namespace : namespaces) {
builder.addRequirement(namespace, directives, attributes);
}
}
}
Aggregations