Skip to content

Commit 3aaaf47

Browse files
committed
Merge branch 'pr-39'
2 parents 13f8ba4 + bcbe5f5 commit 3aaaf47

File tree

11 files changed

+198
-3
lines changed

11 files changed

+198
-3
lines changed

ReleaseNotes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Eclipse Update Site:
1313

1414
* Updated PMD to 6.2.0
1515
* At least Java 1.7 is required now.
16+
* Two new options under Preferences: "Show PMD violations overview when checking code" and "Show PMD violations
17+
outline when checking code". If these options are checked, then theses PMD views are shown automatically,
18+
when PMD check is executed for a project. This behaves similar like "Show PMD perspective", but just doesn't
19+
switch the current perspective.
1620

1721
### Fixed Issues
1822

@@ -26,6 +30,7 @@ Eclipse Update Site:
2630
* [#25](https://github.com/pmd/pmd-eclipse-plugin/pull/25): \[core] Typesafe properties - [Clément Fournier](https://github.com/oowekyala)
2731
* [#26](https://github.com/pmd/pmd-eclipse-plugin/pull/26): Updated french translations - [Clément Fournier](https://github.com/oowekyala)
2832
* [#37](https://github.com/pmd/pmd-eclipse-plugin/pull/37): Global Priority Filter for Violations Overview/Outline - [Phillip Krall](https://github.com/pkrall520)
33+
* [#39](https://github.com/pmd/pmd-eclipse-plugin/pull/39): Show PMD violations overview/outline views when checking code - [Phillip Krall](https://github.com/pkrall520)
2934

3035

3136
## 24-June-2017: 4.0.15.v20170624-2134

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ preference.pmd.group.priorities = Priority levels
2424
preference.pmd.group.review = Violations review parameters
2525
preference.pmd.group.general = General options
2626
preference.pmd.label.perspective_on_check = Show PMD perspective when checking code
27+
preference.pmd.label.violationsoverview_on_check = Show PMD violations overview when checking code
28+
preference.pmd.label.violationsoutline_on_check = Show PMD violations outline when checking code
2729
preference.pmd.label.check_after_saving = Check code after saving
2830
preference.pmd.label.use_dfa = Enable dataflow anomaly analysis (experimental)
2931
preference.pmd.label.use_project_build_path = Enable using Java Project Build Path. Disable if your Eclipse JVM version is incompatible with .class file versions.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ preference.pmd.group.priorities = Niveaux de priorit
2424
preference.pmd.group.review = Paramètres de revue des violations
2525
preference.pmd.group.general = Options générales
2626
preference.pmd.label.perspective_on_check = Basculer sur la perspective PMD après la vérification (mode manuel seulement)
27+
preference.pmd.label.violationsoverview_on_check = Afficher la synthèse des violations de PMD lors de la vérification du code
28+
preference.pmd.label.violationsoutline_on_check = Afficher les violations de PMD lors de la vérification du code
2729
preference.pmd.label.check_after_saving = Vérifier à chaque sauvegarde
2830
preference.pmd.label.use_dfa = Activer l'analyse d'anomalie de flots de données (expérimental)
2931
preference.pmd.label.use_project_build_path = Activer l'utilisation du chemin de construction du projet. A désactiver si la machine virtuelle de votre Eclipse est incompatible avec la version des fichiers .class.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.eclipse.ui.IEditorPart;
4747
import org.eclipse.ui.IEditorReference;
4848
import org.eclipse.ui.IWorkbenchPart;
49+
import org.eclipse.ui.PartInitException;
4950
import org.eclipse.ui.PlatformUI;
5051
import org.eclipse.ui.plugin.AbstractUIPlugin;
5152
import org.osgi.framework.Bundle;
@@ -88,6 +89,8 @@ public class PMDPlugin extends AbstractUIPlugin {
8889
private static File pluginFolder;
8990

9091
private FileChangeReviewer changeReviewer;
92+
public static final String VIOLATIONS_OVERVIEW_ID = "net.sourceforge.pmd.eclipse.ui.views.violationOverview";
93+
public static final String VIOLATIONS_OUTLINE_ID = "net.sourceforge.pmd.eclipse.ui.views.violationOutline";
9194

9295
private Map<RGB, Color> coloursByRGB = new HashMap<RGB, Color>();
9396

@@ -264,6 +267,24 @@ public Set<IFile> getOpenFiles() {
264267
}
265268
return files;
266269
}
270+
271+
/**
272+
* Open a view to the id passed in.
273+
*
274+
* @param viewId id of the view
275+
*/
276+
public void showView(final String viewId) {
277+
Display.getDefault().asyncExec(new Runnable() {
278+
@Override
279+
public void run() {
280+
try {
281+
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewId);
282+
} catch (PartInitException e) {
283+
LOG.error(e);
284+
}
285+
}
286+
});
287+
}
267288

268289
public void fileChangeListenerEnabled(boolean flag) {
269290

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import name.herlin.command.CommandException;
8686
import name.herlin.command.Timer;
8787

88+
8889
/**
8990
* This command executes the PMD engine on a specified resource
9091
*
@@ -100,6 +101,8 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
100101
private Map<IFile, Set<MarkerInfo2>> markersByFile = new HashMap<IFile, Set<MarkerInfo2>>();
101102
private boolean taskMarker;
102103
private boolean openPmdPerspective;
104+
private boolean openPmdViolationsOverviewView;
105+
private boolean openPmdViolationsOutlineView;
103106
private int ruleCount;
104107
private int fileCount;
105108
private long pmdDuration;
@@ -144,6 +147,8 @@ public static void runCodeReviewOnFiles(Set<IFile> files) throws CommandExceptio
144147
cmd.setStepCount(files.size());
145148
cmd.setTaskMarker(true);
146149
cmd.setOpenPmdPerspective(PMDPlugin.getDefault().loadPreferences().isPmdPerspectiveEnabled());
150+
cmd.setOpenPmdViolationsOverviewView(PMDPlugin.getDefault().loadPreferences().isPmdViolationsOverviewEnabled());
151+
cmd.setOpenPmdViolationsOutlineView(PMDPlugin.getDefault().loadPreferences().isPmdViolationsOutlineEnabled());
147152
cmd.setUserInitiated(true);
148153
cmd.setRunAlways(true);
149154
for (IResource file : files) {
@@ -255,6 +260,14 @@ public void run() {
255260
});
256261
}
257262

263+
if (openPmdViolationsOverviewView) {
264+
PMDPlugin.getDefault().showView(PMDPlugin.VIOLATIONS_OVERVIEW_ID);
265+
}
266+
267+
if (openPmdViolationsOutlineView) {
268+
PMDPlugin.getDefault().showView(PMDPlugin.VIOLATIONS_OUTLINE_ID);
269+
}
270+
258271
} catch (CoreException e) {
259272
throw new CommandException("Core exception when reviewing code", e);
260273
} finally {
@@ -338,6 +351,24 @@ public void setRunAlways(boolean runAlways) {
338351
public void setOpenPmdPerspective(boolean openPmdPerspective) {
339352
this.openPmdPerspective = openPmdPerspective;
340353
}
354+
355+
/**
356+
* Set the open violations view to run after code review.
357+
*
358+
* @param openPmdViolationsView should open
359+
*/
360+
public void setOpenPmdViolationsOverviewView(boolean openPmdViolationsView) {
361+
this.openPmdViolationsOverviewView = openPmdViolationsView;
362+
}
363+
364+
/**
365+
* Set the open violations outline view to run after code review.
366+
*
367+
* @param openPmdViolationsOutlineView should open
368+
*/
369+
public void setOpenPmdViolationsOutlineView(boolean openPmdViolationsOutlineView) {
370+
this.openPmdViolationsOutlineView = openPmdViolationsOutlineView;
371+
}
341372

342373
/**
343374
* @see name.herlin.command.Command#reset()
@@ -348,6 +379,8 @@ public void reset() {
348379
markersByFile = new HashMap<IFile, Set<MarkerInfo2>>();
349380
setTerminated(false);
350381
openPmdPerspective = false;
382+
openPmdViolationsOverviewView = false;
383+
openPmdViolationsOutlineView = false;
351384
onErrorIssue = null;
352385
runAlways = false;
353386
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public interface IPreferences {
5656

5757
boolean PROJECT_BUILD_PATH_ENABLED_DEFAULT = true;
5858
boolean PMD_PERSPECTIVE_ENABLED_DEFAULT = true;
59+
boolean PMD_VIOLATIONS_OVERVIEW_ENABLED_DEFAULT = false;
60+
boolean PMD_VIOLATIONS_OUTLINE_ENABLED_DEFAULT = false;
5961
boolean PMD_CHECK_AFTER_SAVE_DEFAULT = false;
6062
boolean PMD_USE_CUSTOM_PRIORITY_NAMES_DEFAULT = true;
6163
int MAX_VIOLATIONS_PFPR_DEFAULT = 5;
@@ -110,6 +112,18 @@ public interface IPreferences {
110112
* is launched ?
111113
*/
112114
boolean isPmdPerspectiveEnabled();
115+
116+
/**
117+
* Should the plugin show the PMD violations overview when a code review is launched?
118+
* @return
119+
*/
120+
boolean isPmdViolationsOverviewEnabled();
121+
122+
/**
123+
* Should the plugin show the PMD violations outline when a code review is launched?
124+
* @return
125+
*/
126+
boolean isPmdViolationsOutlineEnabled();
113127

114128
/**
115129
* Should the plugin scan any newly-saved code?
@@ -130,6 +144,18 @@ public interface IPreferences {
130144
* review is launched
131145
*/
132146
void setPmdPerspectiveEnabled(boolean pmdPerspectiveEnabled);
147+
148+
/**
149+
* Set whether the plugin switch to the PMD violations overview when a manual code
150+
* review is launched
151+
*/
152+
void setPmdViolationsOverviewEnabled(boolean pmdViolationsOverviewEnabled);
153+
154+
/**
155+
* Set whether the plugin switch to the PMD violations outline when a manual code
156+
* review is launched
157+
*/
158+
void setPmdViolationsOutlineEnabled(boolean pmdViolationsOutlineEnabled);
133159

134160
/**
135161
* Get the maximum number of violations per file per rule reported by the

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class PreferencesImpl implements IPreferences {
6666
private IPreferencesManager preferencesManager;
6767
private boolean projectBuildPathEnabled;
6868
private boolean pmdPerspectiveEnabled;
69+
private boolean pmdViolationsOverviewEnabled;
70+
private boolean pmdViolationsOutlineEnabled;
6971
private boolean checkAfterSaveEnabled;
7072
private boolean useCustomPriorityNames;
7173
private int maxViolationsPerFilePerRule;
@@ -146,6 +148,14 @@ public void isCheckAfterSaveEnabled(boolean flag) {
146148
public void setPmdPerspectiveEnabled(boolean pmdPerspectiveEnabled) {
147149
this.pmdPerspectiveEnabled = pmdPerspectiveEnabled;
148150
}
151+
152+
/**
153+
* @see net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences#setPmdViolationsOverviewEnabled(boolean)
154+
*/
155+
public void setPmdViolationsOverviewEnabled(boolean pmdViolationsOverviewEnabled) {
156+
this.pmdViolationsOverviewEnabled = pmdViolationsOverviewEnabled;
157+
}
158+
149159

150160
/**
151161
* @see net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences#getMaxViolationsPerFilePerRule()
@@ -323,9 +333,25 @@ public void useCustomPriorityNames(boolean flag) {
323333
public Set<String> activeReportRenderers() {
324334
return activeRendererNames;
325335
}
326-
336+
337+
@Override
327338
public void activeReportRenderers(Set<String> names) {
328339
activeRendererNames = names;
329340
}
330341

342+
@Override
343+
public boolean isPmdViolationsOverviewEnabled() {
344+
return pmdViolationsOverviewEnabled;
345+
}
346+
347+
@Override
348+
public boolean isPmdViolationsOutlineEnabled() {
349+
return pmdViolationsOutlineEnabled;
350+
}
351+
352+
@Override
353+
public void setPmdViolationsOutlineEnabled(boolean pmdViolationsOutlineEnabled) {
354+
this.pmdViolationsOutlineEnabled = pmdViolationsOutlineEnabled;
355+
}
356+
331357
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class PreferencesManagerImpl implements IPreferencesManager {
9494

9595
private static final String PROJECT_BUILD_PATH_ENABLED = PMDPlugin.PLUGIN_ID + ".project_build_path_enabled";
9696
private static final String PMD_PERSPECTIVE_ENABLED = PMDPlugin.PLUGIN_ID + ".pmd_perspective_enabled";
97+
private static final String PMD_VIOLATIONS_OVERVIEW_ENABLED = PMDPlugin.PLUGIN_ID + ".pmd_overview_enabled";
98+
private static final String PMD_VIOLATIONS_OUTLINE_ENABLED = PMDPlugin.PLUGIN_ID + ".pmd_outline_enabled";
9799
private static final String PMD_CHECK_AFTER_SAVE_ENABLED = PMDPlugin.PLUGIN_ID + ".pmd_check_after_save_enabled";
98100
private static final String MAX_VIOLATIONS_PFPR = PMDPlugin.PLUGIN_ID + ".max_violations_pfpr";
99101
private static final String REVIEW_ADDITIONAL_COMMENT = PMDPlugin.PLUGIN_ID + ".review_additional_comment";
@@ -174,6 +176,8 @@ public IPreferences reloadPreferences() {
174176

175177
loadProjectBuildPathEnabled();
176178
loadPmdPerspectiveEnabled();
179+
loadPmdViolationsOverviewEnabled();
180+
loadPmdViolationsOutlineEnabled();
177181
loadCheckAfterSaveEnabled();
178182
loadUseCustomPriorityNames();
179183
loadMaxViolationsPerFilePerRule();
@@ -238,6 +242,8 @@ public void storePreferences(IPreferences thePreferences) {
238242

239243
storeProjectBuildPathEnabled();
240244
storePmdPerspectiveEnabled();
245+
storePmdViolationsOverviewEnabled();
246+
storePmdViolationsOutlineEnabled();
241247
storeCheckAfterSaveEnabled();
242248
storeUseCustomPriorityNames();
243249
storeMaxViolationsPerFilePerRule();
@@ -283,7 +289,17 @@ private void loadPmdPerspectiveEnabled() {
283289
loadPreferencesStore.setDefault(PMD_PERSPECTIVE_ENABLED, IPreferences.PMD_PERSPECTIVE_ENABLED_DEFAULT);
284290
preferences.setPmdPerspectiveEnabled(loadPreferencesStore.getBoolean(PMD_PERSPECTIVE_ENABLED));
285291
}
286-
292+
293+
private void loadPmdViolationsOverviewEnabled() {
294+
loadPreferencesStore.setDefault(PMD_VIOLATIONS_OVERVIEW_ENABLED, IPreferences.PMD_VIOLATIONS_OVERVIEW_ENABLED_DEFAULT);
295+
preferences.setPmdPerspectiveEnabled(loadPreferencesStore.getBoolean(PMD_VIOLATIONS_OVERVIEW_ENABLED));
296+
}
297+
298+
private void loadPmdViolationsOutlineEnabled() {
299+
loadPreferencesStore.setDefault(PMD_VIOLATIONS_OUTLINE_ENABLED, IPreferences.PMD_VIOLATIONS_OUTLINE_ENABLED_DEFAULT);
300+
preferences.setPmdPerspectiveEnabled(loadPreferencesStore.getBoolean(PMD_VIOLATIONS_OUTLINE_ENABLED));
301+
}
302+
287303
private void loadCheckAfterSaveEnabled() {
288304
loadPreferencesStore.setDefault(PMD_CHECK_AFTER_SAVE_ENABLED, IPreferences.PMD_CHECK_AFTER_SAVE_DEFAULT);
289305
preferences.isCheckAfterSaveEnabled(loadPreferencesStore.getBoolean(PMD_CHECK_AFTER_SAVE_ENABLED));
@@ -428,6 +444,14 @@ private void storePmdPerspectiveEnabled() {
428444
storePreferencesStore.setValue(PMD_PERSPECTIVE_ENABLED, preferences.isPmdPerspectiveEnabled());
429445
}
430446

447+
private void storePmdViolationsOverviewEnabled() {
448+
storePreferencesStore.setValue(PMD_VIOLATIONS_OVERVIEW_ENABLED, preferences.isPmdViolationsOverviewEnabled());
449+
}
450+
451+
private void storePmdViolationsOutlineEnabled() {
452+
storePreferencesStore.setValue(PMD_VIOLATIONS_OUTLINE_ENABLED, preferences.isPmdViolationsOutlineEnabled());
453+
}
454+
431455
private void storeMaxViolationsPerFilePerRule() {
432456
storePreferencesStore.setValue(MAX_VIOLATIONS_PFPR, preferences.getMaxViolationsPerFilePerRule());
433457
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/actions/PMDCheckAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ private void setupAndExecute(ReviewCodeCmd cmd, int count) throws CommandExcepti
131131
cmd.setStepCount(count);
132132
cmd.setTaskMarker(true);
133133
cmd.setOpenPmdPerspective(PMDPlugin.getDefault().loadPreferences().isPmdPerspectiveEnabled());
134+
cmd.setOpenPmdViolationsOverviewView(PMDPlugin.getDefault().loadPreferences().isPmdViolationsOverviewEnabled());
135+
cmd.setOpenPmdViolationsOutlineView(PMDPlugin.getDefault().loadPreferences().isPmdViolationsOutlineEnabled());
134136
cmd.setUserInitiated(true);
135137
cmd.setRunAlways(true);
136138
cmd.performExecute();

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/nls/StringKeys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public class StringKeys {
6666
public static final String PREF_GENERAL_GROUP_PRIORITIES = "preference.pmd.group.priorities";
6767
public static final String PREF_GENERAL_GROUP_GENERAL = "preference.pmd.group.general";
6868
public static final String PREF_GENERAL_LABEL_SHOW_PERSPECTIVE = "preference.pmd.label.perspective_on_check";
69+
// TODO (pk) Add the Fr version
70+
public static final String PREF_GENERAL_LABEL_SHOW_VIOLATIONS_OVERVIEW = "preference.pmd.label.violationsoverview_on_check";
71+
public static final String PREF_GENERAL_LABEL_SHOW_VIOLATIONS_OUTLINE = "preference.pmd.label.violationsoutline_on_check";
6972
public static final String PREF_GENERAL_LABEL_CHECK_AFTER_SAVING = "preference.pmd.label.check_after_saving";
7073
public static final String PREF_GENERAL_LABEL_USE_DFA = "preference.pmd.label.use_dfa";
7174
public static final String PREF_GENERAL_LABEL_USE_PROJECT_BUILD_PATH = "preference.pmd.label.use_project_build_path";

0 commit comments

Comments
 (0)