werken      2002/06/05 08:06:46

  Modified:    src/java/org/apache/maven/jelly AntBuildTag.java
                        MavenInitTag.java MavenTagLibrary.java
               src/scripts/bob build.xml maven maven-bootstrap.jelly
                        maven-build.xml maven.jelly project.properties
  Added:       src/java/org/apache/maven/jelly MavenTargetTag.java
               src/scripts/bob build-maven.xml maven-properties.jelly
                        maven-scripts.jelly
  Log:
  More maven+jelly musings to remove delegators and such.
  
  Revision  Changes    Path
  1.3       +85 -16    
jakarta-turbine-maven/src/java/org/apache/maven/jelly/AntBuildTag.java
  
  Index: AntBuildTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jelly/AntBuildTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AntBuildTag.java  4 Jun 2002 23:30:32 -0000       1.2
  +++ AntBuildTag.java  5 Jun 2002 15:06:45 -0000       1.3
  @@ -62,6 +62,7 @@
   import java.util.Enumeration;
   import java.util.Properties;
   import java.util.Vector;
  +import java.util.Hashtable;
   
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.MissingAttributeException;
  @@ -73,6 +74,7 @@
   import org.apache.tools.ant.Target;
   import org.apache.tools.ant.BuildLogger;
   import org.apache.tools.ant.NoBannerLogger;
  +import org.apache.tools.ant.BuildException;
   
   public class AntBuildTag
       extends TagSupport
  @@ -91,9 +93,12 @@
   
       private boolean emacsMode;
   
  +    private boolean ignore;
  +
       public AntBuildTag()
       {
           this.msgLevel = "info";
  +        this.ignore = false;
       }
       
       /**
  @@ -139,6 +144,23 @@
           return this.emacsMode;
       }
   
  +    public void setIgnore(String ignore)
  +    {
  +        if ( "true".equals( ignore ) )
  +        {
  +            this.ignore = true;
  +        }
  +        else
  +        {
  +            this.ignore = false;
  +        }
  +    }
  +
  +    public boolean getIgnore()
  +    {
  +        return this.ignore;
  +    }
  +
       /**
        * Description of the Method
        */
  @@ -147,7 +169,9 @@
       {
           // Check to make sure that we have a valid POM
           // before processing.
  -        if (buildFile == null)
  +        if (buildFile == null
  +            &&
  +            context.getVariable( "ant-project" ) == null ) 
           {
               throw new MissingAttributeException("buildFile");
           }
  @@ -165,29 +189,74 @@
   
           try 
           {
  -            File buildFile = new File( getBuildFile() );
  -
  -            Project project = (Project) context.getParent().getVariable( 
"ant-project" );
  -
  -            project.setUserProperty("ant.file" , buildFile.getAbsolutePath() );
  +            Project project = null;
   
  -            Class.forName( "javax.xml.parsers.SAXParserFactory" );
  -
  -            ProjectHelper.configureProject( project,
  -                                            buildFile );
  -
  -            Vector targets = new Vector();
  +            if (getBuildFile() != null )
  +            {
  +                project = new Project();
  +                BuildLogger logger = new NoBannerLogger();
  +        
  +                logger.setMessageOutputLevel( Project.MSG_VERBOSE );
  +                logger.setOutputPrintStream( System.out );
  +                logger.setErrorPrintStream( System.err);
  +                
  +                project.addBuildListener( logger );
  +                
  +                project.init();
  +
  +                File buildFile = new File( getBuildFile() );
  +
  +                project.setUserProperty("ant.file" , buildFile.getAbsolutePath() );
  +
  +                Class.forName( "javax.xml.parsers.SAXParserFactory" );
  +                
  +                ProjectHelper.configureProject( project,
  +                                                buildFile );
  +            }
  +            else
  +            {
  +                project = (Project) context.getVariable( "ant-project" );
  +            }
  +                
  +            Hashtable projTargets = project.getTargets();
  +            String target = getTarget();
   
  -            if ( getTarget() == null )
  +            if ( target == null )
               {
  -                targets.addElement( project.getDefaultTarget() );
  +                target = project.getDefaultTarget();
               }
               else
               {
  -                targets.addElement( getTarget() );
  +                if ( ! projTargets.containsKey( getTarget() ) )
  +                {
  +                    target = null;
  +                }
  +            }
  +
  +            if ( target != null )
  +            {
  +                try
  +                {
  +                    project.executeTarget( target );
  +                    getContext().setVariable( "target_status",
  +                                              "ok" );
  +                }
  +                catch (BuildException e)
  +                {
  +                    getContext().setVariable( "target_status",
  +                                              "failed" );
  +                }
               }
  +            else 
  +            {
  +                getContext().setVariable( "target_status",
  +                                          "unknown_target" );
   
  -            project.executeTargets(targets);
  +                if ( ! getIgnore() )
  +                {
  +                    throw new Exception( "No target \"" + target + "\" in " + 
project.getUserProperty( "ant.file" ) );
  +                }
  +            }
           }
           catch( Exception e ) 
           {
  
  
  
  1.2       +12 -1     
jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenInitTag.java
  
  Index: MavenInitTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenInitTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MavenInitTag.java 4 Jun 2002 23:30:32 -0000       1.1
  +++ MavenInitTag.java 5 Jun 2002 15:06:45 -0000       1.2
  @@ -69,6 +69,7 @@
   // import org.apache.maven.project.Project;
   
   import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.ProjectHelper;
   import org.apache.tools.ant.BuildLogger;
   import org.apache.tools.ant.NoBannerLogger;
   
  @@ -124,13 +125,23 @@
   
           BuildLogger logger = new NoBannerLogger();
           
  -        logger.setMessageOutputLevel( Project.MSG_INFO );
  +        logger.setMessageOutputLevel( Project.MSG_VERBOSE );
           logger.setOutputPrintStream( System.out );
           logger.setErrorPrintStream( System.err);
   
           project.addBuildListener( logger );
           
           project.init();
  +
  +        File mavenBuildFile = new File( getDir(),
  +                                        "build-maven.xml" );
  +        
  +        Class.forName( "javax.xml.parsers.SAXParserFactory" );
  +                
  +        ProjectHelper.configureProject( project,
  +                                        mavenBuildFile );
  +
  +        project.setUserProperty("ant.file" , mavenBuildFile.getAbsolutePath() );
   
           context.registerTagLibrary( "jelly:ant", new AntTagLibrary(project) );
   
  
  
  
  1.5       +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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MavenTagLibrary.java      4 Jun 2002 23:30:32 -0000       1.4
  +++ MavenTagLibrary.java      5 Jun 2002 15:06:45 -0000       1.5
  @@ -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.4 2002/06/04 23:30:32 werken Exp $
  + * @version $Id: MavenTagLibrary.java,v 1.5 2002/06/05 15:06:45 werken Exp $
    */
   public class MavenTagLibrary
        extends CoreTagLibrary
  @@ -72,5 +72,6 @@
           registerTag( "pom", PomTag.class );
           registerTag( "build", AntBuildTag.class );
           registerTag( "init", MavenInitTag.class );
  +        registerTag( "maven", MavenTargetTag.class );
       }        
   }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenTargetTag.java
  
  Index: MavenTargetTag.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.Properties;
  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.commons.jelly.Script;
  
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.ProjectHelper;
  import org.apache.tools.ant.Target;
  import org.apache.tools.ant.BuildLogger;
  import org.apache.tools.ant.NoBannerLogger;
  
  public class MavenTargetTag
      extends TagSupport
  {
      private String target;
  
      public void setTarget(String target)
      {
          this.target = target;
      }
  
      public String getTarget()
      {
          return this.target;
      }
  
      /**
       * Description of the Method
       */
      public void doTag(XMLOutput output)
          throws Exception
      {
          // Check to make sure that we have a valid POM
          // before processing.
          if ( getTarget() == null)
          {
              throw new MissingAttributeException("target");
          }
          
          Script script = lookupScript( target );
  
          script.run( getContext(),
                      output );
      }
  
      private Script lookupScript(String target)
      {
          Script script = null;
  
          if ( target.startsWith( "maven:" ) )
          {
              String base = target.substring( 6 );
  
              String scriptName = "target_maven";
  
              script = (Script) getContext().getVariable( scriptName );
          }
          else
          {
              script = (Script) getContext().getVariable( "target_user" );
          }
  
          if ( script == null )
          {
              script = (Script) getContext().getVariable( "target_unknown" );
          }
  
          return script;
      }
  }
  
  
  
  1.2       +0 -10     jakarta-turbine-maven/src/scripts/bob/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/scripts/bob/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml 4 Jun 2002 23:30:33 -0000       1.1
  +++ build.xml 5 Jun 2002 15:06:45 -0000       1.2
  @@ -5,20 +5,10 @@
     <target
       name="test">
       
  -    <touch file="touched-file-by-ant"/>
  -    
       <echo>
         Hello! I'm an Ant build being run from Jelly!
       </echo>
     
     </target>
   
  -  <target name="maven:env">
  -    <echo>
  -    maven.home = ${maven.home}
  -      lib.repo = ${lib.repo}
  -      cheese = ${maven.cheese}
  -    </echo>
  -  </target>
  -  
   </project>
  
  
  
  1.2       +1 -1      jakarta-turbine-maven/src/scripts/bob/maven
  
  Index: maven
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/scripts/bob/maven,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- maven     4 Jun 2002 23:30:33 -0000       1.1
  +++ maven     5 Jun 2002 15:06:45 -0000       1.2
  @@ -147,4 +147,4 @@
   echo $LOCALCLASSPATH
   
   $JAVACMD -classpath "$LOCALCLASSPATH" -Dmaven.home="${MAVEN_HOME}" $MAVEN_OPTS \
  -    org.apache.commons.jelly.Jelly $MAVEN_ARGS "$@"
  +    org.apache.commons.jelly.Jelly maven-bootstrap.jelly $MAVEN_ARGS "$@"
  
  
  
  1.2       +22 -1     jakarta-turbine-maven/src/scripts/bob/maven-bootstrap.jelly
  
  Index: maven-bootstrap.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/scripts/bob/maven-bootstrap.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- maven-bootstrap.jelly     4 Jun 2002 23:30:33 -0000       1.1
  +++ maven-bootstrap.jelly     5 Jun 2002 15:06:45 -0000       1.2
  @@ -1,10 +1,31 @@
  +<!--
  +  ||   This file lives in ${maven.home}
  +  -->
   <jelly:jelly
  +  trim="true"
     xmlns:jelly="jelly:core"
     xmlns:def="jelly:define"
     xmlns:maven="jelly:org.apache.maven.jelly.MavenTagLibrary">
   
  +  <!--
  +    || Read the project's build-maven.xml, project.xml, etc
  +    -->
     <maven:init dir="./"/>
   
  -  <jelly:include uri="maven.jelly"/>
  +  <!--
  +    || Walk the properties-files chain.
  +    -->
  +  <jelly:include uri="maven-properties.jelly" inherit="true" export="true"/>
  +
  +  <!--
  +    || Load maven scripts
  +    -->
  +  <jelly:include uri="maven-scripts.jelly" inherit="true" export="true"/>
  +
  +  <!--
  +    || Run the main maven loop.
  +    -->
  +  <jelly:include uri="maven.jelly" inherit="true" export="true"/>
  +
   
   </jelly:jelly>
  
  
  
  1.2       +13 -2     jakarta-turbine-maven/src/scripts/bob/maven-build.xml
  
  Index: maven-build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/scripts/bob/maven-build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- maven-build.xml   4 Jun 2002 23:30:33 -0000       1.1
  +++ maven-build.xml   5 Jun 2002 15:06:45 -0000       1.2
  @@ -1,10 +1,21 @@
   <?xml version="1.0"?>
   
  +<!--
  +  || 
  +  || This file is the equivalent of core/build.xml, in that it
  +  || holds the core ant-side portion of Maven.
  +  || 
  +  -->
  +
   <project name="maven-internal" default="init" basedir=".">
   
  +  <!--
  +    || We only have to use this target currently because Jelly
  +    || doesn't support the type coercion necessary to use the
  +    || "file" attribute on the 'property' tag.
  +    -->
     <target
  -    name="init">
  -    
  +    name="load-properties">
       <property file="${user.home}/build.properties"/>
       <property file="build.properties"/>
       <property file="project.properties"/>
  
  
  
  1.2       +10 -27    jakarta-turbine-maven/src/scripts/bob/maven.jelly
  
  Index: maven.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/scripts/bob/maven.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- maven.jelly       4 Jun 2002 23:30:33 -0000       1.1
  +++ maven.jelly       5 Jun 2002 15:06:45 -0000       1.2
  @@ -1,38 +1,21 @@
  +<!--
  +  ||   This file lives in ${maven.home}
  +  -->
   <jelly:jelly
  +  trim="true"
     xmlns:ant="jelly:ant"
     xmlns:jelly="jelly:core"
     xmlns:util="maven:util"
     xmlns:maven="jelly:org.apache.maven.jelly.MavenTagLibrary">
  - 
  -  <maven:build buildFile="maven-build.xml" target="init" msgLevel="info" />
   
  +  <!-- 
  +    || Dispatch each argument as a maven build target.
  +    -->
     <jelly:forEach 
  -    var="arg"
  -    items='${context.parent.getVariable("args")}'
  +    var="target"
  +    items="${args}"
       begin="1">
  -  
  -    <jelly:set var="build_file" value="maven-build.xml"/>
  -    <jelly:set var="build_target" value=""/>
  -
  -    <jelly:choose>
  -
  -      <jelly:when test='${arg == "maven:compile"}'>
  -        <jelly:set var="build_target" value="${arg}"/>
  -      </jelly:when>
  -
  -      <jelly:when test='${arg == "maven:jar"}'>
  -        <jelly:set var="build_target" value="${arg}"/>
  -      </jelly:when>
  -
  -      <jelly:otherwise>
  -        <jelly:set var="build_target" value="${arg}"/>
  -        <jelly:set var="build_file"   value="build.xml"/>
  -      </jelly:otherwise>
  -
  -    </jelly:choose>
  -
  -    <jelly:expr value="${build_file}"/> : <jelly:expr value="${build_target}"/>
  -
  +    <maven:maven target="${target}"/>  
     </jelly:forEach>
   
   </jelly:jelly>
  
  
  
  1.2       +1 -2      jakarta-turbine-maven/src/scripts/bob/project.properties
  
  Index: project.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/scripts/bob/project.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- project.properties        4 Jun 2002 23:30:33 -0000       1.1
  +++ project.properties        5 Jun 2002 15:06:45 -0000       1.2
  @@ -1,3 +1,2 @@
   
  -maven.cheese = gouda ${maven.home}
  -
  +cheese = gouda
  
  
  
  1.1                  jakarta-turbine-maven/src/scripts/bob/build-maven.xml
  
  Index: build-maven.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    || This file lives in ${basedir} and is the project's
    || normal build file.
    ||
    || It does not require any Maven delegators.
    ||
    || It may contain both user-defined project-specific targets
    || which may be executed directly by name using "maven [target]".
    ||
    || It may also contain maven pre- and post-target callback
    || targets, which are never directly invoked by a user.
    -->
  
  <project name="maven" default="test" basedir=".">
  
    <target
      name="test">
      <property name="lib.repo" value="cheese"/>
      
      <echo>
        Hello! I'm an Ant build being run from Jelly!
        lib.repo = ${lib.repo}
      </echo>
    
    </target>
  
    <target name="failure">
      <fail/>
    </target>
  
  </project>
  
  
  
  1.1                  jakarta-turbine-maven/src/scripts/bob/maven-properties.jelly
  
  Index: maven-properties.jelly
  ===================================================================
  <!--
    ||   This file lives in ${maven.home}
    -->
  <jelly:jelly
    trim="true"
    xmlns:ant="jelly:ant"
    xmlns:jelly="jelly:core"
    xmlns:def="jelly:define"
    xmlns:maven="jelly:org.apache.maven.jelly.MavenTagLibrary">
  
    <ant:property file="${user.home}/build.properties"/>
    <ant:property file="build.properties"/>
    <ant:property file="project.properties"/>
    <ant:property name="cheese" value="toast"/>
   
    <ant:echo message="user.home = ${user.home}"/>
    <ant:echo message="cheese = ${cheese}"/>
    <ant:echo message="goober = ${goober}"/>
  
    <ant:echo message="${ant.project.name}"/>
    
  
  </jelly:jelly>
  
  
  
  1.1                  jakarta-turbine-maven/src/scripts/bob/maven-scripts.jelly
  
  Index: maven-scripts.jelly
  ===================================================================
  
  <!--
    ||   This file lives in ${maven.home}
    -->
  
  <jelly:jelly
    trim="true"
    xmlns:ant="jelly:ant"
    xmlns:jelly="jelly:core"
    xmlns:def="jelly:define"
    xmlns:maven="jelly:org.apache.maven.jelly.MavenTagLibrary">
  
    <!--
      ||    maven:target
      -->
    <def:script var="target_maven">
      running [maven_target] <jelly:expr value="${target}"/>
      maven.home = <jelly:expr value="${maven.home}"/>
      lib.repo = <jelly:expr value="${lib.repo}"/>
    </def:script>
  
    <!--
      ||    bogus maven:target
      -->
    <def:script var="target_unknown">
      ======================================================================
      == ERROR
      ==
      == The target "<jelly:expr value="${target}"/>" is not  valid for this project.
      ======================================================================
    </def:script>
  
    <!--
      ||    user-defined target
      -->
    <def:script var="target_user">
      <maven:build target="${target}" ignore="true"/>
      <jelly:choose>
        <jelly:when test='${target_status == "unknown_target"}'>
          <jelly:jelly body="${target_unknown}"/>
        </jelly:when>
        <jelly:when test='${target_status == "failed"}'>
          <jelly:jelly body="${target_failed}"/>
        </jelly:when>
      </jelly:choose>
    </def:script>
  
    <!--
      ||    general ant target failure
      -->
    <def:script var="target_failed">
      ======================================================================
      == ERROR
      ==
      == The target "<jelly:expr value="${target}"/>" failed.
      ======================================================================
    </def:script>
  
  </jelly:jelly>
  
  
  

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

Reply via email to