ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/ant1compat/src/java/org/apache/tools/ant/types Path.java
Date Thu, 11 Jul 2002 03:43:58 GMT
donaldp     2002/07/10 20:43:58

  Modified:    ant1compat/src/java/org/apache/tools/ant Task.java
  Removed:     ant1compat/src/java/org/apache/tools/ant LoaderUtils.java
               ant1compat/src/java/org/apache/tools/ant/types Path.java
  Log:
  Merged augmentation of Path from LoaderUtils/Path objects back into Task object to make
it easier to maintain diffs to ant1.x
  
  Revision  Changes    Path
  1.4       +77 -10    jakarta-ant-myrmidon/ant1compat/src/java/org/apache/tools/ant/Task.java
  
  Index: Task.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/ant1compat/src/java/org/apache/tools/ant/Task.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Task.java	27 May 2002 02:10:18 -0000	1.3
  +++ Task.java	11 Jul 2002 03:43:58 -0000	1.4
  @@ -12,6 +12,10 @@
   import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.api.metadata.ModelException;
   import org.apache.myrmidon.api.metadata.Modeller;
  +import org.apache.tools.ant.types.Path;
  +import java.net.URLClassLoader;
  +import java.net.URL;
  +import java.io.File;
   
   /**
    * Ant1 Task proxy for Myrmidon.
  @@ -27,35 +31,51 @@
       extends OriginalAnt1Task
       implements org.apache.myrmidon.api.Task, Modeller
   {
  -    protected TaskContext m_context;
  +    //Modified from original source.
  +    //Append Ant1Compat classpath to systemclasspath.
  +    // ------------------Modified--------------------------------
  +    static
  +    {
  +        // Add Ant1Compat.atl to system classpath.
  +        final String classpath = getClasspath( Path.class.getClassLoader() );
  +        Path.systemClasspath.append( new Path( null, classpath ) );
  +    }
  +    //-----------------End Modified------------------------------
  +    private TaskContext m_context;
  +
  +    protected final TaskContext getTaskContext()
  +    {
  +        return m_context;
  +    }
   
       /**
        * Specify the context in which the task operates in.
        * The Task will use the TaskContext to receive information
        * about it's environment.
        */
  -    public void contextualize( TaskContext context )
  +    public void contextualize( final TaskContext context )
           throws TaskException
       {
           m_context = context;
   
  -        this.setTaskType( context.getName() );
  -        this.setTaskName( context.getName() );
  +        setTaskType( context.getName() );
  +        setTaskName( context.getName() );
   
           // Create/recontextualise the Ant1 Project.
  +        final String key = Ant1CompatProject.ANT1_PROJECT_PROP;
           Ant1CompatProject project =
  -            (Ant1CompatProject)context.getProperty( Ant1CompatProject.ANT1_PROJECT_PROP
);
  +            (Ant1CompatProject)context.getProperty( key );
           if( project == null )
           {
               project = createProject();
  -            m_context.setProperty( Ant1CompatProject.ANT1_PROJECT_PROP, project );
  +            getTaskContext().setProperty( key, project );
           }
           else
           {
               project.recontextulize( context );
           }
   
  -        this.setProject( project );
  +        setProject( project );
       }
   
       /**
  @@ -64,7 +84,8 @@
       private Ant1CompatProject createProject()
           throws TaskException
       {
  -        Ant1CompatProject project = new Ant1CompatProject( m_context );
  +        final Ant1CompatProject project =
  +            new Ant1CompatProject( getTaskContext() );
           project.init();
           return project;
       }
  @@ -100,10 +121,56 @@
       {
           //TODO Maybe provide different ModelElement order for tasks not in a target,
           // elements in a TaskContainer etc...
  -        Ant1CompatConfigurer configurer =
  +        final Ant1CompatConfigurer configurer =
               new Ant1CompatConfigurer( target, modelElement, project );
           configurer.createChildren();
           configurer.configure();
           this.init();
  +    }
  +
  +    /**
  +     * Get the classpath from a classloader. This can only extract path
  +     * components from the loaders which are instances of URLClassLoaders
  +     *
  +     * @param loader the loader whose path is required
  +     * @return the loader's configuration expressed as a classpath
  +     */
  +    private static String getClasspath( ClassLoader loader )
  +    {
  +        StringBuffer pathBuffer = null;
  +        if( loader instanceof URLClassLoader )
  +        {
  +            URLClassLoader urlLoader = (URLClassLoader)loader;
  +            URL[] urls = urlLoader.getURLs();
  +            for( int i = 0; i < urls.length; ++i )
  +            {
  +                if( !urls[ i ].getProtocol().equals( "file" ) )
  +                {
  +                    continue;
  +                }
  +                String pathElement = urls[ i ].getFile();
  +                if( pathBuffer == null )
  +                {
  +                    pathBuffer = new StringBuffer( pathElement );
  +                }
  +                else
  +                {
  +                    pathBuffer.append( File.pathSeparatorChar );
  +                    pathBuffer.append( pathElement );
  +                }
  +            }
  +        }
  +        String path = pathBuffer == null ? "" : pathBuffer.toString();
  +        ClassLoader parentLoader = loader.getParent();
  +        if( parentLoader != null )
  +        {
  +            String parentPath = getClasspath( parentLoader );
  +            if( parentPath.length() != 0 )
  +            {
  +                path = parentPath + File.pathSeparator + path;
  +            }
  +        }
  +
  +        return path;
       }
   }
  
  
  

--
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