Skip to content

Commit 1e2bded

Browse files
committed
Merge branch 'pr-106'
2 parents 32b591f + d4037a4 commit 1e2bded

File tree

9 files changed

+223
-1
lines changed

9 files changed

+223
-1
lines changed

ReleaseNotes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ This is a minor release.
1313

1414
### New and noteworthy
1515

16+
* PMD specific marker property page: This version adds a PMD specific property page to the
17+
marker properties which shows more information from the rule violation and rule itself.
18+
For more information, see [Marker Property Page (wiki)](https://github.com/pmd/pmd-eclipse-plugin/wiki/Marker-Property-Page).
19+
1620
### Fixed Issues
1721

22+
* [#84](https://github.com/pmd/pmd-eclipse-plugin/issues/84): Rule Name in Tooltip
23+
1824
### API Changes
1925

2026
### External Contributions

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCmdTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public void testReviewCmdBasic() throws CoreException {
112112
Assert.assertEquals(markers.get(sourceFile).size(), imarkers.size());
113113
for (IMarker marker : imarkers) {
114114
Assert.assertTrue(marker.isSubtypeOf(IMarker.PROBLEM));
115+
Assert.assertTrue(((String) marker.getAttribute(IMarker.MESSAGE))
116+
.startsWith((String) marker.getAttribute(PMDRuntimeConstants.KEY_MARKERATT_RULENAME)));
115117
}
116118
}
117119

net.sourceforge.pmd.eclipse.plugin/messages.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ property.button.include_derived_files = Include derived files
1313
property.button.full_build_enabled = Full build enabled
1414
property.button.violations_as_errors = Handle high priority violations as Eclipse errors
1515

16+
# Marker Property Page
17+
markerPropertyPage.label.rulename = Rule:
18+
markerPropertyPage.label.category = Category:
19+
markerPropertyPage.label.priority = Priority:
20+
markerPropertyPage.label.message = Message:
21+
markerPropertyPage.label.description = Description:
22+
markerPropertyPage.label.externalInfoUrl = External Info URL:
23+
1624
# General preferences page
1725
preference.pmd.header = PMD-Plugin Options
1826
preference.pmd.title = PMD General Preferences

net.sourceforge.pmd.eclipse.plugin/nl/fr/messages.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ property.button.include_derived_files = Inclure les fichiers d
1313
property.button.full_build_enabled = Full build enabled
1414
property.button.violations_as_errors = Traiter les violations de haute priorité comme des erreurs d'Eclipse
1515

16+
# Marker Property Page
17+
markerPropertyPage.label.rulename = Règle:
18+
markerPropertyPage.label.category = Catégorie:
19+
markerPropertyPage.label.priority = Priorité:
20+
markerPropertyPage.label.message = Message:
21+
markerPropertyPage.label.description = Description:
22+
markerPropertyPage.label.externalInfoUrl = URL d'information externe:
23+
1624
# General preferences page
1725
preference.pmd.header = Préférences Générales PMD
1826
preference.pmd.title = Préférences Générales PMD

net.sourceforge.pmd.eclipse.plugin/plugin.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,22 @@
359359
class="net.sourceforge.pmd.eclipse.ui.properties.PMDProjectPropertyPage"
360360
id="net.sourceforge.pmd.eclipse.ui.properties.pmdPropertyPage">
361361
</page>
362+
<page
363+
adaptable="true"
364+
class="net.sourceforge.pmd.eclipse.ui.properties.PMDMarkerPropertyPage"
365+
id="net.sourceforge.pmd.eclipse.ui.properties.markerPropertyPage"
366+
name="PMD Marker"
367+
nameFilter="*"
368+
objectClass="org.eclipse.core.resources.IMarker">
369+
<enabledWhen>
370+
<adapt
371+
type="org.eclipse.core.resources.IMarker">
372+
<test
373+
property="net.sourceforge.pmd.eclipse.plugin.isPMDMarker">
374+
</test>
375+
</adapt>
376+
</enabledWhen>
377+
</page>
362378
</extension>
363379

364380
<extension
@@ -803,5 +819,15 @@
803819
</public>
804820
</catalogContribution>
805821
</extension>
822+
<extension
823+
point="org.eclipse.core.expressions.propertyTesters">
824+
<propertyTester
825+
class="net.sourceforge.pmd.eclipse.ui.properties.MarkerPropertyTester"
826+
id="net.sourceforge.pmd.eclipse.isPMDMarker"
827+
namespace="net.sourceforge.pmd.eclipse.plugin"
828+
properties="isPMDMarker"
829+
type="org.eclipse.core.resources.IMarker">
830+
</propertyTester>
831+
</extension>
806832

807833
</plugin>

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/PMDRuntimeConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public class PMDRuntimeConstants {
4141
public static final String KEY_MARKERATT_LINE2 = "line2";
4242
public static final String KEY_MARKERATT_VARIABLE = "variable";
4343
public static final String KEY_MARKERATT_METHODNAME = "method";
44+
/**
45+
* The message from the rule violation. This is additionally here, since IMarker.MESSAGE will
46+
* contain both rule name + message.
47+
*/
48+
public static final String KEY_MARKERATT_MESSAGE = "pmd_message";
4449

4550
public static final String PLUGIN_STYLE_REVIEW_COMMENT = "// @PMD:REVIEWED:";
4651
public static final String PMD_STYLE_REVIEW_COMMENT = "// NOPMD";

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/BaseVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ private MarkerInfo2 getMarkerInfo(RuleViolation violation, String type) throws P
629629

630630
MarkerInfo2 info = new MarkerInfo2(type, 7);
631631

632-
info.add(IMarker.MESSAGE, violation.getDescription());
632+
info.add(IMarker.MESSAGE, rule.getName() + ": " + violation.getDescription());
633+
info.add(PMDRuntimeConstants.KEY_MARKERATT_MESSAGE, violation.getDescription());
633634
info.add(IMarker.LINE_NUMBER, violation.getBeginLine());
634635
info.add(PMDRuntimeConstants.KEY_MARKERATT_LINE2, violation.getEndLine());
635636
info.add(PMDRuntimeConstants.KEY_MARKERATT_RULENAME, rule.getName());
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.eclipse.ui.properties;
6+
7+
import org.eclipse.core.expressions.PropertyTester;
8+
import org.eclipse.core.resources.IMarker;
9+
import org.eclipse.core.runtime.CoreException;
10+
11+
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
12+
13+
public class MarkerPropertyTester extends PropertyTester {
14+
@Override
15+
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
16+
if (!(receiver instanceof IMarker)) {
17+
return false;
18+
}
19+
20+
IMarker marker = (IMarker) receiver;
21+
22+
try {
23+
return marker.getType().startsWith(PMDPlugin.PLUGIN_ID);
24+
} catch (CoreException e) {
25+
PMDPlugin.getDefault().logError(e.getMessage(), e);
26+
}
27+
return false;
28+
}
29+
30+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/**
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.eclipse.ui.properties;
6+
7+
import java.net.MalformedURLException;
8+
import java.net.URL;
9+
10+
import org.eclipse.core.resources.IMarker;
11+
import org.eclipse.core.runtime.CoreException;
12+
import org.eclipse.swt.SWT;
13+
import org.eclipse.swt.events.SelectionEvent;
14+
import org.eclipse.swt.events.SelectionListener;
15+
import org.eclipse.swt.layout.GridData;
16+
import org.eclipse.swt.layout.GridLayout;
17+
import org.eclipse.swt.widgets.Composite;
18+
import org.eclipse.swt.widgets.Control;
19+
import org.eclipse.swt.widgets.Label;
20+
import org.eclipse.swt.widgets.Link;
21+
import org.eclipse.swt.widgets.Text;
22+
import org.eclipse.ui.PartInitException;
23+
import org.eclipse.ui.PlatformUI;
24+
import org.eclipse.ui.browser.IWebBrowser;
25+
import org.eclipse.ui.dialogs.PropertyPage;
26+
27+
import net.sourceforge.pmd.Rule;
28+
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
29+
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
30+
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
31+
import net.sourceforge.pmd.eclipse.ui.nls.StringTable;
32+
33+
public class PMDMarkerPropertyPage extends PropertyPage {
34+
35+
@Override
36+
protected Control createContents(Composite parent) {
37+
noDefaultAndApplyButton();
38+
39+
Composite composite = new Composite(parent, SWT.NULL);
40+
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
41+
GridLayout layout = new GridLayout();
42+
layout.numColumns = 2;
43+
composite.setLayout(layout);
44+
45+
46+
IMarker marker = (IMarker) getElement();
47+
Rule rule = PMDPlugin.getDefault().getPreferencesManager().getRuleSet()
48+
.getRuleByName(MarkerUtil.ruleNameFor(marker));
49+
50+
StringTable messages = PMDPlugin.getDefault().getStringTable();
51+
52+
try {
53+
addLabel(composite, messages.getString("markerPropertyPage.label.rulename"));
54+
addText(composite, rule.getName());
55+
56+
addLabel(composite, messages.getString("markerPropertyPage.label.category"));
57+
addText(composite, rule.getRuleSetName());
58+
59+
addLabel(composite, messages.getString("markerPropertyPage.label.priority"));
60+
addText(composite, rule.getPriority().name());
61+
62+
addLabel(composite, messages.getString("markerPropertyPage.label.message"));
63+
addText(composite, getViolationMessage(marker));
64+
65+
addLabel(composite, messages.getString("markerPropertyPage.label.description"), 2);
66+
addDescription(composite, rule);
67+
68+
addLabel(composite, messages.getString("markerPropertyPage.label.externalInfoUrl"));
69+
addLink(composite, rule);
70+
} catch (CoreException e) {
71+
PMDPlugin.getDefault().logError(e.getMessage(), e);
72+
}
73+
74+
return composite;
75+
}
76+
77+
private String getViolationMessage(IMarker marker) throws CoreException {
78+
String defaultMessage = marker.getAttribute(IMarker.MESSAGE, "");
79+
return marker.getAttribute(PMDRuntimeConstants.KEY_MARKERATT_MESSAGE, defaultMessage);
80+
}
81+
82+
private void addDescription(Composite composite, Rule rule) {
83+
Text descriptionText = new Text(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
84+
GridData gridData = new GridData(GridData.FILL_BOTH);
85+
gridData.horizontalSpan = 2;
86+
gridData.heightHint = 50;
87+
descriptionText.setLayoutData(gridData);
88+
descriptionText.setText(rule.getDescription());
89+
}
90+
91+
private void addLink(Composite composite, Rule rule) {
92+
Link link = new Link(composite, SWT.NONE);
93+
link.setText("<a href=\"" + rule.getExternalInfoUrl() + "\">" + rule.getExternalInfoUrl() + "</a>");
94+
link.addSelectionListener(new LinkClickListener());
95+
}
96+
97+
private void addText(Composite parent, String value) {
98+
Text text = new Text(parent, SWT.READ_ONLY | SWT.SINGLE);
99+
text.setBackground(parent.getBackground());
100+
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
101+
text.setLayoutData(gridData);
102+
text.setText(value);
103+
}
104+
105+
private void addLabel(Composite parent, String label) {
106+
addLabel(parent, label, 1);
107+
}
108+
109+
private void addLabel(Composite parent, String text, int columnSpan) {
110+
Label label = new Label(parent, SWT.NONE);
111+
if (columnSpan > 1) {
112+
GridData gridData = new GridData();
113+
gridData.horizontalSpan = columnSpan;
114+
label.setLayoutData(gridData);
115+
}
116+
label.setText(text);
117+
}
118+
119+
private static final class LinkClickListener implements SelectionListener {
120+
@Override
121+
public void widgetSelected(SelectionEvent e) {
122+
try {
123+
URL url = new URL(e.text);
124+
IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser();
125+
browser.openURL(url);
126+
} catch (MalformedURLException | PartInitException e1) {
127+
PMDPlugin.getDefault().logError(e1.getMessage(), e1);
128+
}
129+
}
130+
131+
@Override
132+
public void widgetDefaultSelected(SelectionEvent e) {
133+
widgetSelected(e);
134+
}
135+
}
136+
}

0 commit comments

Comments
 (0)