1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import org.apache.tools.ant.*;
import java.io.*;
public class Compilateur {
//public Compilateur();
public boolean Compilateur(String buildxml, String target){
boolean result=true;
File buildFile = new File(buildxml);
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
try {
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(target);
p.fireBuildFinished(null);
return result;
} catch (BuildException e) {
//Traiter cette exception
result=false;
return result;
//p.fireBuildFinished(e);
}
}
} |
Partager