You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@apache.org on 2002/05/26 09:03:24 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Definer.java

costin      02/05/26 00:03:24

  Modified:    src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        Definer.java
  Log:
  The fix for Definer.
  
  'loaderRef' attribute is used to identify the loader. If a <loader> type
  will be later introduced the code here needs just minor changes to support
  it.
  
  Please review and let me know if there are any problems, I know classloader
  is a tricky area.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.15.2.1  +53 -2     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.15
  retrieving revision 1.15.2.1
  diff -u -r1.15 -r1.15.2.1
  --- Definer.java	18 Apr 2002 06:54:54 -0000	1.15
  +++ Definer.java	26 May 2002 07:03:24 -0000	1.15.2.1
  @@ -84,7 +84,9 @@
       private File file;
       private String resource;
       private boolean reverseLoader = false;
  -
  +    private String loaderId=null;
  +    private String classpathId=null;
  +    
       public void setReverseLoader(boolean reverseLoader) {
           this.reverseLoader = reverseLoader;
           log("The reverseloader attribute is DEPRECATED. It will be removed", 
  @@ -112,9 +114,23 @@
       }
   
       public void setClasspathRef(Reference r) {
  +        classpathId=r.getRefId();
           createClasspath().setRefid(r);
       }
   
  +    /**
  +     * Use the reference to locate the loader. If the loader is not found, taskdef will
  +     * use the specified classpath and register it with the specified name.
  +     *     
  +     * This allow multiple taskdef/typedef to use the same class loader,
  +     * so they can be used togheter. It eliminate the need to
  +     * put them in the CLASSPATH.
  +     */
  +    public void setLoaderRef( Reference r ) {
  +        loaderId=r.getRefId();
  +    }
  +
  +    
       public void execute() throws BuildException {
           AntClassLoader al = createLoader();
   
  @@ -205,8 +221,35 @@
           }
       }
   
  -
  +    static final String REUSE_LOADER_REF="ant.reuse.loader";
  +    
       private AntClassLoader createLoader() {
  +        // magic property 
  +        if( project.getProperty( REUSE_LOADER_REF ) != null ) {
  +            // Generate the 'reuse' name automatically from the reference.
  +            // This allows <taskdefs> that work on both ant1.4 and ant1.5.
  +            // ( in 1.4 it'll require the task/type to be in classpath if they
  +            //   are used togheter ).
  +            if( loaderId==null && classpathId !=null ) {
  +                loaderId="ant.loader." + classpathId;
  +            }
  +        }
  +
  +        // If a loader has been set ( either by loaderRef or magic property )
  +        if( loaderId != null ) {
  +            Object reusedLoader=project.getReference( loaderId );
  +                if( reusedLoader != null ) {
  +                    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);
  +                    // }
  +                }
  +            }
  +        }
  +       
           AntClassLoader al = null;
           if (classpath != null) {
               al = new AntClassLoader(project, classpath, !reverseLoader);
  @@ -218,6 +261,14 @@
           // task we want to define will never be a Task but always
           // be wrapped into a TaskAdapter.
           al.addSystemPackageRoot("org.apache.tools.ant");
  +
  +
  +        // If the loader is new, record it for future uses by other task/typedefs
  +        if( loaderId != null ) {
  +            if( project.getReference( loaderId ) == null ) 
  +                project.addReference( loaderId, al );
  +        }
  +
           return al;
       }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Definer.java

Posted by Stefan Bodewig <bo...@apache.org>.
On 26 May 2002, <co...@apache.org> wrote:

>   Please review and let me know if there are any problems,

I couldn't see any problems so far - I committed a few changes to the
coding style to make the source look consistent (needed to up my CVS
commits per day statistics 8-) and made the magic property thing
private.  These should be enough to make checkstyle happy.

I'm willing to roll back that change if you can convince me that it
should be package private.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>