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/src/test/org/apache/commons/jelly example_ant_tasks.jelly
Date Thu, 30 May 2002 12:15:25 GMT
jstrachan    02/05/30 05:15:25

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/ant
                        TaskTag.java AntTagLibrary.java DataTypeTag.java
               jelly/src/java/org/apache/commons/jelly/tags/xml
                        XMLTagLibrary.java
               jelly/src/test/org/apache/commons/jelly
                        example_ant_tasks.jelly
  Added:       jelly/src/java/org/apache/commons/jelly/tags/ant
                        TaskPropertyTag.java
  Log:
  Got the Ant tag library working so that Ant tasks can be invoked inside Jelly scripts.
  
  Revision  Changes    Path
  1.2       +2 -3      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskTag.java
  
  Index: TaskTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TaskTag.java	30 May 2002 08:11:55 -0000	1.1
  +++ TaskTag.java	30 May 2002 12:15:25 -0000	1.2
  @@ -92,13 +92,12 @@
       // Tag interface
       //------------------------------------------------------------------------- 
       public void doTag(XMLOutput output) throws Exception {
  -        Task task = getTask();
           task.init();
  -        
  +                
           // run the body first to configure the task via nested
           getBody().run(context, output);
           
  -        task.execute();        
  +        task.execute();   
       }
       
       // Properties
  
  
  
  1.2       +12 -5     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AntTagLibrary.java	30 May 2002 08:11:55 -0000	1.1
  +++ AntTagLibrary.java	30 May 2002 12:15:25 -0000	1.2
  @@ -113,14 +113,21 @@
               Tag tag = new TaskTag( task );
               return TagScript.newInstance(tag);
           }
  +        Object dataType = null;
           type = (Class) project.getDataTypeDefinitions().get(name);
  -        if ( type != null ) {
  -            DataType dataType = (DataType) type.newInstance();
  -            dataType.setProject(project);
  -            Tag tag = new DataTypeTag( name, dataType );
  +        if ( type != null ) {            
  +            dataType = type.newInstance();
  +        }
  +        else {
  +            dataType = project.createDataType(name);
  +        }
  +        if ( dataType != null ) {
  +            DataTypeTag tag = new DataTypeTag( name, dataType );
  +            tag.getDynaBean().set( "project", project );
               return TagScript.newInstance(tag);
           }
  -        return null;
  +        Tag tag = new TaskPropertyTag( name );
  +        return TagScript.newInstance(tag);
       }
   
       
  
  
  
  1.2       +5 -5      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/DataTypeTag.java
  
  Index: DataTypeTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/DataTypeTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DataTypeTag.java	30 May 2002 08:11:55 -0000	1.1
  +++ DataTypeTag.java	30 May 2002 12:15:25 -0000	1.2
  @@ -88,12 +88,12 @@
       private String name;
       
       /** the Ant DataType */
  -    private DataType dataType;
  +    private Object dataType;
   
       public DataTypeTag() {
       }
   
  -    public DataTypeTag(String name, DataType dataType) {
  +    public DataTypeTag(String name, Object dataType) {
           this.name = name;
           this.dataType = dataType;
           setDynaBean( new WrapDynaBean(dataType) );
  @@ -108,7 +108,7 @@
           }        
           
           Task task = tag.getTask();
  -        DataType dataType = getDataType();
  +        Object dataType = getDataType();
   
           // now we need to configure the task with the data type
           
  @@ -166,14 +166,14 @@
       /** 
        * @return the Ant dataType
        */
  -    public DataType getDataType() {
  +    public Object getDataType() {
           return dataType;
       }
       
       /** 
        * Sets the Ant dataType
        */
  -    public void setDataType(DataType dataType) {
  +    public void setDataType(Object dataType) {
           this.dataType = dataType;
           setDynaBean( new WrapDynaBean(dataType) );
       }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskPropertyTag.java
  
  Index: TaskPropertyTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v
1.6 2002/05/17 15:18:08 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/05/17 15:18:08 $
   *
   * ====================================================================
   *
   * 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: IfTag.java,v 1.6 2002/05/17 15:18:08 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;
  
  import java.lang.reflect.Method;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.commons.beanutils.BeanUtils;
  import org.apache.commons.beanutils.DynaBean;
  import org.apache.commons.beanutils.WrapDynaBean;
  
  import org.apache.commons.jelly.CompilableTag;
  import org.apache.commons.jelly.DynaBeanTagSupport;
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.XMLOutput;
  
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.types.DataType;
  import org.apache.tools.ant.types.Reference;
  
  /** 
   * A tag which configures a property bean of a Task, 
   * such as a &lt;classpath&lt; element inside a &lt;java&gt; element.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.6 $
   */
  public class TaskPropertyTag extends DynaBeanTagSupport implements CompilableTag {
  
      private static final Class[] emptyParameterTypes = {};
      private static final Object[] emptyParameters = {};
      
      /** the name of the property */
      private String name;
      
      public TaskPropertyTag() {
      }
  
      public TaskPropertyTag(String name) {
          setName(name);
      }
  
      // DynaTag interface
      //------------------------------------------------------------------------- 
      public void setAttribute(String name, Object value) {
          if ( name.equals( "refid" ) ) {
              if ( value instanceof String ) {
                  value = new Reference( (String) value );
              }
          }
          super.setAttribute(name, value);
      }
  
      // CompilableTag interface
      //------------------------------------------------------------------------- 
      public void compile() throws Exception {
          TaskTag tag = (TaskTag) findAncestorWithClass( TaskTag.class );
          if ( tag == null ) {
              throw new JellyException( "You should only use Ant DataType tags within an Ant
Task" );
          }        
          
          Task task = tag.getTask();
          Class taskClass = task.getClass();
          String methodName = "create" + name.substring(0,1).toUpperCase() + name.substring(1);
          Method method = taskClass.getMethod( methodName, emptyParameterTypes );
          if ( method == null ) {
              throw new JellyException( 
                  "Cannot create Task property: " + name + " of Ant task: " + task 
                  + " as no method called: " + methodName + " could be found" 
              );
          }            
          
          Object propertyBean = method.invoke( task, emptyParameters );
          if ( propertyBean == null ) {
              throw new JellyException( "No property: " + name + " of task: " + task + " was
returned." );
          }
          
          setDynaBean( new WrapDynaBean(propertyBean) );
      }
      
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          // do nothing; just configuring the underlying property bean of the Task is enough
      }
      
      // Properties
      //-------------------------------------------------------------------------        
       
      
      /** 
       * @return the name of the Task property bean 
       */
      public String getName() {
          return name;
      }
      
      /** 
       * Sets the name of the Task property bean
       */
      public void setName(String name) {
          this.name = name;
      }    
  }
  
  
  
  1.7       +6 -6      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java
  
  Index: XMLTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XMLTagLibrary.java	17 May 2002 18:04:00 -0000	1.6
  +++ XMLTagLibrary.java	30 May 2002 12:15:25 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v
1.6 2002/05/17 18:04:00 jstrachan Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/05/17 18:04:00 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v
1.7 2002/05/30 12:15:25 jstrachan Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/05/30 12:15:25 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: XMLTagLibrary.java,v 1.6 2002/05/17 18:04:00 jstrachan Exp $
  + * $Id: XMLTagLibrary.java,v 1.7 2002/05/30 12:15:25 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.xml;
   
  @@ -83,7 +83,7 @@
   /** Describes the Taglib. This class could be generated by XDoclet
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.6 $
  +  * @version $Revision: 1.7 $
     */
   public class XMLTagLibrary extends TagLibrary {
   
  @@ -105,7 +105,7 @@
           ExpressionFactory factory,
           String tagName,
           String attributeName,
  -        String attributeValue) throws JellyException {
  +        String attributeValue) throws Exception {
   
           // #### may need to include some namespace URI information in the XPath instance?
           
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example_ant_tasks.jelly
  
  Index: example_ant_tasks.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example_ant_tasks.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- example_ant_tasks.jelly	30 May 2002 08:11:55 -0000	1.1
  +++ example_ant_tasks.jelly	30 May 2002 12:15:25 -0000	1.2
  @@ -1,2 +1,2 @@
  -<?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core" xmlns="jelly:ant">

  <!--
this example attempts to invoke some Ant tasks -->
  <echo message="Invoking the echo
task from inside Jelly; the Maven repository is ${lib.repo}"/>	  	
  -
  <!-- lets try invoke a program -->
  <java classname="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>
    
</j:jelly>
  \ No newline at end of file
  +<?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}"/>	  	
  +
  <!-- lets try invoke a program -->
  <java classname="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>
  \ No newline at end of file
  
  
  

--
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