jvanzyl     2002/06/03 20:38:31

  Modified:    src/java/org/apache/maven/jelly MavenTagLibrary.java
                        PomTag.java
  Added:       src/java/org/apache/maven/jelly AntBuildTag.java
  Log:
  Added an AntBuildTag that allows you to run an Ant build from within
  a Jelly script. So this could be used to integrate all our existing
  build files and integrate 100% with Ant while allowing us to move toward
  using Jelly entirely for our internal procedures.
  
  This would allow something like a parameterized compile tag that we could
  use in a consistent way for:
  
  <sourceDirectory>
  <testSourceDirectory>
  <exampleSourceDirectory>
  
  It's really limitless what we could do with this. As much as I dislike
  taglibs in the web arena Jelly would sure allow some nifty stuff and
  it would radically simplify internal library. We could get rid of what's
  becoming a rat's nest of ant build files with some clean tag libs. I like
  it so far.
  
  Revision  Changes    Path
  1.3       +2 -1      
jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenTagLibrary.java
  
  Index: MavenTagLibrary.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenTagLibrary.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MavenTagLibrary.java      3 Jun 2002 22:10:51 -0000       1.2
  +++ MavenTagLibrary.java      4 Jun 2002 03:38:31 -0000       1.3
  @@ -62,7 +62,7 @@
    * Maven tag library for use in Jelly scripts.
    *
    * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: MavenTagLibrary.java,v 1.2 2002/06/03 22:10:51 jvanzyl Exp $
  + * @version $Id: MavenTagLibrary.java,v 1.3 2002/06/04 03:38:31 jvanzyl Exp $
    */
   public class MavenTagLibrary
        extends CoreTagLibrary
  @@ -70,5 +70,6 @@
       public MavenTagLibrary()
       {
           registerTag( "pom", PomTag.class );
  +        registerTag( "build", AntBuildTag.class );
       }        
   }
  
  
  
  1.4       +3 -3      
jakarta-turbine-maven/src/java/org/apache/maven/jelly/PomTag.java
  
  Index: PomTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jelly/PomTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PomTag.java       3 Jun 2002 22:10:51 -0000       1.3
  +++ PomTag.java       4 Jun 2002 03:38:31 -0000       1.4
  @@ -74,7 +74,7 @@
    * only parsed once in a given Jelly script?
    *
    * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: PomTag.java,v 1.3 2002/06/03 22:10:51 jvanzyl Exp $
  + * @version $Id: PomTag.java,v 1.4 2002/06/04 03:38:31 jvanzyl Exp $
    */
   public class PomTag
        extends TagSupport
  @@ -82,7 +82,7 @@
       /**
        * Maven project descriptor.
        */
  -    private File projectDescriptor;
  +    private String projectDescriptor;
   
       /**
        * Maven POM
  @@ -92,7 +92,7 @@
       /**
        * Set Maven project descriptor.
        */
  -    public void setProjectDescriptor(File projectDescriptor)
  +    public void setProjectDescriptor(String projectDescriptor)
       {
           this.projectDescriptor = projectDescriptor;
       }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/jelly/AntBuildTag.java
  
  Index: AntBuildTag.java
  ===================================================================
  package org.apache.maven.jelly;
  
  /* ====================================================================
   * 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 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 [EMAIL PROTECTED]
   *
   * 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.io.File;
  import java.io.PrintStream;
  
  import java.util.Enumeration;
  import java.util.Vector;
  
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.ProjectHelper;
  import org.apache.tools.ant.Target;
  
  public class AntBuildTag
      extends TagSupport
  {
      /**
       * Ant build file.
       */
      private String buildFile;
      
      /**
       * Set the Ant build file.
       */
      public void setBuildFile(String buildFile)
      {
          this.buildFile = buildFile;
      }        
  
      /**
       * Description of the Method
       */
      public void doTag(XMLOutput output)
          throws Exception
      {
          // Check to make sure that we have a valid POM
          // before processing.
          if (buildFile == null)
          {
              throw new MissingAttributeException("buildFile");
          }
          
          executeBuild();
      }
      
      /**
       * Execute the Ant build using the build file specified.
       */
      public void executeBuild()
      {
          PrintStream err = System.err;
          PrintStream out = System.out;
          
          try 
          {
              Project project = new Project();
              project.init();
              project.setUserProperty( "ant.file",  buildFile );
              Class.forName( "javax.xml.parsers.SAXParserFactory" );
              ProjectHelper.configureProject( project, new File( buildFile ));
              
              //Vector targets = project.getTargets().elements();
              // We will try this with the default target for now.
              Vector targets = new Vector();
  
              // make sure that we have a target to execute
              if (targets.size() == 0) 
              {
                  targets.addElement(project.getDefaultTarget());
              }
  
              project.executeTargets(targets);
          }
          catch( Exception e ) 
          {
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to