Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track whether the manifest of a bundle component has an explicit EE #1292

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.Version;
import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

Expand All @@ -92,6 +93,8 @@
*/
public class BundleComponent extends Component {

private static final String[] NO_EXECUTION_ENRIONMENTS = new String[0];

static final String TMP_API_FILE_PREFIX = "api"; //$NON-NLS-1$

/**
Expand Down Expand Up @@ -151,10 +154,18 @@ public class BundleComponent extends Component {
private final long fBundleId;

/**
* Tracks where/wehn the component was disposed to give better error message
* Tracks where/when the component was disposed to give better error message
*/
private volatile RuntimeException disposeSource;

/**
* Whether the manifest declares an explicit execution environment requirement
*
* @see #getExecutionEnvironments()
* @see #hasDeclaredRequiredEE(Map)
*/
private volatile boolean fHasDeclaredRequiredEE;

/**
* Constructs a new API component from the specified location in the file
* system in the given baseline.
Expand Down Expand Up @@ -295,6 +306,7 @@ protected void init() throws CoreException {
BundleDescription bundleDescription = getBundleDescription(manifest, fLocation, fBundleId);
fSymbolicName = bundleDescription.getSymbolicName();
fVersion = bundleDescription.getVersion();
fHasDeclaredRequiredEE = hasDeclaredRequiredEE(manifest);
setName(manifest.get(Constants.BUNDLE_NAME));
fBundleDescription = bundleDescription;
} catch (BundleException e) {
Expand Down Expand Up @@ -869,7 +881,9 @@ private static InputStream loadFixedBundleApiDescription(String bundleAndVersion

@Override
public String[] getExecutionEnvironments() throws CoreException {
return getBundleDescription().getExecutionEnvironments();
// Return the EE from the description only if explicitly specified in the
// manifest.
return fHasDeclaredRequiredEE ? getBundleDescription().getExecutionEnvironments() : NO_EXECUTION_ENRIONMENTS;
}

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

/*
* This is a copy of
* org.eclipse.pde.internal.core.MinimalState.hasDeclaredRequiredEE(Map<String,
* String>). PDE ends up adding a synthetic EE to the manifest when that method
* returns false, and that ends up in the bundle description such that we cannot
* determine whether the EE was actually present or was synthesized. So we
* repeat that computation here
*/
@SuppressWarnings("deprecation")
private boolean hasDeclaredRequiredEE(Map<String, String> manifest) {
if (manifest.containsKey(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT)) {
return true;
}
try {
String capability = manifest.get(Constants.REQUIRE_CAPABILITY);
ManifestElement[] header = ManifestElement.parseHeader(Constants.REQUIRE_CAPABILITY, capability);
return header != null && Arrays.stream(header).map(ManifestElement::getValue)
.anyMatch(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE::equals);
} catch (BundleException e) {
return false; // ignore
}
}

}
Loading