keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Sat Feb 17, 2007 2:50 pm Post subject: Make DSSS extendable like Ant is |
|
|
Ant can be easily extended by user tasks. To implement a user task, the task does not need to parser arguments or such. In Java it is easy, reflection is used. If a method
setMyValue( boolean a ){...}
exists, this means the Tasks can get an bool option called "myvalue" in the build.xml.
See also http://ant.apache.org/manual/index.html
Dsss could do the same. simply define a user task in the dsss.conf file with a .d file. Then dsss compiles the .d together with some files from dsss itself. The aim is, to provide a unified interface to the users tasks. It is now in a separated binary, but the arguments are passed in a well known way. And the needed args can be retrieved.
Dsss supplies this:
Code: |
public class Args{
Option[] getOptions();
Argument[] getArgument();
}
// more classes for different kinds of options
// bool, string, integer, file, fileset, dirs
// optional/non-optional
// help/usage texts
interface DsssTask{
// return object that describes the possible arguments.
// Dsss fills in the data from the dsss.conf and the commandline args.
public Args getArgs();
// Dsss will call this if all args are in place.
// shall throw DsssBuildException in case of error.
public void execute();
}
// ...
|
Dsss compile the users task together with this main module.
This module is part of the dsss distro.
Code: |
import dsss.CustomTask;
extern DsssTask getDsssTask();
int main( char[][] args ){
CustomTask.main( args, getDsssTask() );
}
|
A user task can look like this. This module is written by third party.
Code: |
DsssTask getDsssTask(){
return new MyTask();
}
class MyTask : DsssTask {
MyArgs args;
public this(){
args = new MyArgs();
}
override Args getArgs(){
return args;
}
override void execute(){
foreach( Option opt; args.getOptions ){
....
}
....
}
}
|
The main function can now provide something like a -discribeargs option, to output all options in a way, the main dsss can parse it and call the task a second time with all information it requires.
With simple arguments there is no big advantage. but now it is also possible to provide file collections or build more complex functionality on this.
Is it understandable what i want to say |
|