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 #1386
  • Loading branch information
iloveeclipse committed Sep 5, 2024
1 parent 0953a33 commit 84827f7
Showing 1 changed file with 33 additions and 1 deletion.
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 84827f7

Please sign in to comment.