Author: nbubna
Date: Thu Mar 12 21:12:03 2009
New Revision: 753018

URL: http://svn.apache.org/viewvc?rev=753018&view=rev
Log:
VELOCITY-704 remove #evaluate local scope now that $evaluate is provided, and 
don't catch #stop at #evaluate since #break does that now

Removed:
    
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/context/EvaluateContext.java
    
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/EvaluateContextTestCase.java
Modified:
    
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Evaluate.java
    
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/StopCommand.java
    
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/EvaluateTestCase.java
    velocity/engine/branches/2.0_Exp/test/evaluate/compare/eval1.cmp
    velocity/engine/branches/2.0_Exp/test/evaluate/eval1.vm

Modified: 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Evaluate.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Evaluate.java?rev=753018&r1=753017&r2=753018&view=diff
==============================================================================
--- 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Evaluate.java
 (original)
+++ 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Evaluate.java
 Thu Mar 12 21:12:03 2009
@@ -22,8 +22,6 @@
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.Writer;
-
-import org.apache.velocity.context.EvaluateContext;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.context.InternalContextAdapterImpl;
 import org.apache.velocity.exception.MethodInvocationException;
@@ -179,15 +177,13 @@
 
         if (nodeTree != null)
         {
-            InternalContextAdapter ica = new EvaluateContext(context, rsvc);
-
-            ica.pushCurrentTemplateName( templateName );
+            context.pushCurrentTemplateName(templateName);
 
             try
             {
                 try
                 {
-                    nodeTree.init( ica, rsvc );
+                    nodeTree.init(context, rsvc);
                 }
                 catch (TemplateInitException pex)
                 {
@@ -197,12 +193,12 @@
 
                 try 
                 {
-                    preRender(ica);
+                    preRender(context);
 
                     /*
                      *  now render, and let any exceptions fly
                      */
-                    nodeTree.render( ica, writer );
+                    nodeTree.render(context, writer);
                 }
                 catch (StopCommand stop)
                 {
@@ -210,10 +206,6 @@
                     {
                         throw stop;
                     }
-                    else if (rsvc.getLog().isDebugEnabled())
-                    {
-                        rsvc.getLog().debug(stop.getMessage());
-                    }
                 }
                 catch (ParseErrorException pex)
                 {
@@ -224,8 +216,8 @@
             }
             finally
             {
-                ica.popCurrentTemplateName();
-                postRender(ica);
+                context.popCurrentTemplateName();
+                postRender(context);
             }
             return true;
         }

Modified: 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/StopCommand.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/StopCommand.java?rev=753018&r1=753017&r2=753018&view=diff
==============================================================================
--- 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/StopCommand.java
 (original)
+++ 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/StopCommand.java
 Thu Mar 12 21:12:03 2009
@@ -21,7 +21,6 @@
 
 import org.apache.velocity.Template;
 import org.apache.velocity.runtime.RuntimeInstance;
-import org.apache.velocity.runtime.directive.Evaluate;
 
 /**
  * Stop command for directive Control objects.  In an ideal JDK,
@@ -82,8 +81,7 @@
         else // only stop for the top :)
         {
             return (that instanceof Template ||
-                    that instanceof RuntimeInstance ||
-                    that instanceof Evaluate);
+                    that instanceof RuntimeInstance);
         }
     }
 }

Modified: 
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/EvaluateTestCase.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/EvaluateTestCase.java?rev=753018&r1=753017&r2=753018&view=diff
==============================================================================
--- 
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/EvaluateTestCase.java
 (original)
+++ 
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/EvaluateTestCase.java
 Thu Mar 12 21:12:03 2009
@@ -27,10 +27,6 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
@@ -88,16 +84,12 @@
         super(name);
     }
 
-    public void setUp()
+    public void setUp() throws Exception
     {
+        super.setUp();
         assureResultsDirectoryExists(RESULTS_DIR);
     }
 
-    public static Test suite()
-    {
-       return new TestSuite(EvaluateTestCase.class);
-    }
-
     /**
      * Test basic functionality.
      * @throws Exception
@@ -105,7 +97,8 @@
     public void testEvaluate()
     throws Exception
     {
-        testFile("eval1", new HashMap());
+        Map props = new HashMap();
+        testFile("eval1", props);
     }
 
     /**
@@ -116,14 +109,10 @@
     throws Exception
     {
         Map properties = new HashMap();
-        properties.clear();
         testFile("eval2", properties);
 
-        properties.clear();
         
properties.put(RuntimeConstants.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL,"false");
         testFile("eval2", properties);
-
-
     }
 
     /**
@@ -137,25 +126,16 @@
     }
 
     /**
-     * Test #stop (since it is attached to context).
+     * Test #stop and #break
      * @throws Exception
      */
-    public void testStop()
-    throws Exception
+    public void testStopAndBreak()
     {
-        VelocityEngine ve = new VelocityEngine();
-        ve.init();
-        
-        Context context = new VelocityContext();        
-        StringWriter writer = new StringWriter();
-        ve.evaluate(context, writer, "test","test #stop test2 
#evaluate('test3')");
-        assertEquals("test ", writer.toString());
-        
-        context = new VelocityContext();        
-        writer = new StringWriter();
-        ve.evaluate(context, writer, "test","test test2 #evaluate('test3 #stop 
test4') test5");
-        assertEquals("test test2 test3  test5", writer.toString());
-        
+        assertEvalEquals("t ", "t #stop t2 #evaluate('t3')");
+        assertEvalEquals("t ", "t #break t2 #evaluate('t3')");
+        assertEvalEquals("t t2 t3 ", "t t2 #evaluate('t3 #stop t4') t5");
+        assertEvalEquals("t t2 t3  t5", "t t2 #evaluate('t3 #break t4') t5");
+        assertEvalEquals("t t2 t3 ", "t t2 #evaluate('t3 
#break($evaluate.topmost) t4') t5");
     }
 
     /**
@@ -265,7 +245,8 @@
     private void testFile(String basefilename, Map properties)
     throws Exception
     {
-        VelocityEngine ve = new VelocityEngine();
+        info("Test file: "+basefilename);
+        VelocityEngine ve = engine;
         ve.addProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, 
FILE_RESOURCE_LOADER_PATH);
      
         for (Iterator i = properties.keySet().iterator(); i.hasNext();)
@@ -273,6 +254,7 @@
             String key = (String) i.next();
             String value = (String) properties.get(key);
             ve.addProperty(key, value);
+            info("Add property: "+key+" = "+value);
         }
         
         ve.init();
@@ -280,7 +262,6 @@
         Template template;
         FileOutputStream fos;
         Writer fwriter;
-        Context context;
         
         template = ve.getTemplate( getFileName(null, basefilename, 
TMPL_FILE_EXT) );
         
@@ -289,8 +270,6 @@
         
         fwriter = new BufferedWriter( new OutputStreamWriter(fos) );
         
-        context = new VelocityContext();
-        setupContext(context);
         template.merge(context, fwriter);
         fwriter.flush();
         fwriter.close();
@@ -308,10 +287,5 @@
             fail(msg);
         }
     }
-        
-    public void setupContext(Context context)
-    {
-    } 
-    
-    
+
 }

Modified: velocity/engine/branches/2.0_Exp/test/evaluate/compare/eval1.cmp
URL: 
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/test/evaluate/compare/eval1.cmp?rev=753018&r1=753017&r2=753018&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/test/evaluate/compare/eval1.cmp (original)
+++ velocity/engine/branches/2.0_Exp/test/evaluate/compare/eval1.cmp Thu Mar 12 
21:12:03 2009
@@ -5,4 +5,4 @@
 zz
 
 reference zz changes to xx
-test1: zz
+test1: xx

Modified: velocity/engine/branches/2.0_Exp/test/evaluate/eval1.vm
URL: 
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/test/evaluate/eval1.vm?rev=753018&r1=753017&r2=753018&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/test/evaluate/eval1.vm (original)
+++ velocity/engine/branches/2.0_Exp/test/evaluate/eval1.vm Thu Mar 12 21:12:03 
2009
@@ -9,12 +9,12 @@
 
 #evaluate($test2)
 
-## Now check that #evaluate doesn't change context
+## Now check that #evaluate does change context
 ## Need to use single quote to surround #set to prevent premature evaluation
 
 #set($teststring = "reference $test2 changes to" +
           '#set($test1 = "xx") $test1')
 #evaluate($teststring)
 
-## Check that test1 hasn't changed
+## Check that test1 has changed
 test1: $test1


Reply via email to