|
82 | 82 | import org.osgi.framework.Constants;
|
83 | 83 | import org.osgi.framework.FrameworkUtil;
|
84 | 84 | import org.osgi.framework.Version;
|
| 85 | +import org.osgi.framework.namespace.ExecutionEnvironmentNamespace; |
85 | 86 | import org.xml.sax.InputSource;
|
86 | 87 | import org.xml.sax.SAXException;
|
87 | 88 |
|
|
92 | 93 | */
|
93 | 94 | public class BundleComponent extends Component {
|
94 | 95 |
|
| 96 | + private static final String[] NO_EXECUTION_ENRIONMENTS = new String[0]; |
| 97 | + |
95 | 98 | static final String TMP_API_FILE_PREFIX = "api"; //$NON-NLS-1$
|
96 | 99 |
|
97 | 100 | /**
|
@@ -151,10 +154,18 @@ public class BundleComponent extends Component {
|
151 | 154 | private final long fBundleId;
|
152 | 155 |
|
153 | 156 | /**
|
154 |
| - * Tracks where/wehn the component was disposed to give better error message |
| 157 | + * Tracks where/when the component was disposed to give better error message |
155 | 158 | */
|
156 | 159 | private volatile RuntimeException disposeSource;
|
157 | 160 |
|
| 161 | + /** |
| 162 | + * Whether the manifest declares an explicit execution environment requirement |
| 163 | + * |
| 164 | + * @see #getExecutionEnvironments() |
| 165 | + * @see #hasDeclaredRequiredEE(Map) |
| 166 | + */ |
| 167 | + private volatile boolean fHasDeclaredRequiredEE; |
| 168 | + |
158 | 169 | /**
|
159 | 170 | * Constructs a new API component from the specified location in the file
|
160 | 171 | * system in the given baseline.
|
@@ -295,6 +306,7 @@ protected void init() throws CoreException {
|
295 | 306 | BundleDescription bundleDescription = getBundleDescription(manifest, fLocation, fBundleId);
|
296 | 307 | fSymbolicName = bundleDescription.getSymbolicName();
|
297 | 308 | fVersion = bundleDescription.getVersion();
|
| 309 | + fHasDeclaredRequiredEE = hasDeclaredRequiredEE(manifest); |
298 | 310 | setName(manifest.get(Constants.BUNDLE_NAME));
|
299 | 311 | fBundleDescription = bundleDescription;
|
300 | 312 | } catch (BundleException e) {
|
@@ -869,7 +881,9 @@ private static InputStream loadFixedBundleApiDescription(String bundleAndVersion
|
869 | 881 |
|
870 | 882 | @Override
|
871 | 883 | public String[] getExecutionEnvironments() throws CoreException {
|
872 |
| - return getBundleDescription().getExecutionEnvironments(); |
| 884 | + // Return the EE from the description only if explicitly specified in the |
| 885 | + // manifest. |
| 886 | + return fHasDeclaredRequiredEE ? getBundleDescription().getExecutionEnvironments() : NO_EXECUTION_ENRIONMENTS; |
873 | 887 | }
|
874 | 888 |
|
875 | 889 | @Override
|
@@ -1185,4 +1199,27 @@ protected void baselineDisposed(IApiBaseline baseline) throws CoreException {
|
1185 | 1199 | NLS.bind(Messages.BundleApiComponent_baseline_disposed, getName(), baseline.getName()), disposeSource));
|
1186 | 1200 | }
|
1187 | 1201 |
|
| 1202 | + /* |
| 1203 | + * This is a copy of |
| 1204 | + * org.eclipse.pde.internal.core.MinimalState.hasDeclaredRequiredEE(Map<String, |
| 1205 | + * String>). PDE ends up adding a synthetic EE to the manifest when that method |
| 1206 | + * returns false, and that ends up in the bundle description such that we cannot |
| 1207 | + * determine whether the EE was actually present or was synthesized. So we |
| 1208 | + * repeat that computation here |
| 1209 | + */ |
| 1210 | + @SuppressWarnings("deprecation") |
| 1211 | + private boolean hasDeclaredRequiredEE(Map<String, String> manifest) { |
| 1212 | + if (manifest.containsKey(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT)) { |
| 1213 | + return true; |
| 1214 | + } |
| 1215 | + try { |
| 1216 | + String capability = manifest.get(Constants.REQUIRE_CAPABILITY); |
| 1217 | + ManifestElement[] header = ManifestElement.parseHeader(Constants.REQUIRE_CAPABILITY, capability); |
| 1218 | + return header != null && Arrays.stream(header).map(ManifestElement::getValue) |
| 1219 | + .anyMatch(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE::equals); |
| 1220 | + } catch (BundleException e) { |
| 1221 | + return false; // ignore |
| 1222 | + } |
| 1223 | + } |
| 1224 | + |
1188 | 1225 | }
|
0 commit comments