Search in sources :

Example 16 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project tycho by eclipse.

the class StandardExecutionEnvironment method parseEEVersion.

private EEVersion parseEEVersion(String systemCaps) {
    List<EEVersion> eeVersions = new ArrayList<>();
    try {
        ManifestElement[] systemCapValues = ManifestElement.parseHeader("org.osgi.framework.system.capabilities", systemCaps);
        for (int i = 0; i < systemCapValues.length; i++) {
            Version version;
            String singleVersion = systemCapValues[i].getAttribute("version:Version");
            if (singleVersion != null) {
                version = Version.parseVersion(singleVersion);
            } else {
                String[] versions = systemCapValues[i].getAttribute("version:List<Version>").split(",");
                List<Version> osgiVersions = new ArrayList<>(versions.length);
                for (String currentVersion : versions) {
                    osgiVersions.add(Version.parseVersion(currentVersion));
                }
                version = Collections.max(osgiVersions);
            }
            String execEnv = systemCapValues[i].getAttribute("osgi.ee");
            EEType eeType = EEType.fromName(execEnv);
            if (eeType != null) {
                eeVersions.add(new EEVersion(version, eeType));
            }
        }
        return Collections.max(eeVersions);
    } catch (BundleException e) {
        throw new RuntimeException(e);
    }
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) ArrayList(java.util.ArrayList) EEType(org.eclipse.tycho.core.ee.EEVersion.EEType) Version(org.osgi.framework.Version) BundleException(org.osgi.framework.BundleException)

Example 17 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project tycho by eclipse.

the class MutableBundleManifest method getRequiredBundleVersions.

/**
 * Read the RequiredBundle with optional versions
 *
 * @return
 */
public Map<String, String> getRequiredBundleVersions() {
    ManifestElement[] requireBundleElements = parseHeader(Constants.REQUIRE_BUNDLE);
    if (requireBundleElements == null || requireBundleElements.length == 0) {
        return Collections.emptyMap();
    }
    Map<String, String> result = new HashMap<>();
    for (ManifestElement manifestElement : requireBundleElements) {
        String symbolicName = manifestElement.getValue();
        String versionRangeString = manifestElement.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
        result.put(symbolicName, versionRangeString);
    }
    return result;
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) HashMap(java.util.HashMap)

Example 18 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project tycho by eclipse.

the class MutableBundleManifest method getImportPackagesVersions.

/**
 * Get a map containing the name of packages in Import-Package manifest attribute as a map.
 * <p>
 * The map keys are the package names and the values are the version range if present or null
 * when absent.
 *
 * @return
 */
public Map<String, String> getImportPackagesVersions() {
    ManifestElement[] importPackageElements = parseHeader(Constants.IMPORT_PACKAGE);
    if (importPackageElements == null || importPackageElements.length == 0) {
        return Collections.emptyMap();
    }
    Map<String, String> result = new HashMap<>();
    for (ManifestElement manifestElement : importPackageElements) {
        String packageName = manifestElement.getValue();
        String versionRangeString = manifestElement.getAttribute(Constants.VERSION_ATTRIBUTE);
        result.put(packageName, versionRangeString);
    }
    return result;
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) HashMap(java.util.HashMap)

Example 19 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project tycho by eclipse.

the class MutableBundleManifest method getExportedPackagesVersion.

/**
 * Get a map containing the name of packages in Export-Package manifest attribute as a map.
 *
 * @return the package/version map. Keys are the package names and the values are the version if
 *         present or null when absent.
 */
public Map<String, String> getExportedPackagesVersion() {
    ManifestElement[] exportPackageElements = parseHeader(Constants.EXPORT_PACKAGE);
    if (exportPackageElements == null || exportPackageElements.length == 0) {
        return Collections.emptyMap();
    }
    Map<String, String> result = new HashMap<>();
    for (ManifestElement manifestElement : exportPackageElements) {
        String packageName = manifestElement.getValue();
        String versionRangeString = manifestElement.getAttribute(Constants.VERSION_ATTRIBUTE);
        result.put(packageName, versionRangeString);
    }
    return result;
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) HashMap(java.util.HashMap)

Example 20 with ManifestElement

use of org.eclipse.osgi.util.ManifestElement in project tycho by eclipse.

the class MutableManifestElement method parseHeader.

public static List<MutableManifestElement> parseHeader(String name, String value) throws BundleException {
    ManifestElement[] manifestElements = ManifestElement.parseHeader(name, value);
    if (manifestElements == null) {
        return null;
    }
    List<MutableManifestElement> mutableManifestElements = new ArrayList<>();
    for (ManifestElement manifestElement : manifestElements) {
        mutableManifestElements.add(new MutableManifestElement(manifestElement));
    }
    return mutableManifestElements;
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) ArrayList(java.util.ArrayList)

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