ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Lévy-Lambert <anto...@antbuild.com>
Subject Re: Embedding Ant...
Date Fri, 18 Jul 2003 21:05:47 GMT
Joseph :

here is one class which I wrote to run a part of the official tests of the
jar task in ant.
What you want to write to embed ant can be something like this.
Write a build.xml file somewhere and with the sequence of function calls you
see here you can call some targets of your build.xml
It is also possible not to write any build.xml and to create your targets
and your tasks programmatically, but I do not have an example for that at
hand.
Cheers,
Antoine

package com.tonisoft;

import org.apache.tools.ant.*;

import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: administrator
 * Date: Jan 21, 2003
 * Time: 2:25:50 PM
 * To change this template use Options | File Templates.
 */
public class testjartask {
    public static void main (String [] argv){

        //String filename="/dev/testant/build.xml";
        String
filename="/dev/gnu/ant/jakarta-ant/src/etc/testcases/taskdefs/jar.xml";
        StringBuffer logBuffer;
        StringBuffer fullLogBuffer;
        Project project=new Project();
        logBuffer = new StringBuffer();
        fullLogBuffer = new StringBuffer();
        project = new Project();
        project.init();
        project.setUserProperty( "ant.file" , new
File(filename).getAbsolutePath() );
        ProjectHelper.configureProject(project, new File(filename));
        project.addBuildListener(createLogger());
        //project.executeTarget("cleanup");
        project.executeTarget("test4");
        project.executeTarget("testRecreateNewerFileSetup");
        project.executeTarget("testRecreateWithUpdateNewerFile");
    }
    private static BuildLogger createLogger() {
        BuildLogger logger = null;
        logger = new DefaultLogger();
        logger.setMessageOutputLevel(Project.MSG_INFO);
        logger.setOutputPrintStream(System.out);
        logger.setErrorPrintStream(System.err);
        logger.setEmacsMode(false);

        return logger;
    }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message