|
43 | 43 | import java.io.StringWriter; |
44 | 44 | import java.util.ArrayList; |
45 | 45 | import java.util.HashMap; |
| 46 | +import java.util.HashSet; |
46 | 47 | import java.util.List; |
47 | 48 | import java.util.Map; |
| 49 | +import java.util.Set; |
48 | 50 | import javax.xml.bind.DataBindingException; |
49 | 51 | import javax.xml.bind.JAXBContext; |
50 | 52 | import javax.xml.bind.JAXBElement; |
@@ -102,6 +104,7 @@ private static JAXBContext initJaxbContext() { |
102 | 104 | * @param project |
103 | 105 | * a project |
104 | 106 | */ |
| 107 | + @Override |
105 | 108 | public IProjectProperties loadProjectProperties(final IProject project) throws PropertiesException { |
106 | 109 | LOG.debug("Loading project properties for project " + project.getName()); |
107 | 110 | try { |
@@ -134,6 +137,7 @@ public IProjectProperties loadProjectProperties(final IProject project) throws P |
134 | 137 | /** |
135 | 138 | * @see net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager#storeProjectProperties(net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties) |
136 | 139 | */ |
| 140 | + @Override |
137 | 141 | public void storeProjectProperties(IProjectProperties projectProperties) throws PropertiesException { |
138 | 142 | LOG.debug("Storing project properties for project " + projectProperties.getProject().getName()); |
139 | 143 | try { |
@@ -257,14 +261,24 @@ private void fillProjectProperties(IProjectProperties projectProperties, Project |
257 | 261 | private void setRuleSetFromProperties(IProjectProperties projectProperties, RuleSpecTO[] rules) |
258 | 262 | throws PropertiesException { |
259 | 263 | final RuleSet pluginRuleSet = PMDPlugin.getDefault().getPreferencesManager().getRuleSet(); |
260 | | - int n = rules == null ? 0 : rules.length; |
| 264 | + |
| 265 | + // de-duplicate rules |
| 266 | + Set<String> ruleNamesToAdd = new HashSet<>(); |
| 267 | + for (RuleSpecTO rule : rules) { |
| 268 | + if (!ruleNamesToAdd.add(rule.getName())) { |
| 269 | + PMDPlugin.getDefault().logInformation("Duplicated Rule found: " + rule.getName() + ". This rule will be ignored."); |
| 270 | + LOG.debug("Duplicated Rule found: " + rule.getName() + ". This rule will be ignored."); |
| 271 | + } |
| 272 | + } |
| 273 | + |
261 | 274 | List<Rule> rulesToAdd = new ArrayList<Rule>(); |
262 | | - for (int i = 0; i < n; i++) { |
263 | | - final Rule rule = pluginRuleSet.getRuleByName(rules[i].getName()); |
| 275 | + for (String ruleName : ruleNamesToAdd) { |
| 276 | + Rule rule = pluginRuleSet.getRuleByName(ruleName); |
264 | 277 | if (rule != null) { |
265 | 278 | rulesToAdd.add(rule); |
266 | 279 | } else { |
267 | | - LOG.debug("The rule " + rules[i].getName() + " cannot be found. ignore."); |
| 280 | + PMDPlugin.getDefault().logInformation("The rule " + ruleName + " could not be found. The rule will be ignored."); |
| 281 | + LOG.debug("The rule " + ruleName + " could not be found. The rule will be ignored."); |
268 | 282 | } |
269 | 283 | } |
270 | 284 |
|
|
0 commit comments