From c1392befa4126fb1b36f195b5702905c28be3cca Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sun, 30 Jun 2024 18:16:51 +0200 Subject: [PATCH] Consider EE requirements in EE-Section of ManifestEditor --- .../plugin/ExecutionEnvironmentSection.java | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) 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 82cefeeeec..f5ef92152f 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 @@ -15,6 +15,7 @@ *******************************************************************************/ package org.eclipse.pde.internal.ui.editor.plugin; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.StringJoiner; @@ -23,6 +24,7 @@ import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -41,6 +43,7 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.ViewerDropAdapter; import org.eclipse.jface.window.Window; +import org.eclipse.osgi.util.ManifestElement; import org.eclipse.pde.core.IModelChangedEvent; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.PluginRegistry; @@ -51,6 +54,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; @@ -78,7 +82,10 @@ import org.eclipse.ui.forms.widgets.Hyperlink; import org.eclipse.ui.forms.widgets.Section; import org.eclipse.ui.forms.widgets.TableWrapData; +import org.osgi.framework.BundleException; import org.osgi.framework.Constants; +import org.osgi.framework.namespace.ExecutionEnvironmentNamespace; +import org.osgi.resource.Namespace; public class ExecutionEnvironmentSection extends TableSection { @@ -140,12 +147,7 @@ protected void createClient(Section section, FormToolkit toolkit) { fEETable = tablePart.getTableViewer(); fEETable.setContentProvider((IStructuredContentProvider) inputElement -> { if (inputElement instanceof IBundleModel model) { - IBundle bundle = model.getBundle(); - @SuppressWarnings("deprecation") - IManifestHeader header = bundle.getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); - if (header instanceof RequiredExecutionEnvironmentHeader breeHeader) { - return breeHeader.getEnvironments(); - } + return getRequiredEEs(model.getBundle()).toArray(String[]::new); } return new Object[0]; }); @@ -331,14 +333,45 @@ private String getLineDelimiter() { } private IExecutionEnvironment[] getEnvironments() { - RequiredExecutionEnvironmentHeader header = getHeader(); IExecutionEnvironmentsManager eeManager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] envs = eeManager.getExecutionEnvironments(); - if (header == null) { - return envs; + IBundle bundle = getBundle(); + if (bundle != null) { + List requiredEEs = getRequiredEEs(bundle).stream() // + .map(eeManager::getEnvironment).toList(); + if (!requiredEEs.isEmpty()) { + return Arrays.stream(envs).filter(ee -> !requiredEEs.contains(ee)) + .toArray(IExecutionEnvironment[]::new); + } + } + return envs; + } + + private static List getRequiredEEs(IBundle bundle) { + List requiredEEs = new ArrayList<>(); + @SuppressWarnings("deprecation") + IManifestHeader header = bundle.getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); + if (header instanceof RequiredExecutionEnvironmentHeader breeHeader) { + for (ExecutionEnvironment ee : breeHeader.getEnvironments()) { + requiredEEs.add(ee.getName()); + } + } + IManifestHeader requiredCapabilitiesHeader = bundle.getManifestHeader(Constants.REQUIRE_CAPABILITY); + if (requiredCapabilitiesHeader != null) { + String eeRequirement = requiredCapabilitiesHeader.getValue(); + try { + ManifestElement[] required = ManifestElement.parseHeader(Constants.REQUIRE_CAPABILITY, eeRequirement); + for (ManifestElement requiredCapability : required) { + if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(requiredCapability.getValue())) { + String filter = requiredCapability.getDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE); + ManifestUtils.parseRequiredEEsFromFilter(filter, requiredEEs::add); + } + } + } catch (BundleException e) { + ILog.get().error("Failed to parse " + Constants.REQUIRE_CAPABILITY + " header: " + eeRequirement, e); //$NON-NLS-1$//$NON-NLS-2$ + } } - List ees = header.getElementNames().stream().map(eeManager::getEnvironment).toList(); - return Arrays.stream(envs).filter(ee -> !ees.contains(ee)).toArray(IExecutionEnvironment[]::new); + return requiredEEs; } @Override