forked from phoedos/pmd
Fixed bug in ruleset properties customization: patch submitted by trausch at gmx.at, test added.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7173 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -39,6 +39,8 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.prefs.BackingStoreException;
|
||||
import java.util.prefs.Preferences;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import org.openide.util.NbPreferences;
|
||||
|
||||
/**
|
||||
@ -87,7 +89,7 @@ public class PMDOptionsSettings {
|
||||
"AvoidReassigningParametersRule, OnlyOneReturn, UseSingletonRule, " +
|
||||
"DontImportJavaLang, UnusedImports, DuplicateImports, ";
|
||||
|
||||
/** Name of key for storing part of cumstom rulesets settings. */
|
||||
/** Name of key for storing part of custom rule-set settings. */
|
||||
private static String PROP_INCLUDE_STD_RULES = "includeStdRules";
|
||||
|
||||
private static final String NODE_RULESETS = "rulesets";
|
||||
@ -189,7 +191,7 @@ public class PMDOptionsSettings {
|
||||
int idx = keyName.indexOf(".", PROP_RULE_PROPERTIES.length()+2);
|
||||
if (idx == -1)
|
||||
continue;
|
||||
String ruleName = keyName.substring(PROP_RULE_PROPERTIES.length()+1, idx - 1);
|
||||
String ruleName = keyName.substring(PROP_RULE_PROPERTIES.length()+1, idx);
|
||||
Map<String, String> props = ruleProps.get(ruleName);
|
||||
if (props == null) {
|
||||
props = new HashMap<String, String>();
|
||||
@ -223,7 +225,7 @@ public class PMDOptionsSettings {
|
||||
int idx = keyName.indexOf(".", PROP_RULE_PROPERTIES.length()+2);
|
||||
if (idx == -1)
|
||||
continue;
|
||||
String ruleName = keyName.substring(PROP_RULE_PROPERTIES.length()+1, idx - 1);
|
||||
String ruleName = keyName.substring(PROP_RULE_PROPERTIES.length()+1, idx);
|
||||
String propName = keyName.substring(idx+1);
|
||||
if (ruleProperties.get(ruleName) != null && ruleProperties.get(ruleName).get(propName) == null) {
|
||||
prefs.remove(keyName);
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003, the pmd-netbeans team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*/
|
||||
package pmd.config;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import org.netbeans.junit.NbTestCase;
|
||||
|
||||
/**
|
||||
* @author radim
|
||||
*/
|
||||
public class PMDOptionsSettingsTest extends NbTestCase {
|
||||
|
||||
public PMDOptionsSettingsTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getHelpCtx method, of class pmd.RunPMDAction.
|
||||
*/
|
||||
public void testRuleProperties() {
|
||||
// Preferences prefs = mock(Preferences.class);
|
||||
// PMDOptionsSettings settings = new PMDOptionsSettings(prefs);
|
||||
PMDOptionsSettings settings = PMDOptionsSettings.getDefault();
|
||||
Map<String, Map<String, String>> ruleProperties = new HashMap<String, Map<String, String>>();
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put("propA", "valueA");
|
||||
properties.put("propB", "valueB");
|
||||
ruleProperties.put("rule1", properties);
|
||||
properties = new HashMap<String, String>();
|
||||
properties.put("prop1", "value1");
|
||||
ruleProperties.put("rule2", properties);
|
||||
settings.setRuleProperties(ruleProperties);
|
||||
|
||||
Map<String, Map<String, String>> readRuleProperties = settings.getRuleProperties();
|
||||
assertNotNull(readRuleProperties);
|
||||
assertTrue("correct size of " + readRuleProperties, readRuleProperties.size() == ruleProperties.size());
|
||||
for(Map.Entry<String, Map<String, String>> entry : readRuleProperties.entrySet()) {
|
||||
assertTrue(ruleProperties.containsKey(entry.getKey()));
|
||||
assertEquals(entry.getValue(), ruleProperties.get(entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user