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 "defaults.properties" 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 org.apache.tools.ant.Main, 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() ) {
org.apache.tools.ant.taskdefs.Expand exp = new org.apache.tools.ant.taskdefs.Expand();
exp.setProject( p );
exp.setLocation( Location.UNKNOWN_LOCATION );
exp.init();
exp.setSrc( files[i] );
exp.setDest( expandDir );
exp.execute();
}
}
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++) {
org.apache.tools.ant.taskdefs.Taskdef td = new org.apache.tools.ant.taskdefs.Taskdef();
td.setProject( p );
td.setLocation( Location.UNKNOWN_LOCATION );
td.init();
org.apache.tools.ant.types.Path path = td.createClasspath();
org.apache.tools.ant.types.FileSet fs = new org.apache.tools.ant.types.FileSet();
fs.setDir( files[i] );
fs.setIncludes( "*.jar" );
path.addFileset( fs );
File taskDefs = new File ( files[i], "defaults.properties" );
if (taskDefs.exists()) td.setFile( taskDefs );
td.execute();
}
}
}
--
To unsubscribe, e-mail: <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>
|