costin      2002/12/28 21:56:26

  Modified:    src/main/org/apache/tools/ant/taskdefs Definer.java
  Log:
  Few small changes. If the core loader is set and no explicit classpath
  is present, use it.
  
  I think this can be further cleaned up to use the right parent loader
  etc. But probably the best would be to just use the loaderRef.
  Or just deprecate Definer completely - when we have a good antlib solution
  
  Also added getters ( it's nice to have access to info - especially with
  dynamic properties :-)
  
  Revision  Changes    Path
  1.23      +50 -8     
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Definer.java
  
  Index: Definer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Definer.java      21 Dec 2002 15:04:17 -0000      1.22
  +++ Definer.java      29 Dec 2002 05:56:26 -0000      1.23
  @@ -98,6 +98,34 @@
               Project.MSG_WARN);
       }
   
  +    public String getName() {
  +        return name;
  +    }
  +
  +    public Path getClasspath() {
  +        return classpath;
  +    }
  +
  +    public File getFile() {
  +        return file;
  +    }
  +
  +    public String getResource() {
  +        return resource;
  +    }
  +
  +    public boolean isReverseLoader() {
  +        return reverseLoader;
  +    }
  +
  +    public String getLoaderId() {
  +        return loaderId;
  +    }
  +
  +    public String getClasspathId() {
  +        return classpathId;
  +    }
  +
       /**
        * Set the classpath to be used when searching for component being 
defined
        *
  @@ -147,7 +175,7 @@
   
   
       public void execute() throws BuildException {
  -        AntClassLoader al = createLoader();
  +        ClassLoader al = createLoader();
   
           if (file == null && resource == null) {
   
  @@ -243,7 +271,7 @@
       /**
        * create a classloader for this definition
        */
  -    private AntClassLoader createLoader() {
  +    private ClassLoader createLoader() {
           // magic property
           if (getProject().getProperty(REUSE_LOADER_REF) != null) {
               // Generate the 'reuse' name automatically from the reference.
  @@ -259,9 +287,10 @@
           if (loaderId != null) {
               Object reusedLoader = getProject().getReference(loaderId);
               if (reusedLoader != null) {
  -                if (reusedLoader instanceof AntClassLoader) {
  -                    return (AntClassLoader)reusedLoader;
  -                }
  +                return (ClassLoader)reusedLoader;
  +                //if (reusedLoader instanceof AntClassLoader) {
  +                //    return (AntClassLoader)reusedLoader;
  +                //}
                   // In future the reference object may be the <loader> type
                   // if( reusedLoader instanceof Loader ) {
                   //      return ((Loader)reusedLoader).getLoader(project);
  @@ -269,17 +298,30 @@
               }
           }
   
  -        AntClassLoader al = null;
  +        ClassLoader al = null;
  +
  +        if( classpath ==null ) {
  +            // do we need to create another loader ?
  +            al=project.getCoreLoader();
  +            if( al != null ) {
  +                return al;
  +            }
  +        }
  +
           if (classpath != null) {
  +            project.log( "Creating new loader for taskdef using " + 
classpath +
  +                    " reverse=" + reverseLoader, Project.MSG_DEBUG );
               al = new AntClassLoader(getProject(), classpath, !reverseLoader);
           } else {
  +            // XXX Probably it would be better to reuse 
getClass().getClassLoader()
  +            // I don't think we need a new ( identical ) loader for each task
               al = new AntClassLoader(getProject(), Path.systemClasspath,
  -                                    !reverseLoader);
  +                    !reverseLoader);
           }
           // need to load Task via system classloader or the new
           // task we want to define will never be a Task but always
           // be wrapped into a TaskAdapter.
  -        al.addSystemPackageRoot("org.apache.tools.ant");
  +        ((AntClassLoader)al).addSystemPackageRoot("org.apache.tools.ant");
   
   
           // If the loader is new, record it for future uses by other
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to