velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r651712 - in /velocity/tools/trunk/src: main/java/org/apache/velocity/tools/config/ main/java/org/apache/velocity/tools/view/ test/java/org/apache/velocity/tools/test/whitebox/
Date Fri, 25 Apr 2008 22:07:39 GMT
Author: nbubna
Date: Fri Apr 25 15:07:38 2008
New Revision: 651712

URL: http://svn.apache.org/viewvc?rev=651712&view=rev
Log:
make combined configurations easier to debug by tracking source info on them

Modified:
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/XmlFactoryConfiguration.java
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/VelocityView.java
    velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java?rev=651712&r1=651711&r2=651712&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java
Fri Apr 25 15:07:38 2008
@@ -74,7 +74,8 @@
      */
     public static FactoryConfiguration getDefaultTools()
     {
-        FileFactoryConfiguration config = new XmlFactoryConfiguration();
+        FileFactoryConfiguration config =
+            new XmlFactoryConfiguration("ConfigurationUtils.getDefaultTools()");
         config.read(GENERIC_DEFAULTS_PATH);
 
         // view tools and struts tools may not be available
@@ -92,7 +93,8 @@
      */
     public static FactoryConfiguration getGenericTools()
     {
-        FileFactoryConfiguration config = new XmlFactoryConfiguration();
+        FileFactoryConfiguration config =
+            new XmlFactoryConfiguration("ConfigurationUtils.getGenericTools()");
         config.read(GENERIC_DEFAULTS_PATH);
 
         // defaults should *always* be clean!
@@ -108,7 +110,8 @@
      */
     public static FactoryConfiguration getVelocityView()
     {
-        FileFactoryConfiguration config = new XmlFactoryConfiguration();
+        FileFactoryConfiguration config =
+            new XmlFactoryConfiguration("ConfigurationUtils.getVelocityView()");
         config.read(GENERIC_DEFAULTS_PATH);
         config.read(VIEW_DEFAULTS_PATH);
 
@@ -126,7 +129,8 @@
      */
     public static FactoryConfiguration getVelocityStruts()
     {
-        FileFactoryConfiguration config = new XmlFactoryConfiguration();
+        FileFactoryConfiguration config =
+            new XmlFactoryConfiguration("ConfigurationUtils.getVelocityStruts()");
         config.read(GENERIC_DEFAULTS_PATH);
         config.read(VIEW_DEFAULTS_PATH);
         config.read(STRUTS_DEFAULTS_PATH);
@@ -174,7 +178,7 @@
         else
         {
             // start out blank
-            auto = new FactoryConfiguration();
+            auto = new FactoryConfiguration("ConfigurationUtils.getAutoLoaded(false)");
         }
 
         //TODO: look for any Tools classes in the root of the classpath
@@ -365,7 +369,8 @@
         else
         {
             // create a base config to combine the others into
-            FactoryConfiguration config = new FactoryConfiguration();
+            FactoryConfiguration config =
+                new FactoryConfiguration("ConfigurationUtils.findInClassPath("+path+","+caller+")");
             boolean readAConfig = false;
             for (URL resource : found)
             {
@@ -400,13 +405,14 @@
     {
         FileFactoryConfiguration config = null;
         String path = url.toString();
+        String source = "ConfigurationUtils.read("+url.toString()+")";
         if (path.endsWith(".xml"))
         {
-            config = new XmlFactoryConfiguration();
+            config = new XmlFactoryConfiguration(source);
         }
         else if (path.endsWith(".properties"))
         {
-            config = new PropertiesFactoryConfiguration();
+            config = new PropertiesFactoryConfiguration(source);
         }
         else if (path.endsWith(".class"))
         {

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java?rev=651712&r1=651711&r2=651712&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/EasyFactoryConfiguration.java
Fri Apr 25 15:07:38 2008
@@ -19,6 +19,7 @@
  * under the License.
  */
 
+import java.util.List;
 import org.apache.velocity.tools.ToolboxFactory;
 
 /**
@@ -98,9 +99,28 @@
      */
     public EasyFactoryConfiguration(boolean includeDefaults)
     {
+        // just give the param name as source
+        this(includeDefaults, String.valueOf(includeDefaults));
+    }
+
+    /**
+     * @param includeDefaults Sets whether this instance should start with the
+     *        {@link ConfigurationUtils#getDefaultTools()} configuration or not.
+     * @param source a string identify where this instance was created, or
+     *        something else useful to identify this instance during debugging
+     */
+    public EasyFactoryConfiguration(boolean includeDefaults, String source)
+    {
+        super(EasyFactoryConfiguration.class, source);
+
         if (includeDefaults)
         {
             addDefaultTools();
+            // now put the root source last, since the defaults were really first
+            // and nothing could have been added prior to them
+            List<String> sources = getSources();
+            String first = sources.remove(0);
+            sources.add(first);
         }
     }
 

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java?rev=651712&r1=651711&r2=651712&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FactoryConfiguration.java
Fri Apr 25 15:07:38 2008
@@ -19,7 +19,9 @@
  * under the License.
  */
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
 import org.apache.velocity.tools.ToolboxFactory;
@@ -35,6 +37,44 @@
     extends CompoundConfiguration<ToolboxConfiguration>
 {
     private final SortedSet<Data> data = new TreeSet<Data>();
+    private final List<String> sources = new ArrayList<String>();
+
+    public FactoryConfiguration()
+    {
+        this("");
+    }
+    
+    /**
+     * Creates a new instance with the specified source name
+     * combined with this class's name as the initial source.
+     */
+    public FactoryConfiguration(String source)
+    {
+        this(FactoryConfiguration.class, source);
+    }
+
+    /**
+     * Allows subclasses to construct an instance that uses their classname.
+     */
+    protected FactoryConfiguration(Class clazz, String source)
+    {
+        addSource(clazz.getName()+"("+source+")");
+    }
+
+    /**
+     * Returns the list of sources for this configuration info in
+     * order starting from the source name given to this instance
+     * (if any) and going to the most recently added source.
+     */
+    public List<String> getSources()
+    {
+        return this.sources;
+    }
+
+    public void addSource(String source)
+    {
+        this.sources.add(source);
+    }
 
     public void addData(Data newDatum)
     {
@@ -130,6 +170,12 @@
         // add config's Data to our own
         setData(config.getData());
 
+        // add config's sources to our own
+        for (String source : config.getSources())
+        {
+            addSource(source);
+        }
+
         // pass to CompoundConfiguration's to add properties
         super.addConfiguration(config);
     }
@@ -148,8 +194,18 @@
     @Override
     public String toString()
     {
+        return toString(true);
+    }
+
+    public String toString(boolean includeSources)
+    {
         StringBuilder out = new StringBuilder();
-        out.append("\nFactoryConfiguration ");
+        out.append("\nFactoryConfiguration from ");
+        if (includeSources)
+        {
+            out.append(getSources().size());
+            out.append(" sources ");
+        }
         appendProperties(out);
         if (hasData())
         {
@@ -172,6 +228,18 @@
                 out.append(datum);
                 out.append("\n ");
             }
+        }
+        if (includeSources)
+        {
+            int count = 0;
+            for (String source : getSources())
+            {
+                out.append("\n Source ");
+                out.append(count++);
+                out.append(": ");
+                out.append(source);
+            }
+            out.append("\n");
         }
         return out.toString();
     }

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java?rev=651712&r1=651711&r2=651712&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/FileFactoryConfiguration.java
Fri Apr 25 15:07:38 2008
@@ -37,6 +37,11 @@
  */
 public abstract class FileFactoryConfiguration extends FactoryConfiguration
 {
+    protected FileFactoryConfiguration(Class clazz, String source)
+    {
+        super(clazz, source);
+    }
+
     /**
      * <p>Reads an configuration from an {@link InputStream}.</p>
      * 
@@ -143,6 +148,8 @@
         try
         {
             read(url, url.openStream(), required, log);
+            // only add the sources which can be read
+            addSource("    .read("+url.toString()+")");
         }
         catch (IOException ioe)
         {

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java?rev=651712&r1=651711&r2=651712&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/PropertiesFactoryConfiguration.java
Fri Apr 25 15:07:38 2008
@@ -54,6 +54,16 @@
  */
 public class PropertiesFactoryConfiguration extends FileFactoryConfiguration
 {
+    public PropertiesFactoryConfiguration()
+    {
+        this("");
+    }
+
+    public PropertiesFactoryConfiguration(String source)
+    {
+        super(PropertiesFactoryConfiguration.class, source);
+    }
+
     /**
      * <p>Reads an properties file from an {@link InputStream}
      * and uses it to configure this {@link FactoryConfiguration}.</p>

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/XmlFactoryConfiguration.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/XmlFactoryConfiguration.java?rev=651712&r1=651711&r2=651712&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/XmlFactoryConfiguration.java
(original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/config/XmlFactoryConfiguration.java
Fri Apr 25 15:07:38 2008
@@ -38,11 +38,22 @@
 
     public XmlFactoryConfiguration()
     {
-        this(false);
+        this(false, "");
     }
 
     public XmlFactoryConfiguration(boolean supportOldConfig)
     {
+        this(supportOldConfig, String.valueOf(supportOldConfig));
+    }
+
+    public XmlFactoryConfiguration(String source)
+    {
+        this(false, source);
+    }
+
+    public XmlFactoryConfiguration(boolean supportOldConfig, String source)
+    {
+        super(XmlFactoryConfiguration.class, source);
         setRuleSet(new XmlFactoryConfigurationRuleSet());
         this.supportOldXml = supportOldConfig;
     }

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/VelocityView.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/VelocityView.java?rev=651712&r1=651711&r2=651712&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/VelocityView.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/VelocityView.java Fri
Apr 25 15:07:38 2008
@@ -477,7 +477,7 @@
      */
     protected void configure(final JeeConfig config, final ToolboxFactory factory)
     {
-        FactoryConfiguration factoryConfig = new FactoryConfiguration();
+        FactoryConfiguration factoryConfig = new FactoryConfiguration("VelocityView.configure(config,factory)");
 
         boolean hasOldToolbox = false;
         if (this.deprecationSupportMode)
@@ -722,13 +722,14 @@
 
         // then make sure it's a file type we recognize
         FileFactoryConfiguration config = null;
+        String source = "VelocityView.getConfiguration("+path+","+required+")";
         if (path.endsWith(".xml"))
         {
-            config = new XmlFactoryConfiguration(this.deprecationSupportMode);
+            config = new XmlFactoryConfiguration(this.deprecationSupportMode, source);
         }
         else if (path.endsWith(".properties"))
         {
-            config = new PropertiesFactoryConfiguration();
+            config = new PropertiesFactoryConfiguration(source);
         }
         else
         {

Modified: velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java?rev=651712&r1=651711&r2=651712&view=diff
==============================================================================
--- velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
(original)
+++ velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
Fri Apr 25 15:07:38 2008
@@ -406,6 +406,15 @@
         assertEquals(one.toString(), two.toString());
     }
 
+    protected void assertConfigEquals(FactoryConfiguration one, FactoryConfiguration two)
+    {
+        assertNotNull(one);
+        assertNotNull(two);
+
+        // for now, just compare the toString() output without source info
+        assertEquals(one.toString(false), two.toString(false));
+    }
+
     protected void assertValid(Data valid)
     {
         assertNotNull(valid);



Mime
View raw message