Skip to content

Commit

Permalink
API error on SWT on a 4.34 master
Browse files Browse the repository at this point in the history
Don't try to add EE to bundles that don't have any requirements defined
in manifest.

ManifestUtils.getRequiredExecutionEnvironments() currently returns
"generic" bundle runtime requirements from OSGI for bundles that don't
define anything, and it seem to be violation of the
org.osgi.framework.wiring.BundleRevision.getDeclaredRequirements(String)
contract that isn't supposed to return anything if nothing is specified
in the manifest.

At least for API baseline tooling use of OSGI generic requirements not
specified in the manifest do not make sense, as we compare what's
written in the manifest and not what is derived from the platform or
host.

Fixes eclipse-pde#1386
  • Loading branch information
iloveeclipse committed Sep 4, 2024
1 parent 6506ee6 commit b2c330e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.pde.api.tools;singleton:=true
Bundle-Version: 1.3.500.qualifier
Bundle-Version: 1.3.600.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
Expand Down
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_ENVIRONMENTS = new String[0];

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

/**
Expand Down Expand Up @@ -310,7 +313,12 @@ protected void init() throws CoreException {
BundleDescription bundleDescription = getBundleDescription(manifest, fLocation, fBundleId);
fSymbolicName = bundleDescription.getSymbolicName();
fVersion = bundleDescription.getVersion();
fdeclaredRequiredEE = ManifestUtils.getRequiredExecutionEnvironments(bundleDescription).toArray(String[]::new);
if (hasDeclaredRequiredEE(manifest)) {
fdeclaredRequiredEE = ManifestUtils.getRequiredExecutionEnvironments(bundleDescription)
.toArray(String[]::new);
} else {
fdeclaredRequiredEE = NO_EXECUTION_ENVIRONMENTS;
}
setName(manifest.get(Constants.BUNDLE_NAME));
fBundleDescription = bundleDescription;
} catch (BundleException e) {
Expand Down Expand Up @@ -1204,4 +1212,28 @@ protected void baselineDisposed(IApiBaseline baseline) throws CoreException {
new Object[] { getName(), baseline.getName(), Thread.currentThread().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
}
}

}

0 comments on commit b2c330e

Please sign in to comment.