Skip to content

Commit 7000b2d

Browse files
committed
Remove the storage of inactive rules.
Log a warning, if global rule management is active and not all rules are being applied.
1 parent a9fb274 commit 7000b2d

File tree

8 files changed

+19
-30
lines changed

8 files changed

+19
-30
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ public void storeAndLoadInactiveRules() {
2525
IPreferences preferences = manager.loadPreferences();
2626
preferences.isActive(ruleName, false);
2727
manager.storePreferences(preferences);
28-
Assert.assertFalse(preferences.getInactiveRuleNames().isEmpty());
29-
Assert.assertTrue(preferences.getInactiveRuleNames().contains(ruleName));
28+
Assert.assertFalse(preferences.getActiveRuleNames().contains(ruleName));
3029

3130
preferences = manager.reloadPreferences();
32-
Assert.assertFalse(preferences.getInactiveRuleNames().isEmpty());
33-
Assert.assertTrue(preferences.getInactiveRuleNames().contains(ruleName));
31+
Assert.assertFalse(preferences.getActiveRuleNames().contains(ruleName));
3432
}
3533
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ public void logInformation(String message) {
416416
getLog().log(new Status(IStatus.INFO, getBundle().getSymbolicName(), 0, message, null));
417417
}
418418

419+
public void logWarn(String message) {
420+
getLog().log(new Status(IStatus.WARNING, getBundle().getSymbolicName(), 0, message, null));
421+
}
422+
419423
/**
420424
* @return an instance of an AST writer
421425
*/

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,19 @@ private RuleSet filteredRuleSet(IProjectProperties properties) throws CommandExc
463463

464464
final RuleSet ruleSet = properties.getProjectRuleSet();
465465
IPreferences preferences = PMDPlugin.getDefault().getPreferencesManager().loadPreferences();
466-
Set<String> inactiveRuleNames = preferences.getInactiveRuleNames();
466+
Set<String> onlyActiveRuleNames = preferences.getActiveRuleNames();
467467

468468
RuleSet filteredRuleSet = RuleSetUtil.newCopyOf(ruleSet);
469+
int rulesBefore = filteredRuleSet.size();
469470
if (preferences.getGlobalRuleManagement()) {
470-
RuleSetUtil.remove(filteredRuleSet, inactiveRuleNames);
471+
RuleSetUtil.retainOnly(filteredRuleSet, onlyActiveRuleNames);
472+
int rulesAfter = filteredRuleSet.size();
473+
474+
if (rulesAfter < rulesBefore) {
475+
PMDPlugin.getDefault().logWarn("Ruleset has been filtered as Global Rule Management is active. "
476+
+ rulesAfter + " of " + rulesBefore + " rules are active and are used. "
477+
+ (rulesBefore - rulesAfter) + " rules will be ignored.");
478+
}
471479
}
472480
filteredRuleSet.addExcludePatterns(preferences.activeExclusionPatterns());
473481
filteredRuleSet.addIncludePatterns(preferences.activeInclusionPatterns());

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public interface IPreferences {
6969
String ACTIVE_RENDERERS = "text";
7070
String ACTIVE_EXCLUSIONS = "";
7171
String ACTIVE_INCLUSIONS = "";
72-
String INACTIVE_RULES = "";
7372

7473
boolean GLOBAL_RULE_MANAGEMENT_DEFAULT = false;
7574

@@ -94,12 +93,8 @@ public interface IPreferences {
9493

9594
Set<String> getActiveRuleNames();
9695

97-
Set<String> getInactiveRuleNames();
98-
9996
void setActiveRuleNames(Set<String> ruleNames);
10097

101-
void setInactiveRuleNames(Set<String> ruleNames);
102-
10398
/**
10499
* Should the Project Build Path be used?
105100
*/

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class PreferencesManagerImpl implements IPreferencesManager {
107107
private static final String LOG_FILENAME = PMDPlugin.PLUGIN_ID + ".log_filename";
108108
private static final String LOG_LEVEL = PMDPlugin.PLUGIN_ID + ".log_level";
109109
private static final String GLOBAL_RULE_MANAGEMENT = PMDPlugin.PLUGIN_ID + ".globalRuleManagement";
110-
private static final String INACTIVE_RULES = PMDPlugin.PLUGIN_ID + ".inactive_rules";
111110
private static final String ACTIVE_RULES = PMDPlugin.PLUGIN_ID + ".active_rules";
112111
private static final String ACTIVE_RENDERERS = PMDPlugin.PLUGIN_ID + ".active_renderers";
113112
private static final String ACTIVE_EXCLUSIONS = PMDPlugin.PLUGIN_ID + ".active_exclusions";
@@ -171,7 +170,6 @@ public IPreferences reloadPreferences() {
171170
loadLogFileName();
172171
loadLogLevel();
173172
loadGlobalRuleManagement();
174-
loadInactiveRules();
175173
loadActiveRules();
176174
loadActiveReportRenderers();
177175
loadActiveExclusions();
@@ -236,7 +234,6 @@ public void storePreferences(IPreferences thePreferences) {
236234
storeLogFileName();
237235
storeLogLevel();
238236
storeGlobalRuleManagement();
239-
storeInactiveRules();
240237
storeActiveRules();
241238
storeActiveReportRenderers();
242239
storeActiveExclusions();
@@ -319,11 +316,6 @@ private void loadGlobalRuleManagement() {
319316
preferences.setGlobalRuleManagement(loadPreferencesStore.getBoolean(GLOBAL_RULE_MANAGEMENT));
320317
}
321318

322-
private void loadInactiveRules() {
323-
loadPreferencesStore.setDefault(INACTIVE_RULES, IPreferences.INACTIVE_RULES);
324-
preferences.setInactiveRuleNames(asStringSet(loadPreferencesStore.getString(INACTIVE_RULES), ","));
325-
}
326-
327319
private void loadActiveRules() {
328320
loadPreferencesStore.setDefault(ACTIVE_RULES, preferences.getDefaultActiveRules());
329321
preferences.setActiveRuleNames(asStringSet(loadPreferencesStore.getString(ACTIVE_RULES), ","));
@@ -384,9 +376,6 @@ private void storeGlobalRuleManagement() {
384376
storePreferencesStore.setValue(GLOBAL_RULE_MANAGEMENT, preferences.getGlobalRuleManagement());
385377
}
386378

387-
private void storeInactiveRules() {
388-
storePreferencesStore.setValue(INACTIVE_RULES, asDelimitedString(preferences.getInactiveRuleNames(), ","));
389-
}
390379
private void storeActiveRules() {
391380
storePreferencesStore.setValue(ACTIVE_RULES, asDelimitedString(preferences.getActiveRuleNames(), ","));
392381
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void retainOnly(RuleSet ruleSet, Set<String> wantedRuleNames) {
4040
Collection<Rule> rules = ruleSet.getRules();
4141
Collection<Rule> ruleCopy = new ArrayList<Rule>(rules.size());
4242
ruleCopy.addAll(rules);
43-
43+
4444
for (Rule rule : ruleCopy) {
4545
if (!wantedRuleNames.contains(rule.getName())) {
4646
rules.remove(rule);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package net.sourceforge.pmd.eclipse.ui.preferences.br;
22

33
import java.lang.reflect.InvocationTargetException;
4-
import java.util.Collections;
54
import java.util.HashSet;
65
import java.util.List;
76
import java.util.Set;
@@ -522,9 +521,7 @@ private void storeActiveRules() {
522521
activeRules.add(rule.getName());
523522
}
524523

525-
// first remove all inactive rules
526-
preferences.setInactiveRuleNames(new HashSet<String>());
527-
// then override the active rules
524+
// override all the active rules
528525
preferences.setActiveRuleNames(activeRules);
529526

530527
// System.out.println("Active rules: " + preferences.getActiveRuleNames());

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,7 @@ protected void setAllItemsActive() {
952952
activeRules.add(rulesArray[i].getName());
953953
}
954954

955-
// remove first all inactive rules
956-
preferences.setInactiveRuleNames(new HashSet<String>());
957-
// then set all active rules
955+
// set all active rules
958956
preferences.setActiveRuleNames(activeRules);
959957

960958
treeViewer().setCheckedElements(rulesArray);

0 commit comments

Comments
 (0)