commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly build.xml
Date Fri, 21 Jun 2002 02:57:17 GMT
jstrachan    2002/06/20 19:57:17

  Modified:    jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/java/org/apache/commons/jelly/impl
                        DynaTagScript.java TagScript.java
                        BeanTagScript.java
               jelly/src/java/org/apache/commons/jelly JellyException.java
               jelly/xdocs todo.xml
               jelly    build.xml
  Added:       jelly/src/test/org/apache/commons/jelly/ant typoTest.jelly
  Log:
  Added support for line and column numbering in exceptions that get generated so that its
easy for users to see where in their scripts the typeos or problems originated.
  Going forward it might be nice to also include the file name that caused the problem as
well.
  Also JellyException now properly handles nested exception stack traces now.
  There's a sample jelly script now for working with Ant that has some typos in it and Jelly
reports the wrong line succesfully. For some reason the column number is -1 which could well
be the SAX parser.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/typoTest.jelly
  
  Index: typoTest.jelly
  ===================================================================
  <?xml version="1.0"?>
  <j:jelly xmlns:j="jelly:core" xmlns="jelly:ant">
    Lets start by calling the echo task
      
    <!-- this example attempts to invoke some Ant tasks -->
    <echo message="Invoking the echo task from inside Jelly; the Maven repository is ${lib.repo}"/>
         
  
    <echo>
    	Maven home is ${maven.home}
    </echo>
  
    <!-- lets try invoke a program -->
    <!-- typeo on the next line -->
    <java classnam="org.apache.commons.jelly.Jelly" fork="yes">
      <classpath refid="test.classpath"/>
      <arg value="src/test/org/apache/commons/jelly/show_args.jelly"/> 
      <arg value="one"/> 
      <arg value="two"/> 
      <arg value="three"/> 
    </java>
  
    We should be back to the Jelly script again now...    
  </j:jelly>
  
  
  
  1.23      +10 -5     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java
  
  Index: XMLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- XMLParser.java	14 Jun 2002 15:25:18 -0000	1.22
  +++ XMLParser.java	21 Jun 2002 02:57:17 -0000	1.23
  @@ -588,6 +588,11 @@
                   Tag tag = tagScript.getTag();
                   tag.setParent(parentTag);
                   
  +                // set the line number details
  +                if ( locator != null ) {
  +                    tagScript.setLocator(locator);
  +                }
  +                
                   // pop another tag onto the stack
                   if ( parentTag != null ) {
                       tagStack.add( parentTag );                
  
  
  
  1.7       +7 -6      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java
  
  Index: DynaTagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DynaTagScript.java	18 Jun 2002 18:36:42 -0000	1.6
  +++ DynaTagScript.java	21 Jun 2002 02:57:17 -0000	1.7
  @@ -127,6 +127,7 @@
               Object value = expression.evaluate(context);
               dynaTag.setAttribute(name, value);
           }
  -        tag.doTag(output);
  +        
  +        runTag(output);
       }
   }
  
  
  
  1.11      +75 -5     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java
  
  Index: TagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TagScript.java	17 May 2002 15:18:10 -0000	1.10
  +++ TagScript.java	21 Jun 2002 02:57:17 -0000	1.11
  @@ -73,16 +73,21 @@
   import java.util.Map;
   
   import org.apache.commons.beanutils.ConvertUtils;
  +
   import org.apache.commons.jelly.CompilableTag;
   import org.apache.commons.jelly.JellyContext;
  +import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.DynaTag;
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.expression.Expression;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +import org.xml.sax.Locator;
  +
   /** 
    * <p><code>TagScript</code> abstract base class for a 
    * script that evaluates a custom tag.</p>
  @@ -100,6 +105,12 @@
   
       /** The attribute expressions that are created */
       protected Map attributes = new HashMap();
  +    
  +    /** the line number of the tag */
  +    private int lineNumber = -1;
  +    
  +    /** the column number of the tag */
  +    private int columnNumber = -1;
   
       public TagScript() {
       }
  @@ -112,6 +123,16 @@
           return super.toString() + "[tag=" + tag + "]";
       }
       
  +    /**
  +     * Configures this TagScript from the SAX Locator, setting the column
  +     * and line numbers
  +     */
  +    public void setLocator(Locator locator) {
  +        setLineNumber( locator.getLineNumber() );
  +        setColumnNumber( locator.getColumnNumber() );
  +    }
  +
  +    
       /** 
        * @return a new TagScript based on whether 
        * the tag is a bean tag or DynaTag 
  @@ -145,8 +166,57 @@
           this.tag = tag;
       }
       
  +    /** 
  +     * @return the line number of the tag 
  +     */
  +    public int getLineNumber() {
  +        return lineNumber;
  +    }
  +    
  +    /** 
  +     * Sets the line number of the tag 
  +     */
  +    public void setLineNumber(int lineNumber) {
  +        this.lineNumber = lineNumber;
  +    }
  +
  +    /** 
  +     * @return the column number of the tag 
  +     */
  +    public int getColumnNumber() {
  +        return columnNumber;
  +    }
  +    
  +    /** 
  +     * Sets the column number of the tag 
  +     */
  +    public void setColumnNumber(int columnNumber) {
  +        this.columnNumber = columnNumber;
  +    }
  +    
       // Implementation methods
       //-------------------------------------------------------------------------      
  +    
  +    /**
  +     * Evaluates the tag, catching any exceptions and rethrowing them in
  +     * a wrapped exception which includes the line and column numbers
  +     */
  +    protected void runTag(XMLOutput output) throws Exception {
  +		try {
  +			tag.doTag(output);
  +		} 
  +        catch (JellyException e) {
  +			if (e.getLineNumber() == -1) {
  +				e.setColumnNumber(columnNumber);
  +				e.setLineNumber(lineNumber);
  +			}
  +			throw e;
  +		}
  +        catch (Exception e) {
  +            throw new JellyException(e, columnNumber, lineNumber);            
  +        }
  +    }
  +    
       /** Converts the given value to the required type. 
        *
        * @param value is the value to be converted. This will not be null
  
  
  
  1.10      +7 -6      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java
  
  Index: BeanTagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BeanTagScript.java	18 Jun 2002 18:36:42 -0000	1.9
  +++ BeanTagScript.java	21 Jun 2002 02:57:17 -0000	1.10
  @@ -227,6 +227,7 @@
                   );
               }
           }
  -        tag.doTag(output);
  +        
  +        runTag(output);
       }
   }
  
  
  
  1.4       +70 -5     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyException.java
  
  Index: JellyException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyException.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JellyException.java	17 May 2002 15:18:12 -0000	1.3
  +++ JellyException.java	21 Jun 2002 02:57:17 -0000	1.4
  @@ -62,6 +62,9 @@
   
   package org.apache.commons.jelly;
   
  +import java.io.PrintStream;
  +import java.io.PrintWriter;
  +
   /** 
    * <p><code>JellyException</code> is the root of all Jelly exceptions.</p>
    *
  @@ -71,8 +74,16 @@
   
   public class JellyException extends Exception {
       
  +    /** the underlying cause of the exception */
       private Throwable cause;
   
  +    /** the line number in the script of the error */
  +    private int lineNumber = -1;
  +    
  +    /** the column number in the script of the error */
  +    private int columnNumber = -1;
  +
  +
       public JellyException() {
       }
   
  @@ -90,10 +101,64 @@
           this.cause = cause;
       }
       
  +    public JellyException(Throwable cause, int columnNumber, int lineNumber) {
  +        super(cause.getLocalizedMessage());
  +        this.cause = cause;
  +        this.columnNumber = columnNumber;
  +        this.lineNumber = lineNumber;
  +    }
  +    
       public Throwable getCause() {
           return cause;
       }
   
  +    
  +    /** 
  +     * @return the line number of the tag 
  +     */
  +    public int getLineNumber() {
  +        return lineNumber;
  +    }
  +    
  +    /** 
  +     * Sets the line number of the tag 
  +     */
  +    public void setLineNumber(int lineNumber) {
  +        this.lineNumber = lineNumber;
  +    }
  +
  +    /** 
  +     * @return the column number of the tag 
  +     */
  +    public int getColumnNumber() {
  +        return columnNumber;
  +    }
  +    
  +    /** 
  +     * Sets the column number of the tag 
  +     */
  +    public void setColumnNumber(int columnNumber) {
  +        this.columnNumber = columnNumber;
  +    }
  +    
  +    public String getMessage() {
  +        return super.getMessage() + " At column: " 
  +            + columnNumber + " line: " + lineNumber;
  +    }
       // #### overload the printStackTrace methods...
  +    public void printStackTrace(PrintWriter s) { 
  +        super.printStackTrace(s);
  +        if  (cause != null) {
  +            s.println("Root cause");
  +            cause.printStackTrace(s);
  +        }
  +    }
           
  +    public void printStackTrace(PrintStream s) {
  +        super.printStackTrace(s);
  +        if  (cause != null) {
  +            s.println("Root cause");
  +            cause.printStackTrace(s);
  +        }
  +    }
   }
  
  
  
  1.13      +0 -4      jakarta-commons-sandbox/jelly/xdocs/todo.xml
  
  Index: todo.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/xdocs/todo.xml,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- todo.xml	17 Jun 2002 09:40:35 -0000	1.12
  +++ todo.xml	21 Jun 2002 02:57:17 -0000	1.13
  @@ -16,10 +16,6 @@
         
       <section name="Core tasks"> 
         <ul>
  -        <li>
  -        	add a SAX Locator to TagScript instances so that exceptions get adorned with nice

  -        	line number information for debugging when things go wrong
  -        </li>
           <li>write a Cocoon JellyTransformer so that Jelly scripts can be used easily
inside Cocoon</li>
           <li>autogenerate tag library documentation, in a kinda javadoc style, showing
all tag libraries, 
   			their tags and descriptions of their tags. 
  
  
  
  1.52      +7 -0      jakarta-commons-sandbox/jelly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- build.xml	19 Jun 2002 10:31:13 -0000	1.51
  +++ build.xml	21 Jun 2002 02:57:17 -0000	1.52
  @@ -286,6 +286,13 @@
   	
      </target>
   
  +   <target name="demo.ant.typo" depends="compile" 
  +      description="Runs demo which has typeo to test line numbering">
  +      
  +	<jelly file="src/test/org/apache/commons/jelly/ant/typoTest.jelly"/>
  +	
  +   </target>
  +
      <target name="demo.ant.files" depends="compile" 
         description="Runs Ant demo which scans files">
         
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message