[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ant-dev
Subject:    cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder Converting
From:       darrell () apache ! org
Date:       2002-03-31 10:56:58
[Download RAW message or body]

darrell     02/03/31 02:56:58

  Modified:    proposal/myrmidon build.xml
               proposal/myrmidon/src/ant1compat/org/apache/tools/ant
                        Ant1CompatProject.java
               proposal/myrmidon/src/ant1compat/org/apache/tools/ant/types
                        Path.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/builder
                        TransformingProjectBuilder.java
  Added:       proposal/myrmidon/lib jaxp.jar
               proposal/myrmidon/src/java/org/apache/myrmidon/components/builder
                        ConvertingProjectBuilder.java
  Removed:     proposal/myrmidon/lib xalan.jar xml-apis.jar
  Log:
  * New ProjectBuilder which programmatically converts from Ant1 to Myrmidon
    project, rather than using a stylesheet. (This is now the default builder for
    ".xml" files.)
  
  * Removed xml-apis.jar and xalan.jar, and added jaxp.jar back in. Hopefully, this
    will keep us out of avoid jar version hell.
  
  * Added more stuff to the ${java.class.path} property available to ant1 tasks.
  
  * Can now fully build Myrmidon using Ant1 compatibility layer. All test bar one
    (Ant1CompatTestCase) pass when run using Myrmidon.
  
  Revision  Changes    Path
  1.98      +22 -18    jakarta-ant/proposal/myrmidon/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
  retrieving revision 1.97
  retrieving revision 1.98
  diff -u -r1.97 -r1.98
  --- build.xml	30 Mar 2002 06:56:04 -0000	1.97
  +++ build.xml	31 Mar 2002 10:56:57 -0000	1.98
  @@ -48,6 +48,7 @@
       <property name="build.ext" value="${build.dir}/ext"/>
       <property name="build.src" value="${build.dir}/src"/>
       <property name="build.classes" value="${build.dir}/classes"/>
  +    <property name="build.custom-tasks" value="${build.dir}/tasks"/>
   
       <property name="src.base" value="src"/>
       <property name="manifest.dir" value="${src.base}/manifest"/>
  @@ -70,14 +71,15 @@
       <property name="constants.file" value="org/apache/myrmidon/Constants.java"/>
   
       <path id="project.class.path">
  -        <pathelement path="${java.class.path}" />
           <pathelement location="../../lib/optional/junit.jar" />
           <pathelement location="../xdocs/lib/xdoclet.jar" />
           <pathelement location="../xdocs/lib/log4j-core.jar" />
           <fileset dir="${lib.dir}">
               <include name="*.jar" />
           </fileset>
  -        <pathelement path="${build.classes}" />
  +        <pathelement location="${build.classes}"/>
  +        <!-- Need this to get tools.jar in the classpath -->
  +        <pathelement path="${java.class.path}"/>
       </path>
   
       <!-- Main target -->
  @@ -199,7 +201,6 @@
   
       <!-- Compiles and installs the custom build tasks -->
       <target name="custom-tasks">
  -        <property name="build.custom-tasks" value="${build.dir}/tasks"/>
           <property name="custom-package-dir" \
value="${build.custom-tasks}/org/apache/myrmidon/build"/>  <mkdir \
dir="${build.custom-tasks}"/>  <javac srcdir="src/make" \
destdir="${build.custom-tasks}">  @@ -236,7 +237,10 @@
           <javac
               destdir="${build.classes}"
               debug="${debug}"
  -            deprecation="${deprecation}" >
  +            deprecation="${deprecation}" 
  +            includeAntRuntime="false"
  +            includeJavaRuntime="false">
  +            
               <classpath refid="project.class.path"/>
               <src location="src/todo"/>
               <src path="${java.dir}" />
  @@ -255,16 +259,6 @@
               <include name="org/apache/antlib/**"/>
           </javac>
   
  -        <mkdir dir="${test.classes}"/>
  -        <javac srcdir="src/test"
  -            destdir="${test.classes}"
  -            debug="${debug}"
  -            deprecation="${deprecation}">
  -            <classpath refid="project.class.path"/>
  -            <exclude name="**/SmbFileSystemTestCase.java" unless="jcifs.present"/>
  -            <exclude name="**/FtpFileSystemTestCase.java" \
                unless="netcomp.present"/>
  -        </javac>
  -
           <copy todir="${build.classes}">
               <fileset dir="${java.dir}">
                   <exclude name="**/*.java"/>
  @@ -290,6 +284,7 @@
               <include name="org/apache/myrmidon/components/**" />
               <include name="org/apache/myrmidon/frontends/**" />
               <include name="org/apache/myrmidon/*" />
  +            <exclude name="**/TransformingProjectBuilder.java" \
unless="trax.present"/>  </patternset>
   
           <patternset id="aut.include">
  @@ -551,7 +546,12 @@
               destdir="${test.classes}"
               debug="${debug}"
               deprecation="${deprecation}">
  -            <classpath refid="project.class.path"/>
  +            
  +            <classpath>
  +              <pathelement location="${build.classes}"/>
  +              <path refid="project.class.path"/>
  +            </classpath>
  +            
               <exclude name="**/SmbFileSystemTestCase.java" unless="jcifs.present"/>
               <exclude name="**/FtpFileSystemTestCase.java" \
unless="netcomp.present"/>  </javac>
  @@ -611,12 +611,12 @@
               tofile="${test.classes}/META-INF/ant-descriptor.xml"/>
   
           <!-- Run all the tests -->
  -        <junit printsummary="on" fork="true" failureProperty="test.failed">
  +        <junit printsummary="on" 
  +               fork="true" failureProperty="test.failed">
               <formatter type="brief" usefile="false"/>
  -            <classpath location="${build.classes}"/>
               <classpath>
                   <fileset dir="${test.working.dir}/dist/bin/lib" \
                includes="**/*.jar"/>
  -                <fileset dir="${test.working.dir}/dist/lib" includes="**/*.jar, \
**/*.atl" excludes="crimson.jar"/>  +                <fileset \
dir="${test.working.dir}/dist/lib" includes="**/*.jar, **/*.atl" \
excludes="**/crimson.jar"/>  </classpath>
               <classpath location="${test.classes}"/>
   
  @@ -767,6 +767,8 @@
                   <exclude name="jdepend.jar"/>
               </fileset>
           </copy>
  +        
  +        <copy todir="${dist.lib}" file="../../lib/optional/junit.jar" />
   
           <copy todir="${dist.bin}">
               <fileset dir="${script.dir}"/>
  @@ -797,6 +799,8 @@
       <!-- Cleans up the compiled classes -->
       <target name="clean-classes">
           <delete dir="${build.classes}"/>
  +        <delete dir="${test.classes}"/>
  +        <delete dir="${build.custom-tasks}"/>
       </target>
   
       <!-- Rebuilds the distribution -->
  
  
  
  1.3       +0 -0      jakarta-ant/proposal/myrmidon/lib/jaxp.jar
  
  	<<Binary file>>
  
  
  1.12      +6 -15     \
jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java
  
  Index: Ant1CompatProject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Ant1CompatProject.java	30 Mar 2002 06:56:04 -0000	1.11
  +++ Ant1CompatProject.java	31 Mar 2002 10:56:58 -0000	1.12
  @@ -10,7 +10,6 @@
   import java.io.File;
   import java.io.IOException;
   import java.io.InputStream;
  -import java.security.CodeSource;
   import java.util.Enumeration;
   import java.util.HashSet;
   import java.util.Hashtable;
  @@ -25,6 +24,8 @@
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   
  +import org.apache.tools.ant.types.Path;
  +
   /**
    * Ant1 Project proxy for Myrmidon. Provides hooks between Myrmidon TaskContext
    * and Ant1 project.
  @@ -33,7 +34,7 @@
    * Ant1 original, this class contains the extensions.
    *
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  - * @version $Revision: 1.11 $ $Date: 2002/03/30 06:56:04 $
  + * @version $Revision: 1.12 $ $Date: 2002/03/31 10:56:58 $
    */
   public class Ant1CompatProject extends Project
   {
  @@ -42,19 +43,9 @@
           org.apache.myrmidon.interfaces.model.Project.PROJECT;
       public static final String ANT1_PROJECT_PROP = "ant1.project";
   
  -    private static String javaclasspath;
  -
  -    static
  -    {
  -        // Find the path to the Ant1 antlib file.
  -        CodeSource ant1codesource =
  -            Ant1CompatProject.class.getProtectionDomain().getCodeSource();
  -        String ant1jar = ant1codesource.getLocation().getFile().toString();
  -
  -        // Append this to the java.class.path system property.
  -        javaclasspath = System.getProperty( "java.class.path" );
  -        javaclasspath = javaclasspath + File.pathSeparator + ant1jar;
  -    }
  +    // Add everything in the current classloader to the
  +    // java.class.path property.
  +    private static String javaclasspath = Path.systemClasspath.toString();
   
       private final Converter m_converter;
   
  
  
  
  1.2       +2 -1      \
jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/types/Path.java  
  Index: Path.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/types/Path.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Path.java	20 Mar 2002 01:14:26 -0000	1.1
  +++ Path.java	31 Mar 2002 10:56:58 -0000	1.2
  @@ -112,10 +112,11 @@
   
   
       //Modified from original source.
  -    //Append Ant1 codebase to systemclasspath.
  +    //Append Ant1Compat classpath to systemclasspath.
       // ------------------Modified--------------------------------
       static
       {
  +        // Add Ant1Compat.atl to system classpath.
           String classpath = LoaderUtils.getClasspath( Path.class.getClassLoader() \
);  systemClasspath.append( new Path( null, classpath ) );
       }
  
  
  
  1.4       +2 -2      \
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/TransformingProjectBuilder.java
  
  Index: TransformingProjectBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/TransformingProjectBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TransformingProjectBuilder.java	29 Mar 2002 12:56:03 -0000	1.3
  +++ TransformingProjectBuilder.java	31 Mar 2002 10:56:58 -0000	1.4
  @@ -25,9 +25,9 @@
    * A Project Builder which performs an XSL transformation on a project.
    *
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  - * @version $Revision: 1.3 $ $Date: 2002/03/29 12:56:03 $
  + * @version $Revision: 1.4 $ $Date: 2002/03/31 10:56:58 $
    *
  - * @ant.type type="project-builder" name="xml"
  + * @ant.type type="project-builder" name="ant-transform"
    */
   public class TransformingProjectBuilder
       extends DefaultProjectBuilder
  
  
  
  1.1                  \
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ConvertingProjectBuilder.java
  
  Index: ConvertingProjectBuilder.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.components.builder;
  
  import java.util.HashSet;
  import java.util.Set;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.apache.myrmidon.interfaces.builder.ProjectException;
  
  /**
   * A simple ProjectBuilder, which programmatically converts an Ant1 Project
   * configuration into a Myrmidon one.
   *
   * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/31 10:56:58 $
   *
   * @ant.type type="project-builder" name="xml"
   */
  public class ConvertingProjectBuilder
      extends DefaultProjectBuilder
  {
      private static final String VERSION_ATTRIBUTE = "version";
  
      protected Configuration parseProject( String systemID )
          throws ProjectException
      {
          Configuration originalConfig = super.parseProject( systemID );
  
          // Check the version, if it's present, just use this config.
          // TODO: check for version < 2.0
          if( originalConfig.getAttribute( VERSION_ATTRIBUTE, null ) != null )
          {
              return originalConfig;
          }
  
          // Convert the config by prepending "ant1." on tasks,
          // and using <if> tasks instead of target 'if=' and 'unless='
          DefaultConfiguration newConfig = copyConfiguration( originalConfig );
  
          // Put a new version attribute.
          newConfig.setAttribute( VERSION_ATTRIBUTE, "2.0" );
  
          // Copy the remaining attributes.
          Set omitAttributes = new HashSet();
          omitAttributes.add( VERSION_ATTRIBUTE );
          copyAttributes( originalConfig, newConfig, omitAttributes );
  
          // Now copy/convert the children
          Configuration[] children = originalConfig.getChildren();
          for( int i = 0; i < children.length; i++ )
          {
              Configuration child = children[ i ];
  
              if( child.getName().equals( "target" ) )
              {
                  newConfig.addChild( convertTarget( child ) );
              }
              else
              {
                  newConfig.addChild( convertTask( child ) );
              }
          }
  
          return newConfig;
      }
  
      /**
       * Converts Configuration for an Ant1 Target into a Myrmidon version.
       * @param originalTarget The Ant1 Target
       * @return the converted target
       */
      private Configuration convertTarget( Configuration originalTarget )
      {
          DefaultConfiguration newTarget = copyConfiguration( originalTarget );
  
          // Copy all attributes except 'if' and 'unless'
          Set omitAttributes = new HashSet();
          omitAttributes.add( "if" );
          omitAttributes.add( "unless" );
          copyAttributes( originalTarget, newTarget, omitAttributes );
  
          DefaultConfiguration containerElement = newTarget;
  
          // For 'if="prop-name"', replace with <if> task.
          String ifAttrib = originalTarget.getAttribute( "if", null );
          if ( ifAttrib != null )
          {
              DefaultConfiguration ifElement =
                  buildIfElement( ifAttrib, false, originalTarget.getLocation() );
              containerElement.addChild( ifElement );
              // Treat the ifElement as the enclosing target.
              containerElement = ifElement;
          }
  
          // For 'unless="prop-name"', replace with <if> task (negated).
          String unlessAttrib = originalTarget.getAttribute( "unless", null );
          if ( unlessAttrib != null )
          {
              DefaultConfiguration unlessElement =
                  buildIfElement( unlessAttrib, true, originalTarget.getLocation() );
              containerElement.addChild( unlessElement );
              // Treat the unlessElement as the enclosing target.
              containerElement = unlessElement;
          }
  
          // Now copy in converted tasks.
          Configuration[] tasks = originalTarget.getChildren();
          for( int i = 0; i < tasks.length; i++ )
          {
              containerElement.addChild( convertTask( tasks[ i ] ) );
          }
  
          return newTarget;
      }
  
      /**
       * Builds configuration for an <if> task, to replace a "if" or "unless"
       * attribute on a Ant1 target.
       * @param ifProperty the name of the property from the Ant1 attribute.
       * @param unless if the attribute is actually an "unless" attribute.
       * @param location the configuration location to use
       * @return The configuration for an <if> task
       */
      private DefaultConfiguration buildIfElement( String ifProperty,
                                                   boolean unless,
                                                   final String location )
      {
          // <if>
          //      <condition>
          //          <is-set property="prop-name"/>
          //      </condition>
          //      .. tasks
          // </if>
          DefaultConfiguration isSetElement =
              new DefaultConfiguration( "is-set", location );
          isSetElement.setAttribute( "property", ifProperty );
  
          DefaultConfiguration conditionElement =
              new DefaultConfiguration( "condition", location );
  
          if ( unless )
          {
              // Surround <is-set> with <not>
              DefaultConfiguration notElement =
                  new DefaultConfiguration( "not", location );
              notElement.addChild( isSetElement );
              conditionElement.addChild( notElement );
          }
          else
          {
              conditionElement.addChild( isSetElement );
          }
  
  
          DefaultConfiguration ifElement =
              new DefaultConfiguration( "if", location );
          ifElement.addChild( conditionElement );
  
          return ifElement;
      }
  
      /**
       * Converts Configuration for an Ant1 Task into a Myrmidon version.
       * @param originalTask The Ant1 Task
       * @return the converted task
       */
      private Configuration convertTask( Configuration originalTask )
      {
          // Create a new configuration with the "ant1." prefix.
          String newTaskName = "ant1." + originalTask.getName();
          DefaultConfiguration newTask =
              new DefaultConfiguration( newTaskName, originalTask.getLocation() );
  
          // Copy all attributes and elements of the task.
          copyAttributes( originalTask, newTask, new HashSet() );
          copyChildren( originalTask, newTask );
  
          return newTask;
      }
  
      /**
       * Copies all child elements from one configuration to another
       * @param from Configuration to copy from
       * @param to Configuration to copy to
       */
      private void copyChildren( Configuration from, DefaultConfiguration to )
      {
          Configuration[] children = from.getChildren();
          for( int i = 0; i < children.length; i++ )
          {
              to.addChild( children[ i ] );
          }
      }
  
      /**
       * Copies all attributes from one configuration to another, excluding
       * specified attribute names.
       * @param from Configuration to copy from
       * @param to Configuration to copy to
       * @param omitAttributes a Set of attribute names to exclude
       */
      private void copyAttributes( Configuration from,
                                   DefaultConfiguration to,
                                   Set omitAttributes )
      {
          // Copy other attributes
          String[] attribs = from.getAttributeNames();
          for( int i = 0; i < attribs.length; i++ )
          {
              String name = attribs[ i ];
              if( omitAttributes.contains( name ) )
              {
                  continue;
              }
              String value = from.getAttribute( name, "" );
              to.setAttribute( name, value );
          }
      }
  
      /**
       * Creates a DefaultConfiguration with the same name and location as
       * the one supplied.
       * @param originalConfig the COnfiguration to copy.
       * @return the new Configuration
       */
      private DefaultConfiguration copyConfiguration( Configuration originalConfig )
      {
          return new DefaultConfiguration( originalConfig.getName(),
                                           originalConfig.getLocation() );
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic