diff --git a/build.xml b/build.xml index 6d51d2190..d4dd1a031 100644 --- a/build.xml +++ b/build.xml @@ -11,6 +11,7 @@ + @@ -22,6 +23,7 @@ + diff --git a/lib/commons-beanutils.jar b/lib/commons-beanutils.jar new file mode 100644 index 000000000..150e4be9a Binary files /dev/null and b/lib/commons-beanutils.jar differ diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java index 8f316451c..8dfb72a72 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java @@ -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; } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java index f5145bef3..8933ca3a4 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java @@ -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 **/ diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java index 9fdd971ca..20604d48a 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java @@ -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() { diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java index a78cf6a17..126953d1e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java @@ -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, }; diff --git a/src/tests/com/puppycrawl/tools/checkstyle/BaseCheckTestCase.java b/src/tests/com/puppycrawl/tools/checkstyle/BaseCheckTestCase.java index 2ca7fb3a2..24766f073 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/BaseCheckTestCase.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/BaseCheckTestCase.java @@ -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}); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java index 7a070e85b..b6fe3cc05 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -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);