Browse Source

Removed AntClassLoader and replaced it with URLClassLoader. Now new ClassLoaders do not include the ant runtime by default

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270450 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
093967db0e
34 changed files with 356 additions and 2643 deletions
  1. +5
    -8
      proposal/myrmidon/src/java/org/apache/antlib/xml/XMLValidateTask.java
  2. +3
    -5
      proposal/myrmidon/src/java/org/apache/antlib/xml/XSLTProcess.java
  3. +0
    -1118
      proposal/myrmidon/src/main/org/apache/tools/ant/AntClassLoader.java
  4. +70
    -92
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Available.java
  5. +21
    -30
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
  6. +7
    -15
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java
  7. +2
    -2
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Rmic.java
  8. +18
    -20
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
  9. +1
    -2
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  10. +4
    -3
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java
  11. +2
    -2
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
  12. +2
    -2
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
  13. +2
    -2
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
  14. +8
    -9
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  15. +0
    -4
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  16. +3
    -7
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
  17. +5
    -6
      proposal/myrmidon/src/main/org/apache/tools/ant/types/Mapper.java
  18. +29
    -1
      proposal/myrmidon/src/main/org/apache/tools/ant/types/Path.java
  19. +0
    -1118
      proposal/myrmidon/src/todo/org/apache/tools/ant/AntClassLoader.java
  20. +70
    -92
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Available.java
  21. +21
    -30
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/ExecuteJava.java
  22. +7
    -15
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java
  23. +2
    -2
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Rmic.java
  24. +18
    -20
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/SQLExec.java
  25. +1
    -2
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  26. +4
    -3
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/depend/Depend.java
  27. +2
    -2
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
  28. +2
    -2
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
  29. +2
    -2
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
  30. +8
    -9
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  31. +0
    -4
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  32. +3
    -7
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
  33. +5
    -6
      proposal/myrmidon/src/todo/org/apache/tools/ant/types/Mapper.java
  34. +29
    -1
      proposal/myrmidon/src/todo/org/apache/tools/ant/types/Path.java

+ 5
- 8
proposal/myrmidon/src/java/org/apache/antlib/xml/XMLValidateTask.java View File

@@ -15,13 +15,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
@@ -369,17 +368,15 @@ public class XMLValidateTask
// load the parser class
// with JAXP, we would use a SAXParser factory
Class readerClass = null;
//Class readerImpl = null;
//Class parserImpl = null;
if( classpath != null )
{
AntClassLoader loader = new AntClassLoader( getProject(), classpath );
// loader.addSystemPackageRoot("org.xml"); // needed to avoid conflict
readerClass = loader.loadClass( readerClassName );
AntClassLoader.initializeClass( readerClass );
final ClassLoader classLoader = new URLClassLoader( classpath.toURLs() );
readerClass = classLoader.loadClass( readerClassName );
}
else
{
readerClass = Class.forName( readerClassName );
}

// then check it implements XMLReader
if( XMLReader.class.isAssignableFrom( readerClass ) )


+ 3
- 5
proposal/myrmidon/src/java/org/apache/antlib/xml/XSLTProcess.java View File

@@ -8,10 +8,10 @@
package org.apache.antlib.xml;

import java.io.File;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
@@ -378,10 +378,8 @@ public class XSLTProcess
}
else
{
AntClassLoader al = new AntClassLoader( getProject(), m_classpath );
Class c = al.loadClass( classname );
AntClassLoader.initializeClass( c );
return c;
final ClassLoader classLoader = new URLClassLoader( m_classpath.toURLs() );
return classLoader.loadClass( classname );
}
}



+ 0
- 1118
proposal/myrmidon/src/main/org/apache/tools/ant/AntClassLoader.java
File diff suppressed because it is too large
View File


+ 70
- 92
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Available.java View File

@@ -8,8 +8,9 @@
package org.apache.tools.ant.taskdefs;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.condition.Condition;
import org.apache.tools.ant.types.EnumeratedAttribute;
@@ -29,22 +30,22 @@ public class Available
extends Task
implements Condition
{
private String value = "true";
private String classname;
private Path classpath;
private String file;
private Path filepath;
private AntClassLoader loader;
private String m_value = "true";
private String m_classname;
private Path m_classpath;
private String m_file;
private Path m_filepath;
private ClassLoader m_classLoader;

private String property;
private String resource;
private FileDir type;
private String m_property;
private String m_resource;
private FileDir m_type;

public void setClassname( String classname )
{
if( !"".equals( classname ) )
{
this.classname = classname;
m_classname = classname;
}
}

@@ -62,7 +63,7 @@ public class Available

public void setFile( String file )
{
this.file = file;
m_file = file;
}

public void setFilepath( Path filepath )
@@ -73,102 +74,98 @@ public class Available

public void setProperty( String property )
{
this.property = property;
m_property = property;
}

public void setResource( String resource )
{
this.resource = resource;
m_resource = resource;
}

public void setType( FileDir type )
{
this.type = type;
m_type = type;
}

public void setValue( String value )
{
this.value = value;
m_value = value;
}

public Path createClasspath()
throws TaskException
{
if( this.classpath == null )
if( m_classpath == null )
{
this.classpath = new Path();
m_classpath = new Path();
}
return this.classpath.createPath();
return m_classpath.createPath();
}

public Path createFilepath()
throws TaskException
{
if( this.filepath == null )
if( m_filepath == null )
{
this.filepath = new Path();
m_filepath = new Path();
}
return this.filepath.createPath();
return m_filepath.createPath();
}

public boolean eval()
throws TaskException
{
if( classname == null && file == null && resource == null )
if( m_classname == null && m_file == null && m_resource == null )
{
throw new TaskException( "At least one of (classname|file|resource) is required" );
}

if( type != null )
if( m_type != null )
{
if( file == null )
if( m_file == null )
{
throw new TaskException( "The type attribute is only valid when specifying the file attribute." );
}
}

if( classpath != null )
if( m_classpath != null )
{
this.loader = new AntClassLoader( getProject(), classpath );
final URL[] urls = m_classpath.toURLs();
m_classLoader = new URLClassLoader( urls );
}

if( ( classname != null ) && !checkClass( classname ) )
if( ( m_classname != null ) && !checkClass( m_classname ) )
{
getLogger().debug( "Unable to load class " + classname + " to set property " + property );
getLogger().debug( "Unable to load class " + m_classname + " to set property " + m_property );
return false;
}

if( ( file != null ) && !checkFile() )
if( ( m_file != null ) && !checkFile() )
{
if( type != null )
if( m_type != null )
{
getLogger().debug( "Unable to find " + type + " " + file + " to set property " + property );
getLogger().debug( "Unable to find " + m_type + " " + m_file + " to set property " + m_property );
}
else
{
getLogger().debug( "Unable to find " + file + " to set property " + property );
getLogger().debug( "Unable to find " + m_file + " to set property " + m_property );
}
return false;
}

if( ( resource != null ) && !checkResource( resource ) )
if( ( m_resource != null ) && !checkResource( m_resource ) )
{
getLogger().debug( "Unable to load resource " + resource + " to set property " + property );
getLogger().debug( "Unable to load resource " + m_resource + " to set property " + m_property );
return false;
}

if( loader != null )
{
loader.cleanup();
}

return true;
}

public void execute()
throws TaskException
{
if( property == null )
if( m_property == null )
{
throw new TaskException( "property attribute is required" );
}
@@ -176,9 +173,9 @@ public class Available
if( eval() )
{
String lSep = System.getProperty( "line.separator" );
if( null == getProject().getProperty( property ) )
if( null == getProject().getProperty( m_property ) )
{
setProperty( property, value );
setProperty( m_property, m_value );
}
//else ignore
}
@@ -188,24 +185,8 @@ public class Available
{
try
{
if( loader != null )
{
loader.loadClass( classname );
}
else
{
ClassLoader l = this.getClass().getClassLoader();
// Can return null to represent the bootstrap class loader.
// see API docs of Class.getClassLoader.
if( l != null )
{
l.loadClass( classname );
}
else
{
Class.forName( classname );
}
}
final ClassLoader classLoader = getClassLoader();
classLoader.loadClass( classname );
return true;
}
catch( ClassNotFoundException e )
@@ -221,13 +202,13 @@ public class Available
private boolean checkFile()
throws TaskException
{
if( filepath == null )
if( m_filepath == null )
{
return checkFile( resolveFile( file ), file );
return checkFile( resolveFile( m_file ), m_file );
}
else
{
String[] paths = filepath.list();
String[] paths = m_filepath.list();
for( int i = 0; i < paths.length; ++i )
{
getLogger().debug( "Searching " + paths[ i ] );
@@ -248,20 +229,20 @@ public class Available

// ** full-pathname specified == path in list
// ** simple name specified == path in list
if( path.exists() && file.equals( paths[ i ] ) )
if( path.exists() && m_file.equals( paths[ i ] ) )
{
if( type == null )
if( m_type == null )
{
getLogger().debug( "Found: " + path );
return true;
}
else if( type.isDir()
else if( m_type.isDir()
&& path.isDirectory() )
{
getLogger().debug( "Found directory: " + path );
return true;
}
else if( type.isFile()
else if( m_type.isFile()
&& path.isFile() )
{
getLogger().debug( "Found file: " + path );
@@ -274,14 +255,14 @@ public class Available
File parent = path.getParentFile();
// ** full-pathname specified == parent dir of path in list
if( parent != null && parent.exists()
&& file.equals( parent.getAbsolutePath() ) )
&& m_file.equals( parent.getAbsolutePath() ) )
{
if( type == null )
if( m_type == null )
{
getLogger().debug( "Found: " + parent );
return true;
}
else if( type.isDir() )
else if( m_type.isDir() )
{
getLogger().debug( "Found directory: " + parent );
return true;
@@ -293,8 +274,8 @@ public class Available
// ** simple name specified == path in list + name
if( path.exists() && path.isDirectory() )
{
if( checkFile( new File( path, file ),
file + " in " + path ) )
if( checkFile( new File( path, m_file ),
m_file + " in " + path ) )
{
return true;
}
@@ -303,8 +284,8 @@ public class Available
// ** simple name specified == parent dir + name
if( parent != null && parent.exists() )
{
if( checkFile( new File( parent, file ),
file + " in " + parent ) )
if( checkFile( new File( parent, m_file ),
m_file + " in " + parent ) )
{
return true;
}
@@ -316,8 +297,8 @@ public class Available
File grandParent = parent.getParentFile();
if( grandParent != null && grandParent.exists() )
{
if( checkFile( new File( grandParent, file ),
file + " in " + grandParent ) )
if( checkFile( new File( grandParent, m_file ),
m_file + " in " + grandParent ) )
{
return true;
}
@@ -330,9 +311,9 @@ public class Available

private boolean checkFile( File f, String text )
{
if( type != null )
if( m_type != null )
{
if( type.isDir() )
if( m_type.isDir() )
{
if( f.isDirectory() )
{
@@ -340,7 +321,7 @@ public class Available
}
return f.isDirectory();
}
else if( type.isFile() )
else if( m_type.isFile() )
{
if( f.isFile() )
{
@@ -358,22 +339,19 @@ public class Available

private boolean checkResource( String resource )
{
if( loader != null )
final ClassLoader classLoader = getClassLoader();
return ( null != classLoader.getResourceAsStream( resource ) );
}

private ClassLoader getClassLoader()
{
if( null == m_classLoader )
{
return ( loader.getResourceAsStream( resource ) != null );
return ClassLoader.getSystemClassLoader();
}
else
{
ClassLoader cL = this.getClass().getClassLoader();
if( cL != null )
{
return ( cL.getResourceAsStream( resource ) != null );
}
else
{
return
( ClassLoader.getSystemResourceAsStream( resource ) != null );
}
return m_classLoader;
}
}



+ 21
- 30
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java View File

@@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava;
@@ -20,56 +21,51 @@ import org.apache.tools.ant.types.Path;
* @author thomas.haas@softwired-inc.com
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/

public class ExecuteJava
{
private Commandline m_javaCommand;
private Path m_classpath;
private CommandlineJava.SysProperties m_sysProperties;

private Commandline javaCommand = null;
private Path classpath = null;
private CommandlineJava.SysProperties sysProperties = null;

public void setClasspath( Path p )
public void setClasspath( final Path classpath )
{
classpath = p;
m_classpath = classpath;
}

public void setJavaCommand( Commandline javaCommand )
public void setJavaCommand( final Commandline javaCommand )
{
this.javaCommand = javaCommand;
m_javaCommand = javaCommand;
}

public void setSystemProperties( CommandlineJava.SysProperties s )
public void setSystemProperties( final CommandlineJava.SysProperties sysProperties )
{
sysProperties = s;
m_sysProperties = sysProperties;
}

public void execute( Project project )
throws TaskException
{
final String classname = javaCommand.getExecutable();
final Object[] argument = {javaCommand.getArguments()};
final String classname = m_javaCommand.getExecutable();
final Object[] argument = {m_javaCommand.getArguments()};

AntClassLoader loader = null;
try
{
if( sysProperties != null )
if( m_sysProperties != null )
{
sysProperties.setSystem();
m_sysProperties.setSystem();
}

final Class[] param = {Class.forName( "[Ljava.lang.String;" )};
Class target = null;
if( classpath == null )
if( m_classpath == null )
{
target = Class.forName( classname );
}
else
{
loader = new AntClassLoader( Project.class.getClassLoader(), project, classpath, false );
loader.setIsolated( true );
loader.setThreadContextLoader();
target = loader.forceLoadClass( classname );
AntClassLoader.initializeClass( target );
final URL[] urls = m_classpath.toURLs();
final URLClassLoader classLoader = new URLClassLoader( urls );
target = classLoader.loadClass( classname );
}
final Method main = target.getMethod( "main", param );
main.invoke( null, argument );
@@ -100,14 +96,9 @@ public class ExecuteJava
}
finally
{
if( loader != null )
{
loader.resetThreadContextLoader();
loader.cleanup();
}
if( sysProperties != null )
if( m_sysProperties != null )
{
sysProperties.restoreSystem();
m_sysProperties.restoreSystem();
}
}
}


+ 7
- 15
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java View File

@@ -11,13 +11,13 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Iterator;
import java.util.Properties;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.exec.Environment;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
@@ -269,26 +269,18 @@ public class Property
getLogger().debug( "Resource Loading " + name );
try
{
ClassLoader cL = null;
InputStream is = null;
ClassLoader classLoader = null;

if( m_classpath != null )
{
cL = new AntClassLoader( getProject(), m_classpath );
final URL[] urls = m_classpath.toURLs();
classLoader = new URLClassLoader( urls );
}
else
{
cL = getClass().getClassLoader();
}

if( cL == null )
{
is = ClassLoader.getSystemResourceAsStream( name );
}
else
{
is = cL.getResourceAsStream( name );
classLoader = ClassLoader.getSystemClassLoader();
}
final InputStream is = classLoader.getResourceAsStream( name );

if( is != null )
{


+ 2
- 2
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -9,11 +9,11 @@ package org.apache.tools.ant.taskdefs;

import java.io.File;
import java.io.IOException;
import java.net.URLClassLoader;
import java.rmi.Remote;
import java.util.ArrayList;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.rmic.RmicAdapter;
import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory;
@@ -525,7 +525,7 @@ public class Rmic extends MatchingTask
adapter.setRmic( this );

Path classpath = adapter.getClasspath();
loader = new AntClassLoader( getProject(), classpath );
loader = new URLClassLoader( classpath.toURLs() );

// scan base dirs to build up compile lists only if a
// specific classname is not given


+ 18
- 20
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -18,6 +18,7 @@ import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import java.io.StringReader;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
@@ -31,7 +32,6 @@ import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.EnumeratedAttribute;
@@ -47,9 +47,9 @@ import org.apache.tools.ant.types.Reference;
* @author <A href="mailto:gholam@xtra.co.nz">Michael McCallum</A>
* @author <A href="mailto:tim.stephenson@sybase.com">Tim Stephenson</A>
*/
public class SQLExec extends Task
public class SQLExec
extends Task
{

private int goodSql = 0, totalSql = 0;

private ArrayList filesets = new ArrayList();
@@ -57,42 +57,42 @@ public class SQLExec extends Task
/**
* Database connection
*/
private Connection conn = null;
private Connection conn;

/**
* Autocommit flag. Default value is false
*/
private boolean autocommit = false;
private boolean autocommit;

/**
* SQL statement
*/
private Statement statement = null;
private Statement statement;

/**
* DB driver.
*/
private String driver = null;
private String driver;

/**
* DB url.
*/
private String url = null;
private String url;

/**
* User name.
*/
private String userId = null;
private String userId;

/**
* Password
*/
private String password = null;
private String password;

/**
* SQL input file
*/
private File srcFile = null;
private File srcFile;

/**
* SQL input command
@@ -118,7 +118,7 @@ public class SQLExec extends Task
/**
* Print SQL results.
*/
private boolean print = false;
private boolean print;

/**
* Print header columns.
@@ -128,17 +128,17 @@ public class SQLExec extends Task
/**
* Results Output file.
*/
private File output = null;
private File output;

/**
* RDBMS Product needed for this SQL.
*/
private String rdbms = null;
private String rdbms;

/**
* RDBMS Version needed for this SQL.
*/
private String version = null;
private String version;

/**
* Action to perform if an error is found
@@ -148,12 +148,10 @@ public class SQLExec extends Task
/**
* Encoding to use when reading SQL statements from a file
*/
private String encoding = null;
private String encoding;

private Path classpath;

private AntClassLoader loader;

/**
* Set the autocommit flag for the DB connection.
*
@@ -457,8 +455,8 @@ public class SQLExec extends Task
{
getLogger().debug( "Loading " + driver + " using AntClassLoader with classpath " + classpath );

loader = new AntClassLoader( getProject(), classpath );
dc = loader.loadClass( driver );
final ClassLoader classLoader = new URLClassLoader( classpath.toURLs() );
dc = classLoader.loadClass( driver );
}
else
{


+ 1
- 2
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -401,8 +401,7 @@ public abstract class DefaultCompilerAdapter
}
catch( IOException e )
{
throw new TaskException( "Error running " + args[ 0 ]
+ " compiler", e );
throw new TaskException( "Error running " + args[ 0 ] + " compiler", e );
}
}
finally


+ 4
- 3
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java View File

@@ -15,12 +15,12 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
@@ -579,7 +579,7 @@ public class Depend extends MatchingTask
{
// now determine which jars each class depends upon
classpathDependencies = new Hashtable();
AntClassLoader loader = new AntClassLoader( getProject(), dependClasspath );
final ClassLoader classLoader = new URLClassLoader( dependClasspath.toURLs() );

Hashtable classpathFileCache = new Hashtable();
Object nullFileMarker = new Object();
@@ -599,7 +599,8 @@ public class Depend extends MatchingTask

if( !dependency.startsWith( "java." ) && !dependency.startsWith( "javax." ) )
{
URL classURL = loader.getResource( dependency.replace( '.', '/' ) + ".class" );
final String name = dependency.replace( '.', '/' ) + ".class";
URL classURL = classLoader.getResource( name );
if( classURL != null )
{
if( classURL.getProtocol().equals( "jar" ) )


+ 2
- 2
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java View File

@@ -12,6 +12,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
@@ -27,7 +28,6 @@ import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.bcel.*;
import org.apache.bcel.classfile.*;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
@@ -329,7 +329,7 @@ public class GenericDeploymentTool
}
else
{
classpathLoader = new AntClassLoader( getTask().getProject(), combinedClasspath );
classpathLoader = new URLClassLoader( combinedClasspath.toURLs() );
}

return classpathLoader;


+ 2
- 2
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java View File

@@ -12,6 +12,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLClassLoader;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.jar.JarEntry;
@@ -21,7 +22,6 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.Path;
import org.xml.sax.InputSource;
@@ -332,7 +332,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool
lookupPath.append( classpath );
}

return new AntClassLoader( getTask().getProject(), lookupPath );
return new URLClassLoader( lookupPath.toURLs() );
}

protected DescriptorHandler getWeblogicDescriptorHandler( final File srcDir )


+ 2
- 2
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java View File

@@ -11,13 +11,13 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLClassLoader;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.Argument;
import org.apache.tools.ant.types.EnumeratedAttribute;
@@ -410,7 +410,7 @@ public class WebsphereDeploymentTool
{
lookupPath.append( classpath );
}
return new AntClassLoader( getTask().getProject(), lookupPath );
return new URLClassLoader( lookupPath.toURLs() );
}

protected DescriptorHandler getDescriptorHandler( File srcDir )


+ 8
- 9
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -12,6 +12,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -19,7 +20,6 @@ import java.util.Iterator;
import java.util.Properties;
import java.util.Random;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.exec.Execute;
import org.apache.tools.ant.taskdefs.exec.LogOutputStream;
@@ -694,19 +694,18 @@ public class JUnitTask extends Task
try
{
getLogger().debug( "Using System properties " + System.getProperties() );
AntClassLoader cl = null;
ClassLoader classLoader = null;
Path classpath = commandline.getClasspath();
if( classpath != null )
{
getLogger().debug( "Using CLASSPATH " + classpath );

cl = new AntClassLoader( null, getProject(), classpath, false );
// make sure the test will be accepted as a TestCase
cl.addSystemPackageRoot( "junit" );
// will cause trouble in JDK 1.1 if omitted
cl.addSystemPackageRoot( "org.apache.tools.ant" );
classLoader = new URLClassLoader( classpath.toURLs() );
}
runner = new JUnitTestRunner( test, test.getHaltonerror(), test.getFiltertrace(), test.getHaltonfailure(), cl );
runner = new JUnitTestRunner( test,
test.getHaltonerror(),
test.getFiltertrace(),
test.getHaltonfailure(),
classLoader );
if( summary )
{
getLogger().info( "Running " + test.getName() );


+ 0
- 4
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -28,9 +28,6 @@ import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.apache.avalon.framework.ExceptionUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.StringUtils;

/**
* Simple Testrunner for JUnit that runs all tests of a testsuite. <p>
@@ -179,7 +176,6 @@ public class JUnitTestRunner implements TestListener
else
{
testClass = loader.loadClass( test.getName() );
AntClassLoader.initializeClass( testClass );
}

Method suiteMethod = null;


+ 3
- 7
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java View File

@@ -24,7 +24,6 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.util.DOMElementWriter;
import org.apache.tools.ant.util.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
@@ -184,7 +183,7 @@ public class XMLResultAggregator extends Task implements XMLConstants
}
if( toDir == null )
{
toDir = FileUtil.resolveFile( getProject().getBaseDir(), DEFAULT_DIR );
toDir = FileUtil.resolveFile( getBaseDirectory(), DEFAULT_DIR );
}
return new File( toDir, toFile );
}
@@ -210,16 +209,13 @@ public class XMLResultAggregator extends Task implements XMLConstants
if( pathname.endsWith( ".xml" ) )
{
File file = new File( ds.getBasedir(), pathname );
file = FileUtil.
resolveFile( getProject().getBaseDir(), file.getPath() );
file = FileUtil.resolveFile( getBaseDirectory(), file.getPath() );
v.add( file );
}
}
}

File[] files = new File[ v.size() ];
v.copyInto( files );
return files;
return (File[])v.toArray( new File[ v.size() ] );
}

/**


+ 5
- 6
proposal/myrmidon/src/main/org/apache/tools/ant/types/Mapper.java View File

@@ -7,10 +7,10 @@
*/
package org.apache.tools.ant.types;

import java.util.Properties;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Stack;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.util.FileNameMapper;

/**
@@ -182,10 +182,9 @@ public class Mapper
}
else
{
AntClassLoader al = new AntClassLoader( getProject(),
m_classpath );
c = al.loadClass( m_classname );
AntClassLoader.initializeClass( c );
final URL[] urls = m_classpath.toURLs();
final URLClassLoader classLoader = new URLClassLoader( urls );
c = classLoader.loadClass( m_classname );
}

FileNameMapper m = (FileNameMapper)c.newInstance();


+ 29
- 1
proposal/myrmidon/src/main/org/apache/tools/ant/types/Path.java View File

@@ -8,6 +8,8 @@
package org.apache.tools.ant.types;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
@@ -644,6 +646,33 @@ public class Path
}
}

/**
* Returns an array of URLs - useful for building a ClassLoader.
*/
public URL[] toURLs()
throws TaskException
{
try
{
final String[] list = list();

final URL[] result = new URL[ list.length ];

// path containing one or more elements
for( int i = 0; i < list.length; i++ )
{
result[ i ] = new File( list[ i ] ).toURL();
}

return result;
}
catch( final IOException ioe )
{
final String message = "Malformed path entry. Reason:" + ioe;
throw new TaskException( message, ioe );
}
}

/**
* Overrides the version of DataType to recurse on all DataType child
* elements that may have been added.
@@ -655,7 +684,6 @@ public class Path
protected void dieOnCircularReference( Stack stk, Project p )
throws TaskException
{

if( checked )
{
return;


+ 0
- 1118
proposal/myrmidon/src/todo/org/apache/tools/ant/AntClassLoader.java
File diff suppressed because it is too large
View File


+ 70
- 92
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Available.java View File

@@ -8,8 +8,9 @@
package org.apache.tools.ant.taskdefs;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.condition.Condition;
import org.apache.tools.ant.types.EnumeratedAttribute;
@@ -29,22 +30,22 @@ public class Available
extends Task
implements Condition
{
private String value = "true";
private String classname;
private Path classpath;
private String file;
private Path filepath;
private AntClassLoader loader;
private String m_value = "true";
private String m_classname;
private Path m_classpath;
private String m_file;
private Path m_filepath;
private ClassLoader m_classLoader;

private String property;
private String resource;
private FileDir type;
private String m_property;
private String m_resource;
private FileDir m_type;

public void setClassname( String classname )
{
if( !"".equals( classname ) )
{
this.classname = classname;
m_classname = classname;
}
}

@@ -62,7 +63,7 @@ public class Available

public void setFile( String file )
{
this.file = file;
m_file = file;
}

public void setFilepath( Path filepath )
@@ -73,102 +74,98 @@ public class Available

public void setProperty( String property )
{
this.property = property;
m_property = property;
}

public void setResource( String resource )
{
this.resource = resource;
m_resource = resource;
}

public void setType( FileDir type )
{
this.type = type;
m_type = type;
}

public void setValue( String value )
{
this.value = value;
m_value = value;
}

public Path createClasspath()
throws TaskException
{
if( this.classpath == null )
if( m_classpath == null )
{
this.classpath = new Path();
m_classpath = new Path();
}
return this.classpath.createPath();
return m_classpath.createPath();
}

public Path createFilepath()
throws TaskException
{
if( this.filepath == null )
if( m_filepath == null )
{
this.filepath = new Path();
m_filepath = new Path();
}
return this.filepath.createPath();
return m_filepath.createPath();
}

public boolean eval()
throws TaskException
{
if( classname == null && file == null && resource == null )
if( m_classname == null && m_file == null && m_resource == null )
{
throw new TaskException( "At least one of (classname|file|resource) is required" );
}

if( type != null )
if( m_type != null )
{
if( file == null )
if( m_file == null )
{
throw new TaskException( "The type attribute is only valid when specifying the file attribute." );
}
}

if( classpath != null )
if( m_classpath != null )
{
this.loader = new AntClassLoader( getProject(), classpath );
final URL[] urls = m_classpath.toURLs();
m_classLoader = new URLClassLoader( urls );
}

if( ( classname != null ) && !checkClass( classname ) )
if( ( m_classname != null ) && !checkClass( m_classname ) )
{
getLogger().debug( "Unable to load class " + classname + " to set property " + property );
getLogger().debug( "Unable to load class " + m_classname + " to set property " + m_property );
return false;
}

if( ( file != null ) && !checkFile() )
if( ( m_file != null ) && !checkFile() )
{
if( type != null )
if( m_type != null )
{
getLogger().debug( "Unable to find " + type + " " + file + " to set property " + property );
getLogger().debug( "Unable to find " + m_type + " " + m_file + " to set property " + m_property );
}
else
{
getLogger().debug( "Unable to find " + file + " to set property " + property );
getLogger().debug( "Unable to find " + m_file + " to set property " + m_property );
}
return false;
}

if( ( resource != null ) && !checkResource( resource ) )
if( ( m_resource != null ) && !checkResource( m_resource ) )
{
getLogger().debug( "Unable to load resource " + resource + " to set property " + property );
getLogger().debug( "Unable to load resource " + m_resource + " to set property " + m_property );
return false;
}

if( loader != null )
{
loader.cleanup();
}

return true;
}

public void execute()
throws TaskException
{
if( property == null )
if( m_property == null )
{
throw new TaskException( "property attribute is required" );
}
@@ -176,9 +173,9 @@ public class Available
if( eval() )
{
String lSep = System.getProperty( "line.separator" );
if( null == getProject().getProperty( property ) )
if( null == getProject().getProperty( m_property ) )
{
setProperty( property, value );
setProperty( m_property, m_value );
}
//else ignore
}
@@ -188,24 +185,8 @@ public class Available
{
try
{
if( loader != null )
{
loader.loadClass( classname );
}
else
{
ClassLoader l = this.getClass().getClassLoader();
// Can return null to represent the bootstrap class loader.
// see API docs of Class.getClassLoader.
if( l != null )
{
l.loadClass( classname );
}
else
{
Class.forName( classname );
}
}
final ClassLoader classLoader = getClassLoader();
classLoader.loadClass( classname );
return true;
}
catch( ClassNotFoundException e )
@@ -221,13 +202,13 @@ public class Available
private boolean checkFile()
throws TaskException
{
if( filepath == null )
if( m_filepath == null )
{
return checkFile( resolveFile( file ), file );
return checkFile( resolveFile( m_file ), m_file );
}
else
{
String[] paths = filepath.list();
String[] paths = m_filepath.list();
for( int i = 0; i < paths.length; ++i )
{
getLogger().debug( "Searching " + paths[ i ] );
@@ -248,20 +229,20 @@ public class Available

// ** full-pathname specified == path in list
// ** simple name specified == path in list
if( path.exists() && file.equals( paths[ i ] ) )
if( path.exists() && m_file.equals( paths[ i ] ) )
{
if( type == null )
if( m_type == null )
{
getLogger().debug( "Found: " + path );
return true;
}
else if( type.isDir()
else if( m_type.isDir()
&& path.isDirectory() )
{
getLogger().debug( "Found directory: " + path );
return true;
}
else if( type.isFile()
else if( m_type.isFile()
&& path.isFile() )
{
getLogger().debug( "Found file: " + path );
@@ -274,14 +255,14 @@ public class Available
File parent = path.getParentFile();
// ** full-pathname specified == parent dir of path in list
if( parent != null && parent.exists()
&& file.equals( parent.getAbsolutePath() ) )
&& m_file.equals( parent.getAbsolutePath() ) )
{
if( type == null )
if( m_type == null )
{
getLogger().debug( "Found: " + parent );
return true;
}
else if( type.isDir() )
else if( m_type.isDir() )
{
getLogger().debug( "Found directory: " + parent );
return true;
@@ -293,8 +274,8 @@ public class Available
// ** simple name specified == path in list + name
if( path.exists() && path.isDirectory() )
{
if( checkFile( new File( path, file ),
file + " in " + path ) )
if( checkFile( new File( path, m_file ),
m_file + " in " + path ) )
{
return true;
}
@@ -303,8 +284,8 @@ public class Available
// ** simple name specified == parent dir + name
if( parent != null && parent.exists() )
{
if( checkFile( new File( parent, file ),
file + " in " + parent ) )
if( checkFile( new File( parent, m_file ),
m_file + " in " + parent ) )
{
return true;
}
@@ -316,8 +297,8 @@ public class Available
File grandParent = parent.getParentFile();
if( grandParent != null && grandParent.exists() )
{
if( checkFile( new File( grandParent, file ),
file + " in " + grandParent ) )
if( checkFile( new File( grandParent, m_file ),
m_file + " in " + grandParent ) )
{
return true;
}
@@ -330,9 +311,9 @@ public class Available

private boolean checkFile( File f, String text )
{
if( type != null )
if( m_type != null )
{
if( type.isDir() )
if( m_type.isDir() )
{
if( f.isDirectory() )
{
@@ -340,7 +321,7 @@ public class Available
}
return f.isDirectory();
}
else if( type.isFile() )
else if( m_type.isFile() )
{
if( f.isFile() )
{
@@ -358,22 +339,19 @@ public class Available

private boolean checkResource( String resource )
{
if( loader != null )
final ClassLoader classLoader = getClassLoader();
return ( null != classLoader.getResourceAsStream( resource ) );
}

private ClassLoader getClassLoader()
{
if( null == m_classLoader )
{
return ( loader.getResourceAsStream( resource ) != null );
return ClassLoader.getSystemClassLoader();
}
else
{
ClassLoader cL = this.getClass().getClassLoader();
if( cL != null )
{
return ( cL.getResourceAsStream( resource ) != null );
}
else
{
return
( ClassLoader.getSystemResourceAsStream( resource ) != null );
}
return m_classLoader;
}
}



+ 21
- 30
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/ExecuteJava.java View File

@@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava;
@@ -20,56 +21,51 @@ import org.apache.tools.ant.types.Path;
* @author thomas.haas@softwired-inc.com
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/

public class ExecuteJava
{
private Commandline m_javaCommand;
private Path m_classpath;
private CommandlineJava.SysProperties m_sysProperties;

private Commandline javaCommand = null;
private Path classpath = null;
private CommandlineJava.SysProperties sysProperties = null;

public void setClasspath( Path p )
public void setClasspath( final Path classpath )
{
classpath = p;
m_classpath = classpath;
}

public void setJavaCommand( Commandline javaCommand )
public void setJavaCommand( final Commandline javaCommand )
{
this.javaCommand = javaCommand;
m_javaCommand = javaCommand;
}

public void setSystemProperties( CommandlineJava.SysProperties s )
public void setSystemProperties( final CommandlineJava.SysProperties sysProperties )
{
sysProperties = s;
m_sysProperties = sysProperties;
}

public void execute( Project project )
throws TaskException
{
final String classname = javaCommand.getExecutable();
final Object[] argument = {javaCommand.getArguments()};
final String classname = m_javaCommand.getExecutable();
final Object[] argument = {m_javaCommand.getArguments()};

AntClassLoader loader = null;
try
{
if( sysProperties != null )
if( m_sysProperties != null )
{
sysProperties.setSystem();
m_sysProperties.setSystem();
}

final Class[] param = {Class.forName( "[Ljava.lang.String;" )};
Class target = null;
if( classpath == null )
if( m_classpath == null )
{
target = Class.forName( classname );
}
else
{
loader = new AntClassLoader( Project.class.getClassLoader(), project, classpath, false );
loader.setIsolated( true );
loader.setThreadContextLoader();
target = loader.forceLoadClass( classname );
AntClassLoader.initializeClass( target );
final URL[] urls = m_classpath.toURLs();
final URLClassLoader classLoader = new URLClassLoader( urls );
target = classLoader.loadClass( classname );
}
final Method main = target.getMethod( "main", param );
main.invoke( null, argument );
@@ -100,14 +96,9 @@ public class ExecuteJava
}
finally
{
if( loader != null )
{
loader.resetThreadContextLoader();
loader.cleanup();
}
if( sysProperties != null )
if( m_sysProperties != null )
{
sysProperties.restoreSystem();
m_sysProperties.restoreSystem();
}
}
}


+ 7
- 15
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java View File

@@ -11,13 +11,13 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Iterator;
import java.util.Properties;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.exec.Environment;
import org.apache.myrmidon.framework.exec.ExecException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
@@ -269,26 +269,18 @@ public class Property
getLogger().debug( "Resource Loading " + name );
try
{
ClassLoader cL = null;
InputStream is = null;
ClassLoader classLoader = null;

if( m_classpath != null )
{
cL = new AntClassLoader( getProject(), m_classpath );
final URL[] urls = m_classpath.toURLs();
classLoader = new URLClassLoader( urls );
}
else
{
cL = getClass().getClassLoader();
}

if( cL == null )
{
is = ClassLoader.getSystemResourceAsStream( name );
}
else
{
is = cL.getResourceAsStream( name );
classLoader = ClassLoader.getSystemClassLoader();
}
final InputStream is = classLoader.getResourceAsStream( name );

if( is != null )
{


+ 2
- 2
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -9,11 +9,11 @@ package org.apache.tools.ant.taskdefs;

import java.io.File;
import java.io.IOException;
import java.net.URLClassLoader;
import java.rmi.Remote;
import java.util.ArrayList;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.rmic.RmicAdapter;
import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory;
@@ -525,7 +525,7 @@ public class Rmic extends MatchingTask
adapter.setRmic( this );

Path classpath = adapter.getClasspath();
loader = new AntClassLoader( getProject(), classpath );
loader = new URLClassLoader( classpath.toURLs() );

// scan base dirs to build up compile lists only if a
// specific classname is not given


+ 18
- 20
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -18,6 +18,7 @@ import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import java.io.StringReader;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
@@ -31,7 +32,6 @@ import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.EnumeratedAttribute;
@@ -47,9 +47,9 @@ import org.apache.tools.ant.types.Reference;
* @author <A href="mailto:gholam@xtra.co.nz">Michael McCallum</A>
* @author <A href="mailto:tim.stephenson@sybase.com">Tim Stephenson</A>
*/
public class SQLExec extends Task
public class SQLExec
extends Task
{

private int goodSql = 0, totalSql = 0;

private ArrayList filesets = new ArrayList();
@@ -57,42 +57,42 @@ public class SQLExec extends Task
/**
* Database connection
*/
private Connection conn = null;
private Connection conn;

/**
* Autocommit flag. Default value is false
*/
private boolean autocommit = false;
private boolean autocommit;

/**
* SQL statement
*/
private Statement statement = null;
private Statement statement;

/**
* DB driver.
*/
private String driver = null;
private String driver;

/**
* DB url.
*/
private String url = null;
private String url;

/**
* User name.
*/
private String userId = null;
private String userId;

/**
* Password
*/
private String password = null;
private String password;

/**
* SQL input file
*/
private File srcFile = null;
private File srcFile;

/**
* SQL input command
@@ -118,7 +118,7 @@ public class SQLExec extends Task
/**
* Print SQL results.
*/
private boolean print = false;
private boolean print;

/**
* Print header columns.
@@ -128,17 +128,17 @@ public class SQLExec extends Task
/**
* Results Output file.
*/
private File output = null;
private File output;

/**
* RDBMS Product needed for this SQL.
*/
private String rdbms = null;
private String rdbms;

/**
* RDBMS Version needed for this SQL.
*/
private String version = null;
private String version;

/**
* Action to perform if an error is found
@@ -148,12 +148,10 @@ public class SQLExec extends Task
/**
* Encoding to use when reading SQL statements from a file
*/
private String encoding = null;
private String encoding;

private Path classpath;

private AntClassLoader loader;

/**
* Set the autocommit flag for the DB connection.
*
@@ -457,8 +455,8 @@ public class SQLExec extends Task
{
getLogger().debug( "Loading " + driver + " using AntClassLoader with classpath " + classpath );

loader = new AntClassLoader( getProject(), classpath );
dc = loader.loadClass( driver );
final ClassLoader classLoader = new URLClassLoader( classpath.toURLs() );
dc = classLoader.loadClass( driver );
}
else
{


+ 1
- 2
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -401,8 +401,7 @@ public abstract class DefaultCompilerAdapter
}
catch( IOException e )
{
throw new TaskException( "Error running " + args[ 0 ]
+ " compiler", e );
throw new TaskException( "Error running " + args[ 0 ] + " compiler", e );
}
}
finally


+ 4
- 3
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/depend/Depend.java View File

@@ -15,12 +15,12 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
@@ -579,7 +579,7 @@ public class Depend extends MatchingTask
{
// now determine which jars each class depends upon
classpathDependencies = new Hashtable();
AntClassLoader loader = new AntClassLoader( getProject(), dependClasspath );
final ClassLoader classLoader = new URLClassLoader( dependClasspath.toURLs() );

Hashtable classpathFileCache = new Hashtable();
Object nullFileMarker = new Object();
@@ -599,7 +599,8 @@ public class Depend extends MatchingTask

if( !dependency.startsWith( "java." ) && !dependency.startsWith( "javax." ) )
{
URL classURL = loader.getResource( dependency.replace( '.', '/' ) + ".class" );
final String name = dependency.replace( '.', '/' ) + ".class";
URL classURL = classLoader.getResource( name );
if( classURL != null )
{
if( classURL.getProtocol().equals( "jar" ) )


+ 2
- 2
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java View File

@@ -12,6 +12,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
@@ -27,7 +28,6 @@ import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.bcel.*;
import org.apache.bcel.classfile.*;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
@@ -329,7 +329,7 @@ public class GenericDeploymentTool
}
else
{
classpathLoader = new AntClassLoader( getTask().getProject(), combinedClasspath );
classpathLoader = new URLClassLoader( combinedClasspath.toURLs() );
}

return classpathLoader;


+ 2
- 2
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java View File

@@ -12,6 +12,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLClassLoader;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.jar.JarEntry;
@@ -21,7 +22,6 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.Path;
import org.xml.sax.InputSource;
@@ -332,7 +332,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool
lookupPath.append( classpath );
}

return new AntClassLoader( getTask().getProject(), lookupPath );
return new URLClassLoader( lookupPath.toURLs() );
}

protected DescriptorHandler getWeblogicDescriptorHandler( final File srcDir )


+ 2
- 2
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java View File

@@ -11,13 +11,13 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLClassLoader;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.Argument;
import org.apache.tools.ant.types.EnumeratedAttribute;
@@ -410,7 +410,7 @@ public class WebsphereDeploymentTool
{
lookupPath.append( classpath );
}
return new AntClassLoader( getTask().getProject(), lookupPath );
return new URLClassLoader( lookupPath.toURLs() );
}

protected DescriptorHandler getDescriptorHandler( File srcDir )


+ 8
- 9
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -12,6 +12,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -19,7 +20,6 @@ import java.util.Iterator;
import java.util.Properties;
import java.util.Random;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.exec.Execute;
import org.apache.tools.ant.taskdefs.exec.LogOutputStream;
@@ -694,19 +694,18 @@ public class JUnitTask extends Task
try
{
getLogger().debug( "Using System properties " + System.getProperties() );
AntClassLoader cl = null;
ClassLoader classLoader = null;
Path classpath = commandline.getClasspath();
if( classpath != null )
{
getLogger().debug( "Using CLASSPATH " + classpath );

cl = new AntClassLoader( null, getProject(), classpath, false );
// make sure the test will be accepted as a TestCase
cl.addSystemPackageRoot( "junit" );
// will cause trouble in JDK 1.1 if omitted
cl.addSystemPackageRoot( "org.apache.tools.ant" );
classLoader = new URLClassLoader( classpath.toURLs() );
}
runner = new JUnitTestRunner( test, test.getHaltonerror(), test.getFiltertrace(), test.getHaltonfailure(), cl );
runner = new JUnitTestRunner( test,
test.getHaltonerror(),
test.getFiltertrace(),
test.getHaltonfailure(),
classLoader );
if( summary )
{
getLogger().info( "Running " + test.getName() );


+ 0
- 4
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -28,9 +28,6 @@ import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.apache.avalon.framework.ExceptionUtil;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.StringUtils;

/**
* Simple Testrunner for JUnit that runs all tests of a testsuite. <p>
@@ -179,7 +176,6 @@ public class JUnitTestRunner implements TestListener
else
{
testClass = loader.loadClass( test.getName() );
AntClassLoader.initializeClass( testClass );
}

Method suiteMethod = null;


+ 3
- 7
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java View File

@@ -24,7 +24,6 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.util.DOMElementWriter;
import org.apache.tools.ant.util.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
@@ -184,7 +183,7 @@ public class XMLResultAggregator extends Task implements XMLConstants
}
if( toDir == null )
{
toDir = FileUtil.resolveFile( getProject().getBaseDir(), DEFAULT_DIR );
toDir = FileUtil.resolveFile( getBaseDirectory(), DEFAULT_DIR );
}
return new File( toDir, toFile );
}
@@ -210,16 +209,13 @@ public class XMLResultAggregator extends Task implements XMLConstants
if( pathname.endsWith( ".xml" ) )
{
File file = new File( ds.getBasedir(), pathname );
file = FileUtil.
resolveFile( getProject().getBaseDir(), file.getPath() );
file = FileUtil.resolveFile( getBaseDirectory(), file.getPath() );
v.add( file );
}
}
}

File[] files = new File[ v.size() ];
v.copyInto( files );
return files;
return (File[])v.toArray( new File[ v.size() ] );
}

/**


+ 5
- 6
proposal/myrmidon/src/todo/org/apache/tools/ant/types/Mapper.java View File

@@ -7,10 +7,10 @@
*/
package org.apache.tools.ant.types;

import java.util.Properties;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Stack;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.util.FileNameMapper;

/**
@@ -182,10 +182,9 @@ public class Mapper
}
else
{
AntClassLoader al = new AntClassLoader( getProject(),
m_classpath );
c = al.loadClass( m_classname );
AntClassLoader.initializeClass( c );
final URL[] urls = m_classpath.toURLs();
final URLClassLoader classLoader = new URLClassLoader( urls );
c = classLoader.loadClass( m_classname );
}

FileNameMapper m = (FileNameMapper)c.newInstance();


+ 29
- 1
proposal/myrmidon/src/todo/org/apache/tools/ant/types/Path.java View File

@@ -8,6 +8,8 @@
package org.apache.tools.ant.types;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
@@ -644,6 +646,33 @@ public class Path
}
}

/**
* Returns an array of URLs - useful for building a ClassLoader.
*/
public URL[] toURLs()
throws TaskException
{
try
{
final String[] list = list();

final URL[] result = new URL[ list.length ];

// path containing one or more elements
for( int i = 0; i < list.length; i++ )
{
result[ i ] = new File( list[ i ] ).toURL();
}

return result;
}
catch( final IOException ioe )
{
final String message = "Malformed path entry. Reason:" + ioe;
throw new TaskException( message, ioe );
}
}

/**
* Overrides the version of DataType to recurse on all DataType child
* elements that may have been added.
@@ -655,7 +684,6 @@ public class Path
protected void dieOnCircularReference( Stack stk, Project p )
throws TaskException
{

if( checked )
{
return;


Loading…
Cancel
Save