* 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 <path> may not contain nested <pathlocation> elements any more. Nested <path> elements can be used to do the same thing. * Removed Path.systemClasspath and Path.concatSystemClassPath(). The goal is to add specialised <systemclasspath>, <antruntime>, and <javaruntime> 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-ffa450edef68master
@@ -387,14 +387,12 @@ Legal: | |||
</zipfileset> | |||
</jar> | |||
<!-- | |||
<jar jarfile="${build.lib}/ant1.atl" basedir="${build.classes}"> | |||
<include name="org/apache/antlib/ant1/**"/> | |||
<zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml"> | |||
<include name="ant1-ant-descriptor.xml"/> | |||
</zipfileset> | |||
</jar> | |||
--> | |||
</target> | |||
@@ -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 ); | |||
} | |||
} | |||
} | |||
} | |||
@@ -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 ) ) | |||
{ | |||
@@ -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 ) ) | |||
{ | |||
@@ -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 ) ) | |||
{ | |||
@@ -94,7 +94,7 @@ public class Kjc extends DefaultCompilerAdapter | |||
if( m_extdirs != null ) | |||
{ | |||
cp.addExtdirs( m_extdirs ); | |||
addExtdirs( cp ); | |||
} | |||
cp.append( classpath ); | |||
@@ -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" ); | |||
@@ -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(); | |||
} | |||
@@ -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" ); | |||
@@ -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 ); | |||
@@ -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(); | |||
@@ -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(); | |||
@@ -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 | |||
@@ -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 | |||
{ | |||
@@ -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(); | |||
@@ -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 <a | |||
@@ -204,9 +203,7 @@ public class MParse | |||
final Path classPath = m_cmdl.createClasspath(); | |||
for( int i = 0; i < jars.length; i++ ) | |||
{ | |||
final PathElement pathElement = new PathElement(); | |||
classPath.addPathElement( pathElement ); | |||
pathElement.setLocation( jars[ i ] ); | |||
classPath.addLocation( jars[ i ] ); | |||
} | |||
// set the metamata.home property | |||
@@ -177,34 +177,14 @@ public abstract class DefaultRmicAdapter | |||
// add dest dir to classpath so that previously compiled and | |||
// untouched classes are on classpath | |||
Path classpath = new Path(); | |||
classpath.setLocation( attributes.getBase() ); | |||
classpath.addLocation( attributes.getBase() ); | |||
// Combine the build classpath with the system classpath, in an | |||
// order determined by the value of build.classpath | |||
if( attributes.getClasspath() == null ) | |||
{ | |||
if( attributes.getIncludeantruntime() ) | |||
{ | |||
classpath.addExisting( Path.systemClasspath ); | |||
} | |||
} | |||
else | |||
// add the classpath | |||
if ( attributes.getClasspath() != null ) | |||
{ | |||
if( attributes.getIncludeantruntime() ) | |||
{ | |||
classpath.addExisting( attributes.getClasspath().concatSystemClasspath( "last" ) ); | |||
} | |||
else | |||
{ | |||
classpath.addExisting( attributes.getClasspath().concatSystemClasspath( "ignore" ) ); | |||
} | |||
classpath.addExisting( attributes.getClasspath() ); | |||
} | |||
if( attributes.getIncludejavaruntime() ) | |||
{ | |||
classpath.addJavaRuntime(); | |||
} | |||
return classpath; | |||
} | |||
@@ -132,11 +132,10 @@ public class CommandlineJava | |||
pos += sysProperties.size(); | |||
} | |||
// classpath is a vm option too.. | |||
Path fullClasspath = classpath != null ? classpath.concatSystemClasspath( "ignore" ) : null; | |||
if( fullClasspath != null && fullClasspath.toString().trim().length() > 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 <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; | |||
} | |||
@@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
*/ | |||
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 <code>setXXX(Path p)</code> 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 <code>null</code> | |||
* 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 <code>null</code> | |||
* 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 <code><path></code> element. | |||
* | |||
@@ -338,16 +214,9 @@ public class Path | |||
m_elements.add( path ); | |||
} | |||
/** | |||
* Creates the nested <code><pathelement></code> 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 <pathelement>" ); | |||
@@ -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 <code><pathelement></code> values. | |||
* Helper class, holds <code><></code> 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 ); | |||
} | |||
} |
@@ -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; | |||
} | |||
} | |||
@@ -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() ); | |||
} | |||
@@ -1,5 +1,17 @@ | |||
<ant-lib> | |||
<types> | |||
<task name="ant1-tasklib" classname="org.apache.myrmidon.libs.ant1.Ant1Tasklib" /> | |||
<data-type name="path" classname="org.apache.tools.ant.types.Path" /> | |||
<task name="path" classname="org.apache.myrmidon.framework.TypeInstanceTask" /> | |||
</types> | |||
<converters> | |||
<converter | |||
classname="org.apache.tools.ant.types.converters.StringToPathConverter" | |||
source="java.lang.String" | |||
destination="org.apache.tools.ant.types.Path" | |||
/> | |||
</converters> | |||
</ant-lib> |
@@ -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 ); | |||
} | |||
} | |||
} | |||
} | |||
@@ -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 ) ) | |||
{ | |||
@@ -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 ) ) | |||
{ | |||
@@ -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 ) ) | |||
{ | |||
@@ -94,7 +94,7 @@ public class Kjc extends DefaultCompilerAdapter | |||
if( m_extdirs != null ) | |||
{ | |||
cp.addExtdirs( m_extdirs ); | |||
addExtdirs( cp ); | |||
} | |||
cp.append( classpath ); | |||
@@ -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" ); | |||
@@ -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(); | |||
} | |||
@@ -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" ); | |||
@@ -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 ); | |||
@@ -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(); | |||
@@ -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(); | |||
@@ -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 | |||
@@ -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 | |||
{ | |||
@@ -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(); | |||
@@ -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 <a | |||
@@ -204,9 +203,7 @@ public class MParse | |||
final Path classPath = m_cmdl.createClasspath(); | |||
for( int i = 0; i < jars.length; i++ ) | |||
{ | |||
final PathElement pathElement = new PathElement(); | |||
classPath.addPathElement( pathElement ); | |||
pathElement.setLocation( jars[ i ] ); | |||
classPath.addLocation( jars[ i ] ); | |||
} | |||
// set the metamata.home property | |||
@@ -177,34 +177,14 @@ public abstract class DefaultRmicAdapter | |||
// add dest dir to classpath so that previously compiled and | |||
// untouched classes are on classpath | |||
Path classpath = new Path(); | |||
classpath.setLocation( attributes.getBase() ); | |||
classpath.addLocation( attributes.getBase() ); | |||
// Combine the build classpath with the system classpath, in an | |||
// order determined by the value of build.classpath | |||
if( attributes.getClasspath() == null ) | |||
{ | |||
if( attributes.getIncludeantruntime() ) | |||
{ | |||
classpath.addExisting( Path.systemClasspath ); | |||
} | |||
} | |||
else | |||
// add the classpath | |||
if ( attributes.getClasspath() != null ) | |||
{ | |||
if( attributes.getIncludeantruntime() ) | |||
{ | |||
classpath.addExisting( attributes.getClasspath().concatSystemClasspath( "last" ) ); | |||
} | |||
else | |||
{ | |||
classpath.addExisting( attributes.getClasspath().concatSystemClasspath( "ignore" ) ); | |||
} | |||
classpath.addExisting( attributes.getClasspath() ); | |||
} | |||
if( attributes.getIncludejavaruntime() ) | |||
{ | |||
classpath.addJavaRuntime(); | |||
} | |||
return classpath; | |||
} | |||
@@ -132,11 +132,10 @@ public class CommandlineJava | |||
pos += sysProperties.size(); | |||
} | |||
// classpath is a vm option too.. | |||
Path fullClasspath = classpath != null ? classpath.concatSystemClasspath( "ignore" ) : null; | |||
if( fullClasspath != null && fullClasspath.toString().trim().length() > 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 <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; | |||
} | |||
@@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
*/ | |||
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 <code>setXXX(Path p)</code> 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 <code>null</code> | |||
* 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 <code>null</code> | |||
* 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 <code><path></code> element. | |||
* | |||
@@ -338,16 +214,9 @@ public class Path | |||
m_elements.add( path ); | |||
} | |||
/** | |||
* Creates the nested <code><pathelement></code> 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 <pathelement>" ); | |||
@@ -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 <code><pathelement></code> values. | |||
* Helper class, holds <code><></code> 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 ); | |||
} | |||
} |
@@ -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; | |||
} | |||
} | |||
@@ -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() ); | |||
} | |||