Showing posts with label ant. Show all posts
Showing posts with label ant. Show all posts

01 November 2007

CompilationTask

The C preprocessor contains some predefined macros that can be used to identify the date when your pogram was compiled:

(...)
printf("%s Compiled on %s at %s.\n",argv[0],__DATE__,__TIME__);
(...)


Java has no preprocessor, and is missing this kind of information: I wrote a custom ant task generating a java file called Compilation.java and containing all the needed informations.


Compilation:
<taskdef name="compileInfoTask"
classname="org.lindenb.ant.CompileInfoTask"
classpath="build/ant"/>
(...)
<compileInfoTask name="Pubmed2Wikipedia" package="org.lindenb.util" dir="build/compile"/>




Result:


package org.lindenb.util;
import java.util.GregorianCalendar;
public class Compilation
{
private Compilation() {}
public static String getName() { return "Pubmed2Wikipedia";}
public static String getPath() { return "~/lindenb";}
public static String getUser() { return "pierre";}
public static GregorianCalendar getCalendar() { return new GregorianCalendar(2007,10,1,22,30,11);}
public static String getDate() {return "2007-11-01 at 22:30:11"; }
public static String getLabel() { return (getName()==null?"":getName()+" : ")+"Compiled by "+getUser()+" on "+getDate()+" in "+getPath();}
public static void main(String args[]) { System.out.println(getLabel());}
}


The source code is available here:

http://lindenb.googlecode.com/svn/trunk/src/java/org/lindenb/ant/CompileInfoTask.java


Pierre

Ant custom tasks

Ant, the java Make can be extended by creating your own custom task. I had fun today by creating a new Ant Task called SplashTask. It generates an new logo on the fly to be used as a java splashScreen.

Declaration:


(...) <taskdef name="makeSplash"
classname="org.lindenb.ant.SplashTask"
classpath="build/ant"/>
(...)
<target name="splash" depends="compile-ant-tasks">
<makeSplash title="Hello World !" file="task.jpeg"/>
</target>
(...)


Usage:

pierre@linux:~/lindenb> ant x
Buildfile: build.xml

compile-ant-tasks:

splash:
[makeSplash] Saved SplashScreen "Hello World !" to task.jpeg[349 x 85]



task

The source code is available at http://lindenb.googlecode.com/svn/trunk/src/java/org/lindenb/ant/SplashTask.java


Pierre