james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r526658 - in /james/jsieve/trunk/src/main/java/org/apache/jsieve: Command.java ScriptCoordinate.java SieveContext.java SieveParserVisitorImpl.java Test.java
Date Mon, 09 Apr 2007 06:25:57 GMT
Author: rdonkin
Date: Sun Apr  8 23:25:55 2007
New Revision: 526658

URL: http://svn.apache.org/viewvc?view=rev&rev=526658
Log:
When debugging scripts it's useful to be able to see the coordinates when a command executes.
Commands are executed after the parse so it's necessary to store the coordinate in the command.

Modified:
    james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveParserVisitorImpl.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java?view=diff&rev=526658&r1=526657&r2=526658
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java Sun Apr  8 23:25:55 2007
@@ -36,8 +36,14 @@
     public Object execute(MailAdapter mail) throws SieveException
     {
         Log log = Logger.getLog();
-        if (log.isDebugEnabled())
+        if (log.isDebugEnabled()) {
             log.debug(toString());
+            coordinate.debugDiagnostics(log);
+        }
+        // commands are executed after the parsing phase
+        // recursively from the top level block
+        // so need to use the coordinate recorded from the parse
+        context.setCoordinate(coordinate);
         return CommandManager.getInstance().newInstance(getName()).execute(
             mail,
             getArguments(),
@@ -57,6 +63,14 @@
     private SieveContext context;
     
     /**
+     * Script coordinate for this command.
+     * Commands are executed after the document has been parse.
+     * So this must be recorded on construction
+     * and stored for later use.
+     */
+    private ScriptCoordinate coordinate;
+    
+    /**
      * Constructor for Test.
      */
     private Command()
@@ -74,6 +88,7 @@
     {
         this();
         this.context = context;
+        this.coordinate = context.getCoordinate();
         setName(name);
         setArguments(arguments);
         setBlock(block);        

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java?view=diff&rev=526658&r1=526657&r2=526658
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java Sun Apr  8 23:25:55
2007
@@ -148,4 +148,15 @@
             logger.info("Expression ends line " + endLineNumber + " column " + endColumnNumber);
         }
     }
+    
+    /**
+     * Logs diagnotic information about the script coordinate.
+     * @param logger <code>Log</code>, not null
+     */
+    public void debugDiagnostics(Log logger) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Expression starts line " + startLineNumber + " column " + startColumnNumber);
+            logger.debug("Expression ends line " + endLineNumber + " column " + endColumnNumber);
+        }
+    }
 }

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java?view=diff&rev=526658&r1=526657&r2=526658
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java Sun Apr  8 23:25:55
2007
@@ -30,4 +30,10 @@
      * @return <code>ScriptCoordinate</code>, not null
      */
     public abstract ScriptCoordinate getCoordinate();
+    
+    /**
+     * Sets the script position of the current operation.
+     * @param coordinate <code>ScriptCoordinate</code>, not null
+     */
+    public abstract void setCoordinate(ScriptCoordinate coordinate);
 }

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveParserVisitorImpl.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveParserVisitorImpl.java?view=diff&rev=526658&r1=526657&r2=526658
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveParserVisitorImpl.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveParserVisitorImpl.java Sun Apr
 8 23:25:55 2007
@@ -199,7 +199,7 @@
         Commands commands =
             (Commands) ((List) node.childrenAccept(this, children)).get(0);
         Block block = new Block(commands);
-
+        context.setCoordinate(node.getCoordinate());
         // Answer the result of executing the Block
         return block.execute((MailAdapter)data);
     }

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java?view=diff&rev=526658&r1=526657&r2=526658
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java Sun Apr  8 23:25:55 2007
@@ -45,8 +45,9 @@
     public Object execute(MailAdapter mail) throws SieveException
     {
         Log log = Logger.getLog();
-        if (log.isDebugEnabled())
+        if (log.isDebugEnabled()) {
             log.debug(toString());
+        }
         return new Boolean(
             TestManager.getInstance().newInstance(getName()).execute(
                 mail,



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message