diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java index bf94d25aef..b324a93c65 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java @@ -23,6 +23,7 @@ import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -42,8 +43,11 @@ import org.eclipse.jface.viewers.ViewerDropAdapter; import org.eclipse.jface.window.Window; import org.eclipse.pde.core.IModelChangedEvent; +import org.eclipse.pde.core.plugin.IMatchRules; +import org.eclipse.pde.core.plugin.IPluginBase; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.PluginRegistry; +import org.eclipse.pde.core.plugin.PluginRegistry.PluginFilter; import org.eclipse.pde.internal.core.ClasspathComputer; import org.eclipse.pde.internal.core.ibundle.IBundle; import org.eclipse.pde.internal.core.ibundle.IBundleModel; @@ -51,6 +55,7 @@ import org.eclipse.pde.internal.core.text.bundle.ExecutionEnvironment; import org.eclipse.pde.internal.core.text.bundle.PDEManifestElement; import org.eclipse.pde.internal.core.text.bundle.RequiredExecutionEnvironmentHeader; +import org.eclipse.pde.internal.core.util.ManifestUtils; import org.eclipse.pde.internal.ui.IHelpContextIds; import org.eclipse.pde.internal.ui.PDEPlugin; import org.eclipse.pde.internal.ui.PDEPluginImages; @@ -79,6 +84,7 @@ import org.eclipse.ui.forms.widgets.Section; import org.eclipse.ui.forms.widgets.TableWrapData; import org.osgi.framework.Constants; +import org.osgi.resource.Resource; public class ExecutionEnvironmentSection extends TableSection { @@ -139,12 +145,9 @@ protected void createClient(Section section, FormToolkit toolkit) { createViewerPartControl(container, SWT.FULL_SELECTION | SWT.MULTI, 2, toolkit); fEETable = tablePart.getTableViewer(); fEETable.setContentProvider((IStructuredContentProvider) inputElement -> { - if (inputElement instanceof IBundleModel model) { - IBundle bundle = model.getBundle(); - IManifestHeader header = bundle.getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); - if (header instanceof RequiredExecutionEnvironmentHeader) { - return ((RequiredExecutionEnvironmentHeader) header).getEnvironments(); - } + Resource bundle = getBundleResource(); + if (bundle != null) { + return ManifestUtils.getRequiredExecutionEnvironments(bundle).toArray(String[]::new); } return new Object[0]; }); @@ -329,14 +332,18 @@ private String getLineDelimiter() { } private IExecutionEnvironment[] getEnvironments() { - RequiredExecutionEnvironmentHeader header = getHeader(); IExecutionEnvironmentsManager eeManager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] envs = eeManager.getExecutionEnvironments(); - if (header == null) { - return envs; + Resource bundle = getBundleResource(); + if (bundle != null) { + List requiredEEs = ManifestUtils.getRequiredExecutionEnvironments(bundle) + .map(eeManager::getEnvironment).toList(); + if (!requiredEEs.isEmpty()) { + return Arrays.stream(envs).filter(ee -> !requiredEEs.contains(ee)) + .toArray(IExecutionEnvironment[]::new); + } } - List ees = header.getElementNames().stream().map(eeManager::getEnvironment).toList(); - return Arrays.stream(envs).filter(ee -> !ees.contains(ee)).toArray(IExecutionEnvironment[]::new); + return envs; } @Override @@ -401,12 +408,32 @@ protected RequiredExecutionEnvironmentHeader getHeader() { return null; } + private Resource getBundleResource() { + IPluginModelBase model = getPluginModel(); + IPath installLocation = IPath.fromOSString(model.getInstallLocation()); + // TODO: better add this to the model created + IPluginBase pluginBase = model.getPluginBase(); + IPluginModelBase targetModel = PluginRegistry.findModel(pluginBase.getId(), pluginBase.getVersion(), + IMatchRules.PERFECT, new PluginFilter() { + @Override + public boolean accept(IPluginModelBase model) { + return installLocation.equals(IPath.fromOSString(model.getInstallLocation())); + } + }); + if (targetModel != null) { + return targetModel.getBundleDescription(); + } + return null; + } + protected boolean isFragment() { + IPluginModelBase model = getPluginModel(); + return model != null && model.isFragmentModel(); + } + + private IPluginModelBase getPluginModel() { InputContextManager manager = getPage().getPDEEditor().getContextManager(); - if (manager.getAggregateModel() instanceof IPluginModelBase model) { - return model.isFragmentModel(); - } - return false; + return manager.getAggregateModel() instanceof IPluginModelBase model ? model : null; } @Override