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 Jun 30, 2024
1 parent c0432d2 commit 56dfac0
Showing 1 changed file with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,15 +43,19 @@
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;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
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 @@ -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 {

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

@Override
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 56dfac0

Please sign in to comment.