ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc Tinkler" <>
Subject Automatic Task Discovery
Date Wed, 16 Jan 2002 02:17:22 GMT
One of the stated goals of Ant 2.0 is to "make Ant more easily extendable by allowing additional
tasks to be 'dropped' in". 

I have a suggestion as to how to achieve this in 1.4:

It addresses the following problems / requirements:
1. Third-party tasks (or groups of tasks) need to be able to be dropped in to a well-known
directory and automatically be discovered.
2. Third-party tasks often rely on additional libraries, and need to be isolated from other
Third-party libraries.

My suggestion is to use a "war"-like format (I suggest .aar for Ant archive), which is a zip
file that contains one "" file that defines the taskname-task class mapping,
and any additional jar files needed by those tasks.

Under the Ant distribution, an additional directory named "tasks" would be added. On startup,
Ant would examine the "tasks" directory for ".aar" files, and (a'la tomcat) would extract
them into directories. Then, using the Taskdef Task, would add tasks to the current project.

See code below for an example implementation.

Marc Tinkler

p l u m b d e s i g n 

marc tinkler | cto, principal 
157 chambers st ny ny 10007
p.212-285-8600 x224 f.212-285-8999

The following method would be added to, and would be invoked in
runBuild() right before "project.executeTargets( targets )"


private void installTasks( Project p ) {        
        // find the task directory, and make sure it exists
        File baseDir = new File( new File( p.getProperty( "ant.home" ) ), "tasks" );
        if (!baseDir.exists() || !baseDir.isDirectory()) return;

        File files[] = baseDir.listFiles( new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toUpperCase().endsWith( ".AAR" );

        // unpack all Task Archives (*.aar)...        
        for ( int i=0;i<files.length;i++) {
            String fname = files[i].getName();
            String dirName = fname.substring(0,fname.length()-4);
            File expandDir = new File( baseDir, dirName );
            if (! expandDir.exists() ) {
       exp = new;
                exp.setProject( p );
                exp.setLocation( Location.UNKNOWN_LOCATION );
                exp.setSrc( files[i] );
                exp.setDest( expandDir );

        files = baseDir.listFiles( new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return (new File( dir, name )).isDirectory();

        // install all of the task definitions
        for ( int i=0;i<files.length;i++) {
   td = new;
            td.setProject( p );
            td.setLocation( Location.UNKNOWN_LOCATION );
   path = td.createClasspath();
   fs = new;
            fs.setDir( files[i] );
            fs.setIncludes( "*.jar" );
            path.addFileset( fs );
            File taskDefs = new File ( files[i], "" );
            if (taskDefs.exists()) td.setFile( taskDefs );


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message