You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/06/26 15:09:10 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant AntTagScript.java AntTagLibrary.java

jstrachan    2002/06/26 06:09:09

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/ant
                        AntTagLibrary.java
  Added:       jelly/src/java/org/apache/commons/jelly/tags/ant
                        AntTagScript.java
  Log:
  Patched the Ant tag library so that the body of an Ant task is run before the attributes are set on the Ant Task.
  This seems to get round some problems with certain Ant Tasks where they
  expect their body context to be initialised before they are configured.
  For example setErrorProperty() on a JUnitTask will assume that all the test cases will have been added to the task before the setter is called.
  
  Revision  Changes    Path
  1.15      +3 -3      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java
  
  Index: AntTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- AntTagLibrary.java	25 Jun 2002 20:43:30 -0000	1.14
  +++ AntTagLibrary.java	26 Jun 2002 13:09:09 -0000	1.15
  @@ -226,7 +226,7 @@
               if ( name.equals( "echo" ) ) {
                   tag.setTrim(false);
               }
  -            return TagScript.newInstance(tag);
  +            return new AntTagScript(tag);
           }
           
           /*
  @@ -272,10 +272,10 @@
           // Since ant resolves so many dynamically loaded/created
           // things at run-time, we can make virtually no assumptions
           // as to what this tag might be.  
  -        Tag tag = new OtherAntTag( project,
  +        OtherAntTag tag = new OtherAntTag( project,
                                      name );
   
  -        return TagScript.newInstance( tag );
  +        return new AntTagScript( tag );
       }
   
       public TagScript createRuntimeTaskTagScript(String taskName, Attributes attributes) throws Exception {
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagScript.java
  
  Index: AntTagScript.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java,v 1.8 2002/06/25 17:10:07 jstrachan Exp $
   * $Revision: 1.8 $
   * $Date: 2002/06/25 17:10:07 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: DynaTagScript.java,v 1.8 2002/06/25 17:10:07 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;
  
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.commons.jelly.CompilableTag;
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.Tag;
  import org.apache.commons.jelly.DynaTag;
  import org.apache.commons.jelly.impl.DynaTagScript;
  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;
  
  /** 
   * This TagScript initializes Ant DynaTags slightly differently, by invoking their bodies first
   * and then configuring their properties.
   * This gets around some issues when using things like JUnitTask where setting properties 
   * expects the nested properties, filesets, data types and such like to be fully constructed by then.</p>
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class AntTagScript extends DynaTagScript {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(AntTagScript.class);
  
      public AntTagScript() {
      }
  
      public AntTagScript(DynaTag tag) {
          super(tag);
      }
  
      // Script interface
      //-------------------------------------------------------------------------                
      /** Evaluates the body of a tag */
      public void run(JellyContext context, XMLOutput output) throws Exception {
          tag.setContext(context);
          
          DynaTag dynaTag = (DynaTag) tag;
  
          try {
              // lets invoke the body first to set any nested data structures
              tag.invokeBody(output);
                          
  
  	        // now lets set the properties on this tag            
  	        for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
  	            Map.Entry entry = (Map.Entry) iter.next();
  	            String name = (String) entry.getKey();
  	            Expression expression = (Expression) entry.getValue();
  	
  	            Object value = expression.evaluate(context);
  	            dynaTag.setAttribute(name, value);
  	        }
              
              tag.doTag(output);
          }
          catch (JellyException e) {
              if (e.getLineNumber() == -1) {
                  e.setColumnNumber(getColumnNumber());
                  e.setLineNumber(getLineNumber());
              }
              throw e;
          }
          catch (Exception e) {
              log.error( "Caught exception: " + e, e );
              throw new JellyException(e, getColumnNumber(), getLineNumber());            
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant AntTagScript.java AntTagLibrary.java

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 27 Jun 2002, James Strachan <ja...@yahoo.co.uk>
wrote:

> Thanks *so* much Stefan.

Glad I could help.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant AntTagScript.java AntTagLibrary.java

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Stefan Bodewig" <bo...@apache.org>
> On 26 Jun 2002, <js...@apache.org> wrote:
>
> >   Patched the Ant tag library so that the body of an Ant task is run
> >   before the attributes are set on the Ant Task.
>
> See "The Life-cycle of a Task", especially items 6 and 7 of that list
> in <http://jakarta.apache.org/ant/manual/develop.html#writingowntask>.
>
> It is the defined behavior for Ant.

Thanks *so* much Stefan. As you might have guessed, I've been guessing this
behaviour by patching the Jelly code when things go wierd. This link makes
it all perfectly clear. I cannot say how much joy this link has given me
after much head scratching!

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant AntTagScript.java AntTagLibrary.java

Posted by Stefan Bodewig <bo...@apache.org>.
On 26 Jun 2002, <js...@apache.org> wrote:

>   Patched the Ant tag library so that the body of an Ant task is run
>   before the attributes are set on the Ant Task.

See "The Life-cycle of a Task", especially items 6 and 7 of that list
in <http://jakarta.apache.org/ant/manual/develop.html#writingowntask>.

It is the defined behavior for Ant.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>