Skip to content

Commit

Permalink
Add support for Eclipse-BundleShape in Manifest-Editor
Browse files Browse the repository at this point in the history
Three modes are supported: jar, dir and default.
First two are self-explanatory, third option removes the header
which is the default behaviour.
Fixes: eclipse-pde#864
  • Loading branch information
alshamams authored and HannesWell committed Dec 5, 2023
1 parent b89f8ee commit d48ac73
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,8 @@ public class PDEUIMessages extends NLS {

public static String PluginGeneralInfoSection_singleton;

public static String PluginGeneralInfoSection_bundleshape;

public static String FragmentGeneralInfoSection_singleton;

public static String ClassSearchParticipant_taskMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;

import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.pde.core.IBaseModel;
import org.eclipse.pde.core.IModelChangeProvider;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.ModelChangedEvent;
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.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
Expand All @@ -41,9 +45,11 @@
import org.eclipse.pde.internal.ui.parts.FormEntry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.forms.widgets.FormToolkit;
Expand All @@ -56,6 +62,8 @@
*/
public abstract class GeneralInfoSection extends PDESection {
private static String PLATFORM_FILTER = "Eclipse-PlatformFilter"; //$NON-NLS-1$
private static String BUNDLESHAPE_JAR = "jar"; //$NON-NLS-1$
private static String BUNDLESHAPE_DIR = "dir"; //$NON-NLS-1$

private FormEntry fIdEntry;
private FormEntry fVersionEntry;
Expand All @@ -77,6 +85,12 @@ public abstract class GeneralInfoSection extends PDESection {

protected Button fSingleton;

protected Button fBundleShapeJar;

protected Button fBundleShapeDir;

protected Button fBundleShapeDefault;

public GeneralInfoSection(PDEFormPage page, Composite parent) {
super(page, parent, Section.DESCRIPTION);
createClient(getSection(), page.getEditor().getToolkit());
Expand Down Expand Up @@ -322,6 +336,15 @@ public void modelChanged(IModelChangedEvent e) {
}
}

void refreshBundleShape(Button on, Button off_1, Button off_2) {
if (on != null)
on.setSelection(true);
if (off_1 != null)
off_1.setSelection(false);
if (off_2 != null)
off_2.setSelection(false);
}

@Override
public void refresh() {
IPluginModelBase model = (IPluginModelBase) getPage().getPDEEditor().getContextManager().getAggregateModel();
Expand All @@ -340,6 +363,27 @@ public void refresh() {
IManifestHeader header = getSingletonHeader();
fSingleton.setSelection(header instanceof BundleSymbolicNameHeader && ((BundleSymbolicNameHeader) header).isSingleton());
}
IBundle bundle = getBundle();
Map<String, IManifestHeader> headers = ((Bundle) bundle).getHeaders();
IManifestHeader header = headers.get(ICoreConstants.ECLIPSE_BUNDLE_SHAPE);
if (header != null) {
String value = header.getValue();
if (value != null) {
switch (value) {
case "jar": //$NON-NLS-1$
refreshBundleShape(fBundleShapeJar, fBundleShapeDir, fBundleShapeDefault);
break;
case "dir": //$NON-NLS-1$
refreshBundleShape(fBundleShapeDir, fBundleShapeJar, fBundleShapeDefault);
break;
}
} else {
refreshBundleShape(fBundleShapeDefault, fBundleShapeDir, fBundleShapeJar);
}
} else {
refreshBundleShape(fBundleShapeDefault, fBundleShapeDir, fBundleShapeJar);
}

super.refresh();
}

Expand Down Expand Up @@ -387,6 +431,13 @@ IManifestHeader getSingletonHeader() {
return null;
}

void createBundleShapeHeader(String shape) {
IBundle bundle = getBundle();
if (bundle instanceof Bundle) {
bundle.setHeader(ICoreConstants.ECLIPSE_BUNDLE_SHAPE, shape);
}
}

protected void createSingleton(Composite parent, FormToolkit toolkit, IActionBars actionBars, String label) {
fSingleton = toolkit.createButton(parent, label, SWT.CHECK);
TableWrapData td = new TableWrapData();
Expand All @@ -400,4 +451,49 @@ protected void createSingleton(Composite parent, FormToolkit toolkit, IActionBar
}));
}

protected void createBundleShape(Composite parent, FormToolkit toolkit, IActionBars actionBars, String label) {
Label l = toolkit.createLabel(parent, label, SWT.BORDER);
TableWrapData td = new TableWrapData();
td.colspan = 3;
l.setLayoutData(td);
Composite c = new Composite(parent, SWT.NONE);
GridLayout gd = new GridLayout(3, true);
gd.marginLeft = 0;
gd.marginRight = 0;
gd.horizontalSpacing = 2;
c.setLayout(gd);
fBundleShapeJar = toolkit.createButton(c, BUNDLESHAPE_JAR, SWT.RADIO);
fBundleShapeDir = toolkit.createButton(c, BUNDLESHAPE_DIR, SWT.RADIO);
fBundleShapeDefault = toolkit.createButton(c, "default", SWT.RADIO); //$NON-NLS-1$
fBundleShapeJar.setEnabled(true);
fBundleShapeDir.setEnabled(true);
fBundleShapeDefault.setEnabled(true);
fBundleShapeDefault.setSelection(true);
fBundleShapeJar.addListener(SWT.Selection, event -> {
if (fBundleShapeJar.getSelection()) {
createBundleShapeHeader(BUNDLESHAPE_JAR);
}
});
fBundleShapeDir.addListener(SWT.Selection, event -> {
if (fBundleShapeDir.getSelection()) {
createBundleShapeHeader(BUNDLESHAPE_DIR);
}
});
fBundleShapeDefault.addListener(SWT.Selection, event -> {
if (fBundleShapeDefault.getSelection()) {
if (getBundle() instanceof Bundle bundle) {
Map<String, IManifestHeader> headers = bundle.getHeaders();
Object entry = headers.get(ICoreConstants.ECLIPSE_BUNDLE_SHAPE);
((IManifestHeader) entry).setValue(null);
bundle.setHeader(ICoreConstants.ECLIPSE_BUNDLE_SHAPE, null);
IBundleModel model = bundle.getModel();
((IModelChangeProvider) model).fireModelChanged(
new ModelChangedEvent(model, IModelChangedEvent.REMOVE,
new Object[] { entry }, ICoreConstants.ECLIPSE_BUNDLE_SHAPE));
}

}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected void createSpecificControls(Composite parent, FormToolkit toolkit, IAc
if (isBundle() && (formEditor instanceof ManifestEditor)) {
createLazyStart(parent, toolkit, actionBars);
createSingleton(parent, toolkit, actionBars, PDEUIMessages.PluginGeneralInfoSection_singleton);
createBundleShape(parent, toolkit, actionBars, PDEUIMessages.PluginGeneralInfoSection_bundleshape);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,7 @@ PluginWorkingSet_deselectAll_label=Dese&lect All
PluginDevelopmentPage_presentation=Plug-in Manifest Editor Presentation
PluginGeneralInfoSection_lazyStart=Activate this plug-in when one of its classes is loaded
PluginGeneralInfoSection_singleton=This plug-in is a singleton
PluginGeneralInfoSection_bundleshape=Unpack behavior during P2 installation:
FragmentGeneralInfoSection_singleton=This fragment is a singleton
PluginWorkingSet_deselectAll_toolTip=Unselect all of these plug-ins for this working set.
PluginListPage_initializeFromPlugins=&Initialize from the plug-ins list:
Expand Down

0 comments on commit d48ac73

Please sign in to comment.