Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2012-01-18 20:51:04 +0000
committerThomas Watson2012-01-18 20:51:04 +0000
commit1adfd1b247f8446241bd426923dacb428c59d539 (patch)
tree2f4a08e28ca958196ff56fae10379deeb4f48327 /bundles/org.eclipse.osgi/resolver
parent1c32ce7a576a33732ac92fac2d4cbe8ee6cc57d2 (diff)
downloadrt.equinox.framework-1adfd1b247f8446241bd426923dacb428c59d539.tar.gz
rt.equinox.framework-1adfd1b247f8446241bd426923dacb428c59d539.tar.xz
rt.equinox.framework-1adfd1b247f8446241bd426923dacb428c59d539.zip
Bug 368829 - [R5] Represent required execution environment as required
capability in osgi.ee namespace
Diffstat (limited to 'bundles/org.eclipse.osgi/resolver')
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java124
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java42
2 files changed, 161 insertions, 5 deletions
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java
index a2b6e5a71..d679d2e7d 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -100,7 +100,8 @@ public class StateBuilder {
}
result.setLocation(location);
result.setPlatformFilter(manifest.get(Constants.ECLIPSE_PLATFORMFILTER));
- result.setExecutionEnvironments(ManifestElement.getArrayFromList(manifest.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT)));
+ String[] brees = ManifestElement.getArrayFromList(manifest.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT));
+ result.setExecutionEnvironments(brees);
ManifestElement[] host = ManifestElement.parseHeader(Constants.FRAGMENT_HOST, manifest.get(Constants.FRAGMENT_HOST));
if (host != null)
result.setHost(createHostSpecification(host[0], state));
@@ -117,7 +118,7 @@ public class StateBuilder {
String[][] genericAliases = getGenericAliases(state);
ManifestElement[] genericRequires = getGenericRequires(manifest, genericAliases);
ManifestElement[] osgiRequires = ManifestElement.parseHeader(Constants.REQUIRE_CAPABILITY, manifest.get(Constants.REQUIRE_CAPABILITY));
- result.setGenericRequires(createGenericRequires(genericRequires, osgiRequires));
+ result.setGenericRequires(createGenericRequires(genericRequires, osgiRequires, brees));
ManifestElement[] genericCapabilities = getGenericCapabilities(manifest, genericAliases);
ManifestElement[] osgiCapabilities = ManifestElement.parseHeader(Constants.PROVIDE_CAPABILITY, manifest.get(Constants.PROVIDE_CAPABILITY));
result.setGenericCapabilities(createGenericCapabilities(genericCapabilities, osgiCapabilities, result));
@@ -478,12 +479,127 @@ public class StateBuilder {
return result;
}
- private static GenericSpecification[] createGenericRequires(ManifestElement[] equinoxRequires, ManifestElement[] osgiRequires) throws BundleException {
+ private static GenericSpecification[] createGenericRequires(ManifestElement[] equinoxRequires, ManifestElement[] osgiRequires, String[] brees) throws BundleException {
List<GenericSpecification> result = createEquinoxRequires(equinoxRequires);
result = createOSGiRequires(osgiRequires, result);
+ result = convertBREEs(brees, result);
return result == null ? null : result.toArray(new GenericSpecification[result.size()]);
}
+ static List<GenericSpecification> convertBREEs(String[] brees, List<GenericSpecification> result) throws BundleException {
+ if (brees == null || brees.length == 0)
+ return result;
+ if (result == null)
+ result = new ArrayList<GenericSpecification>(brees.length);
+ List<String> breeFilters = new ArrayList<String>();
+ for (String bree : brees)
+ breeFilters.add(createOSGiEERequirementFilter(bree));
+ String filterSpec;
+ if (breeFilters.size() == 1) {
+ filterSpec = breeFilters.get(0);
+ } else {
+ StringBuffer filterBuf = new StringBuffer("(|"); //$NON-NLS-1$
+ for (String breeFilter : breeFilters) {
+ filterBuf.append(breeFilter);
+ }
+ filterSpec = filterBuf.append(")").toString(); //$NON-NLS-1$
+ }
+ GenericSpecificationImpl spec = new GenericSpecificationImpl();
+ spec.setType("osgi.ee"); //$NON-NLS-1$
+ try {
+ FilterImpl filter = FilterImpl.newInstance(filterSpec);
+ spec.setMatchingFilter(filter);
+ String name = filter.getPrimaryKeyValue(spec.getType());
+ if (name != null)
+ spec.setName(name);
+ } catch (InvalidSyntaxException e) {
+ throw new BundleException("Error converting required execution environment.", e); //$NON-NLS-1$
+ }
+ result.add(spec);
+ return result;
+ }
+
+ private static String createOSGiEERequirementFilter(String bree) throws BundleException {
+ String[] nameVersion = getOSGiEENameVersion(bree);
+ String eeName = nameVersion[0];
+ String v = nameVersion[1];
+ String filterSpec;
+ if (v == null)
+ filterSpec = "(osgi.ee=" + eeName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ else
+ filterSpec = "(&(osgi.ee=" + eeName + ")(version=" + v + "))"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ try {
+ // do a sanity check
+ FilterImpl.newInstance(filterSpec);
+ } catch (InvalidSyntaxException e) {
+ filterSpec = "(osgi.ee=" + bree + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ // do another sanity check
+ FilterImpl.newInstance(filterSpec);
+ } catch (InvalidSyntaxException e1) {
+ throw new BundleException("Error converting required execution environment.", e1); //$NON-NLS-1$
+ }
+ }
+ return filterSpec;
+ }
+
+ static String[] getOSGiEENameVersion(String bree) {
+ String ee1 = null;
+ String ee2 = null;
+ String v1 = null;
+ String v2 = null;
+ int separator = bree.indexOf('/');
+ if (separator <= 0 || separator == bree.length() - 1) {
+ ee1 = bree;
+ } else {
+ ee1 = bree.substring(0, separator);
+ ee2 = bree.substring(separator + 1);
+ }
+ int v1idx = ee1.indexOf('-');
+ if (v1idx > 0 && v1idx < ee1.length() - 1) {
+ // check for > 0 to avoid EEs starting with -
+ // check for < len - 1 to avoid ending with -
+ try {
+ v1 = ee1.substring(v1idx + 1);
+ // sanity check version format
+ Version.parseVersion(v1);
+ ee1 = ee1.substring(0, v1idx);
+ } catch (IllegalArgumentException e) {
+ v1 = null;
+ }
+ }
+
+ int v2idx = ee2 == null ? -1 : ee2.indexOf('-');
+ if (v2idx > 0 && v2idx < ee2.length() - 1) {
+ // check for > 0 to avoid EEs starting with -
+ // check for < len - 1 to avoid ending with -
+ try {
+ v2 = ee2.substring(v2idx + 1);
+ Version.parseVersion(v2);
+ ee2 = ee2.substring(0, v2idx);
+ } catch (IllegalArgumentException e) {
+ v2 = null;
+ }
+ }
+
+ if (v1 == null)
+ v1 = v2;
+ if (v1 != null && v2 != null && !v1.equals(v2)) {
+ ee1 = bree;
+ ee2 = null;
+ v1 = null;
+ v2 = null;
+ }
+ if ("J2SE".equals(ee1)) //$NON-NLS-1$
+ ee1 = "JavaSE"; //$NON-NLS-1$
+ if ("J2SE".equals(ee2)) //$NON-NLS-1$
+ ee2 = "JavaSE"; //$NON-NLS-1$
+
+ String eeName = ee1 + (ee2 == null ? "" : '/' + ee2); //$NON-NLS-1$
+
+ return new String[] {eeName, v1};
+ }
+
static List<GenericSpecification> createOSGiRequires(ManifestElement[] osgiRequires, List<GenericSpecification> result) throws BundleException {
if (osgiRequires == null)
return result;
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
index 383b33a78..78ee9354e 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -791,6 +791,7 @@ public abstract class StateImpl implements State {
performResetSystemExports |= checkProp(this.platformProperties[i].get(Constants.SYSTEM_BUNDLE_SYMBOLICNAME), newPlatformProperties[i].get(Constants.SYSTEM_BUNDLE_SYMBOLICNAME));
performResetSystemCapabilities |= checkProp(this.platformProperties[i].get(Constants.FRAMEWORK_SYSTEMCAPABILITIES), newPlatformProperties[i].get(Constants.FRAMEWORK_SYSTEMCAPABILITIES));
performResetSystemCapabilities |= checkProp(this.platformProperties[i].get(Constants.FRAMEWORK_SYSTEMCAPABILITIES_EXTRA), newPlatformProperties[i].get(Constants.FRAMEWORK_SYSTEMCAPABILITIES_EXTRA));
+ performResetSystemCapabilities |= checkProp(this.platformProperties[i].get(Constants.FRAMEWORK_EXECUTIONENVIRONMENT), newPlatformProperties[i].get(Constants.FRAMEWORK_EXECUTIONENVIRONMENT));
}
}
}
@@ -865,11 +866,50 @@ public abstract class StateImpl implements State {
try {
addSystemCapabilities(capabilities, ManifestElement.parseHeader(Constants.PROVIDE_CAPABILITY, (String) platformProperties[i].get(Constants.FRAMEWORK_SYSTEMCAPABILITIES)), i);
addSystemCapabilities(capabilities, ManifestElement.parseHeader(Constants.PROVIDE_CAPABILITY, (String) platformProperties[i].get(Constants.FRAMEWORK_SYSTEMCAPABILITIES_EXTRA)), i);
+ checkOSGiEE(capabilities, (String) platformProperties[i].get(Constants.FRAMEWORK_EXECUTIONENVIRONMENT), i);
} catch (BundleException e) {
// TODO consider throwing this...
}
}
+ private void checkOSGiEE(List<GenericDescription> capabilities, String profileEE, Integer profileIndex) {
+ if (profileEE == null || profileEE.length() == 0)
+ return;
+ for (GenericDescription capability : capabilities) {
+ if ("osgi.ee".equals(capability.getType()) && profileIndex.equals(capability.getAttributes().get(ExportPackageDescriptionImpl.EQUINOX_EE))) //$NON-NLS-1$
+ return; // profile already specifies osgi.ee capabilities
+ }
+ Map<String, List<String>> eeVersions = new HashMap<String, List<String>>();
+ String[] ees = ManifestElement.getArrayFromList(profileEE);
+ for (String ee : ees) {
+ String[] eeNameVersion = StateBuilder.getOSGiEENameVersion(ee);
+
+ List<String> versions = eeVersions.get(eeNameVersion[0]);
+ if (versions == null) {
+ versions = new ArrayList<String>();
+ eeVersions.put(eeNameVersion[0], versions);
+ }
+ if (eeNameVersion[1] != null && !versions.contains(eeNameVersion[1]))
+ versions.add(eeNameVersion[1]);
+ }
+ for (Map.Entry<String, List<String>> eeVersion : eeVersions.entrySet()) {
+ GenericDescriptionImpl capability = new GenericDescriptionImpl();
+ capability.setType("osgi.ee"); //$NON-NLS-1$
+ Dictionary<String, Object> attributes = new Hashtable<String, Object>();
+ attributes.put(capability.getType(), eeVersion.getKey());
+ if (eeVersion.getValue().size() > 0) {
+ List<Version> versions = new ArrayList<Version>(eeVersion.getValue().size());
+ for (String version : eeVersion.getValue()) {
+ versions.add(new Version(version));
+ }
+ attributes.put("version", versions); //$NON-NLS-1$
+ }
+ attributes.put(ExportPackageDescriptionImpl.EQUINOX_EE, profileIndex);
+ capability.setAttributes(attributes);
+ capabilities.add(capability);
+ }
+ }
+
private void addSystemCapabilities(List<GenericDescription> capabilities, ManifestElement[] elements, Integer profileIndex) {
try {
StateBuilder.createOSGiCapabilities(elements, capabilities, profileIndex);

Back to the top