Skip to content

Commit 0c2fe3d

Browse files
merksfedejeanne
authored andcommitted
Track whether the manifest of a bundle component has an explicit EE
eclipse-pde#1283
1 parent a647544 commit 0c2fe3d

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java

+39-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.osgi.framework.Constants;
8383
import org.osgi.framework.FrameworkUtil;
8484
import org.osgi.framework.Version;
85+
import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
8586
import org.xml.sax.InputSource;
8687
import org.xml.sax.SAXException;
8788

@@ -92,6 +93,8 @@
9293
*/
9394
public class BundleComponent extends Component {
9495

96+
private static final String[] NO_EXECUTION_ENRIONMENTS = new String[0];
97+
9598
static final String TMP_API_FILE_PREFIX = "api"; //$NON-NLS-1$
9699

97100
/**
@@ -151,10 +154,18 @@ public class BundleComponent extends Component {
151154
private final long fBundleId;
152155

153156
/**
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
155158
*/
156159
private volatile RuntimeException disposeSource;
157160

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+
158169
/**
159170
* Constructs a new API component from the specified location in the file
160171
* system in the given baseline.
@@ -295,6 +306,7 @@ protected void init() throws CoreException {
295306
BundleDescription bundleDescription = getBundleDescription(manifest, fLocation, fBundleId);
296307
fSymbolicName = bundleDescription.getSymbolicName();
297308
fVersion = bundleDescription.getVersion();
309+
fHasDeclaredRequiredEE = hasDeclaredRequiredEE(manifest);
298310
setName(manifest.get(Constants.BUNDLE_NAME));
299311
fBundleDescription = bundleDescription;
300312
} catch (BundleException e) {
@@ -869,7 +881,9 @@ private static InputStream loadFixedBundleApiDescription(String bundleAndVersion
869881

870882
@Override
871883
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;
873887
}
874888

875889
@Override
@@ -1185,4 +1199,27 @@ protected void baselineDisposed(IApiBaseline baseline) throws CoreException {
11851199
NLS.bind(Messages.BundleApiComponent_baseline_disposed, getName(), baseline.getName()), disposeSource));
11861200
}
11871201

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+
11881225
}

0 commit comments

Comments
 (0)