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/28 13:05:06 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant FileScannerTag.java FileScanner.java AntTag.java TaskSource.java AntTagLibrary.java AntTagScript.java OtherAntTag.java TaskTag.java AntTagSupport.java DataTypeTag.java

jstrachan    2002/06/28 04:05:06

  Modified:    jelly/src/test/org/apache/commons/jelly/ant
                        filescanner.jelly
               jelly/src/java/org/apache/commons/jelly/tags/ant
                        FileScannerTag.java FileScanner.java AntTag.java
                        TaskSource.java AntTagLibrary.java
  Removed:     jelly/src/java/org/apache/commons/jelly/tags/ant
                        AntTagScript.java OtherAntTag.java TaskTag.java
                        AntTagSupport.java DataTypeTag.java
  Log:
  Patched the Ant Tag library support, tidying things up a bit. Removing lots of old cruft.
  The Ant tag library is now pretty clean and simple. 
  Also patched the fileScanner to work properly now with the new Ant tag library.
  
  Revision  Changes    Path
  1.4       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/filescanner.jelly
  
  Index: filescanner.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/filescanner.jelly,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- filescanner.jelly	13 Jun 2002 09:27:14 -0000	1.3
  +++ filescanner.jelly	28 Jun 2002 11:05:06 -0000	1.4
  @@ -12,6 +12,6 @@
       <!-- here we could parse the file or process it in some way -->
       <!-- such as by calling <ant> with the given build.xml file -->
         
  -    Found <j:expr value="${file.absolutePath}"/>
  +    Found ${file.absolutePath}
     </j:forEach>
   </j:jelly>
  
  
  
  1.3       +0 -8      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScannerTag.java
  
  Index: FileScannerTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScannerTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileScannerTag.java	26 Jun 2002 09:24:34 -0000	1.2
  +++ FileScannerTag.java	28 Jun 2002 11:05:06 -0000	1.3
  @@ -81,15 +81,11 @@
       /** The file walker that gets created */
       private FileScanner fileScanner;
   
  -    /** The DynaBean wrapping the FileScanner */
  -    private DynaBean dynaBean;
  -    
       /** the variable exported */
       private String var;
       
       public FileScannerTag(FileScanner fileScanner) {
           this.fileScanner = fileScanner;
  -        this.dynaBean = new ConvertingWrapDynaBean(fileScanner);
       }
   
       // Tag interface
  @@ -109,10 +105,6 @@
       //------------------------------------------------------------------------- 
       public Object getTaskObject() {
           return fileScanner;
  -    }
  -    
  -    public DynaBean getDynaBean() {
  -        return dynaBean;
       }
       
       // Properties
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScanner.java
  
  Index: FileScanner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScanner.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileScanner.java	2 Jun 2002 17:29:02 -0000	1.1
  +++ FileScanner.java	28 Jun 2002 11:05:06 -0000	1.2
  @@ -97,7 +97,7 @@
       /**
        * Adds a set of files (nested fileset attribute).
        */
  -    public void addFileset(FileSet set) {
  +    public void addFileset(FileSet set) {   
           filesets.add(set);
       }
   
  
  
  
  1.3       +22 -34    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AntTag.java	27 Jun 2002 21:08:08 -0000	1.2
  +++ AntTag.java	28 Jun 2002 11:05:06 -0000	1.3
  @@ -92,7 +92,7 @@
    *  @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    */
  -public class AntTag extends MapTagSupport {
  +public class AntTag extends MapTagSupport implements TaskSource {
   
       /** The Log to which logging calls will be made. */
       private static final Log log = LogFactory.getLog(AntTag.class);
  @@ -185,26 +185,14 @@
               task.perform(); 
           } 
           else {
  -            
  -            // System.err.println( "Setting datatype/nested object of name: " + tagName );
  -            
  -            // must be a datatype.
  -            AntTag ancestor = (AntTag) findAncestorWithClass( AntTag.class );
  -
               Object nested = null;
  +            Object parentObject = null;
               
  +            // must be a datatype.
  +            TaskSource ancestor = (TaskSource) findAncestorWithClass( TaskSource.class );
               if ( ancestor != null ) {
  -                nested = ancestor.createNestedObject( tagName );
  -            }
  -            else
  -            {
  -                // System.err.println( "No ancestor" );
  -
  -                AntTagSupport ancestorToo = (AntTagSupport) findAncestorWithClass( AntTagSupport.class );
  -
  -                if ( ancestorToo != null ) {
  -                    nested = ancestorToo.createNestedObject( tagName );
  -                }
  +                parentObject = ancestor.getTaskObject();
  +                nested = createNestedObject( parentObject, tagName );
               }
               
               if ( nested == null ) {
  @@ -234,16 +222,13 @@
               setBeanProperties();
   
               // now lets add it to its parent
  -            if ( ancestor != null ) {
  -                Object parentObj =  ancestor.getObject();                
  -                if ( parentObj != null ) {
  -                    IntrospectionHelper ih = IntrospectionHelper.getHelper( parentObj.getClass() );                    
  -                    try {
  -                        ih.storeElement( project, parentObj, nested, tagName );
  -                    }
  -                    catch (Exception e) {
  -                        //log.warn( "Caught exception setting nested: " + tagName, e );
  -                    }
  +            if ( parentObject != null ) {
  +                IntrospectionHelper ih = IntrospectionHelper.getHelper( parentObject.getClass() );                    
  +                try {
  +                    ih.storeElement( project, parentObject, nested, tagName );
  +                }
  +                catch (Exception e) {
  +                    //log.warn( "Caught exception setting nested: " + tagName, e );
                   }
               }
           }
  @@ -260,7 +245,7 @@
        *
        *  @return The object underlying this tag.
        */
  -    public Object getObject() {
  +    public Object getTaskObject() {
           return this.object;
       }
       
  @@ -287,7 +272,7 @@
        * Sets the properties on the Ant task
        */
       public void setBeanProperties() throws Exception {
  -        Object object = getObject();
  +        Object object = getTaskObject();
           if ( object != null ) {
   		    Map map = getAttributes();
   		    for ( Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
  @@ -300,7 +285,9 @@
       }
       
       public void setBeanProperty(Object object, String name, Object value) throws Exception {
  -        // System.err.println( "Setting bean property on: "+  object + " name: " + name + " value: " + value );
  +        if ( log.isDebugEnabled() ) {
  +            log.debug( "Setting bean property on: "+  object + " name: " + name + " value: " + value );
  +        }
           
           IntrospectionHelper ih = IntrospectionHelper.getHelper( object.getClass() );
   
  @@ -326,10 +313,11 @@
       }
   
   
  -    public Object createNestedObject(String name) throws Exception {
  +    /**
  +     * Creates a nested object of the given object with the specified name
  +     */
  +    public Object createNestedObject(Object object, String name) throws Exception {
           Object dataType = null;
  -
  -        Object object = getObject();
           if ( object != null ) {
               IntrospectionHelper ih = IntrospectionHelper.getHelper( object.getClass() );
               
  
  
  
  1.3       +2 -9      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskSource.java
  
  Index: TaskSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TaskSource.java	14 Jun 2002 10:24:14 -0000	1.2
  +++ TaskSource.java	28 Jun 2002 11:05:06 -0000	1.3
  @@ -61,10 +61,8 @@
    */
   package org.apache.commons.jelly.tags.ant;
   
  -import org.apache.commons.beanutils.DynaBean;
  -
   /** 
  - * A tag which provides an Ant Task object on which to set Ant DataTypes
  + * A tag which provides an Ant Task object on which to set Ant DataTypes or create nested types
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
  @@ -72,12 +70,7 @@
   public interface TaskSource {
   
       /** 
  -     * @return the task object which may be an Ant Task.
  +     * @return the Ant object which may be an Ant Task or nested element
        */
       public Object getTaskObject() throws Exception;
  -    
  -    /**
  -     * @return a DynaBean wrapper around the Task object
  -     */
  -    public DynaBean getDynaBean();
   }
  
  
  
  1.17      +6 -63     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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AntTagLibrary.java	27 Jun 2002 14:16:24 -0000	1.16
  +++ AntTagLibrary.java	28 Jun 2002 11:05:06 -0000	1.17
  @@ -200,8 +200,11 @@
           logger.setErrorPrintStream( System.err);
   
           project.addBuildListener( logger );
  -        
           project.init();
  +        
  +        // force lazy construction which avoids null pointer exceptions when using 
  +        // file sets
  +        project.getBaseDir();        
           return project;
       }
   
  @@ -222,71 +225,11 @@
               tag.setTrim(false);
           }
           return TagScript.newInstance(tag);
  -
  -        /*
  -        
  -        // is it an Ant task?
  -        Class type = (Class) project.getTaskDefinitions().get(name);
  -        if ( type != null ) {            
  -            TaskTag tag = new TaskTag( project, type, name );
  -            tag.setTrim( true );
  -
  -            if ( name.equals( "echo" ) ) {
  -                tag.setTrim(false);
  -            }
  -            return new AntTagScript(tag);
  -        }
  -        
  -        // an Ant DataType?
  -        DataType dataType = null;
  -        type = (Class) project.getDataTypeDefinitions().get(name);
  -        
  -        if ( type != null ) {            
  -
  -            try {
  -                java.lang.reflect.Constructor ctor = null;
  -                boolean noArg = false;
  -                // DataType can have a "no arg" constructor or take a single 
  -                // Project argument.
  -                try {
  -                    ctor = type.getConstructor(new Class[0]);
  -                    noArg = true;
  -                } catch (NoSuchMethodException nse) {
  -                    ctor = type.getConstructor(new Class[] { Project.class });
  -                    noArg = false;
  -                }
  -                
  -                if (noArg) {
  -                    dataType = (DataType) ctor.newInstance(new Object[0]);
  -                } else {
  -                    dataType = (DataType) ctor.newInstance(new Object[] {project});
  -                }
  -                dataType.setProject( project );
  -
  -            } catch (Throwable t) {
  -                t.printStackTrace();
  -                // ignore 
  -            }
  -        }
  -        if ( dataType != null ) {
  -            DataTypeTag tag = new DataTypeTag( name, dataType );
  -            tag.setAntProject( getProject() );
  -            tag.getDynaBean().set( "project", project );
  -            return TagScript.newInstance(tag);
  -        }
  -        
  -        // 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.  
  -        OtherAntTag tag = new OtherAntTag( project,
  -                                   name );
  -
  -        return new AntTagScript( tag );
  -        */
       }
   
       public TagScript createRuntimeTaskTagScript(String taskName, Attributes attributes) throws Exception {
  -        TaskTag tag = new TaskTag( project, taskName );
  +        //TaskTag tag = new TaskTag( project, taskName );
  +        AntTag tag = new AntTag( project, taskName );
           return TagScript.newInstance( tag );
       }
                                                   
  
  
  

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