Skip to content

Commit a82ae8b

Browse files
committed
Always consider fragments that specify a platform filter
A fragment can declare a Eclipse-PlatformFilter to be only installed on a given platform. If such fragment is currently wired to a host bundle, it is quite likely that fragment is needed but the host usually do not declare an Eclipse-ExtensibleAPI so we currently miss to add such fragment making the native code loading fails. This now adds some code to store the platform filter and if one is given the fragment is always included. Fix #1929
1 parent d9ad053 commit a82ae8b

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathUtilCore.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ public static boolean hasExtensibleAPI(IPluginModelBase model) {
224224
return false;
225225
}
226226

227+
public static String getPlatformFilter(IPluginModelBase model) {
228+
IPluginBase pluginBase = model.getPluginBase();
229+
if (pluginBase instanceof BundlePlugin plugin) {
230+
return plugin.getPlatformFilter();
231+
}
232+
if (pluginBase instanceof BundleFragment fragment) {
233+
return fragment.getPlatformFilter();
234+
}
235+
return null;
236+
}
237+
227238
public static boolean isPatchFragment(Resource desc) {
228239
IPluginModelBase model = PluginRegistry.findModel(desc);
229240
return model instanceof IFragmentModel i ? isPatchFragment(i.getFragment()) : false;

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/DependencyManager.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ public enum Options {
6868
* Specifies to include all non-test fragments into the closure (must
6969
* not be combined with {@link #INCLUDE_ALL_FRAGMENTS}).
7070
*/
71-
INCLUDE_NON_TEST_FRAGMENTS;
71+
INCLUDE_NON_TEST_FRAGMENTS,
72+
/**
73+
* Option that can be set to include native fragments, that are ones
74+
* that define an {@link ICoreConstants#PLATFORM_FILTER} in their
75+
* manifest.
76+
*/
77+
INCLUDE_NATIVE_FRAGMENTS;
7278
}
7379

7480
/**
@@ -168,6 +174,7 @@ public static Set<BundleDescription> findRequirementsClosure(Collection<BundleDe
168174
boolean includeOptional = optionSet.contains(Options.INCLUDE_OPTIONAL_DEPENDENCIES);
169175
boolean includeAllFragments = optionSet.contains(Options.INCLUDE_ALL_FRAGMENTS);
170176
boolean includeNonTestFragments = optionSet.contains(Options.INCLUDE_NON_TEST_FRAGMENTS);
177+
boolean includeNativeFragments = optionSet.contains(Options.INCLUDE_NATIVE_FRAGMENTS);
171178
if (includeAllFragments && includeNonTestFragments) {
172179
throw new AssertionError("Cannot combine INCLUDE_ALL_FRAGMENTS and INCLUDE_NON_TEST_FRAGMENTS"); //$NON-NLS-1$
173180
}
@@ -195,6 +202,12 @@ public static Set<BundleDescription> findRequirementsClosure(Collection<BundleDe
195202
addNewRequiredBundle(fragment, closure, pending);
196203
}
197204
}
205+
} else if (includeNativeFragments) {
206+
for (BundleDescription fragment : bundle.getFragments()) {
207+
if (isNativeFragment(fragment) && !isTestWorkspaceProject(fragment)) {
208+
addNewRequiredBundle(fragment, closure, pending);
209+
}
210+
}
198211
}
199212

200213
if (isFragment(wiring.getRevision())) {
@@ -231,6 +244,14 @@ public static Set<BundleDescription> findRequirementsClosure(Collection<BundleDe
231244
return closure;
232245
}
233246

247+
private static boolean isNativeFragment(BundleDescription fragment) {
248+
Object userObject = fragment.getUserObject();
249+
if (userObject instanceof IPluginModelBase model) {
250+
return ClasspathUtilCore.getPlatformFilter(model) != null;
251+
}
252+
return false;
253+
}
254+
234255
private static boolean isExtensibleApi(BundleDescription bundleDescription) {
235256
if (bundleDescription.getFragments().length == 0) {
236257
return false;

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEAuxiliaryState.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static class PluginInfo {
9797
String localization;
9898
String bundleSourceEntry;
9999
boolean exportsExternalAnnotations;
100+
String platformFilter;
100101
}
101102

102103
/**
@@ -379,6 +380,7 @@ protected void addAuxiliaryData(BundleDescription desc, Map<String, String> mani
379380
info.libraries = getClasspath(manifest);
380381
info.hasExtensibleAPI = "true".equals(manifest.get(ICoreConstants.EXTENSIBLE_API)); //$NON-NLS-1$
381382
info.isPatchFragment = "true".equals(manifest.get(ICoreConstants.PATCH_FRAGMENT)); //$NON-NLS-1$
383+
info.platformFilter = manifest.get(ICoreConstants.PLATFORM_FILTER);
382384
info.localization = manifest.get(Constants.BUNDLE_LOCALIZATION);
383385
info.hasBundleStructure = hasBundleStructure;
384386
info.bundleSourceEntry = manifest.get(ICoreConstants.ECLIPSE_SOURCE_BUNDLE);

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundleFragment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,8 @@ public boolean isPatch() {
122122
return "true".equals(getValue(ICoreConstants.PATCH_FRAGMENT, false)); //$NON-NLS-1$
123123
}
124124

125+
public String getPlatformFilter() {
126+
return getValue(ICoreConstants.PLATFORM_FILTER, false);
127+
}
128+
125129
}

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bundle/BundlePlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ public boolean exportsExternalAnnotations() {
5757
return "true".equals(getValue(ICoreConstants.ECLIPSE_EXPORT_EXTERNAL_ANNOTATIONS, false)); //$NON-NLS-1$
5858
}
5959

60+
public String getPlatformFilter() {
61+
return getValue(ICoreConstants.PLATFORM_FILTER, false);
62+
}
63+
6064
}

ui/org.eclipse.pde.launching/src/org/eclipse/pde/internal/launching/launcher/BundleLauncherHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ private static Stream<IPluginModelBase> computeDependencies(Set<IPluginModelBase
558558
}).forEach(launchBundles::add);
559559

560560
DependencyManager.Options[] options = includeOptional //
561-
? new DependencyManager.Options[] {DependencyManager.Options.INCLUDE_OPTIONAL_DEPENDENCIES}
562-
: new DependencyManager.Options[] {};
561+
? new DependencyManager.Options[] {DependencyManager.Options.INCLUDE_OPTIONAL_DEPENDENCIES, DependencyManager.Options.INCLUDE_NATIVE_FRAGMENTS}
562+
: new DependencyManager.Options[] {DependencyManager.Options.INCLUDE_NATIVE_FRAGMENTS};
563563
Set<BundleDescription> closure = DependencyManager.findRequirementsClosure(launchBundles, options);
564564
return closure.stream().map(launchBundlePlugins::get).map(Objects::requireNonNull) //
565565
.filter(p -> !includedPlugins.contains(p));

0 commit comments

Comments
 (0)