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/java/org/apache/commons/jelly/tags/ant AntTag.java
Date Mon, 11 Nov 2002 18:57:57 GMT
jstrachan    2002/11/11 10:57:57

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/ant AntTag.java
  Added:       jelly/src/test/org/apache/commons/jelly/ant/tag
                        MyTagLibrary.java suite.jelly TestJelly.java
                        DummyTag.java
  Log:
  A new test case to try out the use of Ant Paths from inside a Jelly Tag.
  
  This also includes the patch to make this work! :-)
  
  Also included a JellySwing test case to ensure it keeps working
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/tag/MyTagLibrary.java
  
  Index: MyTagLibrary.java
  ===================================================================
  /*
   * $Header:  $
   * $Revision: 1.0 $
   * $Date:  $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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:  $
   */
  package org.apache.commons.jelly.ant.tag;
  
  import org.apache.commons.jelly.TagLibrary;
  
  /** 
   * Describes the Taglib. 
   * This could be created via Jelly script, or could load the mapping of 
   * tag names to bean classes from properties file etc  but is implemented in Java
   * code for simplicity
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class MyTagLibrary extends TagLibrary {
  
      public MyTagLibrary() {
          registerTag( "dummy", DummyTag.class );
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/tag/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  <?xml version="1.0"?>
  <test:suite 
  	xmlns:j="jelly:core" 
  	xmlns:test="jelly:junit" 
  	xmlns="jelly:jeez"
  	xmlns:my="jelly:org.apache.commons.jelly.ant.tag.MyTagLibrary">
  
  	<test:case name="nestedClasspath">
  			
  		<my:dummy var="path">
  			<classpath>
  				<pathelement path="target/classes"/>
  				<pathelement path="target/test-classes"/>
  			</classpath>			
  		</my:dummy>			
  	
  		<test:assert test="${path != null}"/>
  		
  	</test:case>
  
  </test:suite>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/tag/TestJelly.java
  
  Index: TestJelly.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/JellyTestSuite.java,v
1.8 2002/07/06 13:53:39 dion Exp $
   * $Revision: 1.8 $
   * $Date: 2002/07/06 13:53:39 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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: JellyTestSuite.java,v 1.8 2002/07/06 13:53:39 dion Exp $
   */
  package org.apache.commons.jelly.ant.tag;
  
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.tags.junit.JellyTestSuite;
  
  /** 
   * A helper class to run jelly test cases as part of Ant's JUnit tests
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class TestJelly extends JellyTestSuite {
  
      public static void main( String[] args ) throws Exception {
          TestRunner.run( suite() );
      }
      
      public static TestSuite suite() throws Exception {
          return createTestSuite(TestJelly.class, "suite.jelly");        
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/tag/DummyTag.java
  
  Index: DummyTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v
1.9 2002/10/30 19:16:21 jstrachan Exp $
   * $Revision: 1.9 $
   * $Date: 2002/10/30 19:16:21 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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.9 2002/10/30 19:16:21 jstrachan Exp $
   */
  package org.apache.commons.jelly.ant.tag;
  
  import junit.framework.AssertionFailedError;
  
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.impl.BeanSource;
  import org.apache.commons.jelly.tags.ant.AntTagLibrary;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.tools.ant.types.Path;
  
  /** 
   * A mock tag which is used for testing the Ant nested properties behaviour
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.9 $
   */
  public class DummyTag extends TagSupport implements BeanSource {
  
      /** The Log to which logging calls will be made. */
      private static Log log = LogFactory.getLog(DummyTag.class);
  
  	private String var;
  	
  	private boolean calledCreatepath;
  	private boolean calledSetClasspath;
  	private Path classpath;
  	
      public DummyTag() {
      }
  
      // BeanSource interface
      //-------------------------------------------------------------------------
      public Object getBean() {
      	return this;
      }                
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
      	calledCreatepath = false;    	
      	calledSetClasspath = false;    	
  
          invokeBody(output);
          
          if (! calledCreatepath) {
          	throw new AssertionFailedError("call to createClasspath() was not made");
          }
          
          if (! calledSetClasspath) {
          	throw new AssertionFailedError("call to setClasspath() was not made");
          }
          log.info( "Called with classpath: " + classpath );
          
          if (var != null) {
          	context.setVariable(var, classpath);
          }
      }
      
      // Ant Task-like nested property methods
      //-------------------------------------------------------------------------
      public Path createClasspath() {
      	log.info("called createClasspath()");
      	calledCreatepath = true;    	
      	return new Path( AntTagLibrary.getProject(context) );
      }
      
      public void setClasspath(Path classpath) {
      	log.info("called setClasspath()");
      	calledSetClasspath = true;    	
      	this.classpath = classpath;
      } 
      
      // Tag properties
      //-------------------------------------------------------------------------
      
      public void setVar(String var) {
      	this.var = var;
      }
  }
  
  
  
  1.17      +30 -16    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTag.java
  
  Index: AntTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTag.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AntTag.java	10 Nov 2002 09:58:04 -0000	1.16
  +++ AntTag.java	11 Nov 2002 18:57:57 -0000	1.17
  @@ -149,13 +149,7 @@
   
           Project project = getAntProject();
           String tagName = getTagName();
  -        Object parentObject = null;
  -        
  -        // must be a datatype.
  -        TaskSource ancestor = (TaskSource) findAncestorWithClass( TaskSource.class );
  -        if ( ancestor != null ) {
  -            parentObject = ancestor.getTaskObject();
  -        }
  +        Object parentObject = findBeanAncestor();
   
           // lets assume that Task instances are not nested inside other Task instances
           // for example <manifest> inside a <jar> should be a nested object,
where as 
  @@ -221,10 +215,6 @@
                   log.debug( "Creating a nested object name: " + tagName );            
               }
   
  -            if ( parentObject == null ) {
  -                parentObject = findBeanAncestor();
  -            }
  -
               Object nested = createNestedObject( parentObject, tagName );
   
               if ( nested == null ) {
  @@ -256,10 +246,27 @@
                   if ( parentObject != null ) {
                       IntrospectionHelper ih = IntrospectionHelper.getHelper( parentObject.getClass()
);
                       try {
  +                    	if (log.isDebugEnabled()) {
  +                    		log.debug("About to set the: " + tagName 
  +                    			+ " property on: " + parentObject + " to value: " 
  +                    			+ nested + " with type: " + nested.getClass() 
  +                			);
  +                    	}
  +                    	
                           ih.storeElement( project, parentObject, nested, tagName );
                       }
                       catch (Exception e) {
  -                        //log.warn( "Caught exception setting nested: " + tagName, e );
  +                        log.warn( "Caught exception setting nested: " + tagName, e );
  +                    }
  +                    
  +                    // now try to set the property for good measure
  +                    // as the storeElement() method does not
  +                    // seem to call any setter methods of non-String types
  +                    try {
  +        				BeanUtils.setProperty( parentObject, tagName, nested );
  +                    }
  +                    catch (Exception e) {
  +                    	log.debug("Caught exception trying to set property: " + tagName +
" on: " + parentObject);
                       }
                   }
               }
  @@ -464,17 +471,24 @@
       }
       
       /**
  -     * Attempts to look up in the parent hierarchy for a tag that implements the BeanSource
interface
  -     * which creates a dynamic bean, or will return the parent tag, which is also a bean.
  +     * Attempts to look up in the parent hierarchy for a tag that implements the 
  +     * TaskSource interface, which returns an Ant Task object or that implements
  +     * BeanSource interface which creates a bean, 
  +     * or will return the parent tag, which is also a bean.
        */
       protected Object findBeanAncestor() throws Exception {
           Tag tag = getParent();
  -        if (tag != null) {
  +        while (tag != null) {
               if (tag instanceof BeanSource) {
                   BeanSource beanSource = (BeanSource) tag;
                   return beanSource.getBean();
               }
  +            if (tag instanceof TaskSource) {
  +            	TaskSource taskSource = (TaskSource) tag;
  +            	return taskSource.getTaskObject();
  +            }
  +            tag = tag.getParent();
           }
  -        return tag;
  +        return getParent();
       }
   }
  
  
  

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