Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imported packages showing version of matching packages #1528

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ public class DependencyPropertiesDialog extends StatusDialog {
private String fPluginId;

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

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(), false);
}

public DependencyPropertiesDialog(boolean editable, ExportPackageObject object) {
this(editable, false, false, false, object.getVersion(), false, false, null);
this(editable, false, false, false, object.getVersion(), false, false, null, false);
}

public DependencyPropertiesDialog(boolean editable, boolean showReexport, boolean export, boolean optional, String version, boolean showOptional, boolean isImport, String pluginId) {
public DependencyPropertiesDialog(boolean editable, boolean showReexport, boolean export, boolean optional,
String version, boolean showOptional, boolean isImport, String pluginId, boolean isPlugin) {
super(PDEPlugin.getActiveWorkbenchShell());
fEditable = editable;
fShowReexport = showReexport;
Expand All @@ -68,9 +70,9 @@ public DependencyPropertiesDialog(boolean editable, boolean showReexport, boolea
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 @@ -120,7 +122,6 @@ protected Control createDialogArea(Composite parent) {
ModifyListener ml = e -> updateStatus(fVersionPart.validateFullVersionRangeText(true));
fVersionPart.addListeners(ml, ml);

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

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,46 @@ 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();

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 (name.equalsIgnoreCase(inputElement.toString()))
list.add(po);
}
}
}
return list.toArray();
}

}


private Text fMinVersionText;
private Text fMaxVersionText;
private Combo fMinVersionBound;
Expand All @@ -108,8 +179,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 @@ -153,9 +231,15 @@ 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(id);
}
part.setButtonEnabled(0, false);
}

Expand Down
Loading