ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: [PROPOSAL] Class dependency checking for optional tasks
Date Sun, 21 Jan 2001 03:39:42 GMT
At 10:01  20/1/01 -0500, Bill Burton wrote:
>Hello,

hi ;)

>One of the questions that comes up a lot on the ant-user list is, "Where
>do a find the classes for ftp support, etc?"  As a result, it was good to
>see Nico's patches to clarify the docs in this area.  I've been thinking
>about this problem from a little different perspective.

kewl.

>
>Overview 
>
>Each task requiring external classes should provide a way the task
>developer can declare the required jar file(s) by specifing a class within
>each jar to check for the availability of the jar.  If the class isn't
>available, the task will throw a BuildException with the name of the
>missing jar and the URL where it can be obtained.

sounds good.

>    /**
>     * Tries to load the specified class ensuring any associated jar 
>     * file is available.  If the class is not available, a BuildException
>     * is thrown with the specified comment.  The comment should concisely 
>     * provide information indicating what's missing and where it can be 
>     * obtained.
>     * 
>     * @param name name of class to check in the classpath
>     * @param loader class loader or null for the default 
>     *        class loader
>     * @param comment text describing the name of the class or 
>     *        associated jar file and the URL or location where it 
>     *        can be obtained
>     */
>    public void checkForRequiredClass(String name, ClassLoader loader,
>String comment)
>        throws BuildExeception

Unfortunately this would only work in a small proportion of cases. Namely
the cases that use the class via reflection. In the case of FTP it actually
imports the classes explicitly. Thus the ClassNotFound exception would
still be thrown - when class is loaded. It would not even get the
oportunity to define, and instantiate the class so you could call
checkForRequiredClass().

In some cases with tasks that do act via reflection this would be a great
idea. However instead of placing it in Task class I think it may be better
to create a new class TaskUtil to contain it. So you could use it like

void init() throws BuildException
{
  TaskUtil.checkJavaVersion( JavaVersion.JDK1_2 );
  TaskUtil.checkForRequiredClass("com.oroinc.net.ftp.FTPClient", null
                          "Requires ORO NetComponents available at" +

"http://www.savarese.org/oro/software/NetComponents.html");

  TaskUtil.checkFor...();
}

>If the consensus is that this is a good idea, I'll work on a patch for
>this functionality.

I don't think it would apply to FTP task (or majority of cases) but where
it does apply it would be very useful. Love to see a patch ;)

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*


Mime
View raw message