Skip to content

Commit d3142ed

Browse files
committed
Merge branch 'pr-99'
2 parents c7a9906 + d229996 commit d3142ed

File tree

14 files changed

+310
-123
lines changed

14 files changed

+310
-123
lines changed

ReleaseNotes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ Eclipse Update Site:
1111

1212
This is a bugfix release.
1313

14+
### New and noteworthy
15+
16+
* Filtering by priority has been revamped. In both views "Violation Outline" and "Violation Overview" you can
17+
enable and disable the priorities. Changes in one view affects the other view as well as the markers displayed
18+
in the files. The selected priorities are stored in the preferences. PMD is not rerun when the priority filter
19+
is changed. The markers are only hidden instead. Changing the priority filter therefore affects the settings under
20+
General, Editors, Text Editors, Annotation for PMD Marker Annotations.
21+
1422
### Fixed Issues
1523

24+
* [#56](https://github.com/pmd/pmd-eclipse-plugin/issues/56): PMD not filtering
1625
* [#85](https://github.com/pmd/pmd-eclipse-plugin/issues/85): Gutter Markers not Configured Color
1726
* [#96](https://github.com/pmd/pmd-eclipse-plugin/issues/96): Wrong auxclasspath if project is stored outside of workspace
1827

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
8383
import net.sourceforge.pmd.eclipse.ui.nls.StringTable;
8484
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
85+
import net.sourceforge.pmd.eclipse.ui.views.PriorityFilter;
8586
import net.sourceforge.pmd.eclipse.util.ResourceManager;
8687
import net.sourceforge.pmd.lang.LanguageRegistry;
8788
import net.sourceforge.pmd.lang.LanguageVersion;
@@ -127,6 +128,7 @@ public class PMDPlugin extends AbstractUIPlugin {
127128
* The constructor
128129
*/
129130
public PMDPlugin() {
131+
plugin = this;
130132
}
131133

132134
public Color colorFor(RGB rgb) {
@@ -232,7 +234,6 @@ public static File getPluginFolder() {
232234
*/
233235
public void start(BundleContext context) throws Exception {
234236
super.start(context);
235-
plugin = this;
236237

237238
// this needs to be executed before the preferences are loaded, because
238239
// the standard
@@ -253,14 +254,20 @@ public void resourceChanged(IResourceChangeEvent arg0) {
253254
}
254255
});
255256

257+
// the initialization can only take place, after the plugin has been started.
258+
// otherwise the preferences are not available yet.
259+
PriorityFilter.getInstance().initialize();
260+
256261
version = context.getBundle().getHeaders().get("Bundle-Version");
257262
}
258263

259264
/**
260265
* Get a list of all the files that are open in eclipse currently
261266
*
262267
* @return
268+
* @deprecated will be removed since it is not needed
263269
*/
270+
@Deprecated
264271
public Set<IFile> getOpenFiles() {
265272
Set<IFile> files = new HashSet<IFile>();
266273
IEditorReference[] refs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
@@ -274,7 +281,7 @@ public Set<IFile> getOpenFiles() {
274281
}
275282
return files;
276283
}
277-
284+
278285
/**
279286
* Open a view to the id passed in.
280287
*
@@ -647,8 +654,7 @@ private void registerAdditionalRuleSets() {
647654

648655
public RuleLabelDecorator ruleLabelDecorator() {
649656
IDecoratorManager mgr = getWorkbench().getDecoratorManager();
650-
// TODO don't use a raw string...urgh
651-
return (RuleLabelDecorator) mgr.getBaseLabelProvider("net.sourceforge.pmd.eclipse.plugin.RuleLabelDecorator");
657+
return (RuleLabelDecorator) mgr.getBaseLabelProvider(RuleLabelDecorator.ID);
652658
}
653659

654660
public void changedFiles(Collection<IFile> changedFiles) {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
4848
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
4949
import net.sourceforge.pmd.eclipse.util.IOUtil;
50-
import net.sourceforge.pmd.eclipse.util.PriorityUtil;
5150
import net.sourceforge.pmd.lang.LanguageRegistry;
5251
import net.sourceforge.pmd.lang.LanguageVersion;
5352
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
@@ -521,11 +520,6 @@ private void updateMarkers(IFile file, Iterator<RuleViolation> violations, boole
521520
review.ruleName = rule.getName();
522521
review.lineNumber = violation.getBeginLine();
523522

524-
/* Only show active violations */
525-
if (!PriorityUtil.isPriorityActive(rule.getPriority())) {
526-
continue;
527-
}
528-
529523
if (reviewsList.contains(review)) {
530524
LOG.debug("Ignoring violation of rule " + rule.getName() + " at line " + violation.getBeginLine()
531525
+ " because of a review.");

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class PreferencesManagerImpl implements IPreferencesManager {
105105
StringKeys.VIEW_TOOLTIP_FILTER_PRIORITY, null, Shape.triangleRight, new RGB(255, 0, 0), 13)); // red
106106
DEFAULT_DESCRIPTORS_BY_PRIORITY.put(RulePriority.MEDIUM_HIGH,
107107
new PriorityDescriptor(RulePriority.MEDIUM_HIGH, StringKeys.VIEW_FILTER_PRIORITY_2,
108-
StringKeys.VIEW_TOOLTIP_FILTER_PRIORITY, null, Shape.triangleRight, new RGB(0, 255, 255), 13)); // yellow
108+
StringKeys.VIEW_TOOLTIP_FILTER_PRIORITY, null, Shape.triangleRight, new RGB(0, 255, 255), 13)); // cyan
109109
DEFAULT_DESCRIPTORS_BY_PRIORITY.put(RulePriority.MEDIUM,
110110
new PriorityDescriptor(RulePriority.MEDIUM, StringKeys.VIEW_FILTER_PRIORITY_3,
111111
StringKeys.VIEW_TOOLTIP_FILTER_PRIORITY, null, Shape.triangleRight, new RGB(0, 255, 0), 13)); // green

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/RuleLabelDecorator.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package net.sourceforge.pmd.eclipse.ui;
66

77
import java.util.Collection;
8-
import java.util.HashSet;
98
import java.util.Set;
9+
import java.util.concurrent.CopyOnWriteArraySet;
1010

1111
import org.eclipse.core.resources.IResource;
1212
import org.eclipse.core.runtime.CoreException;
@@ -21,18 +21,18 @@
2121
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
2222
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
2323
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
24+
import net.sourceforge.pmd.eclipse.ui.views.PriorityFilter;
2425

2526
/**
2627
*
2728
* @author Brian Remedios
2829
*/
2930
public class RuleLabelDecorator implements ILightweightLabelDecorator {
30-
private Collection<ILabelProviderListener> listeners;
31+
public static final String ID = "net.sourceforge.pmd.eclipse.plugin.RuleLabelDecorator";
32+
33+
private Set<ILabelProviderListener> listeners = new CopyOnWriteArraySet<>();
3134

3235
public void addListener(ILabelProviderListener listener) {
33-
if (listeners == null) {
34-
listeners = new HashSet<ILabelProviderListener>();
35-
}
3636
listeners.add(listener);
3737
}
3838

@@ -41,16 +41,11 @@ public void dispose() {
4141
}
4242

4343
public void changed(Collection<IResource> resources) {
44-
if (listeners == null) {
45-
return;
46-
}
47-
4844
LabelProviderChangedEvent lpce = new LabelProviderChangedEvent(this, resources.toArray());
4945

5046
for (ILabelProviderListener listener : listeners) {
5147
listener.labelProviderChanged(lpce);
5248
}
53-
5449
}
5550

5651
/**
@@ -65,9 +60,6 @@ public boolean isLabelProperty(Object element, String property) {
6560
}
6661

6762
public void removeListener(ILabelProviderListener listener) {
68-
if (listeners == null) {
69-
return;
70-
}
7163
listeners.remove(listener);
7264
}
7365

@@ -89,8 +81,21 @@ public void decorate(Object element, IDecoration decoration) {
8981
return;
9082
}
9183

92-
Integer first = range.iterator().next();
93-
ImageDescriptor overlay = PriorityDescriptorCache.INSTANCE.descriptorFor(RulePriority.valueOf(first)).getAnnotationImageDescriptor();
84+
// consider only the priorities, that are not filtered
85+
Integer highestPriority = null;
86+
for (Integer priority : range) {
87+
if (PriorityFilter.getInstance().isPriorityEnabled(RulePriority.valueOf(priority))) {
88+
if (highestPriority == null || highestPriority > priority) {
89+
highestPriority = priority;
90+
}
91+
}
92+
}
93+
94+
if (highestPriority == null) {
95+
return;
96+
}
97+
98+
ImageDescriptor overlay = PriorityDescriptorCache.INSTANCE.descriptorFor(RulePriority.valueOf(highestPriority)).getAnnotationImageDescriptor();
9499

95100
try {
96101
boolean hasMarkers = MarkerUtil.hasAnyRuleMarkers(resource);

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/ShapePicker.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public ShapePicker(Composite parent, int style, int theItemWidth) {
5757

5858
itemWidth = theItemWidth;
5959

60-
ShapePicker.this.addPaintListener(new PaintListener() {
60+
addPaintListener(new PaintListener() {
6161
public void paintControl(PaintEvent pe) {
6262
doPaint(pe);
6363
}
6464
});
6565

66-
ShapePicker.this.addMouseMoveListener(new MouseMoveListener() {
66+
addMouseMoveListener(new MouseMoveListener() {
6767
public void mouseMove(MouseEvent e) {
6868
if (!getEnabled()) {
6969
return;
@@ -77,7 +77,7 @@ public void mouseMove(MouseEvent e) {
7777
}
7878
});
7979

80-
ShapePicker.this.addMouseListener(new MouseListener() {
80+
this.addMouseListener(new MouseListener() {
8181
public void mouseDoubleClick(MouseEvent e) {
8282
}
8383

@@ -98,7 +98,7 @@ public void mouseUp(MouseEvent e) {
9898
}
9999
});
100100

101-
ShapePicker.this.addFocusListener(new FocusListener() {
101+
addFocusListener(new FocusListener() {
102102
public void focusGained(FocusEvent e) {
103103
redraw();
104104
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.log4j.Level;
1313
import org.eclipse.core.resources.IFile;
1414
import org.eclipse.core.resources.ResourcesPlugin;
15+
import org.eclipse.core.runtime.preferences.InstanceScope;
1516
import org.eclipse.jface.preference.ColorSelector;
1617
import org.eclipse.jface.preference.PreferenceDialog;
1718
import org.eclipse.jface.preference.PreferencePage;
@@ -48,6 +49,7 @@
4849
import org.eclipse.ui.IWorkbench;
4950
import org.eclipse.ui.IWorkbenchPreferencePage;
5051
import org.eclipse.ui.dialogs.PreferencesUtil;
52+
import org.eclipse.ui.preferences.ScopedPreferenceStore;
5153

5254
import net.sourceforge.pmd.PMD;
5355
import net.sourceforge.pmd.RulePriority;
@@ -749,6 +751,14 @@ public static void setText(Text field, String txt) {
749751
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
750752
*/
751753
protected void performDefaults() {
754+
for (RulePriority priority : RulePriority.values()) {
755+
PriorityDescriptor defaultDescriptor = PMDPlugin.getDefault().getPreferencesManager().defaultDescriptorFor(priority);
756+
PriorityDescriptor descriptor = PriorityDescriptorCache.INSTANCE.descriptorFor(priority);
757+
descriptor.shape.shape = defaultDescriptor.shape.shape;
758+
descriptor.shape.rgbColor = defaultDescriptor.shape.rgbColor;
759+
descriptor.label = defaultDescriptor.label;
760+
}
761+
tableViewer.refresh();
752762

753763
setText(additionalCommentText, IPreferences.REVIEW_ADDITIONAL_COMMENT_DEFAULT);
754764

@@ -821,13 +831,23 @@ private void updateMarkerIcons() {
821831

822832
PriorityDescriptorCache.INSTANCE.storeInPreferences();
823833

834+
// refresh the resources so that the rule label decorator is updated
824835
RootRecord root = new RootRecord(ResourcesPlugin.getWorkspace().getRoot());
825836
Set<IFile> files = MarkerUtil.allMarkedFiles(root);
826837
PMDPlugin.getDefault().changedFiles(files);
827838

828-
/* Refresh the views to pick up the marker change */
839+
// Refresh the views to pick up the marker change
829840
PMDPlugin.getDefault().refreshView(PMDPlugin.VIOLATIONS_OVERVIEW_ID);
830-
PMDPlugin.getDefault().refreshView(PMDPlugin.VIOLATIONS_OUTLINE_ID);
841+
PMDPlugin.getDefault().refreshView(PMDPlugin.VIOLATIONS_OUTLINE_ID);
842+
843+
// Take the color to set the overview ruler color
844+
// net.sourceforge.pmd.eclipse.plugin.annotation.prio1.color
845+
ScopedPreferenceStore editorsPreferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.editors");
846+
for (RulePriority priority : RulePriority.values()) {
847+
PriorityDescriptor descriptor = PriorityDescriptorCache.INSTANCE.descriptorFor(priority);
848+
editorsPreferenceStore.setValue("net.sourceforge.pmd.eclipse.plugin.annotation.prio" + priority.getPriority() + ".color",
849+
descriptor.shape.rgbColor.red + "," + descriptor.shape.rgbColor.green + "," + descriptor.shape.rgbColor.blue);
850+
}
831851
}
832852

833853
public boolean performCancel() {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/priority/PriorityDescriptorCache.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void loadFromPreferences() {
4343
IPreferences preferences = preferencesManager().loadPreferences();
4444
for (RulePriority rp : UISettings.currentPriorities(true)) {
4545
// note: the priority descriptors are cloned here, so that any changes to them
46-
// does not automatically get stored. Changes might occur while configuring the
46+
// do not automatically get stored. Changes might occur while configuring the
4747
// preferences, but the user might cancel.
4848
uiDescriptorsByPriority.put(rp, preferences.getPriorityDescriptor(rp).clone());
4949
}
@@ -55,7 +55,10 @@ public void storeInPreferences() {
5555
IPreferences prefs = mgr.loadPreferences();
5656

5757
for (Map.Entry<RulePriority, PriorityDescriptor> entry : uiDescriptorsByPriority.entrySet()) {
58-
prefs.setPriorityDescriptor(entry.getKey(), entry.getValue());
58+
// note: the priority descriptors are cloned here, so that any changes to them
59+
// do not automatically get stored. Changes might occur while configuring the
60+
// preferences, but the user might cancel.
61+
prefs.setPriorityDescriptor(entry.getKey(), entry.getValue().clone());
5962
}
6063
prefs.sync();
6164
// recreate images with the changed settings

0 commit comments

Comments
 (0)