Search in sources :

Example 61 with Project

use of org.apache.tools.ant.Project 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)

Example 62 with Project

use of org.apache.tools.ant.Project in project groovy by apache.

the class RootLoaderRef method execute.

public void execute() throws BuildException {
    if (taskClasspath == null || taskClasspath.size() == 0) {
        throw new BuildException("no classpath given");
    }
    Project project = getProject();
    AntClassLoader loader = new AntClassLoader(makeRoot(), true);
    project.addReference(name, loader);
}
Also used : Project(org.apache.tools.ant.Project) AntClassLoader(org.apache.tools.ant.AntClassLoader) BuildException(org.apache.tools.ant.BuildException)

Example 63 with Project

use of org.apache.tools.ant.Project in project groovy by apache.

the class GroovycTest method setUp.

protected void setUp() throws Exception {
    //  Potentially throws Exception.
    super.setUp();
    project = new Project();
    project.init();
    ProjectHelper.getProjectHelper().parse(project, antFile);
    project.executeTarget("clean");
    String altJavaHome = System.getProperty("java.home");
    if (altJavaHome.lastIndexOf("jre") >= 0) {
        altJavaHome = altJavaHome.substring(0, altJavaHome.lastIndexOf("jre"));
    } else {
        altJavaHome = altJavaHome + File.separator + "jre";
    }
    try {
        File altFile = new File(altJavaHome);
        if (altFile.exists()) {
            project.setProperty("alt.java.home", altJavaHome);
        }
    } catch (Exception e) {
    // could be security, io, etc.  Ignore it.
    // End result is as if .exists() returned null
    }
}
Also used : Project(org.apache.tools.ant.Project) BuildException(org.apache.tools.ant.BuildException)

Example 64 with Project

use of org.apache.tools.ant.Project in project groovy by apache.

the class Groovy method execGroovy.

/**
     * Exec the statement.
     *
     * @param txt the groovy source to exec
     * @param out not used?
     */
protected void execGroovy(final String txt, final PrintStream out) {
    log.debug("execGroovy()");
    // Check and ignore empty statements
    if ("".equals(txt.trim())) {
        return;
    }
    log.verbose("Script: " + txt);
    if (classpath != null) {
        log.debug("Explicit Classpath: " + classpath.toString());
    }
    if (fork) {
        log.debug("Using fork mode");
        try {
            createClasspathParts();
            createNewArgs(txt);
            super.setFork(fork);
            super.setClassname(useGroovyShell ? "groovy.lang.GroovyShell" : "org.codehaus.groovy.ant.Groovy");
            configureCompiler();
            super.execute();
        } catch (Exception e) {
            StringWriter writer = new StringWriter();
            new ErrorReporter(e, false).write(new PrintWriter(writer));
            String message = writer.toString();
            throw new BuildException("Script Failed: " + message, e, getLocation());
        }
        return;
    }
    Object mavenPom = null;
    final Project project = getProject();
    final ClassLoader baseClassLoader;
    ClassLoader savedLoader = null;
    final Thread thread = Thread.currentThread();
    boolean maven = "org.apache.commons.grant.GrantProject".equals(project.getClass().getName());
    // treat the case Ant is run through Maven, and
    if (maven) {
        if (contextClassLoader) {
            throw new BuildException("Using setContextClassLoader not permitted when using Maven.", getLocation());
        }
        try {
            final Object propsHandler = project.getClass().getMethod("getPropsHandler").invoke(project);
            final Field contextField = propsHandler.getClass().getDeclaredField("context");
            contextField.setAccessible(true);
            final Object context = contextField.get(propsHandler);
            mavenPom = InvokerHelper.invokeMethod(context, "getProject", EMPTY_OBJECT_ARRAY);
        } catch (Exception e) {
            throw new BuildException("Impossible to retrieve Maven's Ant project: " + e.getMessage(), getLocation());
        }
        // load groovy into "root.maven" classloader instead of "root" so that
        // groovy script can access Maven classes
        baseClassLoader = mavenPom.getClass().getClassLoader();
    } else {
        baseClassLoader = GroovyShell.class.getClassLoader();
    }
    if (contextClassLoader || maven) {
        savedLoader = thread.getContextClassLoader();
        thread.setContextClassLoader(GroovyShell.class.getClassLoader());
    }
    final String scriptName = computeScriptName();
    final GroovyClassLoader classLoader = new GroovyClassLoader(baseClassLoader);
    addClassPathes(classLoader);
    configureCompiler();
    final GroovyShell groovy = new GroovyShell(classLoader, new Binding(), configuration);
    try {
        parseAndRunScript(groovy, txt, mavenPom, scriptName, null, new AntBuilder(this));
    } finally {
        groovy.resetLoadedClasses();
        groovy.getClassLoader().clearCache();
        if (contextClassLoader || maven)
            thread.setContextClassLoader(savedLoader);
    }
}
Also used : Binding(groovy.lang.Binding) AntBuilder(groovy.util.AntBuilder) MissingMethodException(groovy.lang.MissingMethodException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) GroovyShell(groovy.lang.GroovyShell) GroovyClassLoader(groovy.lang.GroovyClassLoader) Project(org.apache.tools.ant.Project) Field(java.lang.reflect.Field) ErrorReporter(org.codehaus.groovy.tools.ErrorReporter) StringWriter(java.io.StringWriter) GroovyClassLoader(groovy.lang.GroovyClassLoader) BuildException(org.apache.tools.ant.BuildException) PrintWriter(java.io.PrintWriter)

Example 65 with Project

use of org.apache.tools.ant.Project in project nhin-d by DirectProject.

the class AntExecutor method main.

public static void main(String[] args) {
    try {
        File buildFile = new File(args[0]);
        Project project = new Project();
        project.setUserProperty("ant.file", buildFile.getAbsolutePath());
        project.init();
        ProjectHelper helper = ProjectHelper.getProjectHelper();
        project.addReference("ant.projectHelper", helper);
        helper.parse(project, buildFile);
        project.executeTarget(project.getDefaultTarget());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : Project(org.apache.tools.ant.Project) ProjectHelper(org.apache.tools.ant.ProjectHelper) File(java.io.File)

Aggregations

Project (org.apache.tools.ant.Project)80 File (java.io.File)35 BuildException (org.apache.tools.ant.BuildException)23 IOException (java.io.IOException)17 Test (org.junit.Test)13 FileSet (org.apache.tools.ant.types.FileSet)11 ZipFile (java.util.zip.ZipFile)10 IgniteDeploymentGarAntTask (org.apache.ignite.util.antgar.IgniteDeploymentGarAntTask)8 Path (org.apache.tools.ant.types.Path)6 DefaultLogger (org.apache.tools.ant.DefaultLogger)5 ProjectHelper (org.apache.tools.ant.ProjectHelper)5 MissingMethodException (groovy.lang.MissingMethodException)4 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)4 Task (org.apache.tools.ant.Task)4 AbstractProject (hudson.model.AbstractProject)3 Target (org.apache.tools.ant.Target)3 Zip (org.apache.tools.ant.taskdefs.Zip)3 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)3 Binding (groovy.lang.Binding)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2