Skip to content

Commit

Permalink
Imported packages showing version of matching packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Neha Burnwal committed Dec 18, 2024
1 parent 51ef6fe commit 00cdf58
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ public class DependencyPropertiesDialog extends StatusDialog {
private boolean fShowOptional;
private String fVersion;
private String fPluginId;
private boolean isPlugin;

public DependencyPropertiesDialog(boolean editable, IPluginImport plugin) {
this(editable, true, plugin.isReexported(), plugin.isOptional(), plugin.getVersion(), true, true, plugin.getId());
}

public DependencyPropertiesDialog(boolean editable, ImportPackageObject object) {
this(editable, false, false, object.isOptional(), object.getVersion(), true, true, null);
this(editable, false, false, object.isOptional(), object.getVersion(), true, true, object.getName());
}

public DependencyPropertiesDialog(boolean editable, ExportPackageObject object) {
Expand All @@ -61,16 +62,17 @@ public DependencyPropertiesDialog(boolean editable, ExportPackageObject object)

public DependencyPropertiesDialog(boolean editable, boolean showReexport, boolean export, boolean optional, String version, boolean showOptional, boolean isImport, String pluginId) {
super(PDEPlugin.getActiveWorkbenchShell());
isPlugin = showReexport;
fEditable = editable;
fShowReexport = showReexport;
fExported = export;
fOptional = optional;
fShowOptional = showOptional;
fPluginId = pluginId;
if (isImport)
fVersionPart = new PluginVersionPart(true);
fVersionPart = new PluginVersionPart(true, isPlugin);
else
fVersionPart = new PluginVersionPart(false) {
fVersionPart = new PluginVersionPart(false, isPlugin) {
@Override
protected String getGroupText() {
return PDEUIMessages.DependencyPropertiesDialog_exportGroupText;
Expand Down Expand Up @@ -122,7 +124,7 @@ protected Control createDialogArea(Composite parent) {

// we need a better way to do this
if (fPluginId != null && !fPluginId.equals("system.bundle")) //$NON-NLS-1$
fVersionPart.createVersionSelectionField(comp, fPluginId);
fVersionPart.createVersionSelectionField(comp, fPluginId, isPlugin);

return comp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@
*******************************************************************************/
package org.eclipse.pde.internal.ui.parts;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.ModelEntry;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.core.target.NameVersionDescriptor;
import org.eclipse.pde.internal.build.Utils;
import org.eclipse.pde.internal.core.bundle.Bundle;
import org.eclipse.pde.internal.core.text.bundle.ManifestHeader;
import org.eclipse.pde.internal.core.text.bundle.PackageObject;
import org.eclipse.pde.internal.core.util.UtilMessages;
import org.eclipse.pde.internal.core.util.VersionUtil;
import org.eclipse.pde.internal.ui.PDEPlugin;
Expand Down Expand Up @@ -70,17 +80,38 @@ protected void handleDoubleClick(IStructuredSelection selection) {
protected void buttonSelected(Button button, int index) {
IStructuredSelection selection = getTableViewer().getStructuredSelection();
if (selection.size() == 1) {
IPluginModelBase entry = (IPluginModelBase) selection.getFirstElement();
String version = VersionUtil.computeInitialPluginVersion(entry.getBundleDescription().getVersion().toString());
String version;
if (isPlugin) {
IPluginModelBase entry = (IPluginModelBase) selection.getFirstElement();
version = VersionUtil
.computeInitialPluginVersion(entry.getBundleDescription().getVersion().toString());
} else {
PackageObject po = (PackageObject) selection.getFirstElement();
version = po.getVersion();
}
setVersion(version, ""); //$NON-NLS-1$
} else {
// plug-ins come back in a sorted order so we assume min/max
Object[] objects = selection.toArray();
IPluginModelBase min = (IPluginModelBase) objects[0];
IPluginModelBase max = (IPluginModelBase) objects[objects.length - 1];
String minVersion;
String maxVersion;
if (isPlugin) {
Object[] objects = selection.toArray();
IPluginModelBase min = (IPluginModelBase) objects[0];
IPluginModelBase max = (IPluginModelBase) objects[objects.length - 1];

minVersion = VersionUtil
.computeInitialPluginVersion(min.getBundleDescription().getVersion().toString());
maxVersion = VersionUtil
.computeInitialPluginVersion(max.getBundleDescription().getVersion().toString());
} else {
Object[] objects = selection.toArray();
PackageObject poMin = (PackageObject) objects[0];
PackageObject poMax = (PackageObject) objects[objects.length - 1];

minVersion = poMin.getVersion();
maxVersion = poMax.getVersion();

String minVersion = VersionUtil.computeInitialPluginVersion(min.getBundleDescription().getVersion().toString());
String maxVersion = VersionUtil.computeInitialPluginVersion(max.getBundleDescription().getVersion().toString());
}
setVersion(minVersion, maxVersion);
}
}
Expand All @@ -100,6 +131,52 @@ public Object[] getElements(Object element) {

}

private static class ImportPackageVersionContentProvider implements IStructuredContentProvider {

@Override
public Object[] getElements(Object inputElement) {
IPluginModelBase[] models = PluginRegistry.getActiveModels();
ArrayList<PackageObject> list = new ArrayList<>();
Set<NameVersionDescriptor> nameVersions = new HashSet<>();
for (IPluginModelBase pluginModel : models) {
BundleDescription desc = pluginModel.getBundleDescription();
// If the current model is a fragment, it can export packages
// only if its parent has hasExtensibleAPI set
// if (isFragmentThatCannotExportPackages(pluginModel))
// continue;

String id = desc == null ? null : desc.getSymbolicName();
if (id == null)
continue;
ExportPackageDescription[] exported = desc.getExportPackages();
for (ExportPackageDescription exportedPackage : exported) {
String name = exportedPackage.getName();
ManifestHeader mHeader = new ManifestHeader("Export-Package", "", new Bundle(), "\n"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
PackageObject po = new PackageObject(mHeader, exportedPackage.getName(),
exportedPackage.getVersion().toString(), "version"); //$NON-NLS-1$

NameVersionDescriptor nameVersion = new NameVersionDescriptor(exportedPackage.getName(),
exportedPackage.getVersion().toString(), NameVersionDescriptor.TYPE_PACKAGE);
exportedPackage.getExporter().getBundle();

if (("java".equals(name) || name.startsWith("java."))) //$NON-NLS-1$ //$NON-NLS-2$
// $NON-NLS-2$
continue;
if (nameVersions.add(nameVersion)) {
if(inputElement instanceof ModelEntry)
if (name.equalsIgnoreCase(((ModelEntry) inputElement).getId()))
list.add(po);

}
}
}
return list.toArray();
// TODO Auto-generated method stub
}

}


private Text fMinVersionText;
private Text fMaxVersionText;
private Combo fMinVersionBound;
Expand All @@ -108,8 +185,15 @@ public Object[] getElements(Object element) {
private VersionRange fVersionRange;
private boolean fIsRanged;
private final boolean fRangeAllowed;
private boolean isPlugin;

public PluginVersionPart(boolean rangeAllowed) {
this(rangeAllowed, false);

}

public PluginVersionPart(boolean rangeAllowed, boolean isPlugin) {
this.isPlugin = isPlugin;
fRangeAllowed = rangeAllowed;
}

Expand Down Expand Up @@ -143,7 +227,7 @@ public void createVersionFields(Composite comp, boolean createGroup, boolean edi
preloadFields();
}

public void createVersionSelectionField(Composite comp, String id) {
public void createVersionSelectionField(Composite comp, String id, boolean isPlugin) {
Group group = new Group(comp, SWT.NONE);
group.setText(PDEUIMessages.PluginVersionPart_groupTitle);
group.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL));
Expand All @@ -153,12 +237,19 @@ public void createVersionSelectionField(Composite comp, String id) {
part.createControl(group, SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL, 1, null);
part.setMinimumSize(0, 75);
part.getViewer().setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
part.getViewer().setContentProvider(new PluginVersionContentProvider());
part.getViewer().setComparator(new ViewerComparator());
part.getViewer().setInput(PluginRegistry.findEntry(id));
if (isPlugin) {
part.getViewer().setContentProvider(new PluginVersionContentProvider());
part.getViewer().setComparator(new ViewerComparator());
part.getViewer().setInput(PluginRegistry.findEntry(id));
} else {
part.getViewer().setContentProvider(new ImportPackageVersionContentProvider());
part.getViewer().setComparator(new ViewerComparator());
part.getViewer().setInput(new ModelEntry(id));
}
part.setButtonEnabled(0, false);
}


private void createRangeField(Composite parent, boolean createGroup, boolean editable) {
if (createGroup) {
parent = new Group(parent, SWT.NONE);
Expand Down

0 comments on commit 00cdf58

Please sign in to comment.