Search in sources :

Example 21 with ManifestElement

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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ManifestElement(org.eclipse.osgi.util.ManifestElement) IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) BundleException(org.osgi.framework.BundleException) DerbyPlugin(org.apache.derby.ui.DerbyPlugin)

Example 22 with ManifestElement

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);
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) URISyntaxException(java.net.URISyntaxException) SWTException(org.eclipse.swt.SWTException) BundleException(org.osgi.framework.BundleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 23 with ManifestElement

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;
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) ManifestItem(org.talend.designer.camel.dependencies.core.model.ManifestItem) ArrayList(java.util.ArrayList) BundleException(org.osgi.framework.BundleException)

Example 24 with ManifestElement

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;
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BundleException(org.osgi.framework.BundleException)

Example 25 with ManifestElement

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);
        }
    }
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement)

Aggregations

ManifestElement (org.eclipse.osgi.util.ManifestElement)34 BundleException (org.osgi.framework.BundleException)14 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)3 Attributes (java.util.jar.Attributes)3 VersionRange (org.osgi.framework.VersionRange)3 File (java.io.File)2 JarFile (java.util.jar.JarFile)2 Bundle (org.osgi.framework.Bundle)2 Version (org.osgi.framework.Version)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 List (java.util.List)1 Manifest (java.util.jar.Manifest)1 DerbyPlugin (org.apache.derby.ui.DerbyPlugin)1 Verifier (org.apache.maven.it.Verifier)1 BuildException (org.apache.tools.ant.BuildException)1