Skip to content

Commit 85a7486

Browse files
Phillip KrallPhillip Krall
authored andcommitted
Add new options
Add new options to open to the violations overview or outline after a code review without going to the perspective.
1 parent 4487fa6 commit 85a7486

File tree

10 files changed

+194
-6
lines changed

10 files changed

+194
-6
lines changed

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: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
import org.eclipse.ui.IWorkbenchWindow;
7272
import org.eclipse.ui.PlatformUI;
7373

74+
import name.herlin.command.CommandException;
75+
import name.herlin.command.Timer;
7476
import net.sourceforge.pmd.Rule;
7577
import net.sourceforge.pmd.RuleSet;
7678
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
@@ -82,9 +84,6 @@
8284
import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil;
8385
import net.sourceforge.pmd.util.StringUtil;
8486

85-
import name.herlin.command.CommandException;
86-
import name.herlin.command.Timer;
87-
8887
/**
8988
* This command executes the PMD engine on a specified resource
9089
*
@@ -100,6 +99,8 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
10099
private Map<IFile, Set<MarkerInfo2>> markersByFile = new HashMap<IFile, Set<MarkerInfo2>>();
101100
private boolean taskMarker;
102101
private boolean openPmdPerspective;
102+
private boolean openPmdViolationsOverviewView;
103+
private boolean openPmdViolationsOutlineView;
103104
private int ruleCount;
104105
private int fileCount;
105106
private long pmdDuration;
@@ -144,6 +145,8 @@ public static void runCodeReviewOnFiles(Set<IFile> files) throws CommandExceptio
144145
cmd.setStepCount(files.size());
145146
cmd.setTaskMarker(true);
146147
cmd.setOpenPmdPerspective(PMDPlugin.getDefault().loadPreferences().isPmdPerspectiveEnabled());
148+
cmd.setOpenPmdViolationsOverviewView(PMDPlugin.getDefault().loadPreferences().isPmdViolationsOverviewEnabled());
149+
cmd.setOpenPmdViolationsOutlineView(PMDPlugin.getDefault().loadPreferences().isPmdViolationsOutlineEnabled());
147150
cmd.setUserInitiated(true);
148151
cmd.setRunAlways(true);
149152
for (IResource file : files) {
@@ -255,6 +258,14 @@ public void run() {
255258
});
256259
}
257260

261+
if (openPmdViolationsOverviewView) {
262+
PMDPlugin.getDefault().showView(PMDPlugin.VIOLATIONS_OVERVIEW_ID);
263+
}
264+
265+
if (openPmdViolationsOutlineView) {
266+
PMDPlugin.getDefault().showView(PMDPlugin.VIOLATIONS_OUTLINE_ID);
267+
}
268+
258269
} catch (CoreException e) {
259270
throw new CommandException("Core exception when reviewing code", e);
260271
} finally {
@@ -338,6 +349,24 @@ public void setRunAlways(boolean runAlways) {
338349
public void setOpenPmdPerspective(boolean openPmdPerspective) {
339350
this.openPmdPerspective = openPmdPerspective;
340351
}
352+
353+
/**
354+
* Set the open violations view to run after code review.
355+
*
356+
* @param openPmdViolationsView should open
357+
*/
358+
public void setOpenPmdViolationsOverviewView(boolean openPmdViolationsView) {
359+
this.openPmdViolationsOverviewView = openPmdViolationsView;
360+
}
361+
362+
/**
363+
* Set the open violations outline view to run after code review.
364+
*
365+
* @param openPmdViolationsOutlineView should open
366+
*/
367+
public void setOpenPmdViolationsOutlineView(boolean openPmdViolationsOutlineView) {
368+
this.openPmdViolationsOutlineView = openPmdViolationsOutlineView;
369+
}
341370

342371
/**
343372
* @see name.herlin.command.Command#reset()
@@ -348,6 +377,8 @@ public void reset() {
348377
markersByFile = new HashMap<IFile, Set<MarkerInfo2>>();
349378
setTerminated(false);
350379
openPmdPerspective = false;
380+
openPmdViolationsOverviewView = false;
381+
openPmdViolationsOutlineView = false;
351382
onErrorIssue = null;
352383
runAlways = false;
353384
}

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)