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 JellyContext.java
Date Tue, 27 Aug 2002 14:04:29 GMT
jstrachan    2002/08/27 07:04:29

  Modified:    jelly/src/java/org/apache/commons/jelly/task JellyTask.java
               jelly/src/java/org/apache/commons/jelly/tags/ant AntTag.java
                        AntTagLibrary.java FileScannerTag.java
                        FileScanner.java
               jelly/src/java/org/apache/commons/jelly/tags/jeez
                        JeezTagLibrary.java
               jelly/src/java/org/apache/commons/jelly JellyContext.java
  Added:       jelly/src/java/org/apache/commons/jelly/tags/ant
                        JellyPropsHandler.java
  Log:
  Applied Stephen Haberman's patch adding better Ant support, allowing Jelly to invoke Ant
using commons-grant and cleanly integrating properties.
  
  Revision  Changes    Path
  1.7       +1 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/task/JellyTask.java
  
  Index: JellyTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/task/JellyTask.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JellyTask.java	28 Jun 2002 12:13:27 -0000	1.6
  +++ JellyTask.java	27 Aug 2002 14:04:28 -0000	1.7
  @@ -166,7 +166,7 @@
               context = new AntJellyContext(project, parentContext);
               
               // register the Ant tag library
  -            context.registerTagLibrary( "jelly:ant", new AntTagLibrary(project) );
  +            context.registerTagLibrary( "jelly:ant", new AntTagLibrary() );
           }
           return context;
       }
  
  
  
  1.8       +13 -25    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AntTag.java	19 Aug 2002 21:41:53 -0000	1.7
  +++ AntTag.java	27 Aug 2002 14:04:29 -0000	1.8
  @@ -60,7 +60,6 @@
    * $Id$
    */
   
  -
   package org.apache.commons.jelly.tags.ant;
   
   import java.lang.reflect.Constructor;
  @@ -71,23 +70,21 @@
   import org.apache.commons.beanutils.BeanUtils;
   import org.apache.commons.beanutils.MethodUtils;
   import org.apache.commons.beanutils.PropertyUtils;
  -
  -import org.apache.commons.jelly.JellyContext;
  +import org.apache.commons.grant.DefaultPropsHandler;
  +import org.apache.commons.grant.GrantProject;
  +import org.apache.commons.grant.PropsHandler;
   import org.apache.commons.jelly.MapTagSupport;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.impl.BeanSource;
   import org.apache.commons.jelly.impl.StaticTag;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -
  -import org.apache.tools.ant.Project;
   import org.apache.tools.ant.IntrospectionHelper;
  +import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.TaskAdapter;
   import org.apache.tools.ant.types.DataType;
  -import org.apache.tools.ant.types.Reference;
   
   /**
    * Tag supporting ant's Tasks as well as
  @@ -106,9 +103,6 @@
       /** store the name of the manifest tag for special handling */
       private static final String ANT_MANIFEST_TAG = "manifest";
   
  -    /** The Ant project */
  -    private Project project;
  -
       /** The name of this tag. */
       protected String tagName;
   
  @@ -123,8 +117,7 @@
        *  @param project The Ant project.
        *  @param tagName The name on the tag.
        */
  -    public AntTag(Project project, String tagName) {
  -        this.project = project;
  +    public AntTag(String tagName) {
           this.tagName = tagName;
       }
   
  @@ -132,7 +125,6 @@
           return "[AntTag: name=" + getTagName() + "]";
       }
   
  -
       // Tag interface
       //-------------------------------------------------------------------------
       public void doTag(XMLOutput output) throws Exception {
  @@ -140,7 +132,7 @@
           Project project = getAntProject();
           String tagName = getTagName();
           Object parentObject = null;
  -
  +        
           // must be a datatype.
           TaskSource ancestor = (TaskSource) findAncestorWithClass( TaskSource.class );
           if ( ancestor != null ) {
  @@ -150,7 +142,7 @@
           // 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 
           // if the parent is not a Task the <manifest> should create a ManifestTask
  -                
  +
           if ( ! ( parentObject instanceof Task ) && 
               project.getTaskDefinitions().containsKey( tagName ) ) {                   
        
               
  @@ -214,9 +206,9 @@
               if ( parentObject == null ) {
                   parentObject = findBeanAncestor();
               }
  -                        
  +
               Object nested = createNestedObject( parentObject, tagName );
  -            
  +
               if ( nested == null ) {
                   nested = createDataType( tagName );
               }
  @@ -271,7 +263,7 @@
               
                   tag.doTag(output);
               }
  -        }
  +        }        
       }
   
   
  @@ -297,12 +289,8 @@
           this.object = object;
       }
   
  -    public void setAntProject(Project project) {
  -        this.project = project;
  -    }
  -
       public Project getAntProject() {
  -        return this.project;
  +        return AntTagLibrary.getProject(context);
       }
   
       // Implementation methods
  @@ -405,9 +393,9 @@
                       dataType = (DataType) ctor.newInstance(new Object[0]);
                   }
                   else {
  -                    dataType = (DataType) ctor.newInstance(new Object[] {project});
  +                    dataType = (DataType) ctor.newInstance(new Object[] { getAntProject()
});
                   }
  -                ((DataType)dataType).setProject( project );
  +                ((DataType)dataType).setProject( getAntProject() );
   
               }
               catch (Throwable t) {
  
  
  
  1.19      +17 -55    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- AntTagLibrary.java	1 Aug 2002 09:53:18 -0000	1.18
  +++ AntTagLibrary.java	27 Aug 2002 14:04:29 -0000	1.19
  @@ -62,35 +62,25 @@
   package org.apache.commons.jelly.tags.ant;
   
   import java.io.File;
  -import java.util.Iterator;
  -import java.util.List;
   
  -import org.apache.commons.beanutils.Converter;
   import org.apache.commons.beanutils.ConvertUtils;
  -
  +import org.apache.commons.beanutils.Converter;
  +import org.apache.commons.grant.GrantProject;
   import org.apache.commons.jelly.JellyContext;
  -import org.apache.commons.jelly.JellyException;
  -import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.impl.BeanTagScript;
   import org.apache.commons.jelly.impl.DynaTagScript;
   import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.impl.TagScript;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -
  -import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.ProjectComponent;
  -import org.apache.tools.ant.Task;
   import org.apache.tools.ant.BuildLogger;
   import org.apache.tools.ant.NoBannerLogger;
  -import org.apache.tools.ant.types.DataType;
  -import org.apache.tools.ant.types.Reference;
  -import org.apache.tools.ant.types.EnumeratedAttribute;
  +import org.apache.tools.ant.Project;
   import org.apache.tools.ant.taskdefs.optional.junit.FormatterElement;
  -
  +import org.apache.tools.ant.types.EnumeratedAttribute;
  +import org.apache.tools.ant.types.Reference;
   import org.xml.sax.Attributes;
   
   /** 
  @@ -105,8 +95,7 @@
       /** The Log to which logging calls will be made. */
       private static final Log log = LogFactory.getLog(AntTagLibrary.class);
       
  -    /** the Ant Project for this tag library */
  -    private Project project;
  +    public static final String PROJECT_CONTEXT_HANDLE = "org.apache.commons.jelly.ant.Project";
   
       static {
   
  @@ -163,15 +152,6 @@
               );
       }
   
  -        
  -    public AntTagLibrary() {
  -        this.project = createProject();
  -    }
  -
  -    public AntTagLibrary(Project project) {
  -        this.project = project;
  -    }
  -
   
       /**
        * A helper method which will attempt to find a project in the current context
  @@ -180,10 +160,10 @@
        * #### this method could move to an AntUtils class.
        */
       public static Project getProject(JellyContext context) {
  -        Project project = (Project) context.findVariable( "org.apache.commons.jelly.ant.Project"
);
  +        Project project = (Project) context.findVariable( PROJECT_CONTEXT_HANDLE );
           if ( project == null ) {
  -            project = createProject();
  -            context.setVariable( "org.apache.commons.jelly.ant.Project", project );
  +            project = createProject(context);
  +            context.setVariable( PROJECT_CONTEXT_HANDLE , project );
           }
           return project;
       }
  @@ -193,8 +173,9 @@
        * 
        * #### this method could move to an AntUtils class.
        */    
  -    public static Project createProject() {
  -        Project project = new Project();
  +    public static Project createProject(JellyContext context) {
  +        GrantProject project = new GrantProject();
  +        project.setPropsHandler(new JellyPropsHandler(context));
   
           BuildLogger logger = new NoBannerLogger();
   
  @@ -203,11 +184,10 @@
           logger.setErrorPrintStream( System.err);
   
           project.addBuildListener( logger );
  -        project.init();
           
  -        // force lazy construction which avoids null pointer exceptions when using 
  -        // file sets
  -        project.getBaseDir();        
  +        project.init();
  +        project.getBaseDir();
  +
           return project;
       }
   
  @@ -237,7 +217,7 @@
               return new BeanTagScript(
                   new TagFactory() {
                       public Tag createTag() throws Exception {
  -                        return new FileScannerTag(new FileScanner(getProject()));
  +                        return new FileScannerTag(new FileScanner());
                       }
                   }
               );      
  @@ -249,30 +229,12 @@
        * A helper method which creates an AntTag instance for the given element name
        */
       public Tag createTag(String name) throws Exception {
  -        AntTag tag = new AntTag( getProject(), name );
  +        AntTag tag = new AntTag( name );
           if ( name.equals( "echo" ) ) {
               tag.setTrim(false);
           }
           return tag;
       }
  -    
   
  -    
  -    // Properties
  -    //-------------------------------------------------------------------------       
        
  -    
  -    /**
  -     * @return the Ant Project for this tag library.
  -     */
  -    public Project getProject() {
  -        return project;
  -    }
  -    
  -    /**
  -     * Sets the Ant Project for this tag library.
  -     */
  -    public void setProject(Project project) {
  -        this.project = project;
  -    }
   
   }
  
  
  
  1.5       +2 -0      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FileScannerTag.java	1 Aug 2002 09:53:18 -0000	1.4
  +++ FileScannerTag.java	27 Aug 2002 14:04:29 -0000	1.5
  @@ -91,6 +91,8 @@
       // Tag interface
       //------------------------------------------------------------------------- 
       public void doTag(XMLOutput output) throws Exception {
  +        fileScanner.setProject(AntTagLibrary.getProject(context));
  +        
           fileScanner.clear();
           
           // run the body first to configure the task via nested
  
  
  
  1.6       +3 -2      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FileScanner.java	19 Aug 2002 07:07:00 -0000	1.5
  +++ FileScanner.java	27 Aug 2002 14:04:29 -0000	1.6
  @@ -82,8 +82,9 @@
       
       /** The Ant project */
       private Project project;
  -
  -    public FileScanner(Project project) {
  +    
  +    public void setProject(Project project)
  +    {
           this.project = project;
       }
   
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/JellyPropsHandler.java
  
  Index: JellyPropsHandler.java
  ===================================================================
  package org.apache.commons.jelly.tags.ant;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" 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",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   *
   * ====================================================================
   */
  
  import java.util.Hashtable;
  import java.util.Iterator;
  
  import org.apache.commons.grant.DefaultPropsHandler;
  import org.apache.commons.jelly.JellyContext;
  
  /** Implementation of a Commons Grant <code>propsHandler</code>
   *  to resolve through Jelly's context.
   *
   *  @author <a href="mailto:bob@eng.werken.com">Bob McWhirter</a>
   *  @author <a href="mailto:stephenh@chase3000.com">Stephen Haberman</a>
   */
  public class JellyPropsHandler extends DefaultPropsHandler {
  
      /** The JellyContext. */
      private JellyContext context;
      
      /** Simple constructor with the context to be used.
       * 
       *  @param context The context to be used.
       */
      public JellyPropsHandler(JellyContext context) {
          this.context = context;
      }
      
      /** Set an ant property.
       *
       *  @param name The property name.
       *  @param value The property value.
       */
      public void setProperty(String name, String value) {
          this.context.setVariable(name, value);
      }
  
      /** Retrieve an ant property.
       *
       *  @param name The property name.
       *
       *  @return The property value.
       */
      public String getProperty(String name) {
          if (name == null) {
              return null;
          }
          return (String) this.context.getVariable(name);
      }
  
      /** Retrieve all ant properties.
       *
       *  @return A <code>Hashtable</code> of all properties.
       */
      public Hashtable getProperties() {
          Hashtable h = new Hashtable();
          for (Iterator i = this.context.getVariableNames(); i.hasNext(); ) {
              String name = (String) i.next();
              Object value = this.context.getVariable(name);
              if (value != null) {
                  h.put(name, value);
              }
          }
          return h;
      }
  
  }
  
  
  
  1.7       +6 -22     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez/JeezTagLibrary.java
  
  Index: JeezTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez/JeezTagLibrary.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JeezTagLibrary.java	9 Aug 2002 17:26:41 -0000	1.6
  +++ JeezTagLibrary.java	27 Aug 2002 14:04:29 -0000	1.7
  @@ -106,23 +106,7 @@
       private TagLibrary werkzTagLib = new WerkzTagLibrary();
   
       /** jelly:ant taglib. */
  -    private AntTagLibrary antTagLib;
  -
  -    /**
  -     * Use a default ant Project
  -     */
  -    public JeezTagLibrary() {
  -        this.antTagLib    = new AntTagLibrary();
  -    }
  -
  -    
  -    /** Construct.
  -     *
  -     *  @param antProject The ant Project.
  -     */
  -    public JeezTagLibrary(Project antProject) {
  -        this.antTagLib    = new AntTagLibrary( antProject );
  -    }
  +    private AntTagLibrary antTagLib= new AntTagLibrary();
   
       public TagScript createTagScript(
           final String name,
  
  
  
  1.26      +4 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java
  
  Index: JellyContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- JellyContext.java	27 Aug 2002 07:45:45 -0000	1.25
  +++ JellyContext.java	27 Aug 2002 14:04:29 -0000	1.26
  @@ -337,6 +337,10 @@
           if (isExportLibraries() && parent != null) {
               parent.registerTagLibrary( namespaceURI, taglib );
           }
  +        
  +        if (isExportLibraries() && parent != null) {
  +            parent.registerTagLibrary( namespaceURI, taglib );
  +        }
       }
   
       /** Registers the given tag library class name against the given namespace URI.
  
  
  

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