diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java deleted file mode 100644 index 5d1b92e7e..000000000 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java +++ /dev/null @@ -1,219 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code for adherence to a set of rules. -// Copyright (C) 2001-2002 Oliver Burn -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -//////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; - -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import com.puppycrawl.tools.checkstyle.api.Check; -import com.puppycrawl.tools.checkstyle.api.CheckstyleException; - -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.beanutils.ConvertUtils; -import org.apache.commons.beanutils.converters.BooleanConverter; -import org.apache.commons.beanutils.converters.BooleanArrayConverter; -import org.apache.commons.beanutils.converters.ByteConverter; -import org.apache.commons.beanutils.converters.ByteArrayConverter; -import org.apache.commons.beanutils.converters.CharacterConverter; -import org.apache.commons.beanutils.converters.CharacterArrayConverter; -import org.apache.commons.beanutils.converters.DoubleConverter; -import org.apache.commons.beanutils.converters.DoubleArrayConverter; -import org.apache.commons.beanutils.converters.FloatConverter; -import org.apache.commons.beanutils.converters.FloatArrayConverter; -import org.apache.commons.beanutils.converters.IntegerConverter; -import org.apache.commons.beanutils.converters.IntegerArrayConverter; -import org.apache.commons.beanutils.converters.LongConverter; -import org.apache.commons.beanutils.converters.LongArrayConverter; -import org.apache.commons.beanutils.converters.ShortConverter; -import org.apache.commons.beanutils.converters.ShortArrayConverter; -import org.apache.commons.beanutils.converters.StringArrayConverter; - -/** - * Represents the configuration for a check. - * - * @author Oliver Burn - * @version 1.0 - */ -class CheckConfiguration -{ - static { - initConverters(); - } - - /** - * Setup the jakarta-commons-beanutils type converters so they throw - * a ConversionException instead of using the default value. - */ - private static void initConverters() - { - // TODO: is there a smarter way to tell beanutils not to use defaults? - - boolean booleanArray[] = new boolean[0]; - byte byteArray[] = new byte[0]; - char charArray[] = new char[0]; - double doubleArray[] = new double[0]; - float floatArray[] = new float[0]; - int intArray[] = new int[0]; - long longArray[] = new long[0]; - short shortArray[] = new short[0]; - - ConvertUtils.register(new BooleanConverter(), Boolean.TYPE); - ConvertUtils.register(new BooleanConverter(), Boolean.class); - ConvertUtils.register(new BooleanArrayConverter(), - booleanArray.getClass()); - ConvertUtils.register(new ByteConverter(), Byte.TYPE); - ConvertUtils.register(new ByteConverter(), Byte.class); - ConvertUtils.register(new ByteArrayConverter(byteArray), - byteArray.getClass()); - ConvertUtils.register(new CharacterConverter(), Character.TYPE); - ConvertUtils.register(new CharacterConverter(), Character.class); - ConvertUtils.register(new CharacterArrayConverter(), - charArray.getClass()); - ConvertUtils.register(new DoubleConverter(), Double.TYPE); - ConvertUtils.register(new DoubleConverter(), Double.class); - ConvertUtils.register(new DoubleArrayConverter(doubleArray), - doubleArray.getClass()); - ConvertUtils.register(new FloatConverter(), Float.TYPE); - ConvertUtils.register(new FloatConverter(), Float.class); - ConvertUtils.register(new FloatArrayConverter(), - floatArray.getClass()); - ConvertUtils.register(new IntegerConverter(), Integer.TYPE); - ConvertUtils.register(new IntegerConverter(), Integer.class); - ConvertUtils.register(new IntegerArrayConverter(), - intArray.getClass()); - ConvertUtils.register(new LongConverter(), Long.TYPE); - ConvertUtils.register(new LongConverter(), Long.class); - ConvertUtils.register(new LongArrayConverter(), longArray.getClass()); - ConvertUtils.register(new ShortConverter(), Short.TYPE); - ConvertUtils.register(new ShortConverter(), Short.class); - ConvertUtils.register(new ShortArrayConverter(), - shortArray.getClass()); - ConvertUtils.register(new StringArrayConverter(), - String[].class); - ConvertUtils.register(new IntegerArrayConverter(), - Integer[].class); - - // BigDecimal, BigInteger, Class, Date, String, Time, TimeStamp - // do not use defaults in the default configuration of ConvertUtils - - } - - /** the classname for the check */ - private String mClassname; - /** the tokens the check is interested in */ - private final Set mTokens = new HashSet(); - /** the properties for the check */ - private final Map mProperties = new HashMap(); - - - /** - * Set the classname of the check. - * @param aClassname the classname for the check - */ - void setClassname(String aClassname) - { - mClassname = aClassname; - } - - /** - * Adds a set of tokens the check is interested in. The string is a comma - * separated list of token names. - * @param aStrRep the string representation of the tokens interested in - */ - void addTokens(String aStrRep) - { - final String trimmed = aStrRep.trim(); - if (trimmed.length() == 0) { - return; - } - - final StringTokenizer st = new StringTokenizer(trimmed, ","); - while (st.hasMoreTokens()) { - mTokens.add(st.nextToken().trim()); - } - } - - /** - * Returns the tokens registered for the check. - * @return the set of token names - */ - Set getTokens() - { - return mTokens; - } - - /** - * Adds a property for the check. - * @param aName name of the property - * @param aValue value of the property - */ - void addProperty(String aName, String aValue) - { - mProperties.put(aName, aValue); - } - - /** - * Create an instance of the check that is properly initialised. - * - * @param aLoader the ClassLoader to create the instance with - * @return the created check - * @throws CheckstyleException if an error occurs - */ - Check createInstance(ClassLoader aLoader) - throws CheckstyleException - { - try { - 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); - try { - BeanUtils.copyProperty(check, key, value); - } - catch (InvocationTargetException e) { - throw new CheckstyleException( - "for check " + mClassname + " unable to set " + key - + " with " + value); - } - } - return check; - } - catch (ClassNotFoundException e) { - throw new CheckstyleException( - "Unable to find class for " + mClassname); - } - catch (InstantiationException e) { - throw new CheckstyleException( - "Unable to instantiate " + mClassname); - } - catch (IllegalAccessException e) { - throw new CheckstyleException( - "Unable to instantiate " + mClassname); - } - } -} diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java deleted file mode 100644 index 01d8f71d9..000000000 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java +++ /dev/null @@ -1,171 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code for adherence to a set of rules. -// Copyright (C) 2001-2002 Oliver Burn -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -//////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; - -//import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.ObjectInputStream; -//import java.io.PrintStream; -import java.io.Serializable; -//import java.util.HashMap; -//import java.util.HashSet; -//import java.util.Locale; -//import java.util.Map; -import java.util.Properties; -//import java.util.Set; -// -//import org.apache.regexp.RESyntaxException; -// -//import com.puppycrawl.tools.checkstyle.api.Utils; - -/** - * Represents the configuration that checkstyle uses when checking. A - * configuration is Serializable, however the ClassLoader - * configuration is lost. - * @author Rick Giles - **/ -public class Configuration - implements Serializable -{ - //////////////////////////////////////////////////////////////////////////// - // Member variables - //////////////////////////////////////////////////////////////////////////// - - /** global configuration properties **/ - private GlobalProperties mGlobalProps = new GlobalProperties(); - - /** check configurations **/ - private CheckConfiguration[] mCheckConfigs = - new CheckConfiguration[0]; - - //////////////////////////////////////////////////////////////////////////// - // Constructors - //////////////////////////////////////////////////////////////////////////// - - /** - * Creates a new Configuration instance. - * - * @param aGlobalProps the global properties for the configuration - * @param aCheckConfs array of check configurations - */ - public Configuration(GlobalProperties aGlobalProps, - CheckConfiguration[] aCheckConfs) - { - mGlobalProps = aGlobalProps; - mCheckConfigs = aCheckConfs; - } - - /** - * Creates a new Configuration instance. - */ - public Configuration() - { - } - - - - /** - * Extend default deserialization to initialize the RE member variables. - * - * @param aStream the ObjectInputStream that contains the serialized data - * @throws IOException if an I/O error occurs - * @throws ClassNotFoundException if the class of a serialized object - * could not be found - */ - private void readObject(ObjectInputStream aStream) - throws IOException, ClassNotFoundException - { - // initialize the serialized fields - aStream.defaultReadObject(); - } - - - //////////////////////////////////////////////////////////////////////////// - // Setters - //////////////////////////////////////////////////////////////////////////// - - /** - * Set the class loader for locating classes. - * @param aLoader the class loader - */ - public void setClassLoader(ClassLoader aLoader) - { - mGlobalProps.setClassLoader(aLoader); - } - - //////////////////////////////////////////////////////////////////////////// - // Getters - //////////////////////////////////////////////////////////////////////////// - - /** @return a Properties object representing the current configuration. - * The returned object can be used to recreate the configuration. - * Tip: used on a default object returns all the default objects. */ - public Properties getProperties() - { - return mGlobalProps.getProperties(); - } - - /** @return the class loader **/ - ClassLoader getClassLoader() - { - return mGlobalProps.getClassLoader(); - } - - /** @return the base directory **/ - String getBasedir() - { - return mGlobalProps.getBasedir(); - } - - /** @return locale language to report messages **/ - String getLocaleLanguage() - { - return mGlobalProps.getLocaleLanguage(); - } - - /** @return locale country to report messages **/ - String getLocaleCountry() - { - return mGlobalProps.getLocaleCountry(); - } - - /** @return distance between tab stops */ - int getTabWidth() - { - return mGlobalProps.getTabWidth(); - } - - /** @return the File of the cache file **/ - String getCacheFile() - { - return mGlobalProps.getCacheFile(); - } - - /** @return the global properties **/ - public GlobalProperties getGlobalProperties() - { - return mGlobalProps; - } - - /** @return the check configurations **/ - public CheckConfiguration[] getCheckConfigurations() - { - return mCheckConfigs; - } -} diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/GlobalProperties.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/GlobalProperties.java deleted file mode 100644 index 1622e34ff..000000000 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/GlobalProperties.java +++ /dev/null @@ -1,278 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code for adherence to a set of rules. -// Copyright (C) 2001-2002 Oliver Burn -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -//////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.PrintStream; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Properties; - -import com.puppycrawl.tools.checkstyle.api.Utils; -import org.apache.regexp.RESyntaxException; - -/** - * Represents the global properties that checkstyle uses when checking. A - * global properties object is Serializable, however the ClassLoader - * configuration is lost. - * @author Oliver Burn - **/ -public class GlobalProperties - implements Serializable -{ - //////////////////////////////////////////////////////////////////////////// - // Member variables - //////////////////////////////////////////////////////////////////////////// - - /** - * class loader to resolve classes with. Needs to be transient as unable - * to persist. - **/ - private transient ClassLoader mLoader = - Thread.currentThread().getContextClassLoader(); - - /** map of int properties **/ - private final Map mIntProps = new HashMap(); - { - mIntProps.put(Defn.TAB_WIDTH_PROP, new Integer(8)); - } - - /** map of all String properties - by default are null **/ - private final Map mStringProps = new HashMap(); - { - mStringProps.put(Defn.LOCALE_LANGUAGE_PROP, - Locale.getDefault().getLanguage()); - mStringProps.put(Defn.LOCALE_COUNTRY_PROP, - Locale.getDefault().getCountry()); - } - - //////////////////////////////////////////////////////////////////////////// - // Constructors - //////////////////////////////////////////////////////////////////////////// - - /** - * Creates a new GlobalProperties instance. - * - * @param aProps where to extract configuration parameters from - * @param aLog where to log errors to - * @throws RESyntaxException if an error occurs - * @throws FileNotFoundException if an error occurs - * @throws IOException if an error occurs - */ - public GlobalProperties(Properties aProps, PrintStream aLog) - throws RESyntaxException, FileNotFoundException, IOException - { - for (int i = 0; i < Defn.ALL_INT_PROPS.length; i++) { - setIntProperty(aProps, aLog, Defn.ALL_INT_PROPS[i]); - } - - for (int i = 0; i < Defn.ALL_STRING_PROPS.length; i++) { - setStringProperty(aProps, Defn.ALL_STRING_PROPS[i]); - } - } - - /** - * Creates a new GlobalProperties instance. - * @throws IllegalStateException if an error occurs - */ - public GlobalProperties() - { - } - - /** - * Extend default deserialization to initialize the RE member variables. - * - * @param aStream the ObjectInputStream that contains the serialized data - * @throws IOException if an I/O error occurs - * @throws ClassNotFoundException if the class of a serialized object - * could not be found - */ - private void readObject(ObjectInputStream aStream) - throws IOException, ClassNotFoundException - { - // initialize the serialized fields - aStream.defaultReadObject(); - - // initialize the transient fields - mLoader = Thread.currentThread().getContextClassLoader(); - } - - - //////////////////////////////////////////////////////////////////////////// - // Setters - //////////////////////////////////////////////////////////////////////////// - - /** - * Set the class loader for locating classes. - * @param aLoader the class loader - */ - public void setClassLoader(ClassLoader aLoader) - { - mLoader = aLoader; - } - - //////////////////////////////////////////////////////////////////////////// - // Getters - //////////////////////////////////////////////////////////////////////////// - - /** @return a Properties object representing the current configuration. - * The returned object can be used to recreate the configuration. - * Tip: used on a default object returns all the default objects. */ - public Properties getProperties() - { - final Properties retVal = new Properties(); - - for (int i = 0; i < Defn.ALL_INT_PROPS.length; i++) { - final String key = Defn.ALL_INT_PROPS[i]; - Utils.addObjectString(retVal, key, - Integer.toString(getIntProperty(key))); - } - - for (int i = 0; i < Defn.ALL_STRING_PROPS.length; i++) { - final String key = Defn.ALL_STRING_PROPS[i]; - Utils.addObjectString(retVal, key, getStringProperty(key)); - } - - return retVal; - } - - /** @return the class loader **/ - ClassLoader getClassLoader() - { - return mLoader; - } - - /** @return locale language to report messages **/ - String getLocaleLanguage() - { - return getStringProperty(Defn.LOCALE_LANGUAGE_PROP); - } - - /** @return locale country to report messages **/ - String getLocaleCountry() - { - return getStringProperty(Defn.LOCALE_COUNTRY_PROP); - } - - /** @return distance between tab stops */ - int getTabWidth() - { - return getIntProperty(Defn.TAB_WIDTH_PROP); - } - - /** @return the File of the cache file **/ - String getCacheFile() - { - return getStringProperty(Defn.CACHE_FILE_PROP); - } - - /** - * Set the String property. - * @param aName name of the property. Should be defined in Defn. - * @param aTo the value to set - */ - private void setStringProperty(String aName, String aTo) - { - mStringProps.put(aName, aTo); - } - - /** @return the base directory **/ - String getBasedir() - { - return getStringProperty(Defn.BASEDIR_PROP); - } - - /** - * Set an integer property. - * @param aName name of the property to set - * @param aTo the value to set - */ - private void setIntProperty(String aName, int aTo) - { - mIntProps.put(aName, new Integer(aTo)); - } - - //////////////////////////////////////////////////////////////////////////// - // Private methods - //////////////////////////////////////////////////////////////////////////// - - /** - * @return an integer property - * @param aName the name of the integer property to get - */ - private int getIntProperty(String aName) - { - return ((Integer) mIntProps.get(aName)).intValue(); - } - - /** - * @return an String property - * @param aName the name of the String property to get - */ - private String getStringProperty(String aName) - { - return (String) mStringProps.get(aName); - } - /** - * Set the value of an integer property. If the property is not defined - * or cannot be parsed, then a default value is used. - * @param aProps the properties set to use - * @param aLog where to log errors to - * @param aName the name of the property to parse - */ - private void setIntProperty(Properties aProps, - PrintStream aLog, - String aName) - { - final String strRep = aProps.getProperty(aName); - if (strRep != null) { - try { - final int val = Integer.parseInt(strRep); - setIntProperty(aName, val); - } - catch (NumberFormatException nfe) { - aLog.println( - "Unable to parse " - + aName - + " property with value " - + strRep - + ", defaulting to " - + getIntProperty(aName) - + "."); - } - } - } - - /** - * Set a string property from a property set. - * @param aProps the properties set to extract property from - * @param aName name of the property to extract - */ - private void setStringProperty(Properties aProps, String aName) - { - final String str = aProps.getProperty(aName); - if (str != null) { - setStringProperty(aName, aProps.getProperty(aName)); - } - } -}