Search in sources :

Example 6 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.

the class OSGiManifestBuilderFactory method validateHeaders.

private static void validateHeaders(Map<String, String> manifest) throws BundleException {
    for (int i = 0; i < DEFINED_OSGI_VALIDATE_HEADERS.length; i++) {
        String header = manifest.get(DEFINED_OSGI_VALIDATE_HEADERS[i]);
        if (header != null) {
            ManifestElement[] elements = ManifestElement.parseHeader(DEFINED_OSGI_VALIDATE_HEADERS[i], header);
            checkForDuplicateDirectivesAttributes(DEFINED_OSGI_VALIDATE_HEADERS[i], elements);
            if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.IMPORT_PACKAGE)
                checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, false, false);
            if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.DYNAMICIMPORT_PACKAGE)
                checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, false, true);
            if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.EXPORT_PACKAGE)
                checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, true, false);
            if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.FRAGMENT_HOST)
                checkExtensionBundle(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, manifest);
        } else if (DEFINED_OSGI_VALIDATE_HEADERS[i] == Constants.BUNDLE_SYMBOLICNAME) {
            // $NON-NLS-1$
            throw new BundleException(Constants.BUNDLE_SYMBOLICNAME + " header is required.", BundleException.MANIFEST_ERROR);
        }
    }
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) BundleException(org.osgi.framework.BundleException)

Example 7 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.

the class DynamicImportList method validateSyntaxAndCheckPackagePermission.

private void validateSyntaxAndCheckPackagePermission(String dynamicImportPackageDescription) {
    ManifestElement[] clauses;
    // Validate the syntax of imports that are added.
    try {
        clauses = ManifestElement.parseHeader(Constants.IMPORT_PACKAGE, dynamicImportPackageDescription);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return;
    // for each dynamic import added.
    for (ManifestElement clause : clauses) for (String pkg : clause.getValueComponents()) sm.checkPermission(new PackagePermission(pkg, PackagePermission.IMPORT));
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) PackagePermission(org.osgi.framework.PackagePermission)

Example 8 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.

the class StateObjectFactoryImpl method createImportPackageSpecifications.

public List<ImportPackageSpecification> createImportPackageSpecifications(String declaration) {
    try {
        ManifestElement[] elements = ManifestElement.parseHeader(Constants.IMPORT_PACKAGE, declaration);
        if (elements == null)
            return Collections.<ImportPackageSpecification>emptyList();
        List<ImportPackageSpecification> result = new ArrayList<>(elements.length);
        for (ManifestElement element : elements) StateBuilder.addImportPackages(element, result, 2, false);
        return result;
    } catch (BundleException e) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("Declaration is invalid: " + declaration, e);
    }
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement)

Example 9 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.

the class StateObjectFactoryImpl method createBundleSpecifications.

public List<BundleSpecification> createBundleSpecifications(String declaration) {
    try {
        ManifestElement[] elements = ManifestElement.parseHeader(Constants.REQUIRE_BUNDLE, declaration);
        if (elements == null)
            return Collections.<BundleSpecification>emptyList();
        List<BundleSpecification> result = new ArrayList<>(elements.length);
        for (ManifestElement element : elements) result.add(StateBuilder.createRequiredBundle(element));
        return result;
    } catch (BundleException e) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("Declaration is invalid: " + declaration, e);
    }
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement)

Example 10 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project rt.equinox.framework by eclipse.

the class StateObjectFactoryImpl method createExportPackageDescriptions.

public List<ExportPackageDescription> createExportPackageDescriptions(String declaration) {
    try {
        ManifestElement[] elements = ManifestElement.parseHeader(Constants.IMPORT_PACKAGE, declaration);
        if (elements == null)
            return Collections.<ExportPackageDescription>emptyList();
        List<ExportPackageDescription> result = new ArrayList<>(elements.length);
        for (ManifestElement element : elements) StateBuilder.addExportPackages(element, result, false);
        return result;
    } catch (BundleException e) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("Declaration is invalid: " + declaration, e);
    }
}
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