Skip to content

Commit

Permalink
Consider EE requirements in EE-Section of ManifestEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Jul 2, 2024
1 parent ca4140b commit c1392be
Showing 1 changed file with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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];
});
Expand Down Expand Up @@ -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<IExecutionEnvironment> 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<String> getRequiredEEs(IBundle bundle) {
List<String> 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<IExecutionEnvironment> ees = header.getElementNames().stream().map(eeManager::getEnvironment).toList();
return Arrays.stream(envs).filter(ee -> !ees.contains(ee)).toArray(IExecutionEnvironment[]::new);
return requiredEEs;
}

@Override
Expand Down

0 comments on commit c1392be

Please sign in to comment.