Skip to content

Commit c815c5b

Browse files
committed
Consider EE requirements in EE-Section of ManifestEditor
1 parent 88160e9 commit c815c5b

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.eclipse.pde.internal.core.text.bundle.ExecutionEnvironment;
5252
import org.eclipse.pde.internal.core.text.bundle.PDEManifestElement;
5353
import org.eclipse.pde.internal.core.text.bundle.RequiredExecutionEnvironmentHeader;
54+
import org.eclipse.pde.internal.core.util.ManifestUtils;
5455
import org.eclipse.pde.internal.ui.IHelpContextIds;
5556
import org.eclipse.pde.internal.ui.PDEPlugin;
5657
import org.eclipse.pde.internal.ui.PDEPluginImages;
@@ -79,6 +80,7 @@
7980
import org.eclipse.ui.forms.widgets.Section;
8081
import org.eclipse.ui.forms.widgets.TableWrapData;
8182
import org.osgi.framework.Constants;
83+
import org.osgi.resource.Resource;
8284

8385
public class ExecutionEnvironmentSection extends TableSection {
8486

@@ -139,13 +141,10 @@ protected void createClient(Section section, FormToolkit toolkit) {
139141
createViewerPartControl(container, SWT.FULL_SELECTION | SWT.MULTI, 2, toolkit);
140142
fEETable = tablePart.getTableViewer();
141143
fEETable.setContentProvider((IStructuredContentProvider) inputElement -> {
142-
if (inputElement instanceof IBundleModel model) {
143-
IBundle bundle = model.getBundle();
144-
@SuppressWarnings("deprecation")
145-
IManifestHeader header = bundle.getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
146-
if (header instanceof RequiredExecutionEnvironmentHeader breeHeader) {
147-
return breeHeader.getEnvironments();
148-
}
144+
IPluginModelBase model = getPluginModel();
145+
if (model != null) {
146+
Resource bundle = model.getBundleDescription();
147+
return ManifestUtils.getRequiredExecutionEnvironments(bundle).toArray(String[]::new);
149148
}
150149
return new Object[0];
151150
});
@@ -331,14 +330,19 @@ private String getLineDelimiter() {
331330
}
332331

333332
private IExecutionEnvironment[] getEnvironments() {
334-
RequiredExecutionEnvironmentHeader header = getHeader();
335333
IExecutionEnvironmentsManager eeManager = JavaRuntime.getExecutionEnvironmentsManager();
336334
IExecutionEnvironment[] envs = eeManager.getExecutionEnvironments();
337-
if (header == null) {
338-
return envs;
335+
IPluginModelBase model = getPluginModel();
336+
if (model != null) {
337+
List<IExecutionEnvironment> requiredEEs = ManifestUtils
338+
.getRequiredExecutionEnvironments(model.getBundleDescription()) //
339+
.map(eeManager::getEnvironment).toList();
340+
if (!requiredEEs.isEmpty()) {
341+
return Arrays.stream(envs).filter(ee -> !requiredEEs.contains(ee))
342+
.toArray(IExecutionEnvironment[]::new);
343+
}
339344
}
340-
List<IExecutionEnvironment> ees = header.getElementNames().stream().map(eeManager::getEnvironment).toList();
341-
return Arrays.stream(envs).filter(ee -> !ees.contains(ee)).toArray(IExecutionEnvironment[]::new);
345+
return envs;
342346
}
343347

344348
@Override
@@ -404,11 +408,13 @@ protected RequiredExecutionEnvironmentHeader getHeader() {
404408
}
405409

406410
protected boolean isFragment() {
411+
IPluginModelBase model = getPluginModel();
412+
return model != null && model.isFragmentModel();
413+
}
414+
415+
private IPluginModelBase getPluginModel() {
407416
InputContextManager manager = getPage().getPDEEditor().getContextManager();
408-
if (manager.getAggregateModel() instanceof IPluginModelBase model) {
409-
return model.isFragmentModel();
410-
}
411-
return false;
417+
return manager.getAggregateModel() instanceof IPluginModelBase model ? model : null;
412418
}
413419

414420
@Override

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContextManager.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@
1515

1616
import org.eclipse.core.resources.IFile;
1717
import org.eclipse.core.resources.IProject;
18+
import org.eclipse.core.resources.IResource;
19+
import org.eclipse.core.runtime.IPath;
1820
import org.eclipse.pde.core.IBaseModel;
1921
import org.eclipse.pde.core.IModel;
2022
import org.eclipse.pde.core.IModelChangedEvent;
2123
import org.eclipse.pde.core.ModelChangedEvent;
24+
import org.eclipse.pde.core.plugin.IMatchRules;
25+
import org.eclipse.pde.core.plugin.IPluginBase;
26+
import org.eclipse.pde.core.plugin.IPluginModelBase;
2227
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
28+
import org.eclipse.pde.core.plugin.PluginRegistry;
29+
import org.eclipse.pde.core.plugin.PluginRegistry.PluginFilter;
2330
import org.eclipse.pde.internal.core.ICoreConstants;
2431
import org.eclipse.pde.internal.core.IModelChangeProviderExtension;
2532
import org.eclipse.pde.internal.core.bundle.BundleFragmentModel;
@@ -95,11 +102,29 @@ protected void fireContextChange(InputContext context, boolean added) {
95102

96103
private void bundleAdded(InputContext bundleContext) {
97104
IBundleModel model = (IBundleModel) bundleContext.getModel();
98-
if (model.isFragmentModel())
105+
if (model.isFragmentModel()) {
99106
bmodel = new BundleFragmentModel();
100-
else
107+
} else {
101108
bmodel = new BundlePluginModel();
109+
}
102110
bmodel.setBundleModel(model);
111+
112+
IResource resource = bmodel.getUnderlyingResource();
113+
IPluginModelBase targetModel;
114+
if (resource != null) {
115+
targetModel = PluginRegistry.findModel(resource.getProject());
116+
} else {
117+
IPluginBase pluginBase = bmodel.getPluginBase();
118+
IPath installLocation = IPath.fromOSString(model.getInstallLocation());
119+
targetModel = PluginRegistry.findModel(pluginBase.getId(), pluginBase.getVersion(), IMatchRules.PERFECT,
120+
new PluginFilter() {
121+
@Override
122+
public boolean accept(IPluginModelBase model) {
123+
return installLocation.equals(IPath.fromOSString(model.getInstallLocation()));
124+
}
125+
});
126+
}
127+
bmodel.setBundleDescription(targetModel.getBundleDescription());
103128
syncExtensions();
104129
}
105130

0 commit comments

Comments
 (0)