ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/types PathUtil.java
Date Wed, 27 Mar 2002 07:04:17 GMT
adammurdoch    02/03/26 23:04:17

  Modified:    proposal/myrmidon/src/java/org/apache/antlib/core
                        AbstractAvailableCondition.java
               proposal/myrmidon/src/java/org/apache/antlib/xml
                        XMLValidateTask.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/classloader
                        DefaultClassLoaderManager.java Resources.properties
               proposal/myrmidon/src/java/org/apache/myrmidon/framework/java
                        ExecuteJava.java
               proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/classloader
                        ClassLoaderManager.java
               proposal/myrmidon/src/test/org/apache/myrmidon/components
                        AbstractComponentTest.java
               proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs
                        Property.java SQLExec.java
               proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit
                        JUnitTask.java
               proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic
                        Rmic.java
               proposal/myrmidon/src/todo/org/apache/tools/todo/types
                        PathUtil.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/classloader
                        ClassLoaderException.java
  Log:
  * Added ClassLoaderManager.createClassLoader( File[] ), to create a
    ClassLoader from a class-path.
  
  * Moved responsibility for creation of ClassLoaders out of the tasks, and into
    the ClassLoaderManager, which caches them, and resolves extension dependencies.
  
  * Added PathUtil.createClassLoader() convenience method to create a ClassLoader
    from a Path.
  
  * Changed the PathUtil methods to use the more general FileList, rather than Path.
  
  * Added 'classpath' attribute to the <*-available> conditions.
  
  Revision  Changes    Path
  1.5       +10 -18    jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/AbstractAvailableCondition.java
  
  Index: AbstractAvailableCondition.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/AbstractAvailableCondition.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractAvailableCondition.java	22 Mar 2002 04:12:35 -0000	1.4
  +++ AbstractAvailableCondition.java	27 Mar 2002 07:04:16 -0000	1.5
  @@ -7,8 +7,6 @@
    */
   package org.apache.antlib.core;
   
  -import java.net.URL;
  -import java.net.URLClassLoader;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.framework.conditions.Condition;
  @@ -20,7 +18,7 @@
    * resource in a classpath.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.4 $ $Date: 2002/03/22 04:12:35 $
  + * @version $Revision: 1.5 $ $Date: 2002/03/27 07:04:16 $
    */
   public abstract class AbstractAvailableCondition
       implements Condition
  @@ -30,8 +28,15 @@
       /**
        * Adds a classpath element.
        */
  +    public void setClasspath( final Path classpath )
  +    {
  +        m_classpath.add( classpath );
  +    }
  +
  +    /**
  +     * Adds a classpath element.
  +     */
       public void addClasspath( final Path classpath )
  -        throws TaskException
       {
           m_classpath.add( classpath );
       }
  @@ -41,19 +46,6 @@
        */
       protected ClassLoader buildClassLoader( final TaskContext context ) throws TaskException
       {
  -        final URL[] urls = PathUtil.toURLs( m_classpath, context );
  -        final ClassLoader classLoader;
  -        if( urls.length > 0 )
  -        {
  -            classLoader = new URLClassLoader( urls );
  -        }
  -        else
  -        {
  -            // TODO - using system classloader is kinda useless now, because
  -            // the system classpath contains almost nothing.  Should be using
  -            // the 'common' classloader instead
  -            classLoader = ClassLoader.getSystemClassLoader();
  -        }
  -        return classLoader;
  +        return PathUtil.createClassLoader( m_classpath, context );
       }
   }
  
  
  
  1.26      +8 -33     jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/xml/XMLValidateTask.java
  
  Index: XMLValidateTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/xml/XMLValidateTask.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- XMLValidateTask.java	22 Mar 2002 04:12:36 -0000	1.25
  +++ XMLValidateTask.java	27 Mar 2002 07:04:16 -0000	1.26
  @@ -10,16 +10,14 @@
   import java.io.File;
   import java.io.FileReader;
   import java.io.IOException;
  -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.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.types.DirectoryScanner;
   import org.apache.tools.todo.types.FileSet;
  -import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.types.PathUtil;
   import org.apache.tools.todo.types.ScannerUtil;
   import org.xml.sax.EntityResolver;
  @@ -76,7 +74,7 @@
        * The list of configured DTD locations
        */
       private ArrayList m_dtdLocations = new ArrayList();// sets of file to be validated
  -    private Path m_classpath;
  +    private Path m_classpath = new Path();
   
       /**
        * Specify the class name of the SAX parser to be used. (optional)
  @@ -100,17 +98,10 @@
       /**
        * Specify the classpath to be searched to load the parser (optional)
        */
  -    public void setClasspath( final Path classpath )
  +    public void setClasspath( final String classpath )
           throws TaskException
       {
  -        if( m_classpath == null )
  -        {
  -            m_classpath = classpath;
  -        }
  -        else
  -        {
  -            m_classpath.add( classpath );
  -        }
  +        m_classpath.add( classpath );
       }
   
       /**
  @@ -161,17 +152,10 @@
       /**
        * @see #setClasspath
        */
  -    public Path createClasspath()
  +    public void addClasspath( final Path path )
           throws TaskException
       {
  -        if( m_classpath == null )
  -        {
  -            m_classpath = new Path();
  -        }
  -        Path path1 = m_classpath;
  -        final Path path = new Path();
  -        path1.add( path );
  -        return path;
  +        m_classpath.add( path );
       }
   
       /**
  @@ -327,17 +311,8 @@
           {
               // load the parser class
               // with JAXP, we would use a SAXParser factory
  -            Class readerClass = null;
  -            if( m_classpath != null )
  -            {
  -                final URL[] urls = PathUtil.toURLs( m_classpath, getContext() );
  -                final ClassLoader classLoader = new URLClassLoader( urls );
  -                readerClass = classLoader.loadClass( m_readerClassName );
  -            }
  -            else
  -            {
  -                readerClass = Class.forName( m_readerClassName );
  -            }
  +            final ClassLoader classLoader = PathUtil.createClassLoader( m_classpath, getContext()
);
  +            final Class readerClass = classLoader.loadClass( m_readerClassName );
   
               // then check it implements XMLReader
               if( XMLReader.class.isAssignableFrom( readerClass ) )
  
  
  
  1.2       +81 -37    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/classloader/DefaultClassLoaderManager.java
  
  Index: DefaultClassLoaderManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/classloader/DefaultClassLoaderManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultClassLoaderManager.java	11 Mar 2002 06:02:22 -0000	1.1
  +++ DefaultClassLoaderManager.java	27 Mar 2002 07:04:16 -0000	1.2
  @@ -16,6 +16,7 @@
   import java.util.Arrays;
   import java.util.HashMap;
   import java.util.Map;
  +import java.util.List;
   import java.util.jar.Manifest;
   import org.apache.avalon.excalibur.extension.Extension;
   import org.apache.avalon.excalibur.extension.OptionalPackage;
  @@ -28,11 +29,13 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
  +import org.apache.myrmidon.interfaces.classloader.ClassLoaderException;
   import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
  +import org.apache.tools.todo.types.PathUtil;
   
   /**
  - * A default implementation of a classloader manager.
  + * A default implementation of a ClassLoader manager.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    */
  @@ -49,79 +52,117 @@
       private final Map m_fileDeployers = new HashMap();
   
       private PackageManager m_packageManager;
  -    private ClassLoader m_baseClassLoader;
  +    private ClassLoader m_commonClassLoader;
   
       public void initialize() throws Exception
       {
  -        if( null == m_baseClassLoader )
  +        if( null == m_commonClassLoader )
           {
  -            m_baseClassLoader = Thread.currentThread().getContextClassLoader();
  +            m_commonClassLoader = Thread.currentThread().getContextClassLoader();
           }
       }
   
       /**
  +     * Retrieve relevent services needed to deploy.
  +     */
  +    public void service( final ServiceManager serviceManager )
  +        throws ServiceException
  +    {
  +        final ExtensionManager extensionManager =
  +            (ExtensionManager)serviceManager.lookup( ExtensionManager.ROLE );
  +        m_packageManager = new PackageManager( extensionManager );
  +    }
  +
  +    /**
        * Sets the ClassLoader to use as the parent for all classloaders
        * created by this ClassLoader manager.
        */
  -    public void setBaseClassLoader( final ClassLoader classLoader )
  +    public void setCommonClassLoader( final ClassLoader classLoader )
       {
  -        m_baseClassLoader = classLoader;
  +        m_commonClassLoader = classLoader;
       }
   
       /**
  -     * Retrieve relevent services needed to deploy.
  +     * Returns the common ClassLoader.  This is the parent of all classloaders
  +     * built by this ClassLoaderManager.
        */
  -    public void service( final ServiceManager serviceManager )
  -        throws ServiceException
  +    public ClassLoader getCommonClassLoader()
       {
  -        final ExtensionManager extensionManager =
  -            (ExtensionManager)serviceManager.lookup( ExtensionManager.ROLE );
  -        m_packageManager = new PackageManager( extensionManager );
  +        return m_commonClassLoader;
       }
   
       /**
        * Creates a class loader for a Jar file.
        */
  -    public ClassLoader createClassLoader( File file ) throws DeploymentException
  +    public ClassLoader createClassLoader( final File file ) throws ClassLoaderException
  +    {
  +        return createClassLoader( new File[] { file } );
  +    }
  +
  +    /**
  +     * Creates a class loader for a set of Jar files.
  +     */
  +    public ClassLoader createClassLoader( final File[] files ) throws ClassLoaderException
       {
           try
           {
  -            final File canonFile = file.getCanonicalFile();
  +            // Build a list of canonical file names
  +            final ArrayList canonFiles = new ArrayList( files.length );
  +            for( int i = 0; i < files.length; i++ )
  +            {
  +                canonFiles.add( files[ i ].getCanonicalFile() );
  +            }
   
               // Locate cached classloader, creating it if necessary
  -            URLClassLoader classLoader = (URLClassLoader)m_fileDeployers.get( canonFile
);
  +            ClassLoader classLoader = (ClassLoader)m_fileDeployers.get( canonFiles );
               if( classLoader == null )
               {
  -                checkFile( canonFile );
  -                final File[] extensions = getOptionalPackagesFor( canonFile );
  -                final URL[] urls = buildClasspath( canonFile, extensions );
  -                classLoader = new URLClassLoader( urls, m_baseClassLoader );
  -                m_fileDeployers.put( canonFile, classLoader );
  +                classLoader = buildClassLoader( canonFiles );
  +                m_fileDeployers.put( canonFiles, classLoader );
               }
               return classLoader;
           }
  -        catch( Exception e )
  +        catch( final Exception e )
  +        {
  +            final String fileNames = PathUtil.formatPath( files );
  +            final String message = REZ.getString( "create-classloader-for-file.error",
fileNames );
  +            throw new ClassLoaderException( message, e );
  +        }
  +    }
  +
  +    /**
  +     * Builds the classloader for a set of files.
  +     */
  +    private ClassLoader buildClassLoader( final ArrayList files )
  +        throws Exception
  +    {
  +        final ArrayList allFiles = new ArrayList( files );
  +        final int count = files.size();
  +        for( int i = 0; i < count; i++ )
           {
  -            final String message = REZ.getString( "create-classloader-for-file.error",
file );
  -            throw new DeploymentException( message );
  +            final File file = (File)files.get(i );
  +            checkFile( file );
  +            getOptionalPackagesFor( file, allFiles );
           }
  +
  +        final URL[] urls = buildClasspath( allFiles );
  +        return new URLClassLoader( urls, m_commonClassLoader );
       }
   
       /**
        * Assembles a set of files into a URL classpath.
        */
  -    private URL[] buildClasspath( final File file, final File[] dependencies )
  +    private URL[] buildClasspath( final ArrayList files )
           throws MalformedURLException
       {
  -        final URL[] urls = new URL[ dependencies.length + 1 ];
  -
  -        for( int i = 0; i < dependencies.length; i++ )
  +        final URL[] urls = new URL[ files.size() + 1 ];
  +        final int count = files.size();
  +        for( int i = 0; i < count; i++ )
           {
  -            urls[ i ] = dependencies[ i ].toURL();
  +            final File file = (File)files.get( i );
  +            urls[ i ] = file.toURL();
           }
   
  -        urls[ dependencies.length ] = file.toURL();
  -
           return urls;
       }
   
  @@ -129,13 +170,13 @@
        * Retrieve the files for the optional packages required by
        * the specified typeLibrary jar.
        *
  -     * @param typeLibrary the typeLibrary
  -     * @return the files that need to be added to ClassLoader
  +     * @param jarFile the typeLibrary
  +     * @param packages used to return the files that need to be added to ClassLoader.
        */
  -    private File[] getOptionalPackagesFor( final File typeLibrary )
  +    private void getOptionalPackagesFor( final File jarFile, final List packages )
           throws Exception
       {
  -        final URL url = new URL( "jar:" + typeLibrary.getCanonicalFile().toURL() + "!/"
);
  +        final URL url = new URL( "jar:" + jarFile.getCanonicalFile().toURL() + "!/" );
           final JarURLConnection connection = (JarURLConnection)url.openConnection();
           final Manifest manifest = connection.getManifest();
           final Extension[] available = Extension.getAvailable( manifest );
  @@ -166,9 +207,12 @@
               throw new Exception( message );
           }
   
  -        final OptionalPackage[] packages =
  -            (OptionalPackage[])dependencies.toArray( new OptionalPackage[ 0 ] );
  -        return OptionalPackage.toFiles( packages );
  +        final int count = dependencies.size();
  +        for( int i = 0; i < count; i++ )
  +        {
  +            final OptionalPackage optionalPackage = (OptionalPackage)dependencies.get(i
);
  +            packages.add( optionalPackage.getFile() );
  +        }
       }
   
       /**
  
  
  
  1.2       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/classloader/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/classloader/Resources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties	11 Mar 2002 06:02:22 -0000	1.1
  +++ Resources.properties	27 Mar 2002 07:04:16 -0000	1.2
  @@ -1,4 +1,4 @@
  -create-classloader-for-file.error=Could not create ClassLoader for file {0}.
  +create-classloader-for-file.error=Could not create ClassLoader for files: {0}.
   available-extensions.notice=The list of available extensions for type library includes;
{0}
   required-extensions.notice=The list of required extensions for type library includes; {0}
   unsatisfied.extensions.error=Missing {0} extensions for type library.
  
  
  
  1.3       +5 -15     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/java/ExecuteJava.java
  
  Index: ExecuteJava.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/java/ExecuteJava.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExecuteJava.java	22 Mar 2002 07:18:09 -0000	1.2
  +++ ExecuteJava.java	27 Mar 2002 07:04:17 -0000	1.3
  @@ -10,20 +10,18 @@
   import java.io.File;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  -import java.net.URL;
  -import java.net.URLClassLoader;
   import org.apache.aut.nativelib.Os;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.framework.Execute;
  +import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.types.Commandline;
   import org.apache.tools.todo.types.EnvironmentData;
  -import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.types.PathUtil;
   import org.apache.tools.todo.types.SysProperties;
   import org.apache.tools.todo.util.FileUtils;
  -import org.apache.avalon.excalibur.i18n.ResourceManager;
  -import org.apache.avalon.excalibur.i18n.Resources;
   
   /**
    * A utility class that takes care of executing a Java application.  This
  @@ -236,16 +234,8 @@
           final Class target;
           try
           {
  -            final URL[] urls = PathUtil.toURLs( m_classPath, context );
  -            if( urls.length == 0 )
  -            {
  -                target = Class.forName( m_className );
  -            }
  -            else
  -            {
  -                final URLClassLoader classLoader = new URLClassLoader( urls );
  -                target = classLoader.loadClass( m_className );
  -            }
  +            final ClassLoader classLoader = PathUtil.createClassLoader( m_classPath, context
);
  +            target = classLoader.loadClass( m_className );
           }
           catch( final Exception e )
           {
  
  
  
  1.2       +16 -3     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/classloader/ClassLoaderManager.java
  
  Index: ClassLoaderManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/classloader/ClassLoaderManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassLoaderManager.java	11 Mar 2002 06:02:22 -0000	1.1
  +++ ClassLoaderManager.java	27 Mar 2002 07:04:17 -0000	1.2
  @@ -8,7 +8,6 @@
   package org.apache.myrmidon.interfaces.classloader;
   
   import java.io.File;
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   
   /**
    * Manages a classloader hierarchy.
  @@ -20,7 +19,21 @@
       String ROLE = ClassLoaderManager.class.getName();
   
       /**
  -     * Builds the ClassLoader for a Jar file.
  +     * Builds the ClassLoader for a Jar file, resolving dependencies.
        */
  -    ClassLoader createClassLoader( File jar ) throws DeploymentException;
  +    ClassLoader createClassLoader( File jar ) throws ClassLoaderException;
  +
  +    /**
  +     * Builds the ClassLoader for a set of files, resolving dependencies.
  +     *
  +     * @param jars The Jar/zip files to create the classloader for.  Use null
  +     *             or an empty array to use the common classloader.
  +     */
  +    ClassLoader createClassLoader( File[] jars ) throws ClassLoaderException;
  +
  +    /**
  +     * Returns the common ClassLoader.  This is the parent of all classloaders
  +     * built by this ClassLoaderManager.
  +     */
  +    ClassLoader getCommonClassLoader();
   }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/classloader/ClassLoaderException.java
  
  Index: ClassLoaderException.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.interfaces.classloader;
  
  import org.apache.myrmidon.interfaces.ComponentException;
  
  /**
   * An exception thrown by the ClassLoaderManager.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/27 07:04:17 $
   */
  public class ClassLoaderException
      extends ComponentException
  {
      /**
       * Constructs a non-cascaded exception.
       *
       * @param message The detail message for this exception.
       */
      public ClassLoaderException( final String message )
      {
          super( message );
      }
  
      /**
       * Constructs a cascaded exception.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public ClassLoaderException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  1.20      +1 -1      jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/components/AbstractComponentTest.java
  
  Index: AbstractComponentTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/components/AbstractComponentTest.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- AbstractComponentTest.java	23 Mar 2002 05:03:30 -0000	1.19
  +++ AbstractComponentTest.java	27 Mar 2002 07:04:17 -0000	1.20
  @@ -94,7 +94,7 @@
               components.add( component );
   
               final DefaultClassLoaderManager classLoaderMgr = new DefaultClassLoaderManager();
  -            classLoaderMgr.setBaseClassLoader( getClass().getClassLoader() );
  +            classLoaderMgr.setCommonClassLoader( getClass().getClassLoader() );
               m_serviceManager.put( ClassLoaderManager.ROLE, classLoaderMgr );
               components.add( classLoaderMgr );
   
  
  
  
  1.5       +4 -23     jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Property.java
  
  Index: Property.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Property.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Property.java	22 Mar 2002 04:12:36 -0000	1.4
  +++ Property.java	27 Mar 2002 07:04:17 -0000	1.5
  @@ -10,8 +10,6 @@
   import java.io.File;
   import java.io.IOException;
   import java.io.InputStream;
  -import java.net.URL;
  -import java.net.URLClassLoader;
   import java.util.Iterator;
   import java.util.Properties;
   import org.apache.myrmidon.api.AbstractTask;
  @@ -30,23 +28,16 @@
   public class Property
       extends AbstractTask
   {
  -    private Path m_classpath;
  +    private Path m_classpath = new Path();
   
       private String m_name;
       private String m_resource;
       private String m_value;
   
  -    public void addClasspath( Path classpath )
  +    public void addClasspath( final Path classpath )
           throws TaskException
       {
  -        if( m_classpath == null )
  -        {
  -            m_classpath = classpath;
  -        }
  -        else
  -        {
  -            m_classpath.add( classpath );
  -        }
  +        m_classpath.add( classpath );
       }
   
       public void setLocation( File location )
  @@ -129,17 +120,7 @@
           getContext().debug( "Resource Loading " + name );
           try
           {
  -            ClassLoader classLoader = null;
  -
  -            if( m_classpath != null )
  -            {
  -                final URL[] urls = PathUtil.toURLs( m_classpath, getContext() );
  -                classLoader = new URLClassLoader( urls );
  -            }
  -            else
  -            {
  -                classLoader = ClassLoader.getSystemClassLoader();
  -            }
  +            final ClassLoader classLoader = PathUtil.createClassLoader( m_classpath, getContext()
);
               final InputStream is = classLoader.getResourceAsStream( name );
   
               if( is != null )
  
  
  
  1.5       +6 -27     jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/SQLExec.java
  
  Index: SQLExec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/SQLExec.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SQLExec.java	22 Mar 2002 04:12:36 -0000	1.4
  +++ SQLExec.java	27 Mar 2002 07:04:17 -0000	1.5
  @@ -18,8 +18,6 @@
   import java.io.PrintStream;
   import java.io.Reader;
   import java.io.StringReader;
  -import java.net.URL;
  -import java.net.URLClassLoader;
   import java.sql.Connection;
   import java.sql.DatabaseMetaData;
   import java.sql.Driver;
  @@ -34,10 +32,10 @@
   import java.util.StringTokenizer;
   import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.types.DirectoryScanner;
   import org.apache.tools.todo.types.EnumeratedAttribute;
   import org.apache.tools.todo.types.FileSet;
  -import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.types.PathUtil;
   import org.apache.tools.todo.types.ScannerUtil;
   
  @@ -152,7 +150,7 @@
        */
       private String encoding;
   
  -    private Path classpath;
  +    private Path classpath = new Path();
   
       /**
        * Set the autocommit flag for the DB connection.
  @@ -169,17 +167,10 @@
        *
        * @param classpath The new Classpath value
        */
  -    public void addClasspath( Path classpath )
  +    public void addClasspath( final Path classpath )
           throws TaskException
       {
  -        if( this.classpath == null )
  -        {
  -            this.classpath = classpath;
  -        }
  -        else
  -        {
  -            this.classpath.add( classpath );
  -        }
  +        this.classpath.add( classpath );
       }
   
       /**
  @@ -426,20 +417,8 @@
           // Load the driver using the
           try
           {
  -            Class dc;
  -            if( classpath != null )
  -            {
  -                getContext().debug( "Loading " + driver + " using AntClassLoader with classpath
" + classpath );
  -
  -                final URL[] urls = PathUtil.toURLs( classpath, getContext() );
  -                final ClassLoader classLoader = new URLClassLoader( urls );
  -                dc = classLoader.loadClass( driver );
  -            }
  -            else
  -            {
  -                getContext().debug( "Loading " + driver + " using system loader." );
  -                dc = Class.forName( driver );
  -            }
  +            final ClassLoader classLoader = PathUtil.createClassLoader( classpath, getContext()
);
  +            final Class dc = classLoader.loadClass( driver );
               driverInstance = (Driver)dc.newInstance();
           }
           catch( ClassNotFoundException e )
  
  
  
  1.8       +3 -8      jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java
  
  Index: JUnitTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JUnitTask.java	22 Mar 2002 04:12:37 -0000	1.7
  +++ JUnitTask.java	27 Mar 2002 07:04:17 -0000	1.8
  @@ -11,7 +11,6 @@
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.net.URL;
  -import java.net.URLClassLoader;
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.Properties;
  @@ -19,13 +18,13 @@
   import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.framework.file.Path;
   import org.apache.myrmidon.framework.java.ExecuteJava;
   import org.apache.tools.todo.types.Argument;
   import org.apache.tools.todo.types.Commandline;
   import org.apache.tools.todo.types.EnumeratedAttribute;
   import org.apache.tools.todo.types.EnvironmentData;
   import org.apache.tools.todo.types.EnvironmentVariable;
  -import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.types.PathUtil;
   import org.apache.tools.todo.types.SysProperties;
   
  @@ -641,12 +640,8 @@
           try
           {
               getContext().debug( "Using System properties " + System.getProperties() );
  -            ClassLoader classLoader = null;
  -            final URL[] urls = PathUtil.toURLs( classPath, getContext() );
  -            if( urls.length > 0 )
  -            {
  -                classLoader = new URLClassLoader( urls );
  -            }
  +            final ClassLoader classLoader = PathUtil.createClassLoader( classPath, getContext()
);
  +
               runner = new JUnitTestRunner( test,
                                             test.getHaltonerror(),
                                             test.getFiltertrace(),
  
  
  
  1.6       +2 -5      jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java
  
  Index: Rmic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Rmic.java	22 Mar 2002 07:18:08 -0000	1.5
  +++ Rmic.java	27 Mar 2002 07:04:17 -0000	1.6
  @@ -9,16 +9,14 @@
   
   import java.io.File;
   import java.io.IOException;
  -import java.net.URL;
  -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.myrmidon.framework.FileNameMapper;
  +import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.taskdefs.MatchingTask;
   import org.apache.tools.todo.types.DirectoryScanner;
  -import org.apache.myrmidon.framework.file.Path;
   import org.apache.tools.todo.types.PathUtil;
   import org.apache.tools.todo.types.SourceFileScanner;
   
  @@ -485,8 +483,7 @@
           adapter.setRmic( this );
   
           Path classpath = adapter.getClasspath();
  -        final URL[] urls = PathUtil.toURLs( classpath, getContext() );
  -        loader = new URLClassLoader( urls );
  +        loader = PathUtil.createClassLoader( classpath, getContext() );
   
           // scan base dirs to build up compile lists only if a
           // specific classname is not given
  
  
  
  1.6       +69 -8     jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathUtil.java
  
  Index: PathUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/todo/org/apache/tools/todo/types/PathUtil.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PathUtil.java	26 Mar 2002 02:15:56 -0000	1.5
  +++ PathUtil.java	27 Mar 2002 07:04:17 -0000	1.6
  @@ -14,18 +14,21 @@
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.framework.file.Path;
  +import org.apache.myrmidon.framework.file.FileList;
  +import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
  +import org.apache.myrmidon.interfaces.classloader.ClassLoaderException;
   import org.apache.aut.nativelib.Os;
   
   /**
    * Utilities for operating on Path objects.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.5 $ $Date: 2002/03/26 02:15:56 $
  + * @version $Revision: 1.6 $ $Date: 2002/03/27 07:04:17 $
    */
   public class PathUtil
   {
       /**
  -     * Formats a Path into its native representation.
  +     * Formats a path into its native representation.
        */
       public static String formatPath( final String[] path )
       {
  @@ -47,9 +50,31 @@
       }
   
       /**
  -     * Formats a Path into its native representation.
  +     * Formats a path into its native representation.
        */
  -    public static String formatPath( final Path path, final TaskContext context )
  +    public static String formatPath( final File[] path )
  +    {
  +        // empty path return empty string
  +        if( path.length == 0 )
  +        {
  +            return "";
  +        }
  +
  +        // path containing one or more elements
  +        final StringBuffer result = new StringBuffer( path[ 0 ].toString() );
  +        for( int i = 1; i < path.length; i++ )
  +        {
  +            result.append( File.pathSeparatorChar );
  +            result.append( path[ i ].getAbsolutePath() );
  +        }
  +
  +        return result.toString();
  +    }
  +
  +    /**
  +     * Formats a path into its native representation.
  +     */
  +    public static String formatPath( final FileList path, final TaskContext context )
           throws TaskException
       {
           final String[] list = path.listFiles( context );
  @@ -57,9 +82,24 @@
       }
   
       /**
  -     * Returns an array of URLs - useful for building a ClassLoader.
  +     * Converts a path into an array of Files.
        */
  -    public static URL[] toURLs( final Path path, final TaskContext context )
  +    public static File[] toFiles( final FileList path, final TaskContext context )
  +        throws TaskException
  +    {
  +        final String[] list = path.listFiles( context );
  +        final File[] result = new File[ list.length ];
  +        for( int i = 0; i < list.length; i++ )
  +        {
  +            result[ i ] = new File( list[ i ] );
  +        }
  +        return result;
  +    }
  +
  +    /**
  +     * Converts a path into an array of URLs - useful for building a ClassLoader.
  +     */
  +    public static URL[] toURLs( final FileList path, final TaskContext context )
           throws TaskException
       {
           try
  @@ -83,7 +123,26 @@
       }
   
       /**
  -     * Adds the JVM's runtime to a path.
  +     * Creates a ClassLoader from a class-path.
  +     */
  +    public static ClassLoader createClassLoader( final FileList classpath,
  +                                                 final TaskContext context )
  +        throws TaskException
  +    {
  +        final File[] files = toFiles( classpath, context );
  +        final ClassLoaderManager manager = (ClassLoaderManager)context.getService( ClassLoaderManager.class
);
  +        try
  +        {
  +            return manager.createClassLoader( files );
  +        }
  +        catch( final ClassLoaderException e )
  +        {
  +            throw new TaskException( e.getMessage(), e );
  +        }
  +    }
  +
  +    /**
  +     * Adds this JVM's runtime to a path.
        */
       public static void addJavaRuntime( final Path path )
           throws TaskException
  @@ -129,7 +188,9 @@
       /**
        * Adds the contents of a set of directories to a path.
        */
  -    public static void addExtdirs( final Path toPath, final Path extDirs, TaskContext context
)
  +    public static void addExtdirs( final Path toPath,
  +                                   final Path extDirs,
  +                                   final TaskContext context )
           throws TaskException
       {
           final String[] dirs = extDirs.listFiles( context );
  
  
  

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


Mime
View raw message