forked from phoedos/pmd
Continue refactoring of rullesets management
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4579 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -6,6 +6,9 @@
|
||||
<classpathentry exported="true" kind="lib" path="lib/pmd-3.7.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/xercesImpl-2.6.2.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/xmlParserAPIs-2.6.2.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/castor-0.9.6-xml.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/log4j-1.2.8.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/commons-logging.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
|
@ -26,6 +26,15 @@
|
||||
<library name="lib/xmlParserAPIs-2.6.2.jar">
|
||||
<export name="*"/>
|
||||
</library>
|
||||
<library name="lib/castor-0.9.6-xml.jar">
|
||||
<export name="*"/>
|
||||
</library>
|
||||
<library name="lib/log4j-1.2.8.jar">
|
||||
<export name="*"/>
|
||||
</library>
|
||||
<library name="lib/commons-logging.jar">
|
||||
<export name="*"/>
|
||||
</library>
|
||||
</runtime>
|
||||
|
||||
<requires>
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Created on 2 sept. 2006
|
||||
*
|
||||
* Copyright (c) 2006, PMD for Eclipse Development 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.
|
||||
* * The end-user documentation included with the redistribution, if
|
||||
* any, must include the following acknowledgement:
|
||||
* "This product includes software developed in part by support from
|
||||
* the Defense Advanced Research Project Agency (DARPA)"
|
||||
* * Neither the name of "PMD for Eclipse Development Team" nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* 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 COPYRIGHT OWNER
|
||||
* 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 net.sourceforge.pmd.core;
|
||||
|
||||
/**
|
||||
* Root exception of the CORE plug-in
|
||||
*
|
||||
* @author Herlin
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2006/10/06 16:42:47 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class PMDCoreException extends Exception {
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public PMDCoreException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with a message and a root cause.
|
||||
* @param arg0 exception message.
|
||||
* @param arg1 root cause exception.
|
||||
*/
|
||||
public PMDCoreException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with only a message.
|
||||
* @param arg0 exception message.
|
||||
*/
|
||||
public PMDCoreException(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with a root cause exception only
|
||||
* @param arg0 root cause exception
|
||||
*/
|
||||
public PMDCoreException(Throwable arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
}
|
@ -36,11 +36,10 @@
|
||||
|
||||
package net.sourceforge.pmd.core.rulesets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import net.sourceforge.pmd.core.PMDCoreException;
|
||||
import net.sourceforge.pmd.core.rulesets.vo.RuleSet;
|
||||
import net.sourceforge.pmd.core.rulesets.vo.RuleSets;
|
||||
|
||||
@ -54,6 +53,9 @@ import net.sourceforge.pmd.core.rulesets.vo.RuleSets;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:47 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/21 23:06:41 phherlin
|
||||
* Move the new rule sets management to the core plugin instead of the runtime.
|
||||
* Continue the development.
|
||||
@ -71,9 +73,9 @@ public interface IRuleSetsManager {
|
||||
* @param ruleSetUrls an array of standard PMD rule sets.
|
||||
* @return a plug-in specific rulesets structure.
|
||||
*
|
||||
* @throws RuleSetNotFoundException if one of the rule set url is incorrect.
|
||||
* @throws PMDCoreException if an error occurred. Check the root cause for details.
|
||||
*/
|
||||
RuleSet valueOf(String[] ruleSetUrls) throws RuleSetNotFoundException;
|
||||
RuleSet valueOf(String[] ruleSetUrls) throws PMDCoreException;
|
||||
|
||||
/**
|
||||
* Serialize a rule sets structure to an output stream.
|
||||
@ -81,9 +83,9 @@ public interface IRuleSetsManager {
|
||||
* @param ruleSets a rule sets structure.
|
||||
* @param output an open output stream.
|
||||
*
|
||||
* @throws IOException if an error occurs while writing the stream.
|
||||
* @throws PMDCoreException if an error occurred. Check the root cause for details.
|
||||
*/
|
||||
void writeToXml(RuleSets ruleSets, OutputStream output) throws IOException;
|
||||
void writeToXml(RuleSets ruleSets, OutputStream output) throws PMDCoreException;
|
||||
|
||||
/**
|
||||
* Load a rule sets structure from an input stream than contains an XML
|
||||
@ -92,8 +94,8 @@ public interface IRuleSetsManager {
|
||||
* @param input a valid XML input stream.
|
||||
* @return a rulesets structure ; this is never null.
|
||||
*
|
||||
* @throws IOException if an error occurs while reading from the stream.
|
||||
* @throws PMDCoreException if an error occurred. Check the root cause for details.
|
||||
*/
|
||||
RuleSets readFromXml(InputStream input) throws IOException;
|
||||
RuleSets readFromXml(InputStream input) throws PMDCoreException;
|
||||
|
||||
}
|
||||
|
@ -39,16 +39,27 @@ package net.sourceforge.pmd.core.rulesets.impl;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import net.sourceforge.pmd.core.PMDCoreException;
|
||||
import net.sourceforge.pmd.core.rulesets.IRuleSetsManager;
|
||||
import net.sourceforge.pmd.core.rulesets.vo.Rule;
|
||||
import net.sourceforge.pmd.core.rulesets.vo.RuleSet;
|
||||
import net.sourceforge.pmd.core.rulesets.vo.RuleSets;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.exolab.castor.mapping.Mapping;
|
||||
import org.exolab.castor.mapping.MappingException;
|
||||
import org.exolab.castor.xml.MarshalException;
|
||||
import org.exolab.castor.xml.Marshaller;
|
||||
import org.exolab.castor.xml.ValidationException;
|
||||
|
||||
/**
|
||||
* Implementation of an IRuleSetsManager.
|
||||
* The serialization is based on the usage of Castor.
|
||||
@ -57,6 +68,9 @@ import net.sourceforge.pmd.core.rulesets.vo.RuleSets;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:46 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/21 23:06:41 phherlin
|
||||
* Move the new rule sets management to the core plugin instead of the runtime.
|
||||
* Continue the development.
|
||||
@ -65,11 +79,13 @@ import net.sourceforge.pmd.core.rulesets.vo.RuleSets;
|
||||
*/
|
||||
|
||||
public class RuleSetsManagerImpl implements IRuleSetsManager {
|
||||
private static final Log LOG = LogFactory.getLog(RuleSetsManagerImpl.class);
|
||||
private static final String RULESETS_MAPPING = "/net/sourceforge/pmd/core/rulesets/impl/mapping.xml";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.sourceforge.pmd.core.rulesets.IRuleSetsManager#readFromXml(java.io.InputStream)
|
||||
*/
|
||||
public RuleSets readFromXml(InputStream input) throws IOException {
|
||||
public RuleSets readFromXml(InputStream input) throws PMDCoreException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@ -78,7 +94,8 @@ public class RuleSetsManagerImpl implements IRuleSetsManager {
|
||||
* @throws RuleSetNotFoundException
|
||||
* @see net.sourceforge.pmd.core.rulesets.IRuleSetsManager#valueOf(java.lang.String[])
|
||||
*/
|
||||
public RuleSet valueOf(String[] ruleSetUrls) throws RuleSetNotFoundException {
|
||||
public RuleSet valueOf(String[] ruleSetUrls) throws PMDCoreException {
|
||||
LOG.debug("Compting value of a collection of rule set urls");
|
||||
if (ruleSetUrls == null) {
|
||||
throw new IllegalArgumentException("ruleSetUrls cannot be null");
|
||||
}
|
||||
@ -86,28 +103,61 @@ public class RuleSetsManagerImpl implements IRuleSetsManager {
|
||||
throw new IllegalArgumentException("ruleSetsUrls cannot be empty");
|
||||
}
|
||||
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
|
||||
for (int i = 0; i < ruleSetUrls.length; i++) {
|
||||
final RuleSetFactory factory = new RuleSetFactory(); // NOPMD by Herlin on 21/06/06 23:25
|
||||
final Collection rules = factory.createSingleRuleSet(ruleSetUrls[i]).getRules();
|
||||
for (final Iterator j = rules.iterator(); j.hasNext();) {
|
||||
final net.sourceforge.pmd.Rule pmdRule = (net.sourceforge.pmd.Rule) j.next();
|
||||
final Rule rule = new Rule(); // NOPMD by Herlin on 21/06/06 23:29
|
||||
rule.setRef(ruleSetUrls[i] + '/' + pmdRule.getName());
|
||||
rule.setPmdRule(pmdRule);
|
||||
ruleSet.addRule(rule);
|
||||
try {
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
|
||||
for (int i = 0; i < ruleSetUrls.length; i++) {
|
||||
final RuleSetFactory factory = new RuleSetFactory(); // NOPMD by Herlin on 21/06/06 23:25
|
||||
final Collection rules = factory.createSingleRuleSet(ruleSetUrls[i]).getRules();
|
||||
for (final Iterator j = rules.iterator(); j.hasNext();) {
|
||||
final net.sourceforge.pmd.Rule pmdRule = (net.sourceforge.pmd.Rule) j.next();
|
||||
final Rule rule = new Rule(); // NOPMD by Herlin on 21/06/06 23:29
|
||||
rule.setRef(ruleSetUrls[i] + '/' + pmdRule.getName());
|
||||
rule.setPmdRule(pmdRule);
|
||||
ruleSet.addRule(rule);
|
||||
}
|
||||
}
|
||||
|
||||
return ruleSet;
|
||||
|
||||
} catch (RuleSetNotFoundException e) {
|
||||
LOG.error("A RuleSetsNotFound Exception was thrown.");
|
||||
throw new PMDCoreException("A RuleSetsNotFound Exception was thrown.", e);
|
||||
}
|
||||
|
||||
return ruleSet;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/**
|
||||
* @see net.sourceforge.pmd.core.rulesets.IRuleSetsManager#writeToXml(net.sourceforge.pmd.core.rulesets.vo.RuleSets, java.io.OutputStream)
|
||||
*/
|
||||
public void writeToXml(RuleSets ruleSets, OutputStream output) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void writeToXml(RuleSets ruleSets, OutputStream output) throws PMDCoreException {
|
||||
LOG.debug("Storing plug-in rulesets");
|
||||
try {
|
||||
final Mapping mapping = new Mapping(this.getClass().getClassLoader());
|
||||
final URL mappingSpecUrl = this.getClass().getResource(RULESETS_MAPPING);
|
||||
mapping.loadMapping(mappingSpecUrl);
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
final Marshaller marshaller = new Marshaller(writer);
|
||||
marshaller.setMapping(mapping);
|
||||
marshaller.marshal(ruleSets);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
output.write(writer.getBuffer().toString().getBytes());
|
||||
output.flush();
|
||||
|
||||
} catch (MarshalException e) {
|
||||
LOG.error("A Marshal Exception was thrown.");
|
||||
throw new PMDCoreException("A Marshal Exception was thrown.", e);
|
||||
} catch (ValidationException e) {
|
||||
LOG.error("A Validation Exception was thrown.");
|
||||
throw new PMDCoreException("A Validation Exception was thrown.", e);
|
||||
} catch (MappingException e) {
|
||||
LOG.error("A Mapping Exception was thrown.");
|
||||
throw new PMDCoreException("A Mapping Exception was thrown.", e);
|
||||
} catch (IOException e) {
|
||||
LOG.error("A IO Exception was thrown.");
|
||||
throw new PMDCoreException("A IO Exception was thrown.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mapping xmlns="http://castor.exolab.org/"
|
||||
xmlns:cst="http://castor.exolab.org/"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:type="mapping">
|
||||
<description>PMD For Eclipse RuleSets mapping file</description>
|
||||
|
||||
<class cst:name="net.sourceforge.pmd.core.rulesets.vo.RuleSets">
|
||||
<description>Default mapping for class net.sourceforge.pmd.core.rulesets.vo.RuleSets</description>
|
||||
<map-to cst:xml="rulesets"/>
|
||||
|
||||
<field cst:name="defaultRuleSetName" cst:type="java.lang.String">
|
||||
<bind-xml name="defaultRuleSet" node="attribute"/>
|
||||
</field>
|
||||
|
||||
<field cst:name="ruleSets" cst:type="net.sourceforge.pmd.core.rulesets.vo.RuleSet" cst:collection="collection">
|
||||
<bind-xml name="ruleset" node="element"/>
|
||||
</field>
|
||||
</class>
|
||||
|
||||
<class cst:name="net.sourceforge.pmd.core.rulesets.vo.RuleSet">
|
||||
<description>Default mapping for class net.sourceforge.pmd.core.rulesets.vo.RuleSet</description>
|
||||
<map-to cst:xml="ruleset"/>
|
||||
|
||||
<field cst:name="name" cst:type="java.lang.String">
|
||||
<bind-xml name="name" node="attribute"/>
|
||||
</field>
|
||||
|
||||
<field cst:name="language" cst:type="java.lang.String">
|
||||
<bind-xml name="language" node="attribute"/>
|
||||
</field>
|
||||
|
||||
<field cst:name="description" cst:type="java.lang.String">
|
||||
<bind-xml name="description" node="element"/>
|
||||
</field>
|
||||
|
||||
<field cst:name="rules" cst:type="net.sourceforge.pmd.core.rulesets.vo.Rule" cst:collection="collection">
|
||||
<bind-xml name="rule" node="element"/>
|
||||
</field>
|
||||
</class>
|
||||
|
||||
<class cst:name="net.sourceforge.pmd.core.rulesets.vo.Rule">
|
||||
<description>Default mapping for class net.sourceforge.pmd.core.rulesets.vo.Rule</description>
|
||||
<map-to cst:xml="rule"/>
|
||||
|
||||
<field cst:name="ref" cst:type="java.lang.String">
|
||||
<bind-xml name="ref" node="attribute"/>
|
||||
</field>
|
||||
|
||||
<field cst:name="priority" cst:type="net.sourceforge.pmd.core.rulesets.vo.Priority">
|
||||
<bind-xml name="priority" node="element"/>
|
||||
</field>
|
||||
|
||||
<field cst:name="message" cst:type="java.lang.String">
|
||||
<bind-xml name="message" node="element"/>
|
||||
</field>
|
||||
|
||||
<field cst:name="properties" cst:type="net.sourceforge.pmd.core.rulesets.vo.Properties">
|
||||
<bind-xml name="properties" node="element"/>
|
||||
</field>
|
||||
</class>
|
||||
|
||||
<class cst:name="net.sourceforge.pmd.core.rulesets.vo.Properties">
|
||||
<description>Default mapping for class net.sourceforge.pmd.core.rulesets.vo.Properties</description>
|
||||
<map-to cst:xml="properties"/>
|
||||
|
||||
<field cst:name="properties" cst:type="net.sourceforge.pmd.core.rulesets.vo.Property" cst:collection="set">
|
||||
<bind-xml name="property" node="element"/>
|
||||
</field>
|
||||
</class>
|
||||
|
||||
<class cst:name="net.sourceforge.pmd.core.rulesets.vo.Property">
|
||||
<description>Default mapping for class net.sourceforge.pmd.core.rulesets.vo.Property</description>
|
||||
<map-to cst:xml="property"/>
|
||||
|
||||
<field cst:name="name" cst:type="java.lang.String">
|
||||
<bind-xml name="name" node="attribute"/>
|
||||
</field>
|
||||
|
||||
<field cst:name="value" cst:type="java.lang.String">
|
||||
<bind-xml name="value" node="attribute"/>
|
||||
</field>
|
||||
</class>
|
||||
|
||||
<class cst:name="net.sourceforge.pmd.core.rulesets.vo.Priority">
|
||||
<description>Default mapping for class net.sourceforge.pmd.core.rulesets.vo.Priority</description>
|
||||
<map-to cst:xml="priority"/>
|
||||
|
||||
<field cst:name="priorityValue" cst:type="int">
|
||||
<bind-xml name="priorityValue" node="attribute"/>
|
||||
</field>
|
||||
</class>
|
||||
|
||||
</mapping>
|
@ -47,6 +47,9 @@ package net.sourceforge.pmd.core.rulesets.vo;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:46 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/21 23:06:41 phherlin
|
||||
* Move the new rule sets management to the core plugin instead of the runtime.
|
||||
* Continue the development.
|
||||
@ -109,7 +112,7 @@ public class Priority {
|
||||
*
|
||||
* @param priorityValue The priorityValue to set.
|
||||
*/
|
||||
public void setPriority(int priority) {
|
||||
public void setPriorityValue(int priority) {
|
||||
if ((priority < LEVEL1_LITTERAL) || (priority > LEVEL5_LITTERAL)) {
|
||||
throw new IllegalArgumentException("priorityValue value invalid ; was " + priority + " and should be between "
|
||||
+ LEVEL1_LITTERAL + " and " + LEVEL5_LITTERAL);
|
||||
|
@ -41,7 +41,7 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* This class is a value objet that composes the structure of a rulesets object.
|
||||
* This class is a value objet which composes the structure of a rulesets object.
|
||||
* It holds the definition of a rule set which is actually a named collection of
|
||||
* rules.
|
||||
*
|
||||
@ -49,6 +49,9 @@ import java.util.Iterator;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:46 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/21 23:06:41 phherlin
|
||||
* Move the new rule sets management to the core plugin instead of the runtime.
|
||||
* Continue the development.
|
||||
|
@ -49,6 +49,9 @@ import java.util.List;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:46 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/21 23:06:41 phherlin
|
||||
* Move the new rule sets management to the core plugin instead of the runtime.
|
||||
* Continue the development.
|
||||
@ -116,6 +119,33 @@ public class RuleSets {
|
||||
}
|
||||
this.ruleSetsList = ruleSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the default ruleset
|
||||
* @return the name of the default ruleset
|
||||
*/
|
||||
public String getDefaultRuleSetName() {
|
||||
return this.defaultRuleSet.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default ruleset by its name. If the ruleset does not exist,
|
||||
* the default ruleset is not set.
|
||||
* @param ruleSetName a name of an already defined ruleset.
|
||||
*/
|
||||
public void setDefaultRuleSetName(String ruleSetName) {
|
||||
if (ruleSetName == null) {
|
||||
throw new IllegalArgumentException("The default ruleset name must not ne null");
|
||||
}
|
||||
|
||||
for (final Iterator i = this.ruleSetsList.iterator(); i.hasNext();) {
|
||||
final RuleSet ruleSet = (RuleSet) i.next();
|
||||
if (ruleSet.getName().equals(ruleSetName)) {
|
||||
setDefaultRuleSet(ruleSet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
|
@ -1,9 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/castor-0.9.6-xml.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/log4j-1.2.8.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/commons-logging.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
|
@ -11,15 +11,6 @@
|
||||
<library name="pmd-runtime.jar">
|
||||
<export name="*"/>
|
||||
</library>
|
||||
<library name="lib/castor-0.9.6-xml.jar">
|
||||
<export name="*"/>
|
||||
</library>
|
||||
<library name="lib/log4j-1.2.8.jar">
|
||||
<export name="*"/>
|
||||
</library>
|
||||
<library name="lib/commons-logging.jar">
|
||||
<export name="*"/>
|
||||
</library>
|
||||
</runtime>
|
||||
|
||||
<requires>
|
||||
|
@ -77,6 +77,9 @@ import org.exolab.castor.xml.ValidationException;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:41:57 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/05/22 21:37:35 phherlin
|
||||
* Refactor the plug-in architecture to better support future evolutions
|
||||
* Revision 1.1 2005/06/07 18:38:14 phherlin Move classes to limit packages cycle
|
||||
@ -91,12 +94,12 @@ import org.exolab.castor.xml.ValidationException;
|
||||
public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
private static final Logger log = Logger.getLogger(ProjectPropertiesManagerImpl.class);
|
||||
|
||||
static final String PROJECT_RULESET_FILE = ".ruleset";
|
||||
static final String PROJECT_RULESET_FILE = ".ruleset"; // NOPMD by Herlin on 08/07/06 15:18
|
||||
|
||||
private static final String PROPERTIES_FILE = ".pmd";
|
||||
private static final String PROPERTIES_MAPPING = "/net/sourceforge/pmd/runtime/properties/impl/mapping.xml";
|
||||
|
||||
private Map projectsProperties = new HashMap();
|
||||
private final Map projectsProperties = new HashMap();
|
||||
|
||||
/**
|
||||
* Load a project properties
|
||||
@ -109,7 +112,7 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
IProjectProperties projectProperties = (IProjectProperties) this.projectsProperties.get(project);
|
||||
if (projectProperties == null) {
|
||||
projectProperties = new PropertiesFactoryImpl().newProjectProperties(project, this);
|
||||
ProjectPropertiesTO to = readProjectProperties(project);
|
||||
final ProjectPropertiesTO to = readProjectProperties(project);
|
||||
fillProjectProperties(projectProperties, to);
|
||||
this.projectsProperties.put(project, projectProperties);
|
||||
}
|
||||
@ -121,7 +124,7 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
|
||||
// else resynchronize the ruleset
|
||||
else {
|
||||
boolean needRebuild = synchronizeRuleSet(projectProperties);
|
||||
final boolean needRebuild = synchronizeRuleSet(projectProperties);
|
||||
projectProperties.setNeedRebuild(projectProperties.isNeedRebuild() || needRebuild);
|
||||
}
|
||||
|
||||
@ -182,7 +185,7 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
ProjectPropertiesTO projectProperties = null;
|
||||
|
||||
try {
|
||||
final Mapping mapping = new Mapping();
|
||||
final Mapping mapping = new Mapping(this.getClass().getClassLoader());
|
||||
final URL mappingSpecUrl = this.getClass().getResource(PROPERTIES_MAPPING);
|
||||
mapping.loadMapping(mappingSpecUrl);
|
||||
|
||||
@ -242,7 +245,7 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
* @param rules array of selected rules
|
||||
*/
|
||||
private void setRuleSetFromProperties(IProjectProperties projectProperties, RuleSpecTO[] rules) throws PropertiesException {
|
||||
RuleSet ruleSet = new RuleSet();
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
final RuleSet pluginRuleSet = PMDRuntimePlugin.getDefault().getPreferencesManager().getRuleSet();
|
||||
for (int i = 0; i < rules.length; i++) {
|
||||
try {
|
||||
@ -267,7 +270,7 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
private void writeProjectProperties(final IProject project, final ProjectPropertiesTO projectProperties)
|
||||
throws PropertiesException {
|
||||
try {
|
||||
final Mapping mapping = new Mapping();
|
||||
final Mapping mapping = new Mapping(this.getClass().getClassLoader());
|
||||
final URL mappingSpecUrl = this.getClass().getResource(PROPERTIES_MAPPING);
|
||||
mapping.loadMapping(mappingSpecUrl);
|
||||
|
||||
@ -331,8 +334,8 @@ public class ProjectPropertiesManagerImpl implements IProjectPropertiesManager {
|
||||
private boolean synchronizeRuleSet(IProjectProperties projectProperties) throws PropertiesException {
|
||||
log.debug("Synchronizing the project ruleset with the plugin ruleset");
|
||||
final RuleSet pluginRuleSet = PMDRuntimePlugin.getDefault().getPreferencesManager().getRuleSet();
|
||||
final RuleSet projectRuleSet = projectProperties.getProjectRuleSet();
|
||||
boolean flChanged = false;
|
||||
RuleSet projectRuleSet = projectProperties.getProjectRuleSet();
|
||||
|
||||
if (!projectRuleSet.getRules().equals(pluginRuleSet.getRules())) {
|
||||
log.debug("The project ruleset is different from the plugin ruleset ; synchronizing.");
|
||||
|
@ -36,15 +36,24 @@
|
||||
|
||||
package net.sourceforge.pmd.core.rulesets.impl;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import net.sourceforge.pmd.core.PMDCoreException;
|
||||
import net.sourceforge.pmd.core.rulesets.IRuleSetsManager;
|
||||
import net.sourceforge.pmd.core.rulesets.vo.RuleSet;
|
||||
import junit.framework.TestCase;
|
||||
import net.sourceforge.pmd.core.rulesets.vo.RuleSets;
|
||||
|
||||
/**
|
||||
* RuleSetsManager unit tests
|
||||
@ -53,6 +62,9 @@ import junit.framework.TestCase;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:04 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/21 23:06:54 phherlin
|
||||
* Move the new rule sets management to the core plugin instead of the runtime.
|
||||
* Continue the development.
|
||||
@ -67,7 +79,7 @@ public class RuleSetsManagerImplTest extends TestCase {
|
||||
*
|
||||
* @throws RuleSetNotFoundException
|
||||
*/
|
||||
public void testValueOf1() throws RuleSetNotFoundException {
|
||||
public void testValueOf1() throws PMDCoreException, RuleSetNotFoundException {
|
||||
IRuleSetsManager rsm = new RuleSetsManagerImpl();
|
||||
RuleSet ruleSet = rsm.valueOf(new String[] { "rulesets/basic.xml" });
|
||||
|
||||
@ -87,7 +99,7 @@ public class RuleSetsManagerImplTest extends TestCase {
|
||||
* @throws RuleSetNotFoundException
|
||||
*
|
||||
*/
|
||||
public void testValueOf2() throws RuleSetNotFoundException {
|
||||
public void testValueOf2() throws PMDCoreException {
|
||||
try {
|
||||
IRuleSetsManager rsm = new RuleSetsManagerImpl();
|
||||
RuleSet ruleSet = rsm.valueOf(null);
|
||||
@ -103,7 +115,7 @@ public class RuleSetsManagerImplTest extends TestCase {
|
||||
* @throws RuleSetNotFoundException
|
||||
*
|
||||
*/
|
||||
public void testValueOf3() throws RuleSetNotFoundException {
|
||||
public void testValueOf3() throws PMDCoreException {
|
||||
try {
|
||||
IRuleSetsManager rsm = new RuleSetsManagerImpl();
|
||||
RuleSet ruleSet = rsm.valueOf(new String[] {});
|
||||
@ -112,6 +124,55 @@ public class RuleSetsManagerImplTest extends TestCase {
|
||||
// Sucess
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basically test the writeToXml operation.
|
||||
*
|
||||
*/
|
||||
public void testWriteToXml() throws PMDCoreException, UnsupportedEncodingException, IOException {
|
||||
ByteArrayOutputStream out = null;
|
||||
InputStream in = new FileInputStream("./test/testRuleSetsManager.rulesets");
|
||||
if (in == null) {
|
||||
throw new IllegalStateException("The test file testRuleSetsManager.rulesets cannot be found. The test cannot be performed.");
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[in.available()];
|
||||
in.read(bytes);
|
||||
|
||||
String reference = new String(bytes, "UTF-8");
|
||||
in.close();
|
||||
|
||||
System.out.println("--reference");
|
||||
System.out.println(reference);
|
||||
|
||||
try {
|
||||
IRuleSetsManager rsm = new RuleSetsManagerImpl();
|
||||
RuleSet ruleSet = rsm.valueOf(new String[] { "rulesets/basic.xml" });
|
||||
ruleSet.setName("basic");
|
||||
ruleSet.setLanguage(RuleSet.LANGUAGE_JAVA);
|
||||
|
||||
List ruleSetsList = new ArrayList();
|
||||
ruleSetsList.add(ruleSet);
|
||||
|
||||
RuleSets ruleSets = new RuleSets();
|
||||
ruleSets.setRuleSets(ruleSetsList);
|
||||
ruleSets.setDefaultRuleSet(ruleSet);
|
||||
|
||||
out = new ByteArrayOutputStream();
|
||||
rsm.writeToXml(ruleSets, out);
|
||||
|
||||
String result = new String(out.toByteArray(), "UTF-8");
|
||||
|
||||
System.out.println("--result");
|
||||
System.out.println(result);
|
||||
|
||||
assertEquals("The outpout rulesets is not the expected one", reference, result);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump a collection of rules
|
||||
|
@ -45,6 +45,9 @@ import junit.framework.TestCase;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:03 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/21 23:06:52 phherlin
|
||||
* Move the new rule sets management to the core plugin instead of the runtime.
|
||||
* Continue the development.
|
||||
@ -72,19 +75,19 @@ public class PriorityTest extends TestCase {
|
||||
*/
|
||||
public void testSetPriority() {
|
||||
Priority p = new Priority();
|
||||
p.setPriority(Priority.LEVEL1_LITTERAL);
|
||||
p.setPriorityValue(Priority.LEVEL1_LITTERAL);
|
||||
assertEquals("Constructing a priority level 1 has failed!", Priority.LEVEL1, p);
|
||||
|
||||
p.setPriority(Priority.LEVEL2_LITTERAL);
|
||||
p.setPriorityValue(Priority.LEVEL2_LITTERAL);
|
||||
assertEquals("Constructing a priority level 2 has failed!", Priority.LEVEL2, p);
|
||||
|
||||
p.setPriority(Priority.LEVEL3_LITTERAL);
|
||||
p.setPriorityValue(Priority.LEVEL3_LITTERAL);
|
||||
assertEquals("Constructing a priority level 3 has failed!", Priority.LEVEL3, p);
|
||||
|
||||
p.setPriority(Priority.LEVEL4_LITTERAL);
|
||||
p.setPriorityValue(Priority.LEVEL4_LITTERAL);
|
||||
assertEquals("Constructing a priority level 4 has failed!", Priority.LEVEL4, p);
|
||||
|
||||
p.setPriority(Priority.LEVEL5_LITTERAL);
|
||||
p.setPriorityValue(Priority.LEVEL5_LITTERAL);
|
||||
assertEquals("Constructing a priority level 5 has failed!", Priority.LEVEL5, p);
|
||||
|
||||
}
|
||||
@ -96,7 +99,7 @@ public class PriorityTest extends TestCase {
|
||||
public void testSetPriorityIllegal1() {
|
||||
try {
|
||||
Priority p = new Priority();
|
||||
p.setPriority(0);
|
||||
p.setPriorityValue(0);
|
||||
fail("Setting a priority level to 0 should raise an IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// this is correct
|
||||
@ -110,7 +113,7 @@ public class PriorityTest extends TestCase {
|
||||
public void testSetPriorityIllegal2() {
|
||||
try {
|
||||
Priority p = new Priority();
|
||||
p.setPriority(-15);
|
||||
p.setPriorityValue(-15);
|
||||
fail("Setting a priority level to a negative number should raise an IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// this is correct
|
||||
@ -124,7 +127,7 @@ public class PriorityTest extends TestCase {
|
||||
public void testSetPriorityIllegal3() {
|
||||
try {
|
||||
Priority p = new Priority();
|
||||
p.setPriority(6);
|
||||
p.setPriorityValue(6);
|
||||
fail("Setting a priority level to a high value should raise an IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// this is correct
|
||||
@ -137,7 +140,7 @@ public class PriorityTest extends TestCase {
|
||||
*/
|
||||
public void testEquals1() {
|
||||
Priority p = new Priority();
|
||||
p.setPriority(1);
|
||||
p.setPriorityValue(1);
|
||||
assertFalse("2 priorities with different levels (1:2) are not equals", Priority.LEVEL2.equals(p));
|
||||
assertFalse("2 priorities with different levels (1:3) are not equals", Priority.LEVEL3.equals(p));
|
||||
assertFalse("2 priorities with different levels (1:4) are not equals", Priority.LEVEL4.equals(p));
|
||||
|
@ -50,6 +50,9 @@ import junit.framework.TestCase;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:03 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/21 23:06:52 phherlin
|
||||
* Move the new rule sets management to the core plugin instead of the runtime.
|
||||
* Continue the development.
|
||||
@ -123,7 +126,7 @@ public class RuleSetsTest extends TestCase {
|
||||
try {
|
||||
RuleSets rs = new RuleSets();
|
||||
rs.setDefaultRuleSet(null);
|
||||
fail("setting a defaulr rule set to null should be illegal");
|
||||
fail("setting a default rule set to null should be illegal");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// success
|
||||
}
|
||||
@ -266,4 +269,48 @@ public class RuleSetsTest extends TestCase {
|
||||
|
||||
assertFalse("Different rule sets should have different hash code", rs1.hashCode() == rs2.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the basic usage of the default ruleset setter
|
||||
*
|
||||
*/
|
||||
public void testSetDefaultRuleSetName() throws RuleSetNotFoundException {
|
||||
Rule r1 = new Rule();
|
||||
r1.setRef("ref to a rule");
|
||||
r1.setPmdRule(TestManager.getRule(0));
|
||||
|
||||
Rule r2 = new Rule();
|
||||
r2.setRef("ref to another rule");
|
||||
r2.setPmdRule(TestManager.getRule(1));
|
||||
|
||||
RuleSet rs1 = new RuleSet();
|
||||
rs1.setName("default");
|
||||
rs1.setLanguage(RuleSet.LANGUAGE_JSP);
|
||||
rs1.addRule(r1);
|
||||
rs1.addRule(r2);
|
||||
|
||||
List ruleSetsList = new ArrayList();
|
||||
ruleSetsList.add(rs1);
|
||||
|
||||
RuleSets ruleSets = new RuleSets();
|
||||
ruleSets.setRuleSets(ruleSetsList);
|
||||
|
||||
ruleSets.setDefaultRuleSetName("default");
|
||||
|
||||
assertSame("The default ruleset has not been set correctly", rs1, ruleSets.getDefaultRuleSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting a default ruleset name to null
|
||||
*
|
||||
*/
|
||||
public void testSetDefaultRuleSetNameNull() {
|
||||
try {
|
||||
RuleSets ruleSets = new RuleSets();
|
||||
ruleSets.setDefaultRuleSetName(null);
|
||||
fail("Setting a default ruleset name to null is illegal");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,10 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.runtime.properties;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sourceforge.pmd.AbstractRule;
|
||||
@ -43,6 +46,7 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import net.sourceforge.pmd.core.PMDCorePlugin;
|
||||
import net.sourceforge.pmd.eclipse.EclipseUtils;
|
||||
import net.sourceforge.pmd.runtime.PMDRuntimePlugin;
|
||||
import net.sourceforge.pmd.runtime.builder.PMDNature;
|
||||
@ -65,6 +69,9 @@ import org.eclipse.ui.IWorkingSet;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2006/10/06 16:42:03 phherlin
|
||||
* Continue refactoring of rullesets management
|
||||
*
|
||||
* Revision 1.1 2006/06/18 22:29:51 phherlin
|
||||
* Begin refactoring the unit tests for the plugin
|
||||
* Revision 1.4 2005/12/30 16:29:16
|
||||
@ -169,9 +176,10 @@ public class ProjectPropertiesModelTest extends TestCase {
|
||||
/**
|
||||
* When rules are removed from the plugin preferences, these rules should
|
||||
* also be removed from the project
|
||||
* euh... ben en fait non. annulé.
|
||||
*/
|
||||
public void testProjectRuleSet2() throws PropertiesException, RuleSetNotFoundException, CoreException {
|
||||
|
||||
/*
|
||||
// First ensure that the plugin initial ruleset is equal to the project
|
||||
// ruleset
|
||||
IProjectPropertiesManager mgr = PMDRuntimePlugin.getDefault().getPropertiesManager();
|
||||
@ -190,7 +198,10 @@ public class ProjectPropertiesModelTest extends TestCase {
|
||||
|
||||
projectRuleSet = model.getProjectRuleSet();
|
||||
|
||||
dumpRuleSet(basicRuleSet);
|
||||
dumpRuleSet(projectRuleSet);
|
||||
assertEquals("The project ruleset is not equal to the plugin ruleset", basicRuleSet.getRules(), projectRuleSet.getRules());
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,8 +209,6 @@ public class ProjectPropertiesModelTest extends TestCase {
|
||||
* be added to the project
|
||||
*/
|
||||
public void testProjectRuleSet3() throws PropertiesException, RuleSetNotFoundException, CoreException {
|
||||
RuleSetFactory factory = new RuleSetFactory();
|
||||
RuleSet basicRuleSet = factory.createSingleRuleSet("rulesets/basic.xml");
|
||||
|
||||
// First ensure that the plugin initial ruleset is equal to the project
|
||||
// ruleset
|
||||
@ -207,7 +216,7 @@ public class ProjectPropertiesModelTest extends TestCase {
|
||||
IProjectProperties model = mgr.loadProjectProperties(this.testProject);
|
||||
|
||||
RuleSet projectRuleSet = model.getProjectRuleSet();
|
||||
assertEquals("The project ruleset is not equal to the plugin ruleset", this.initialPluginRuleSet, projectRuleSet);
|
||||
assertEquals("The project ruleset is not equal to the plugin ruleset", this.initialPluginRuleSet.getRules(), projectRuleSet.getRules());
|
||||
|
||||
// 2. add a rule to the plugin rule set
|
||||
Rule myRule = new AbstractRule() {
|
||||
@ -224,7 +233,7 @@ public class ProjectPropertiesModelTest extends TestCase {
|
||||
|
||||
// Test that the project rule set should still be the same as the plugin
|
||||
// rule set
|
||||
model = new ProjectPropertiesImpl(this.testProject, mgr);
|
||||
model = mgr.loadProjectProperties(this.testProject);
|
||||
projectRuleSet = model.getProjectRuleSet();
|
||||
assertEquals("The project ruleset is not equal to the plugin ruleset", PMDRuntimePlugin.getDefault()
|
||||
.getPreferencesManager().getRuleSet().getRules(), projectRuleSet.getRules());
|
||||
@ -242,7 +251,7 @@ public class ProjectPropertiesModelTest extends TestCase {
|
||||
IProjectProperties model = mgr.loadProjectProperties(this.testProject);
|
||||
|
||||
RuleSet projectRuleSet = model.getProjectRuleSet();
|
||||
assertEquals("The project ruleset is not equal to the plugin ruleset", this.initialPluginRuleSet, projectRuleSet);
|
||||
assertEquals("The project ruleset is not equal to the plugin ruleset", this.initialPluginRuleSet.getRules(), projectRuleSet.getRules());
|
||||
|
||||
// 2. remove the first rule (keep its name for assertion)
|
||||
RuleSet newRuleSet = new RuleSet();
|
||||
@ -405,6 +414,11 @@ public class ProjectPropertiesModelTest extends TestCase {
|
||||
|
||||
// 2. Keep the plugin ruleset
|
||||
this.initialPluginRuleSet = PMDRuntimePlugin.getDefault().getPreferencesManager().getRuleSet();
|
||||
this.initialPluginRuleSet.getRules().clear();
|
||||
Set defaultRuleSets = PMDCorePlugin.getDefault().getRuleSetManager().getDefaultRuleSets();
|
||||
for (Iterator i = defaultRuleSets.iterator(); i.hasNext();) {
|
||||
this.initialPluginRuleSet.addRuleSet((RuleSet) i.next());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -434,5 +448,5 @@ public class ProjectPropertiesModelTest extends TestCase {
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -59,7 +59,7 @@ public class UpdateProjectPropertiesCmdTest extends TestCase {
|
||||
|
||||
RuleSet projectRuleSet = model.getProjectRuleSet();
|
||||
assertEquals("The project ruleset is not equal to the plugin ruleset", PMDRuntimePlugin.getDefault()
|
||||
.getPreferencesManager().getRuleSet(), projectRuleSet);
|
||||
.getPreferencesManager().getRuleSet().getRules(), projectRuleSet.getRules());
|
||||
|
||||
// 2. remove the first rule (keep its name for assertion)
|
||||
RuleSet newRuleSet = new RuleSet();
|
||||
|
2
pmd-eclipse-test/test/testRuleSetsManager.rulesets
Normal file
2
pmd-eclipse-test/test/testRuleSetsManager.rulesets
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rulesets xmlns:ns1="http://castor.exolab.org/" ns1:defaultRuleSet="basic"><ns1:ruleset ns1:name="basic" ns1:language="JAVA"><ns1:description></ns1:description><ns1:rule ns1:ref="rulesets/basic.xml/EmptyCatchBlock"/><ns1:rule ns1:ref="rulesets/basic.xml/EmptyIfStmt"/><ns1:rule ns1:ref="rulesets/basic.xml/EmptyWhileStmt"/><ns1:rule ns1:ref="rulesets/basic.xml/EmptyTryBlock"/><ns1:rule ns1:ref="rulesets/basic.xml/EmptyFinallyBlock"/><ns1:rule ns1:ref="rulesets/basic.xml/EmptySwitchStatements"/><ns1:rule ns1:ref="rulesets/basic.xml/JumbledIncrementer"/><ns1:rule ns1:ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/><ns1:rule ns1:ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/><ns1:rule ns1:ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/><ns1:rule ns1:ref="rulesets/basic.xml/DoubleCheckedLocking"/><ns1:rule ns1:ref="rulesets/basic.xml/ReturnFromFinallyBlock"/><ns1:rule ns1:ref="rulesets/basic.xml/EmptySynchronizedBlock"/><ns1:rule ns1:ref="rulesets/basic.xml/UnnecessaryReturn"/><ns1:rule ns1:ref="rulesets/basic.xml/EmptyStaticInitializer"/><ns1:rule ns1:ref="rulesets/basic.xml/UnconditionalIfStatement"/><ns1:rule ns1:ref="rulesets/basic.xml/EmptyStatementNotInLoop"/><ns1:rule ns1:ref="rulesets/basic.xml/BooleanInstantiation"/><ns1:rule ns1:ref="rulesets/basic.xml/UnnecessaryFinalModifier"/><ns1:rule ns1:ref="rulesets/basic.xml/CollapsibleIfStatements"/><ns1:rule ns1:ref="rulesets/basic.xml/UselessOverridingMethod"/><ns1:rule ns1:ref="rulesets/basic.xml/ClassCastExceptionWithToArray"/><ns1:rule ns1:ref="rulesets/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/><ns1:rule ns1:ref="rulesets/basic.xml/UselessOperationOnImmutable"/><ns1:rule ns1:ref="rulesets/basic.xml/MisplacedNullCheck"/><ns1:rule ns1:ref="rulesets/basic.xml/UnusedNullCheckInEquals"/><ns1:rule ns1:ref="rulesets/basic.xml/AvoidThreadGroup"/></ns1:ruleset></rulesets>
|
Reference in New Issue
Block a user