From 29cd889775d70bb1dad99b6bbfb08e826feda1f4 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sat, 19 Jan 2002 07:26:23 +0000 Subject: [PATCH] The attached patch makes useable as a data-type in myrmidon. * Added a String -> Path converter. * Added the appropriate declarations to ant1-ant-descriptor.xml. * PathLocation is now only used internally by Path. This means a may not contain nested elements any more. Nested elements can be used to do the same thing. * Removed Path.systemClasspath and Path.concatSystemClassPath(). The goal is to add specialised , , and data-types to control this explicitly. I left it unfinished, because the as-yet-unwritten Java util stuff will determine how it should be done. * Moved Path.addExtdirs() -> DefaultCompilerAdaptor. This was the only place it was used. * Cleaned out a few more Path createX() methods. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270786 13f79535-47bb-0310-9956-ffa450edef68 --- proposal/myrmidon/build.xml | 2 - .../compilers/DefaultCompilerAdapter.java | 69 ++++--- .../tools/ant/taskdefs/compilers/Gcj.java | 2 +- .../tools/ant/taskdefs/compilers/Jikes.java | 2 +- .../tools/ant/taskdefs/compilers/Jvc.java | 2 +- .../tools/ant/taskdefs/compilers/Kjc.java | 2 +- .../tools/ant/taskdefs/javadoc/Javadoc.java | 14 +- .../tools/ant/taskdefs/optional/Javah.java | 48 ++--- .../optional/ejb/BorlandGenerateClient.java | 3 +- .../optional/ejb/IPlanetEjbcTask.java | 24 +-- .../ant/taskdefs/optional/javacc/JJTree.java | 6 +- .../ant/taskdefs/optional/javacc/JavaCC.java | 6 +- .../ant/taskdefs/optional/jsp/WLJspc.java | 4 +- .../taskdefs/optional/junit/JUnitTask.java | 4 +- .../metamata/AbstractMetamataTask.java | 5 +- .../taskdefs/optional/metamata/MParse.java | 5 +- .../ant/taskdefs/rmic/DefaultRmicAdapter.java | 28 +-- .../tools/ant/types/CommandlineJava.java | 8 +- .../main/org/apache/tools/ant/types/Path.java | 172 ++---------------- .../apache/tools/ant/types/PathElement.java | 17 +- .../converters/StringToPathConverter.java | 53 ++++++ .../org/apache/tools/ant/util/FileUtils.java | 41 ++--- .../src/manifest/ant1-ant-descriptor.xml | 12 ++ .../compilers/DefaultCompilerAdapter.java | 69 ++++--- .../tools/ant/taskdefs/compilers/Gcj.java | 2 +- .../tools/ant/taskdefs/compilers/Jikes.java | 2 +- .../tools/ant/taskdefs/compilers/Jvc.java | 2 +- .../tools/ant/taskdefs/compilers/Kjc.java | 2 +- .../tools/ant/taskdefs/javadoc/Javadoc.java | 14 +- .../tools/ant/taskdefs/optional/Javah.java | 48 ++--- .../optional/ejb/BorlandGenerateClient.java | 3 +- .../optional/ejb/IPlanetEjbcTask.java | 24 +-- .../ant/taskdefs/optional/javacc/JJTree.java | 6 +- .../ant/taskdefs/optional/javacc/JavaCC.java | 6 +- .../ant/taskdefs/optional/jsp/WLJspc.java | 4 +- .../taskdefs/optional/junit/JUnitTask.java | 4 +- .../metamata/AbstractMetamataTask.java | 5 +- .../taskdefs/optional/metamata/MParse.java | 5 +- .../ant/taskdefs/rmic/DefaultRmicAdapter.java | 28 +-- .../tools/ant/types/CommandlineJava.java | 8 +- .../todo/org/apache/tools/ant/types/Path.java | 172 ++---------------- .../apache/tools/ant/types/PathElement.java | 17 +- .../converters/StringToPathConverter.java | 53 ++++++ .../org/apache/tools/ant/util/FileUtils.java | 41 ++--- 44 files changed, 394 insertions(+), 650 deletions(-) create mode 100644 proposal/myrmidon/src/main/org/apache/tools/ant/types/converters/StringToPathConverter.java create mode 100644 proposal/myrmidon/src/todo/org/apache/tools/ant/types/converters/StringToPathConverter.java diff --git a/proposal/myrmidon/build.xml b/proposal/myrmidon/build.xml index b36c6c7a6..7209a3d04 100644 --- a/proposal/myrmidon/build.xml +++ b/proposal/myrmidon/build.xml @@ -387,14 +387,12 @@ Legal: - diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index d0e9da137..ed4875ea6 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -14,10 +14,12 @@ import java.io.PrintWriter; import org.apache.avalon.excalibur.util.StringUtil; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; import org.apache.tools.ant.taskdefs.Javac; import org.apache.tools.ant.taskdefs.exec.Execute2; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.FileSet; /** * This is the default implementation for the CompilerAdapter interface. @@ -77,8 +79,6 @@ public abstract class DefaultCompilerAdapter m_compileList = attributes.getFileList(); m_compileClasspath = attributes.getClasspath(); m_baseDir = attributes.getBaseDirectory(); - m_includeAntRuntime = attributes.getIncludeantruntime(); - m_includeJavaRuntime = attributes.getIncludejavaruntime(); m_memoryInitialSize = attributes.getMemoryInitialSize(); m_memoryMaximumSize = attributes.getMemoryMaximumSize(); } @@ -283,34 +283,13 @@ public abstract class DefaultCompilerAdapter if( m_destDir != null ) { - classpath.setLocation( m_destDir ); + classpath.addLocation( m_destDir ); } - // Combine the build classpath with the system classpath, in an - // order determined by the value of build.classpath - - if( m_compileClasspath == null ) + // add the classpath + if ( m_compileClasspath != null ) { - if( m_includeAntRuntime ) - { - classpath.addExisting( Path.systemClasspath ); - } - } - else - { - if( m_includeAntRuntime ) - { - classpath.addExisting( m_compileClasspath.concatSystemClasspath( "last" ) ); - } - else - { - classpath.addExisting( m_compileClasspath.concatSystemClasspath( "ignore" ) ); - } - } - - if( m_includeJavaRuntime ) - { - classpath.addJavaRuntime(); + classpath.addExisting( m_compileClasspath ); } return classpath; @@ -437,5 +416,41 @@ public abstract class DefaultCompilerAdapter getLogger().debug( niceSourceList.toString() ); } + + /** + * Emulation of extdirs feature in java >= 1.2. This method adds all files + * in the given directories (but not in sub-directories!) to the classpath, + * so that you don't have to specify them all one by one. + */ + protected void addExtdirs( Path path ) + throws TaskException + { + if( m_extdirs == null ) + { + String extProp = System.getProperty( "java.ext.dirs" ); + if( extProp != null ) + { + m_extdirs = new Path( extProp ); + } + else + { + return; + } + } + + final String[] dirs = m_extdirs.list(); + for( int i = 0; i < dirs.length; i++ ) + { + final File dir = new File( dirs[ i ] ); + if( dir.exists() && dir.isDirectory() ) + { + final FileSet fileSet = new FileSet(); + fileSet.setDir( dir ); + fileSet.setIncludes( "*" ); + path.addFileset( fileSet ); + } + } + } + } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java index e8bc69cdc..7a4406f98 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java @@ -55,7 +55,7 @@ public class Gcj extends DefaultCompilerAdapter // gcj doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. - classpath.addExtdirs( m_extdirs ); + addExtdirs( classpath ); if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) ) { diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java index b76e10ec0..95e58d444 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java @@ -52,7 +52,7 @@ public class Jikes // Jikes doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. - classpath.addExtdirs( m_extdirs ); + addExtdirs( classpath ); if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) ) { diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java index 1313c8d20..58ef83b48 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java @@ -40,7 +40,7 @@ public class Jvc extends DefaultCompilerAdapter // jvc doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. - classpath.addExtdirs( m_extdirs ); + addExtdirs( classpath ); if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) ) { diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java index e4fcc74ed..d4892e6a4 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java @@ -94,7 +94,7 @@ public class Kjc extends DefaultCompilerAdapter if( m_extdirs != null ) { - cp.addExtdirs( m_extdirs ); + addExtdirs( cp ); } cp.append( classpath ); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/javadoc/Javadoc.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/javadoc/Javadoc.java index 15b869c43..5daea5815 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/javadoc/Javadoc.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/javadoc/Javadoc.java @@ -559,14 +559,16 @@ public class Javadoc cmd.setExecutable( getJavadocExecutableName() ); // ------------------------------------------------ general javadoc arguments - if( m_classpath == null ) - m_classpath = Path.systemClasspath; - else - m_classpath = m_classpath.concatSystemClasspath( "ignore" ); + // Build the classpath to pass to Javadoc + Path classpath = new Path(); + classpath.addPath( m_sourcePath ); + if ( m_classpath != null ) + { + classpath.addPath( m_classpath ); + } cmd.createArgument().setValue( "-classpath" ); - cmd.createArgument().setValue( m_sourcePath.toString() + - System.getProperty( "path.separator" ) + m_classpath.toString() ); + cmd.createArgument().setValue( classpath.toString() ); if( m_version && m_doclet == null ) cmd.createArgument().setValue( "-version" ); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java index 899994647..9d266a38c 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java @@ -14,6 +14,7 @@ import java.util.StringTokenizer; import org.apache.avalon.excalibur.util.StringUtil; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.AbstractTask; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Path; @@ -52,7 +53,7 @@ import org.apache.tools.ant.types.Path; */ public class Javah - extends AbstractLogEnabled + extends AbstractTask { private final static String FAIL_MSG = "Compile failed, messages should have been provided."; @@ -67,8 +68,10 @@ public class Javah private String m_cls; private File m_destDir; - public void setBootclasspath( final Path bootclasspath ) - throws TaskException + /** + * Adds an element to the bootclasspath. + */ + public void addBootclasspath( final Path bootclasspath ) { if( m_bootclasspath == null ) { @@ -76,7 +79,7 @@ public class Javah } else { - m_bootclasspath.append( bootclasspath ); + m_bootclasspath.addPath( bootclasspath ); } } @@ -85,7 +88,10 @@ public class Javah m_cls = cls; } - public void setClasspath( final Path classpath ) + /** + * Adds an element to the classpath. + */ + public void addClasspath( final Path classpath ) throws TaskException { if( m_classpath == null ) @@ -94,7 +100,7 @@ public class Javah } else { - m_classpath.append( classpath ); + m_classpath.addPath( classpath ); } } @@ -149,18 +155,6 @@ public class Javah m_verbose = verbose; } - public Path createBootclasspath() - { - if( m_bootclasspath == null ) - { - m_bootclasspath = new Path(); - } - Path path1 = m_bootclasspath; - final Path path = new Path(); - path1.addPath( path ); - return path; - } - public ClassArgument createClass() { final ClassArgument ga = new ClassArgument(); @@ -169,18 +163,6 @@ public class Javah return ga; } - public Path createClasspath() - { - if( m_classpath == null ) - { - m_classpath = new Path(); - } - Path path1 = m_classpath; - final Path path = new Path(); - path1.addPath( path ); - return path; - } - /** * Executes the task. */ @@ -188,12 +170,6 @@ public class Javah throws TaskException { validate(); - - if( m_classpath == null ) - { - m_classpath = Path.systemClasspath; - } - doClassicCompile(); } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java index d3c4bf029..0b5a92bf4 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java @@ -215,7 +215,8 @@ public class BorlandGenerateClient extends Task //classpath //add at the end of the classpath //the system classpath in order to find the tools.jar file - execTask.addClasspath( classpath.concatSystemClasspath() ); + // TODO - make sure tools.jar is in the classpath + //execTask.addClasspath( classpath.concatSystemClasspath( "last" ) ); execTask.setFork( true ); execTask.createArg().setValue( "generateclient" ); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java index b160e780f..eea8c25f2 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java @@ -197,22 +197,6 @@ public class IPlanetEjbcTask extends Task executeEjbc( getParser() ); } - /** - * Returns the CLASSPATH to be used when calling EJBc. If no user CLASSPATH - * is specified, the System classpath is returned instead. - * - * @return Path The classpath to be used for EJBc. - */ - private Path getClasspath() - { - if( classpath == null ) - { - classpath = Path.systemClasspath; - } - - return classpath; - } - /** * Returns a SAXParser that may be used to process the XML descriptors. * @@ -311,10 +295,16 @@ public class IPlanetEjbcTask extends Task private void executeEjbc( SAXParser saxParser ) throws TaskException { + String classpath = null; + if( classpath != null ) + { + classpath = this.classpath.toString(); + } + IPlanetEjbc ejbc = new IPlanetEjbc( ejbdescriptor, iasdescriptor, dest, - getClasspath().toString(), + classpath, saxParser ); ejbc.setRetainSource( keepgenerated ); ejbc.setDebugOutput( debug ); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java index 30ffc7782..58d4859bb 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java @@ -17,7 +17,6 @@ import org.apache.tools.ant.taskdefs.exec.Execute2; import org.apache.tools.ant.types.Argument; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathElement; /** * Taskdef for the JJTree compiler compiler. @@ -175,10 +174,7 @@ public class JJTree extends Task throw new TaskException( "Javacchome not set." ); } final Path classpath = cmdl.createClasspath(); - final PathElement pathElement = new PathElement(); - classpath.addPathElement( pathElement ); - pathElement.setPath( javaccHome.getAbsolutePath() + - "/JavaCC.zip" ); + classpath.addLocation( new File( javaccHome, "JavaCC.zip" ) ); classpath.addJavaRuntime(); final Argument arg = cmdl.createVmArgument(); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java index 08ab55195..6754430b6 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java @@ -18,7 +18,6 @@ import org.apache.tools.ant.types.Argument; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathElement; import org.apache.avalon.excalibur.util.StringUtil; /** @@ -229,10 +228,7 @@ public class JavaCC extends Task throw new TaskException( "Javacchome not set." ); } final Path classpath = cmdl.createClasspath(); - final PathElement pathElement = new PathElement(); - classpath.addPathElement( pathElement ); - pathElement.setPath( javaccHome.getAbsolutePath() + - "/JavaCC.zip" ); + classpath.addLocation( new File( javaccHome, "JavaCC.zip" ) ); classpath.addJavaRuntime(); final Argument arg = cmdl.createVmArgument(); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java index 707bbe227..92e0883e9 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java @@ -163,7 +163,9 @@ public class WLJspc extends MatchingTask compileClasspath = new Path(); } - compileClasspath.append( Path.systemClasspath ); + // TODO - make sure tools.jar ends up in the classpath + //compileClasspath.append( Path.systemClasspath ); + String[] files = ds.getIncludedFiles(); //Weblogic.jspc calls System.exit() ... have to fork diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index b347b8293..79c5afc87 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -463,14 +463,14 @@ public class JUnitTask extends Task int pling = u.indexOf( "!" ); String jarName = u.substring( 9, pling ); getLogger().debug( "Implicitly adding " + jarName + " to classpath" ); - createClasspath().setLocation( new File( ( new File( jarName ) ).getAbsolutePath() ) ); + createClasspath().addLocation( new File( jarName ) ); } else if( u.startsWith( "file:" ) ) { int tail = u.indexOf( resource ); String dirName = u.substring( 5, tail ); getLogger().debug( "Implicitly adding " + dirName + " to classpath" ); - createClasspath().setLocation( new File( ( new File( dirName ) ).getAbsolutePath() ) ); + createClasspath().addLocation( new File( dirName ) ); } else { diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java index cb4c04354..1b7c311f7 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java @@ -23,7 +23,6 @@ import org.apache.tools.ant.types.Argument; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathElement; /** * Somewhat abstract framework to be used for other metama 2.0 tasks. This @@ -198,9 +197,7 @@ public abstract class AbstractMetamataTask // set the classpath as the jar file File jar = getMetamataJar( m_metamataHome ); final Path classPath = m_cmdl.createClasspath(); - final PathElement pathElement = new PathElement(); - classPath.addPathElement( pathElement ); - pathElement.setLocation( jar ); + classPath.addLocation( jar ); // set the metamata.home property final Argument vmArgs = m_cmdl.createVmArgument(); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java index 0f78afd06..dc75ad39b 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java @@ -19,7 +19,6 @@ import org.apache.tools.ant.taskdefs.exec.Execute2; import org.apache.tools.ant.types.Argument; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathElement; /** * Simple Metamata MParse task based on the original written by 0 ) + if( classpath != null && classpath.toString().trim().length() > 0 ) { result[ pos++ ] = "-classpath"; - result[ pos++ ] = fullClasspath.toString(); + result[ pos++ ] = classpath.toString(); } // this is the classname to run as well as its arguments. // in case of 'executeJar', the executable is a jar file. @@ -215,8 +214,7 @@ public class CommandlineJava { int size = getActualVMCommand().size() + javaCommand.size() + sysProperties.size(); // classpath is "-classpath " -> 2 args - Path fullClasspath = classpath != null ? classpath.concatSystemClasspath( "ignore" ) : null; - if( fullClasspath != null && fullClasspath.toString().trim().length() > 0 ) + if( classpath != null && classpath.toString().trim().length() > 0 ) { size += 2; } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/types/Path.java b/proposal/myrmidon/src/main/org/apache/tools/ant/types/Path.java index d6ed72453..68d290893 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/types/Path.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/types/Path.java @@ -7,16 +7,15 @@ */ package org.apache.tools.ant.types; +import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.DataType; +import org.apache.tools.ant.util.FileUtils; + import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Locale; -import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.logger.Logger; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.ProjectComponent; -import org.apache.tools.ant.util.FileUtils; /** * This object represents a path as used by CLASSPATH or PATH environment @@ -50,41 +49,24 @@ import org.apache.tools.ant.util.FileUtils; * @author Stefan Bodewig */ public class Path - extends ProjectComponent - implements Cloneable + implements DataType { - public final static Path systemClasspath = createSystemClasspath(); - - private ArrayList m_elements; - - private static Path createSystemClasspath() - { - try - { - return new Path( System.getProperty( "java.class.path" ) ); - } - catch( final TaskException te ) - { - throw new Error( te.toString() ); - } - } + private ArrayList m_elements = new ArrayList(); + private File m_baseDirectory; /** * Invoked by IntrospectionHelper for setXXX(Path p) attribute * setters. */ public Path( final String path ) - throws TaskException { - this(); final PathElement pathElement = new PathElement(); - addPathElement( pathElement ); + m_elements.add( pathElement ); pathElement.setPath( path ); } public Path() { - m_elements = new ArrayList(); } /** @@ -99,28 +81,24 @@ public class Path } /** - * Adds a element definition to the path. - * - * @param location the location of the element to add (must not be null - * nor empty. + * Sets the base directory for this path. */ - public void setLocation( final File location ) + public void setBaseDirectory( final File baseDir ) { - final PathElement pathElement = new PathElement(); - addPathElement( pathElement ); - pathElement.setLocation( location ); + m_baseDirectory = baseDir; } /** - * Parses a path definition and creates single PathElements. + * Adds a element definition to the path. * - * @param path the path definition. + * @param location the location of the element to add (must not be null + * nor empty. */ - public void setPath( String path ) + public void addLocation( final File location ) { final PathElement pathElement = new PathElement(); - addPathElement( pathElement ); - pathElement.setPath( path ); + m_elements.add( pathElement ); + pathElement.setLocation( location ); } /** @@ -138,42 +116,7 @@ public class Path final File file = new File( list[ i ] ); if( file.exists() ) { - setLocation( file ); - } - } - } - - /** - * Emulation of extdirs feature in java >= 1.2. This method adds all files - * in the given directories (but not in sub-directories!) to the classpath, - * so that you don't have to specify them all one by one. - */ - public void addExtdirs( Path extdirs ) - throws TaskException - { - if( extdirs == null ) - { - String extProp = System.getProperty( "java.ext.dirs" ); - if( extProp != null ) - { - extdirs = new Path( extProp ); - } - else - { - return; - } - } - - final String[] dirs = extdirs.list(); - for( int i = 0; i < dirs.length; i++ ) - { - final File dir = resolveFile( dirs[ i ] ); - if( dir.exists() && dir.isDirectory() ) - { - final FileSet fileSet = new FileSet(); - fileSet.setDir( dir ); - fileSet.setIncludes( "*" ); - addFileset( fileSet ); + addLocation( file ); } } } @@ -260,73 +203,6 @@ public class Path } } - /** - * Concatenates the system class path in the order specified by the - * ${build.sysclasspath} property - using "last" as default value. - * - * @return Description of the Returned Value - */ - public Path concatSystemClasspath() - throws TaskException - { - return concatSystemClasspath( "last" ); - } - - /** - * Concatenates the system class path in the order specified by the - * ${build.sysclasspath} property - using the supplied value if - * ${build.sysclasspath} has not been set. - * - * @param defValue Description of Parameter - * @return Description of the Returned Value - */ - public Path concatSystemClasspath( String defValue ) - throws TaskException - { - Path result = new Path(); - - String order = defValue; - if( getProject() != null ) - { - String o = getProject().getProperty( "build.sysclasspath" ); - if( o != null ) - { - order = o; - } - } - - if( order.equals( "only" ) ) - { - // only: the developer knows what (s)he is doing - result.addExisting( Path.systemClasspath ); - } - else if( order.equals( "first" ) ) - { - // first: developer could use a little help - result.addExisting( Path.systemClasspath ); - result.addExisting( this ); - } - else if( order.equals( "ignore" ) ) - { - // ignore: don't trust anyone - result.addExisting( this ); - } - else - { - // last: don't trust the developer - if( !order.equals( "last" ) ) - { - final String message = "invalid value for build.sysclasspath: " + order; - getLogger().warn( message ); - } - - result.addExisting( this ); - result.addExisting( Path.systemClasspath ); - } - - return result; - } - /** * Creates a nested <path> element. * @@ -338,16 +214,9 @@ public class Path m_elements.add( path ); } - /** - * Creates the nested <pathelement> element. - */ - public void addPathElement( final PathElement pathElement ) - { - m_elements.add( pathElement ); - } - /** * Returns all path elements defined by this and nested path objects. + * The paths returned by this method are absolute. */ public String[] list() throws TaskException @@ -363,9 +232,8 @@ public class Path } else if( o instanceof PathElement ) { - final File baseDirectory = getBaseDirectory(); final PathElement element = (PathElement)o; - final String[] parts = element.getParts( baseDirectory, getLogger() ); + final String[] parts = element.getParts( m_baseDirectory ); if( parts == null ) { throw new NullPointerException( "You must either set location or path on " ); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/types/PathElement.java b/proposal/myrmidon/src/main/org/apache/tools/ant/types/PathElement.java index ab2eba7bf..955cbb03a 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/types/PathElement.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/types/PathElement.java @@ -10,17 +10,19 @@ package org.apache.tools.ant.types; import java.io.File; import org.apache.tools.ant.util.FileUtils; import org.apache.avalon.framework.logger.Logger; +import org.apache.myrmidon.api.TaskException; /** - * Helper class, holds the nested <pathelement> values. + * Helper class, holds <> values. */ -public class PathElement +class PathElement { + private String m_location; private String m_path; public void setLocation( final File location ) { - m_path = FileUtils.translateFile( location.getAbsolutePath() ); + m_location = location.getAbsolutePath(); } public void setPath( String path ) @@ -28,8 +30,13 @@ public class PathElement m_path = path; } - protected String[] getParts( final File baseDirectory, final Logger logger ) + protected String[] getParts( final File baseDirectory ) + throws TaskException { - return FileUtils.translatePath( baseDirectory, m_path, logger ); + if ( m_location != null ) + { + return new String[] { m_location }; + } + return FileUtils.translatePath( baseDirectory, m_path ); } } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/types/converters/StringToPathConverter.java b/proposal/myrmidon/src/main/org/apache/tools/ant/types/converters/StringToPathConverter.java new file mode 100644 index 000000000..2e70cccc2 --- /dev/null +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/types/converters/StringToPathConverter.java @@ -0,0 +1,53 @@ +/* + * 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.tools.ant.types.converters; + +import org.apache.avalon.framework.context.Context; +import org.apache.myrmidon.converter.AbstractConverter; +import org.apache.myrmidon.converter.ConverterException; +import org.apache.tools.ant.types.Path; + +/** + * A converter from String to Path. + * + * @author Adam Murdoch + */ +public class StringToPathConverter + extends AbstractConverter +{ + /** + * Constructors a converter. + */ + public StringToPathConverter() + { + super( String.class, Path.class ); + } + + /** + * Converts from String to Path + * + * @param original the original Object + * @param context the context in which to convert + * @return the converted object + * @exception Exception if an error occurs + */ + protected Object convert( Object original, Context context ) + throws ConverterException + { + /* + String path = (String)original; + TaskContext taskContext = (TaskContext)context; + + Path retval = new Path( path ); + retval.setBaseDirectory( taskContext.getBaseDirectory() ); + return retval; + */ + return null; + } +} + diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java b/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java index f75217b56..a1a21aac3 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/util/FileUtils.java @@ -390,11 +390,7 @@ public class FileUtils return ""; final StringBuffer result = new StringBuffer( source ); - for( int i = 0; i < result.length(); i++ ) - { - translateFileSep( result, i ); - } - + translateFileSep( result ); return result.toString(); } @@ -406,22 +402,25 @@ public class FileUtils * @param pos Description of Parameter * @return Description of the Returned Value */ - public static boolean translateFileSep( StringBuffer buffer, int pos ) + public static void translateFileSep( StringBuffer buffer ) { - if( buffer.charAt( pos ) == '/' || buffer.charAt( pos ) == '\\' ) + int len = buffer.length(); + for ( int pos = 0; pos < len; pos++ ) { - buffer.setCharAt( pos, File.separatorChar ); - return true; + char ch = buffer.charAt( pos ); + if( ch == '/' || ch == '\\' ) + { + buffer.setCharAt( pos, File.separatorChar ); + } } - return false; } /** * Splits a PATH (with : or ; as separators) into its parts. */ public static String[] translatePath( final File baseDirectory, - String source, - final Logger logger ) + String source ) + throws TaskException { final ArrayList result = new ArrayList(); if( source == null ) @@ -431,23 +430,13 @@ public class FileUtils StringBuffer element = new StringBuffer(); for( int i = 0; i < elements.length; i++ ) { + // Resolve the file relative to the base directory element.setLength( 0 ); final String pathElement = elements[ i ]; - try - { - element.append( resolveFile( baseDirectory, pathElement ) ); - } - catch( TaskException e ) - { - final String message = - "Dropping path element " + pathElement + " as it is not valid relative to the project"; - logger.debug( message ); - } + element.append( resolveFile( baseDirectory, pathElement ) ); - for( int j = 0; j < element.length(); j++ ) - { - translateFileSep( element, j ); - } + // Tidy up the separators + translateFileSep( element ); result.add( element.toString() ); } diff --git a/proposal/myrmidon/src/manifest/ant1-ant-descriptor.xml b/proposal/myrmidon/src/manifest/ant1-ant-descriptor.xml index bddae2cdc..a11b941c3 100644 --- a/proposal/myrmidon/src/manifest/ant1-ant-descriptor.xml +++ b/proposal/myrmidon/src/manifest/ant1-ant-descriptor.xml @@ -1,5 +1,17 @@ + + + + + + + + \ No newline at end of file diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index d0e9da137..ed4875ea6 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -14,10 +14,12 @@ import java.io.PrintWriter; import org.apache.avalon.excalibur.util.StringUtil; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; import org.apache.tools.ant.taskdefs.Javac; import org.apache.tools.ant.taskdefs.exec.Execute2; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.FileSet; /** * This is the default implementation for the CompilerAdapter interface. @@ -77,8 +79,6 @@ public abstract class DefaultCompilerAdapter m_compileList = attributes.getFileList(); m_compileClasspath = attributes.getClasspath(); m_baseDir = attributes.getBaseDirectory(); - m_includeAntRuntime = attributes.getIncludeantruntime(); - m_includeJavaRuntime = attributes.getIncludejavaruntime(); m_memoryInitialSize = attributes.getMemoryInitialSize(); m_memoryMaximumSize = attributes.getMemoryMaximumSize(); } @@ -283,34 +283,13 @@ public abstract class DefaultCompilerAdapter if( m_destDir != null ) { - classpath.setLocation( m_destDir ); + classpath.addLocation( m_destDir ); } - // Combine the build classpath with the system classpath, in an - // order determined by the value of build.classpath - - if( m_compileClasspath == null ) + // add the classpath + if ( m_compileClasspath != null ) { - if( m_includeAntRuntime ) - { - classpath.addExisting( Path.systemClasspath ); - } - } - else - { - if( m_includeAntRuntime ) - { - classpath.addExisting( m_compileClasspath.concatSystemClasspath( "last" ) ); - } - else - { - classpath.addExisting( m_compileClasspath.concatSystemClasspath( "ignore" ) ); - } - } - - if( m_includeJavaRuntime ) - { - classpath.addJavaRuntime(); + classpath.addExisting( m_compileClasspath ); } return classpath; @@ -437,5 +416,41 @@ public abstract class DefaultCompilerAdapter getLogger().debug( niceSourceList.toString() ); } + + /** + * Emulation of extdirs feature in java >= 1.2. This method adds all files + * in the given directories (but not in sub-directories!) to the classpath, + * so that you don't have to specify them all one by one. + */ + protected void addExtdirs( Path path ) + throws TaskException + { + if( m_extdirs == null ) + { + String extProp = System.getProperty( "java.ext.dirs" ); + if( extProp != null ) + { + m_extdirs = new Path( extProp ); + } + else + { + return; + } + } + + final String[] dirs = m_extdirs.list(); + for( int i = 0; i < dirs.length; i++ ) + { + final File dir = new File( dirs[ i ] ); + if( dir.exists() && dir.isDirectory() ) + { + final FileSet fileSet = new FileSet(); + fileSet.setDir( dir ); + fileSet.setIncludes( "*" ); + path.addFileset( fileSet ); + } + } + } + } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Gcj.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Gcj.java index e8bc69cdc..7a4406f98 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Gcj.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Gcj.java @@ -55,7 +55,7 @@ public class Gcj extends DefaultCompilerAdapter // gcj doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. - classpath.addExtdirs( m_extdirs ); + addExtdirs( classpath ); if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Jikes.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Jikes.java index b76e10ec0..95e58d444 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Jikes.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Jikes.java @@ -52,7 +52,7 @@ public class Jikes // Jikes doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. - classpath.addExtdirs( m_extdirs ); + addExtdirs( classpath ); if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Jvc.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Jvc.java index 1313c8d20..58ef83b48 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Jvc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Jvc.java @@ -40,7 +40,7 @@ public class Jvc extends DefaultCompilerAdapter // jvc doesn't support an extension dir (-extdir) // so we'll emulate it for compatibility and convenience. - classpath.addExtdirs( m_extdirs ); + addExtdirs( classpath ); if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Kjc.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Kjc.java index e4fcc74ed..d4892e6a4 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Kjc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/Kjc.java @@ -94,7 +94,7 @@ public class Kjc extends DefaultCompilerAdapter if( m_extdirs != null ) { - cp.addExtdirs( m_extdirs ); + addExtdirs( cp ); } cp.append( classpath ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/javadoc/Javadoc.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/javadoc/Javadoc.java index 15b869c43..5daea5815 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/javadoc/Javadoc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/javadoc/Javadoc.java @@ -559,14 +559,16 @@ public class Javadoc cmd.setExecutable( getJavadocExecutableName() ); // ------------------------------------------------ general javadoc arguments - if( m_classpath == null ) - m_classpath = Path.systemClasspath; - else - m_classpath = m_classpath.concatSystemClasspath( "ignore" ); + // Build the classpath to pass to Javadoc + Path classpath = new Path(); + classpath.addPath( m_sourcePath ); + if ( m_classpath != null ) + { + classpath.addPath( m_classpath ); + } cmd.createArgument().setValue( "-classpath" ); - cmd.createArgument().setValue( m_sourcePath.toString() + - System.getProperty( "path.separator" ) + m_classpath.toString() ); + cmd.createArgument().setValue( classpath.toString() ); if( m_version && m_doclet == null ) cmd.createArgument().setValue( "-version" ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/Javah.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/Javah.java index 899994647..9d266a38c 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/Javah.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/Javah.java @@ -14,6 +14,7 @@ import java.util.StringTokenizer; import org.apache.avalon.excalibur.util.StringUtil; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.AbstractTask; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Path; @@ -52,7 +53,7 @@ import org.apache.tools.ant.types.Path; */ public class Javah - extends AbstractLogEnabled + extends AbstractTask { private final static String FAIL_MSG = "Compile failed, messages should have been provided."; @@ -67,8 +68,10 @@ public class Javah private String m_cls; private File m_destDir; - public void setBootclasspath( final Path bootclasspath ) - throws TaskException + /** + * Adds an element to the bootclasspath. + */ + public void addBootclasspath( final Path bootclasspath ) { if( m_bootclasspath == null ) { @@ -76,7 +79,7 @@ public class Javah } else { - m_bootclasspath.append( bootclasspath ); + m_bootclasspath.addPath( bootclasspath ); } } @@ -85,7 +88,10 @@ public class Javah m_cls = cls; } - public void setClasspath( final Path classpath ) + /** + * Adds an element to the classpath. + */ + public void addClasspath( final Path classpath ) throws TaskException { if( m_classpath == null ) @@ -94,7 +100,7 @@ public class Javah } else { - m_classpath.append( classpath ); + m_classpath.addPath( classpath ); } } @@ -149,18 +155,6 @@ public class Javah m_verbose = verbose; } - public Path createBootclasspath() - { - if( m_bootclasspath == null ) - { - m_bootclasspath = new Path(); - } - Path path1 = m_bootclasspath; - final Path path = new Path(); - path1.addPath( path ); - return path; - } - public ClassArgument createClass() { final ClassArgument ga = new ClassArgument(); @@ -169,18 +163,6 @@ public class Javah return ga; } - public Path createClasspath() - { - if( m_classpath == null ) - { - m_classpath = new Path(); - } - Path path1 = m_classpath; - final Path path = new Path(); - path1.addPath( path ); - return path; - } - /** * Executes the task. */ @@ -188,12 +170,6 @@ public class Javah throws TaskException { validate(); - - if( m_classpath == null ) - { - m_classpath = Path.systemClasspath; - } - doClassicCompile(); } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java index d3c4bf029..0b5a92bf4 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java @@ -215,7 +215,8 @@ public class BorlandGenerateClient extends Task //classpath //add at the end of the classpath //the system classpath in order to find the tools.jar file - execTask.addClasspath( classpath.concatSystemClasspath() ); + // TODO - make sure tools.jar is in the classpath + //execTask.addClasspath( classpath.concatSystemClasspath( "last" ) ); execTask.setFork( true ); execTask.createArg().setValue( "generateclient" ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java index b160e780f..eea8c25f2 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java @@ -197,22 +197,6 @@ public class IPlanetEjbcTask extends Task executeEjbc( getParser() ); } - /** - * Returns the CLASSPATH to be used when calling EJBc. If no user CLASSPATH - * is specified, the System classpath is returned instead. - * - * @return Path The classpath to be used for EJBc. - */ - private Path getClasspath() - { - if( classpath == null ) - { - classpath = Path.systemClasspath; - } - - return classpath; - } - /** * Returns a SAXParser that may be used to process the XML descriptors. * @@ -311,10 +295,16 @@ public class IPlanetEjbcTask extends Task private void executeEjbc( SAXParser saxParser ) throws TaskException { + String classpath = null; + if( classpath != null ) + { + classpath = this.classpath.toString(); + } + IPlanetEjbc ejbc = new IPlanetEjbc( ejbdescriptor, iasdescriptor, dest, - getClasspath().toString(), + classpath, saxParser ); ejbc.setRetainSource( keepgenerated ); ejbc.setDebugOutput( debug ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java index 30ffc7782..58d4859bb 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java @@ -17,7 +17,6 @@ import org.apache.tools.ant.taskdefs.exec.Execute2; import org.apache.tools.ant.types.Argument; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathElement; /** * Taskdef for the JJTree compiler compiler. @@ -175,10 +174,7 @@ public class JJTree extends Task throw new TaskException( "Javacchome not set." ); } final Path classpath = cmdl.createClasspath(); - final PathElement pathElement = new PathElement(); - classpath.addPathElement( pathElement ); - pathElement.setPath( javaccHome.getAbsolutePath() + - "/JavaCC.zip" ); + classpath.addLocation( new File( javaccHome, "JavaCC.zip" ) ); classpath.addJavaRuntime(); final Argument arg = cmdl.createVmArgument(); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java index 08ab55195..6754430b6 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java @@ -18,7 +18,6 @@ import org.apache.tools.ant.types.Argument; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathElement; import org.apache.avalon.excalibur.util.StringUtil; /** @@ -229,10 +228,7 @@ public class JavaCC extends Task throw new TaskException( "Javacchome not set." ); } final Path classpath = cmdl.createClasspath(); - final PathElement pathElement = new PathElement(); - classpath.addPathElement( pathElement ); - pathElement.setPath( javaccHome.getAbsolutePath() + - "/JavaCC.zip" ); + classpath.addLocation( new File( javaccHome, "JavaCC.zip" ) ); classpath.addJavaRuntime(); final Argument arg = cmdl.createVmArgument(); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java index 707bbe227..92e0883e9 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java @@ -163,7 +163,9 @@ public class WLJspc extends MatchingTask compileClasspath = new Path(); } - compileClasspath.append( Path.systemClasspath ); + // TODO - make sure tools.jar ends up in the classpath + //compileClasspath.append( Path.systemClasspath ); + String[] files = ds.getIncludedFiles(); //Weblogic.jspc calls System.exit() ... have to fork diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index b347b8293..79c5afc87 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -463,14 +463,14 @@ public class JUnitTask extends Task int pling = u.indexOf( "!" ); String jarName = u.substring( 9, pling ); getLogger().debug( "Implicitly adding " + jarName + " to classpath" ); - createClasspath().setLocation( new File( ( new File( jarName ) ).getAbsolutePath() ) ); + createClasspath().addLocation( new File( jarName ) ); } else if( u.startsWith( "file:" ) ) { int tail = u.indexOf( resource ); String dirName = u.substring( 5, tail ); getLogger().debug( "Implicitly adding " + dirName + " to classpath" ); - createClasspath().setLocation( new File( ( new File( dirName ) ).getAbsolutePath() ) ); + createClasspath().addLocation( new File( dirName ) ); } else { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java index cb4c04354..1b7c311f7 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java @@ -23,7 +23,6 @@ import org.apache.tools.ant.types.Argument; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathElement; /** * Somewhat abstract framework to be used for other metama 2.0 tasks. This @@ -198,9 +197,7 @@ public abstract class AbstractMetamataTask // set the classpath as the jar file File jar = getMetamataJar( m_metamataHome ); final Path classPath = m_cmdl.createClasspath(); - final PathElement pathElement = new PathElement(); - classPath.addPathElement( pathElement ); - pathElement.setLocation( jar ); + classPath.addLocation( jar ); // set the metamata.home property final Argument vmArgs = m_cmdl.createVmArgument(); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java index 0f78afd06..dc75ad39b 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java @@ -19,7 +19,6 @@ import org.apache.tools.ant.taskdefs.exec.Execute2; import org.apache.tools.ant.types.Argument; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathElement; /** * Simple Metamata MParse task based on the original written by 0 ) + if( classpath != null && classpath.toString().trim().length() > 0 ) { result[ pos++ ] = "-classpath"; - result[ pos++ ] = fullClasspath.toString(); + result[ pos++ ] = classpath.toString(); } // this is the classname to run as well as its arguments. // in case of 'executeJar', the executable is a jar file. @@ -215,8 +214,7 @@ public class CommandlineJava { int size = getActualVMCommand().size() + javaCommand.size() + sysProperties.size(); // classpath is "-classpath " -> 2 args - Path fullClasspath = classpath != null ? classpath.concatSystemClasspath( "ignore" ) : null; - if( fullClasspath != null && fullClasspath.toString().trim().length() > 0 ) + if( classpath != null && classpath.toString().trim().length() > 0 ) { size += 2; } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Path.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Path.java index d6ed72453..68d290893 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Path.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Path.java @@ -7,16 +7,15 @@ */ package org.apache.tools.ant.types; +import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.DataType; +import org.apache.tools.ant.util.FileUtils; + import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Locale; -import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.logger.Logger; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.ProjectComponent; -import org.apache.tools.ant.util.FileUtils; /** * This object represents a path as used by CLASSPATH or PATH environment @@ -50,41 +49,24 @@ import org.apache.tools.ant.util.FileUtils; * @author Stefan Bodewig */ public class Path - extends ProjectComponent - implements Cloneable + implements DataType { - public final static Path systemClasspath = createSystemClasspath(); - - private ArrayList m_elements; - - private static Path createSystemClasspath() - { - try - { - return new Path( System.getProperty( "java.class.path" ) ); - } - catch( final TaskException te ) - { - throw new Error( te.toString() ); - } - } + private ArrayList m_elements = new ArrayList(); + private File m_baseDirectory; /** * Invoked by IntrospectionHelper for setXXX(Path p) attribute * setters. */ public Path( final String path ) - throws TaskException { - this(); final PathElement pathElement = new PathElement(); - addPathElement( pathElement ); + m_elements.add( pathElement ); pathElement.setPath( path ); } public Path() { - m_elements = new ArrayList(); } /** @@ -99,28 +81,24 @@ public class Path } /** - * Adds a element definition to the path. - * - * @param location the location of the element to add (must not be null - * nor empty. + * Sets the base directory for this path. */ - public void setLocation( final File location ) + public void setBaseDirectory( final File baseDir ) { - final PathElement pathElement = new PathElement(); - addPathElement( pathElement ); - pathElement.setLocation( location ); + m_baseDirectory = baseDir; } /** - * Parses a path definition and creates single PathElements. + * Adds a element definition to the path. * - * @param path the path definition. + * @param location the location of the element to add (must not be null + * nor empty. */ - public void setPath( String path ) + public void addLocation( final File location ) { final PathElement pathElement = new PathElement(); - addPathElement( pathElement ); - pathElement.setPath( path ); + m_elements.add( pathElement ); + pathElement.setLocation( location ); } /** @@ -138,42 +116,7 @@ public class Path final File file = new File( list[ i ] ); if( file.exists() ) { - setLocation( file ); - } - } - } - - /** - * Emulation of extdirs feature in java >= 1.2. This method adds all files - * in the given directories (but not in sub-directories!) to the classpath, - * so that you don't have to specify them all one by one. - */ - public void addExtdirs( Path extdirs ) - throws TaskException - { - if( extdirs == null ) - { - String extProp = System.getProperty( "java.ext.dirs" ); - if( extProp != null ) - { - extdirs = new Path( extProp ); - } - else - { - return; - } - } - - final String[] dirs = extdirs.list(); - for( int i = 0; i < dirs.length; i++ ) - { - final File dir = resolveFile( dirs[ i ] ); - if( dir.exists() && dir.isDirectory() ) - { - final FileSet fileSet = new FileSet(); - fileSet.setDir( dir ); - fileSet.setIncludes( "*" ); - addFileset( fileSet ); + addLocation( file ); } } } @@ -260,73 +203,6 @@ public class Path } } - /** - * Concatenates the system class path in the order specified by the - * ${build.sysclasspath} property - using "last" as default value. - * - * @return Description of the Returned Value - */ - public Path concatSystemClasspath() - throws TaskException - { - return concatSystemClasspath( "last" ); - } - - /** - * Concatenates the system class path in the order specified by the - * ${build.sysclasspath} property - using the supplied value if - * ${build.sysclasspath} has not been set. - * - * @param defValue Description of Parameter - * @return Description of the Returned Value - */ - public Path concatSystemClasspath( String defValue ) - throws TaskException - { - Path result = new Path(); - - String order = defValue; - if( getProject() != null ) - { - String o = getProject().getProperty( "build.sysclasspath" ); - if( o != null ) - { - order = o; - } - } - - if( order.equals( "only" ) ) - { - // only: the developer knows what (s)he is doing - result.addExisting( Path.systemClasspath ); - } - else if( order.equals( "first" ) ) - { - // first: developer could use a little help - result.addExisting( Path.systemClasspath ); - result.addExisting( this ); - } - else if( order.equals( "ignore" ) ) - { - // ignore: don't trust anyone - result.addExisting( this ); - } - else - { - // last: don't trust the developer - if( !order.equals( "last" ) ) - { - final String message = "invalid value for build.sysclasspath: " + order; - getLogger().warn( message ); - } - - result.addExisting( this ); - result.addExisting( Path.systemClasspath ); - } - - return result; - } - /** * Creates a nested <path> element. * @@ -338,16 +214,9 @@ public class Path m_elements.add( path ); } - /** - * Creates the nested <pathelement> element. - */ - public void addPathElement( final PathElement pathElement ) - { - m_elements.add( pathElement ); - } - /** * Returns all path elements defined by this and nested path objects. + * The paths returned by this method are absolute. */ public String[] list() throws TaskException @@ -363,9 +232,8 @@ public class Path } else if( o instanceof PathElement ) { - final File baseDirectory = getBaseDirectory(); final PathElement element = (PathElement)o; - final String[] parts = element.getParts( baseDirectory, getLogger() ); + final String[] parts = element.getParts( m_baseDirectory ); if( parts == null ) { throw new NullPointerException( "You must either set location or path on " ); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/PathElement.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/PathElement.java index ab2eba7bf..955cbb03a 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/PathElement.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/PathElement.java @@ -10,17 +10,19 @@ package org.apache.tools.ant.types; import java.io.File; import org.apache.tools.ant.util.FileUtils; import org.apache.avalon.framework.logger.Logger; +import org.apache.myrmidon.api.TaskException; /** - * Helper class, holds the nested <pathelement> values. + * Helper class, holds <> values. */ -public class PathElement +class PathElement { + private String m_location; private String m_path; public void setLocation( final File location ) { - m_path = FileUtils.translateFile( location.getAbsolutePath() ); + m_location = location.getAbsolutePath(); } public void setPath( String path ) @@ -28,8 +30,13 @@ public class PathElement m_path = path; } - protected String[] getParts( final File baseDirectory, final Logger logger ) + protected String[] getParts( final File baseDirectory ) + throws TaskException { - return FileUtils.translatePath( baseDirectory, m_path, logger ); + if ( m_location != null ) + { + return new String[] { m_location }; + } + return FileUtils.translatePath( baseDirectory, m_path ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/converters/StringToPathConverter.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/converters/StringToPathConverter.java new file mode 100644 index 000000000..2e70cccc2 --- /dev/null +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/converters/StringToPathConverter.java @@ -0,0 +1,53 @@ +/* + * 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.tools.ant.types.converters; + +import org.apache.avalon.framework.context.Context; +import org.apache.myrmidon.converter.AbstractConverter; +import org.apache.myrmidon.converter.ConverterException; +import org.apache.tools.ant.types.Path; + +/** + * A converter from String to Path. + * + * @author Adam Murdoch + */ +public class StringToPathConverter + extends AbstractConverter +{ + /** + * Constructors a converter. + */ + public StringToPathConverter() + { + super( String.class, Path.class ); + } + + /** + * Converts from String to Path + * + * @param original the original Object + * @param context the context in which to convert + * @return the converted object + * @exception Exception if an error occurs + */ + protected Object convert( Object original, Context context ) + throws ConverterException + { + /* + String path = (String)original; + TaskContext taskContext = (TaskContext)context; + + Path retval = new Path( path ); + retval.setBaseDirectory( taskContext.getBaseDirectory() ); + return retval; + */ + return null; + } +} + diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java index f75217b56..a1a21aac3 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/util/FileUtils.java @@ -390,11 +390,7 @@ public class FileUtils return ""; final StringBuffer result = new StringBuffer( source ); - for( int i = 0; i < result.length(); i++ ) - { - translateFileSep( result, i ); - } - + translateFileSep( result ); return result.toString(); } @@ -406,22 +402,25 @@ public class FileUtils * @param pos Description of Parameter * @return Description of the Returned Value */ - public static boolean translateFileSep( StringBuffer buffer, int pos ) + public static void translateFileSep( StringBuffer buffer ) { - if( buffer.charAt( pos ) == '/' || buffer.charAt( pos ) == '\\' ) + int len = buffer.length(); + for ( int pos = 0; pos < len; pos++ ) { - buffer.setCharAt( pos, File.separatorChar ); - return true; + char ch = buffer.charAt( pos ); + if( ch == '/' || ch == '\\' ) + { + buffer.setCharAt( pos, File.separatorChar ); + } } - return false; } /** * Splits a PATH (with : or ; as separators) into its parts. */ public static String[] translatePath( final File baseDirectory, - String source, - final Logger logger ) + String source ) + throws TaskException { final ArrayList result = new ArrayList(); if( source == null ) @@ -431,23 +430,13 @@ public class FileUtils StringBuffer element = new StringBuffer(); for( int i = 0; i < elements.length; i++ ) { + // Resolve the file relative to the base directory element.setLength( 0 ); final String pathElement = elements[ i ]; - try - { - element.append( resolveFile( baseDirectory, pathElement ) ); - } - catch( TaskException e ) - { - final String message = - "Dropping path element " + pathElement + " as it is not valid relative to the project"; - logger.debug( message ); - } + element.append( resolveFile( baseDirectory, pathElement ) ); - for( int j = 0; j < element.length(); j++ ) - { - translateFileSep( element, j ); - } + // Tidy up the separators + translateFileSep( element ); result.add( element.toString() ); }