Search in sources :

Example 1 with ProjectHelper

use of org.apache.tools.ant.ProjectHelper in project processing by processing.

the class JavaBuild method buildWindowsLauncher.

/**
   * Run the launch4j build.xml file through ant to create the exe.
   * Most of this code was lifted from Android mode.
   */
protected boolean buildWindowsLauncher(File buildFile, String target) {
    Project p = new Project();
    String path = buildFile.getAbsolutePath().replace('\\', '/');
    p.setUserProperty("ant.file", path);
    // deals with a problem where javac error messages weren't coming through
    p.setUserProperty("build.compiler", "extJavac");
    // too chatty
    /*
    // try to spew something useful to the console
    final DefaultLogger consoleLogger = new DefaultLogger();
    consoleLogger.setErrorPrintStream(System.err);
    consoleLogger.setOutputPrintStream(System.out);
    // WARN, INFO, VERBOSE, DEBUG
    consoleLogger.setMessageOutputLevel(Project.MSG_ERR);
    p.addBuildListener(consoleLogger);
    */
    DefaultLogger errorLogger = new DefaultLogger();
    ByteArrayOutputStream errb = new ByteArrayOutputStream();
    PrintStream errp = new PrintStream(errb);
    errorLogger.setErrorPrintStream(errp);
    ByteArrayOutputStream outb = new ByteArrayOutputStream();
    PrintStream outp = new PrintStream(outb);
    errorLogger.setOutputPrintStream(outp);
    errorLogger.setMessageOutputLevel(Project.MSG_INFO);
    p.addBuildListener(errorLogger);
    try {
        p.fireBuildStarted();
        p.init();
        final ProjectHelper helper = ProjectHelper.getProjectHelper();
        p.addReference("ant.projectHelper", helper);
        helper.parse(p, buildFile);
        p.executeTarget(target);
        return true;
    } catch (final BuildException e) {
        // Send a "build finished" event to the build listeners for this project.
        p.fireBuildFinished(e);
        String out = new String(outb.toByteArray());
        String err = new String(errb.toByteArray());
        System.out.println(out);
        System.err.println(err);
    }
    return false;
}
Also used : Project(org.apache.tools.ant.Project) ProjectHelper(org.apache.tools.ant.ProjectHelper) BuildException(org.apache.tools.ant.BuildException) DefaultLogger(org.apache.tools.ant.DefaultLogger)

Example 2 with ProjectHelper

use of org.apache.tools.ant.ProjectHelper in project grails-core by grails.

the class GrailsConsoleAntBuilder method createAntProject.

/**
     * @return Factory method to create new Project instances
     */
@SuppressWarnings("unchecked")
protected static Project createAntProject() {
    final Project project = new Project();
    final ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
    // import checks that stack is not empty
    helper.getImportStack().addElement("AntBuilder");
    addGrailsConsoleBuildListener(project);
    project.init();
    project.getBaseDir();
    return project;
}
Also used : Project(org.apache.tools.ant.Project) ProjectHelper(org.apache.tools.ant.ProjectHelper)

Example 3 with ProjectHelper

use of org.apache.tools.ant.ProjectHelper in project gradle by gradle.

the class AntUtil method createProject.

/**
     * @return Factory method to create new Project instances
     */
public static Project createProject() {
    final Project project = new Project();
    final ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
    // import checks that stack is not empty
    helper.getImportStack().addElement("AntBuilder");
    project.addBuildListener(new AntLoggingAdapter());
    project.init();
    project.getBaseDir();
    return project;
}
Also used : Project(org.apache.tools.ant.Project) ProjectHelper(org.apache.tools.ant.ProjectHelper) AntLoggingAdapter(org.gradle.api.internal.project.ant.AntLoggingAdapter)

Example 4 with ProjectHelper

use of org.apache.tools.ant.ProjectHelper in project jsonschema2pojo by joelittlejohn.

the class Jsonschema2PojoTaskIT method invokeAntBuild.

private void invokeAntBuild(String pathToBuildFile) throws URISyntaxException {
    File buildFile = new File(this.getClass().getResource(pathToBuildFile).toURI());
    Project project = new Project();
    project.setUserProperty("ant.file", buildFile.getAbsolutePath());
    project.setUserProperty("targetDirectory", schemaRule.getGenerateDir().getAbsolutePath());
    project.init();
    ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference("ant.projecthelper", helper);
    helper.parse(project, buildFile);
    project.executeTarget(project.getDefaultTarget());
}
Also used : Project(org.apache.tools.ant.Project) ProjectHelper(org.apache.tools.ant.ProjectHelper) File(java.io.File)

Example 5 with ProjectHelper

use of org.apache.tools.ant.ProjectHelper in project querydsl by querydsl.

the class AntMetaDataExporterTest method execute_inside_ant.

@Test
public void execute_inside_ant() {
    File buildFile = new File(getClass().getResource("/build.xml").getFile());
    Project p = new Project();
    p.setUserProperty("ant.file", buildFile.getAbsolutePath());
    p.init();
    ProjectHelper helper = ProjectHelper.getProjectHelper();
    p.addReference("ant.projectHelper", helper);
    helper.parse(p, buildFile);
    p.executeTarget(p.getDefaultTarget());
    assertTrue(new File("target/AntMetaDataExporterTest4").exists());
    assertTrue(new File("target/AntMetaDataExporterTest4/test/QTest.java").exists());
}
Also used : Project(org.apache.tools.ant.Project) ProjectHelper(org.apache.tools.ant.ProjectHelper) File(java.io.File) Test(org.junit.Test)

Aggregations

Project (org.apache.tools.ant.Project)6 ProjectHelper (org.apache.tools.ant.ProjectHelper)6 File (java.io.File)3 BuildException (org.apache.tools.ant.BuildException)1 DefaultLogger (org.apache.tools.ant.DefaultLogger)1 AntLoggingAdapter (org.gradle.api.internal.project.ant.AntLoggingAdapter)1 Test (org.junit.Test)1