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.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272123 13f79535-47bb-0310-9956-ffa450edef68
master
| @@ -48,6 +48,7 @@ Legal: | |||
| <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 @@ Legal: | |||
| <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 @@ Legal: | |||
| <!-- 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 @@ Legal: | |||
| <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 @@ Legal: | |||
| <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 @@ Legal: | |||
| <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 @@ Legal: | |||
| 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 @@ Legal: | |||
| 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 @@ Legal: | |||
| <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 @@ Legal: | |||
| <!-- 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 --> | |||
| @@ -10,7 +10,6 @@ package org.apache.tools.ant; | |||
| 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.api.TaskException; | |||
| 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. | |||
| @@ -42,19 +43,9 @@ public class Ant1CompatProject extends Project | |||
| 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; | |||
| @@ -112,10 +112,11 @@ public class Path extends DataType implements Cloneable { | |||
| //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 ) ); | |||
| } | |||
| @@ -0,0 +1,237 @@ | |||
| /* | |||
| * 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$ $Date$ | |||
| * | |||
| * @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() ); | |||
| } | |||
| } | |||
| @@ -27,7 +27,7 @@ import org.apache.myrmidon.interfaces.builder.ProjectException; | |||
| * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a> | |||
| * @version $Revision$ $Date$ | |||
| * | |||
| * @ant.type type="project-builder" name="xml" | |||
| * @ant.type type="project-builder" name="ant-transform" | |||
| */ | |||
| public class TransformingProjectBuilder | |||
| extends DefaultProjectBuilder | |||