Refactoring the way the Checker is configured. Not happy with the current
approach - it was hack. Changing to be that the Configuration will eventually contain the CheckConfiguration objects. Also adding support setting the properties on created checks. I am adding this using the Jakarta Commons library as it makes it very easy. Oh - I am now back online - no thanks to Sprint blocking my ISP for a couple of days. I may have lost a couple of emails. :-(
This commit is contained in:
parent
9fdee8a722
commit
03c8a0a7ee
|
|
@ -11,6 +11,7 @@
|
|||
<property name="antlr-tools.jar" value="lib/antlr-tools.jar" />
|
||||
<property name="regexp.jar" value="lib/jakarta-regexp-1.2.jar" />
|
||||
<property name="junit.jar" value="lib/junit.jar" />
|
||||
<property name="beanutils.jar" value="lib/commons-beanutils.jar" />
|
||||
|
||||
<property name="checkstyle.dir"
|
||||
value="src/checkstyle/com/puppycrawl/tools/checkstyle" />
|
||||
|
|
@ -22,6 +23,7 @@
|
|||
<path id="build.classpath">
|
||||
<pathelement location="${antlr.jar}" />
|
||||
<pathelement location="${regexp.jar}" />
|
||||
<pathelement location="${beanutils.jar}" />
|
||||
<pathelement location="${ant.home}/lib/ant.jar" />
|
||||
</path>
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -25,6 +25,10 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Iterator;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
|
||||
/**
|
||||
* Represents the configuration for a check.
|
||||
|
|
@ -98,11 +102,19 @@ class CheckConfiguration
|
|||
*/
|
||||
Check createInstance(ClassLoader aLoader)
|
||||
throws ClassNotFoundException, InstantiationException,
|
||||
IllegalAccessException
|
||||
IllegalAccessException, InvocationTargetException,
|
||||
NoSuchMethodException
|
||||
{
|
||||
final Class clazz = Class.forName(mClassname, true, aLoader);
|
||||
final Check check = (Check) clazz.newInstance();
|
||||
// TODO: need to set the properties
|
||||
// Loop setting the properties
|
||||
final Iterator keyIt = mProperties.keySet().iterator();
|
||||
while (keyIt.hasNext()) {
|
||||
final String key = (String) keyIt.next();
|
||||
final String value = (String) mProperties.get(key);
|
||||
PropertyUtils.setSimpleProperty(check, key, value);
|
||||
}
|
||||
return check;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.apache.regexp.RESyntaxException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
|
@ -155,9 +155,9 @@ public class Checker
|
|||
|
||||
public Checker(Configuration aConfig, CheckConfiguration[] aConfigs)
|
||||
throws ClassNotFoundException, InstantiationException,
|
||||
IllegalAccessException
|
||||
IllegalAccessException, InvocationTargetException,
|
||||
NoSuchMethodException
|
||||
{
|
||||
// TODO: document to make testing easier
|
||||
mConfig = aConfig;
|
||||
mCache = new PropertyCacheFile(aConfig);
|
||||
LocalizedMessage.setLocale(new Locale(mConfig.getLocaleLanguage(),
|
||||
|
|
@ -180,35 +180,16 @@ public class Checker
|
|||
*/
|
||||
public Checker(Configuration aConfig)
|
||||
throws RESyntaxException, IOException,
|
||||
ParserConfigurationException, SAXException, ClassNotFoundException, InstantiationException, IllegalAccessException
|
||||
ParserConfigurationException, SAXException,
|
||||
ClassNotFoundException, InstantiationException,
|
||||
IllegalAccessException, InvocationTargetException,
|
||||
NoSuchMethodException
|
||||
{
|
||||
// TODO: remove the dead code and make use the other constuctor
|
||||
mConfig = aConfig;
|
||||
// TODO: delete this method eventually
|
||||
this(aConfig, new CheckConfiguration[0]);
|
||||
mConfig.loadFiles();
|
||||
mCache = new PropertyCacheFile(aConfig);
|
||||
final Verifier v = new Verifier(aConfig);
|
||||
VerifierSingleton.setInstance(v);
|
||||
LocalizedMessage.setLocale(new Locale(mConfig.getLocaleLanguage(),
|
||||
mConfig.getLocaleCountry()));
|
||||
mMessages = new LocalizedMessages(mConfig.getTabWidth());
|
||||
// Load the check configurations
|
||||
final ConfigurationLoader loader = new ConfigurationLoader();
|
||||
final Set configFiles = mConfig.getCheckConfigFiles();
|
||||
// TODO: check for null
|
||||
for (Iterator it = configFiles.iterator(); it.hasNext();) {
|
||||
final String fname = (String) it.next();
|
||||
loader.parseFile(fname);
|
||||
}
|
||||
|
||||
// Initialise the treewalker
|
||||
// TODO: improve the error handing
|
||||
mWalker = new TreeWalker(mMessages);
|
||||
final CheckConfiguration[] configs = loader.getConfigs();
|
||||
for (int i = 0; i < configs.length; i++) {
|
||||
final CheckConfiguration config = configs[i];
|
||||
mWalker.registerCheck(
|
||||
config.createInstance(mConfig.getClassLoader()), config);
|
||||
}
|
||||
}
|
||||
|
||||
/** Cleans up the object **/
|
||||
|
|
|
|||
|
|
@ -118,8 +118,6 @@ public class Configuration
|
|||
/** map of Set properties **/
|
||||
private final Map mStringSetProps = new HashMap();
|
||||
{
|
||||
// TODO: need to remove this next line
|
||||
setStringSetProperty(Defn.CHECK_CONFIG_FILES_PROP, "");
|
||||
setStringSetProperty(Defn.ILLEGAL_IMPORTS_PROP, ILLEGAL_IMPORTS);
|
||||
setStringSetProperty(Defn.ILLEGAL_INSTANTIATIONS_PROP,
|
||||
ILLEGAL_INSTANTIATIONS);
|
||||
|
|
@ -622,12 +620,6 @@ public class Configuration
|
|||
return getStringSetProperty(Defn.ILLEGAL_INSTANTIATIONS_PROP);
|
||||
}
|
||||
|
||||
/** @return Set of check configuration files */
|
||||
Set getCheckConfigFiles()
|
||||
{
|
||||
return getStringSetProperty(Defn.CHECK_CONFIG_FILES_PROP);
|
||||
}
|
||||
|
||||
/** @return pattern to exclude from line lengh checking **/
|
||||
String getIgnoreLineLengthPat()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ public interface Defn
|
|||
/** name of resource bundle for Checkstyle */
|
||||
String CHECKSTYLE_BUNDLE = "com.puppycrawl.tools.checkstyle.messages";
|
||||
|
||||
/** property name for the configuration files */
|
||||
String CHECK_CONFIG_FILES_PROP = "checkstyle.check.configs";
|
||||
/** property name for the to-do pattern **/
|
||||
String TODO_PATTERN_PROP = "checkstyle.pattern.todo";
|
||||
/** property name for the parameter pattern **/
|
||||
|
|
@ -216,7 +214,6 @@ public interface Defn
|
|||
**/
|
||||
String[] ALL_STRING_SET_PROPS = new String[]
|
||||
{
|
||||
CHECK_CONFIG_FILES_PROP,
|
||||
ILLEGAL_IMPORTS_PROP,
|
||||
ILLEGAL_INSTANTIATIONS_PROP,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
|
|
@ -60,7 +61,7 @@ public class BaseCheckTestCase
|
|||
protected Checker createChecker(CheckConfiguration aCheckConfig)
|
||||
throws RESyntaxException, FileNotFoundException, IOException,
|
||||
ParserConfigurationException, SAXException, ClassNotFoundException,
|
||||
InstantiationException, IllegalAccessException
|
||||
InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
|
||||
{
|
||||
final Checker c = new Checker(new Configuration(mProps, mStream),
|
||||
new CheckConfiguration[] {aCheckConfig});
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import java.io.LineNumberReader;
|
|||
import java.io.InputStreamReader;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class CheckerTest
|
||||
extends TestCase
|
||||
|
|
@ -69,7 +70,11 @@ public class CheckerTest
|
|||
}
|
||||
|
||||
protected Checker createChecker()
|
||||
throws RESyntaxException, FileNotFoundException, IOException, ParserConfigurationException, SAXException, ClassNotFoundException, InstantiationException, IllegalAccessException
|
||||
throws RESyntaxException, FileNotFoundException, IOException,
|
||||
ParserConfigurationException, SAXException,
|
||||
ClassNotFoundException, InstantiationException,
|
||||
IllegalAccessException, InvocationTargetException,
|
||||
NoSuchMethodException
|
||||
{
|
||||
final Configuration config = new Configuration(mProps, mStream);
|
||||
final Checker c = new Checker(config);
|
||||
|
|
|
|||
Loading…
Reference in New Issue