 |
Using jrunscript as a build tool
Posted by forax on September 14, 2006 at 03:34 PM | Comments (7)
In my last post, i've described how to use jrunscript to
create a build script.
As olivier wrote in the comments, the build process is usually
a dependency graph and jrunscript doesn't do that by default.
But javascript is far more powerful than XML
thus it's easy to create commands that enable to declare
dependencies betweeen functions as Ant or make does.
I propose the following commands:
- depends_on that declares a set of dependencies of a function.
- run_targets that explores the graph from a function
in a dependency first order.
Javascript enables to put data in an existing
object even a one like Object or Function.
In fact, objects are considered as an hashtable of couples
property/value so the dependencies of a function can be stored
in the function itself.
The build script:
function test1() {
echo("test 1");
}
function test2() {
echo("test 2");
}
test2.depends_on(test1);
function test3() {
echo("test 3");
}
test3.depends_on(test1,test2);
run_targets(test3);
And the script that creates the two commands :
function depends_on() {
var dependencies=new Array();
for (var i=0;i<arguments.length;i++) {
dependencies.push(arguments[i]);
}
this.dependencies=dependencies;
}
Function.prototype.depends_on=depends_on;
function run_targets(target) {
run_targets_internal(target,new Object())
}
function run_targets_internal(target,markers) {
if (markers[target]=="X")
return
markers[target]="X"
for each(dependency in target.dependencies) {
run_targets_internal(dependency,markers);
}
echo("target "+target.name);
target();
}
Now, it's time to drop Ant :)
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
I find the syntax a little ugly; this seems nicer, using Groovy: JavaWorld article on Groovy and Ant
Regards, Patrick
Posted by: pdoubleya on September 15, 2006 at 01:17 AM
-
I often have to copy *.xml and *.properties files from the source folder to the build folder. So the for example the file 'src/mypackage/MyProperties.properties' should become 'classes/mypackage/MyProperties.properties'.
Is there an easy way to do this with jrunscript?
Thanks.
Posted by: gruenewa on September 15, 2006 at 01:22 AM
-
It seems jrunscript could be a nice way to build Java application, but as it allows to select the language of the script it runs, maybe another script language would be better solution than javascript. Anyway this tool offers really interesting possibilities !
Posted by: micf on September 15, 2006 at 01:30 AM
-
Why do people hate ant so much? I find it pretty painless. It takes a few minutes to setup a build script, and it has so many plugins... It's popular because it simply works!
Posted by: ilazarte on September 15, 2006 at 07:31 AM
-
In order to replace ant, you'd have to have everything that ant has (including plugins), you'd have to do it simpler, and you have to be able to do something that ant can't. Specific examples in all three areas would be greatly appreciated.
Posted by: kirillcool on September 15, 2006 at 05:12 PM
-
@gruenewa, see find and mv here.
@pdoubleya, jrunscript uses javascript by default but you can switch to
the script language you like (scripting.dev.java.net) .
@ilazarte, i love Ant because as you said it keep things simple, but i try to
to train my mind to stay open.
@kirillcool, i think that you already know that a Ant task is Java class so it can be called like any other java class,
(see ant external)
thus you can use all the Ant plugins with jrunscript.
Furthermore because Ant and jrunscript rely on Java, all what you can express with Ant can be expressed with jrunscript, not more not less. The both are
bound by Java.
Posted by: forax on September 17, 2006 at 05:10 AM
-
it's a cool idea. I spent some time to develop 7Bee build tool to achieve a similar goal. personally I do not like Ant and Ant based tools, too much footprint, cumbersome syntax, no flexibility of a real scripting language.
Posted by: dmitryr on February 08, 2007 at 03:35 PM
|