HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Customizing Ant"
Vol. 8, Issue 9, p. 38

	



Listing 1 Code template for a custom task

import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;

public class VersionMap extends Task {

    private String file;
    private String dest;

    public VersionMap() {
    }

    public void setFile(String file) {
        this.file = file;
    }

    public void setDest( String dest) {
        this.dest = dest;
    }

    public void execute() throws BuildException {
        try {
            execute0();
        } catch (BuildException be) {
            if (failonerror)
                throw be;
            else
                log(be.getMessage());
        }
    }
}



Listing 2  Triggering a get from CVS

    public void execute0() throws BuildException {
        try {
            this.createSourceDir( this.dest);
            VersionMap map = VersionMap.createFrom( this.file);
            Iterator iter = map.iterator();
            while ( iter.hasNext())
                ((VersionMapEntry)iter.next()).processMapEntry( this);
        } catch (Exception e) {
            throw new BuildException(e);
        }
    }

    private void executeTask(Task task) throws BuildException {
        task.setProject(this.getProject());
        task.setLocation(this.getLocation());
        task.setOwningTarget(this.getOwningTarget());
        task.init();
        task.execute();
    }

    public void getSourceFromCVS(String moduleName, String version, String dest)
    throws BuildException {
        Cvs task = new Cvs();
        task.setCommand("checkout");
        task.setPackage(moduleName);
        task.setTag(version);
        task.setDest(dest);
        this.executeTask(task);
    }

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.