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 88160e9 commit a54f79f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -79,6 +80,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,13 +141,10 @@ 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();
@SuppressWarnings("deprecation")
IManifestHeader header = bundle.getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
if (header instanceof RequiredExecutionEnvironmentHeader breeHeader) {
return breeHeader.getEnvironments();
}
IPluginModelBase model = getPluginModel();
if (model != null) {
Resource bundle = model.getBundleDescription();
return ManifestUtils.getRequiredExecutionEnvironments(bundle).toArray(String[]::new);
}
return new Object[0];
});
Expand Down Expand Up @@ -331,14 +330,19 @@ private String getLineDelimiter() {
}

private IExecutionEnvironment[] getEnvironments() {
RequiredExecutionEnvironmentHeader header = getHeader();
IExecutionEnvironmentsManager eeManager = JavaRuntime.getExecutionEnvironmentsManager();
IExecutionEnvironment[] envs = eeManager.getExecutionEnvironments();
if (header == null) {
return envs;
IPluginModelBase model = getPluginModel();
if (model != null) {
List<IExecutionEnvironment> requiredEEs = ManifestUtils
.getRequiredExecutionEnvironments(model.getBundleDescription()) //
.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 @@ -404,11 +408,13 @@ protected RequiredExecutionEnvironmentHeader getHeader() {
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.pde.core.IBaseModel;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.ModelChangedEvent;
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.ISharedExtensionsModel;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.core.plugin.PluginRegistry.PluginFilter;
import org.eclipse.pde.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.IModelChangeProviderExtension;
import org.eclipse.pde.internal.core.bundle.BundleFragmentModel;
Expand Down Expand Up @@ -95,11 +102,30 @@ protected void fireContextChange(InputContext context, boolean added) {

private void bundleAdded(InputContext bundleContext) {
IBundleModel model = (IBundleModel) bundleContext.getModel();
if (model.isFragmentModel())
if (model.isFragmentModel()) {
bmodel = new BundleFragmentModel();
else
} else {
bmodel = new BundlePluginModel();
}
bmodel.setBundleModel(model);

// Set the BundleDescription from the model in the target-platform
IResource resource = bmodel.getUnderlyingResource();
IPluginModelBase targetModel;
if (resource != null) {
targetModel = PluginRegistry.findModel(resource.getProject());
} else {
IPluginBase pluginBase = bmodel.getPluginBase();
IPath installLocation = IPath.fromOSString(model.getInstallLocation());
targetModel = PluginRegistry.findModel(pluginBase.getId(), pluginBase.getVersion(), IMatchRules.PERFECT,
new PluginFilter() {
@Override
public boolean accept(IPluginModelBase model) {
return installLocation.equals(IPath.fromOSString(model.getInstallLocation()));
}
});
}
bmodel.setBundleDescription(targetModel.getBundleDescription());
syncExtensions();
}

Expand Down

0 comments on commit a54f79f

Please sign in to comment.