Skip to content

Commit c82afe8

Browse files
amelodevHannesWell
authored andcommitted
Add source repository link in Plug-in Selection Spy
Fixes #1626
1 parent b235a27 commit c82afe8

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/ManifestUtils.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import java.util.Map;
3030
import java.util.Map.Entry;
3131
import java.util.function.Consumer;
32+
import java.util.jar.Attributes;
3233
import java.util.jar.JarFile;
34+
import java.util.jar.Manifest;
3335
import java.util.regex.Pattern;
3436
import java.util.stream.Stream;
3537
import java.util.zip.ZipEntry;
@@ -58,6 +60,7 @@
5860
import org.eclipse.pde.internal.core.build.WorkspaceBuildModel;
5961
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
6062
import org.eclipse.pde.internal.core.project.PDEProject;
63+
import org.osgi.framework.Bundle;
6164
import org.osgi.framework.BundleException;
6265
import org.osgi.framework.Constants;
6366
import org.osgi.framework.Filter;
@@ -393,4 +396,36 @@ public static void parseRequiredEEsFromFilter(String eeFilter, Consumer<String>
393396
}
394397
}
395398

399+
/**
400+
* Return the value of "Eclipse-SourceReferences" in MANIFEST.MF from the
401+
* given bundle.
402+
*
403+
* @param bundle
404+
* The bundle to get the source repository
405+
*/
406+
public static String getSourceReferences(Bundle bundle) {
407+
String srcRef = findScmGit(bundle);
408+
if (srcRef != null) {
409+
try {
410+
var element = ManifestElement.parseHeader(ICoreConstants.ECLIPSE_SOURCE_REFERENCES, srcRef)[0];
411+
srcRef = element.getValue().trim().replaceFirst("^scm:git:", ""); //$NON-NLS-1$ //$NON-NLS-2$
412+
} catch (BundleException e) {
413+
}
414+
}
415+
return srcRef;
416+
}
417+
418+
private static String findScmGit(Bundle bundle) {
419+
if (bundle != null) {
420+
try (InputStream is = bundle.getEntry(ICoreConstants.BUNDLE_FILENAME_DESCRIPTOR).openStream()) {
421+
Attributes attributes = new Manifest(is).getMainAttributes();
422+
return attributes.getValue(ICoreConstants.ECLIPSE_SOURCE_REFERENCES);
423+
} catch (IOException e) {
424+
throw new IllegalArgumentException(
425+
ICoreConstants.ECLIPSE_SOURCE_REFERENCES + " not found for bundle : " + bundle); //$NON-NLS-1$
426+
}
427+
}
428+
return null;
429+
}
430+
396431
}

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/PDERuntimeMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class PDERuntimeMessages extends NLS {
6666
public static String SpyDialog_activeWizard_desc;
6767
public static String SpyDialog_activeMenuIds;
6868
public static String SpyDialog_contributingPluginId_title;
69+
public static String SpyDialog_sourceRepository;
6970
public static String SpyDialog_contributingPluginId_desc;
7071
public static String SpyDialog_activeSelection_title;
7172
public static String SpyDialog_activeSelection_desc;

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/pderuntimeresources.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ SpyDialog_activePart_title = Active Part ({0})
7878
SpyDialog_activePart_desc = The active {0} class:
7979
SpyDialog_activeMenuIds = The active menu contribution identifiers:
8080
SpyDialog_contributingPluginId_title = The contributing plug-in:
81+
SpyDialog_sourceRepository = The source repository:
8182
SpyDialog_contributingPluginId_desc = The active {0} identifier:
8283
SpyDialog_activeSelection_title = Active Selection
8384
SpyDialog_activeSelection_desc = The selection class:

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/spy/SpyFormToolkit.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
import java.util.HashMap;
2121
import java.util.Map;
22+
import java.util.regex.Pattern;
2223

2324
import org.eclipse.help.IContext;
2425
import org.eclipse.jface.action.Action;
2526
import org.eclipse.jface.action.ToolBarManager;
2627
import org.eclipse.jface.dialogs.PopupDialog;
2728
import org.eclipse.osgi.util.NLS;
29+
import org.eclipse.pde.internal.core.util.ManifestUtils;
2830
import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
2931
import org.eclipse.pde.internal.runtime.PDERuntimePlugin;
3032
import org.eclipse.pde.internal.runtime.PDERuntimePluginImages;
@@ -41,13 +43,15 @@
4143
import org.eclipse.swt.graphics.Image;
4244
import org.eclipse.swt.graphics.ImageData;
4345
import org.eclipse.swt.graphics.ImageLoader;
46+
import org.eclipse.swt.program.Program;
4447
import org.eclipse.swt.widgets.Composite;
4548
import org.eclipse.swt.widgets.Display;
4649
import org.eclipse.swt.widgets.FileDialog;
4750
import org.eclipse.swt.widgets.Menu;
4851
import org.eclipse.swt.widgets.MenuItem;
4952
import org.eclipse.swt.widgets.ToolBar;
5053
import org.eclipse.swt.widgets.Widget;
54+
import org.eclipse.ui.IWorkbenchPart;
5155
import org.eclipse.ui.forms.events.HyperlinkAdapter;
5256
import org.eclipse.ui.forms.events.HyperlinkEvent;
5357
import org.eclipse.ui.forms.widgets.FormText;
@@ -62,6 +66,8 @@ public class SpyFormToolkit extends FormToolkit {
6266

6367
private static final String BUNDLE_PROTOCOL_PREFIX = "bundle://"; //$NON-NLS-1$
6468

69+
private static final Pattern URL_PATTERN = Pattern.compile("https?://\\S+"); //$NON-NLS-1$
70+
6571
private class SpyHyperlinkAdapter extends HyperlinkAdapter {
6672

6773
private final PopupDialog fDialog;
@@ -82,6 +88,8 @@ public void linkActivated(HyperlinkEvent e) {
8288
String bundle = href.substring(BUNDLE_PROTOCOL_PREFIX.length());
8389
SpyIDEUtil.openBundleManifest(bundle);
8490
fDialog.close();
91+
} else if (URL_PATTERN.matcher(href).matches()) {
92+
Program.launch(href);
8593
}
8694
}
8795
}
@@ -269,8 +277,18 @@ private void createClassReference(StringBuilder buffer, Class<?> clazz) {
269277
}
270278

271279
// TODO refactor me, I'm ugly
272-
public void generatePluginDetailsText(Bundle bundle, String objectId, String objectType, StringBuilder buffer, FormText text) {
280+
@SuppressWarnings("restriction")
281+
public void generatePluginDetailsText(Bundle bundle, IWorkbenchPart part, String objectType, StringBuilder buffer,
282+
FormText text) {
273283
if (bundle != null) {
284+
String objectId = null;
285+
String srcRef;
286+
if (part != null) {
287+
objectId = part.getSite().getId();
288+
srcRef = ManifestUtils.getSourceReferences(FrameworkUtil.getBundle(part.getClass()));
289+
} else {
290+
srcRef = ManifestUtils.getSourceReferences(bundle);
291+
}
274292
String version = (bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION));
275293

276294
buffer.append("<p>"); //$NON-NLS-1$
@@ -292,6 +310,23 @@ public void generatePluginDetailsText(Bundle bundle, String objectId, String obj
292310
}
293311
buffer.append("</li>"); //$NON-NLS-1$
294312

313+
if (srcRef != null) {
314+
buffer.append("<p>"); //$NON-NLS-1$
315+
buffer.append(PDERuntimeMessages.SpyDialog_sourceRepository);
316+
buffer.append("</p>"); //$NON-NLS-1$
317+
buffer.append("<li bindent=\"20\" style=\"image\" value=\"menu\">"); //$NON-NLS-1$
318+
if (PDERuntimePlugin.HAS_IDE_BUNDLES) {
319+
buffer.append("<a href=\""); //$NON-NLS-1$
320+
buffer.append(srcRef);
321+
buffer.append("\">"); //$NON-NLS-1$
322+
}
323+
buffer.append(srcRef);
324+
if (PDERuntimePlugin.HAS_IDE_BUNDLES) {
325+
buffer.append("</a>"); //$NON-NLS-1$
326+
}
327+
buffer.append("</li>"); //$NON-NLS-1$
328+
}
329+
295330
Image pluginImage = PDERuntimePluginImages.get(PDERuntimePluginImages.IMG_PLUGIN_OBJ);
296331
text.setImage("plugin", pluginImage); //$NON-NLS-1$
297332

ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/spy/sections/ActivePartSection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void build(ScrolledForm form, SpyFormToolkit toolkit, ExecutionEvent even
114114
bundle = FrameworkUtil.getBundle(mPart.getObject().getClass());
115115
}
116116

117-
toolkit.generatePluginDetailsText(bundle, part.getSite().getId(), partType, buffer, text);
117+
toolkit.generatePluginDetailsText(bundle, part, partType, buffer, text);
118118

119119
// get menu information using reflection
120120
try {

0 commit comments

Comments
 (0)