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, 23 Sep 2002 12:34:38 GMT
jstrachan    2002/09/23 05:34:38

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/ant AntTag.java
  Log:
  Added a new <setProperty> tag which allows properties to be set on the parent Ant
task which are ignored if the expression is empty. This provides better handling of configurable
properties on Ant Tasks when using Maven plugins.
  
  e.g.
  
  <jmxdoclet>
      <setProperty name="destdir" value="${maven.xdoclet.jmxdoclet.destdir}"/>
  </jmxdoclet>
  
  The <setProperty> tag can also take an optional default you want to code in your plugin
(to override the Ant task default).
  
  e.g.
  
  <jmxdoclet>
      <setProperty name="destdir" value="${maven.xdoclet.jmxdoclet.destdir}" default="{0}Home"/>
  </jmxdoclet>
  
  If the value expression of <setProperty> is null then the property is not set, preserving
the underlying default in the Ant task.
  
  Revision  Changes    Path
  1.12      +42 -29    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AntTag.java	22 Sep 2002 09:16:49 -0000	1.11
  +++ AntTag.java	23 Sep 2002 12:34:38 -0000	1.12
  @@ -126,6 +126,27 @@
           return "[AntTag: name=" + getTagName() + "]";
       }
   
  +    // TaskSource interface
  +    //-------------------------------------------------------------------------
  +    
  +    /** Retrieve the general object underlying this tag.
  +     *
  +     *  @return The object underlying this tag.
  +     */
  +    public Object getTaskObject() {
  +        return this.object;
  +    }
  +
  +    /**
  +     * Allows nested tags to set a property on the task object of this tag
  +     */
  +    public void setTaskProperty(String name, Object value) throws Exception {
  +        Object object = getTaskObject();
  +        if ( object != null ) {
  +            setBeanProperty( object, name, value );
  +        }
  +    }
  +
       // Tag interface
       //-------------------------------------------------------------------------
       public void doTag(XMLOutput output) throws Exception {
  @@ -133,7 +154,7 @@
           Project project = getAntProject();
           String tagName = getTagName();
           Object parentObject = null;
  -
  +        
           // must be a datatype.
           TaskSource ancestor = (TaskSource) findAncestorWithClass( TaskSource.class );
           if ( ancestor != null ) {
  @@ -141,14 +162,14 @@
           }
   
           // 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
  +        // for example <manifest> inside a <jar> should be a nested object,
where as 
           // if the parent is not a Task the <manifest> should create a ManifestTask
   
  -        if ( ! ( parentObject instanceof Task ) &&
  -            project.getTaskDefinitions().containsKey( tagName ) ) {
  -
  +        if ( ! ( parentObject instanceof Task ) && 
  +            project.getTaskDefinitions().containsKey( tagName ) ) {                   
        
  +            
               if ( log.isDebugEnabled() ) {
  -                log.debug( "Creating an ant Task for name: " + tagName );
  +                log.debug( "Creating an ant Task for name: " + tagName );            
               }
               // the following algorithm follows the lifetime of a tag
               // http://jakarta.apache.org/ant/manual/develop.html#writingowntask
  @@ -200,8 +221,8 @@
           }
           else {
   
  -            if ( log.isDebugEnabled() ) {
  -                log.debug( "Creating a nested object name: " + tagName );
  +            if ( log.isDebugEnabled() ) {                            
  +                log.debug( "Creating a nested object name: " + tagName );            
               }
   
               if ( parentObject == null ) {
  @@ -231,10 +252,10 @@
   
                   // now lets invoke the body
                   String body = getBodyText();
  -
  +    
                   // now lets set any attributes of this tag...
                   setBeanProperties();
  -
  +    
                   // now lets add it to its parent
                   if ( parentObject != null ) {
                       IntrospectionHelper ih = IntrospectionHelper.getHelper( parentObject.getClass()
);
  @@ -247,24 +268,24 @@
                   }
               }
               else {
  -                // lets treat this tag as static XML...
  +                // lets treat this tag as static XML...                
                   StaticTag tag = new StaticTag("", tagName, tagName);
                   tag.setParent( getParent() );
                   tag.setBody( getBody() );
  -
  +    
                   tag.setContext(context);
  -
  +        
                   for (Iterator iter = getAttributes().entrySet().iterator(); iter.hasNext();)
{
                       Map.Entry entry = (Map.Entry) iter.next();
                       String name = (String) entry.getKey();
                       Object value = entry.getValue();
  -
  +        
                       tag.setAttribute(name, value);
                   }
  -
  +            
                   tag.doTag(output);
               }
  -        }
  +        }        
       }
   
   
  @@ -274,14 +295,6 @@
           return this.tagName;
       }
   
  -    /** Retrieve the general object underlying this tag.
  -     *
  -     *  @return The object underlying this tag.
  -     */
  -    public Object getTaskObject() {
  -        return this.object;
  -    }
  -
       /** Set the object underlying this tag.
        *
        *  @param object The object.
  @@ -325,9 +338,9 @@
               }
               else
               {
  -                super.setAttribute( name, value.toString() );
  -            }
  -        }
  +            	super.setAttribute( name, value.toString() );
  +        	}                            
  +    	}
       }
   
       public void setBeanProperty(Object object, String name, Object value) throws Exception
{
  @@ -432,7 +445,7 @@
   
       public Task createTask(String taskName,
                              Class taskType) throws Exception {
  -
  +                            
           if (taskType == null) {
               return null;
           }
  @@ -453,7 +466,7 @@
   
           return task;
       }
  -
  +    
       /**
        * 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.
  
  
  

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