Search in sources :

Example 26 with Project

use of org.apache.tools.ant.Project in project maven-plugins by apache.

the class AntRunMojo method execute.

/** {@inheritDoc} */
public void execute() throws MojoExecutionException, MojoFailureException {
    checkDeprecatedParameterUsage(tasks, "tasks", "target");
    checkDeprecatedParameterUsage(sourceRoot, "sourceRoot", "the build-helper-maven-plugin");
    checkDeprecatedParameterUsage(testSourceRoot, "testSourceRoot", "the build-helper-maven-plugin");
    if (skip) {
        getLog().info("Skipping Antrun execution");
        return;
    }
    MavenProject mavenProject = getMavenProject();
    if (target == null) {
        getLog().info("No Ant target defined - SKIPPED");
        return;
    }
    if (propertyPrefix == null) {
        propertyPrefix = "";
    }
    try {
        Project antProject = new Project();
        File antBuildFile = this.writeTargetToProjectFile();
        ProjectHelper.configureProject(antProject, antBuildFile);
        antProject.init();
        DefaultLogger antLogger = new MavenLogger(getLog());
        if (getLog().isDebugEnabled()) {
            antLogger.setMessageOutputLevel(Project.MSG_DEBUG);
        } else if (getLog().isInfoEnabled()) {
            antLogger.setMessageOutputLevel(Project.MSG_INFO);
        } else if (getLog().isWarnEnabled()) {
            antLogger.setMessageOutputLevel(Project.MSG_WARN);
        } else if (getLog().isErrorEnabled()) {
            antLogger.setMessageOutputLevel(Project.MSG_ERR);
        } else {
            antLogger.setMessageOutputLevel(Project.MSG_VERBOSE);
        }
        antProject.addBuildListener(antLogger);
        antProject.setBaseDir(mavenProject.getBasedir());
        Path p = new Path(antProject);
        p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator));
        /* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
        antProject.addReference(MAVEN_REFID_PREFIX + "dependency.classpath", p);
        antProject.addReference(MAVEN_REFID_PREFIX + "compile.classpath", p);
        p = new Path(antProject);
        p.setPath(StringUtils.join(mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator));
        antProject.addReference(MAVEN_REFID_PREFIX + "runtime.classpath", p);
        p = new Path(antProject);
        p.setPath(StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator));
        antProject.addReference(MAVEN_REFID_PREFIX + "test.classpath", p);
        /* set maven.plugin.classpath with plugin dependencies */
        antProject.addReference(MAVEN_REFID_PREFIX + "plugin.classpath", getPathFromArtifacts(pluginArtifacts, antProject));
        antProject.addReference(DEFAULT_MAVEN_PROJECT_REFID, mavenProject);
        antProject.addReference(DEFAULT_MAVEN_PROJECT_REF_REFID, new MavenAntRunProject(mavenProject));
        antProject.addReference(DEFAULT_MAVEN_PROJECT_HELPER_REFID, projectHelper);
        antProject.addReference(MAVEN_REFID_PREFIX + "local.repository", localRepository);
        initMavenTasks(antProject);
        // The Ant project needs actual properties vs. using expression evaluator when calling an external build
        // file.
        copyProperties(mavenProject, antProject);
        if (getLog().isInfoEnabled()) {
            getLog().info("Executing tasks");
        }
        antProject.executeTarget(antTargetName);
        if (getLog().isInfoEnabled()) {
            getLog().info("Executed tasks");
        }
        copyProperties(antProject, mavenProject);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("DependencyResolutionRequiredException: " + e.getMessage(), e);
    } catch (BuildException e) {
        StringBuilder sb = new StringBuilder();
        sb.append("An Ant BuildException has occured: ").append(e.getMessage());
        String fragment = findFragment(e);
        if (fragment != null) {
            sb.append("\n").append(fragment);
        }
        if (!failOnError) {
            getLog().info(sb.toString(), e);
            // do not register roots.
            return;
        } else {
            throw new MojoExecutionException(sb.toString(), e);
        }
    } catch (Throwable e) {
        throw new MojoExecutionException("Error executing Ant tasks: " + e.getMessage(), e);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProject(org.apache.maven.project.MavenProject) Project(org.apache.tools.ant.Project) MavenProject(org.apache.maven.project.MavenProject) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) DefaultLogger(org.apache.tools.ant.DefaultLogger)

Example 27 with Project

use of org.apache.tools.ant.Project in project maven-plugins by apache.

the class TestTask method execute.

public void execute() throws BuildException {
    Project p = this.getProject();
    System.out.println("sourceDirectory:" + p.getProperty("project.build.sourceDirectory"));
    System.out.println("project.cmdline:" + p.getProperty("project.cmdline"));
    System.out.println("basedir:" + p.getProperty("basedir"));
}
Also used : Project(org.apache.tools.ant.Project)

Example 28 with Project

use of org.apache.tools.ant.Project in project xtext-xtend by eclipse.

the class XtendCompilerAntTaskTest method configureProject.

/**
 * Sets up to run the named project
 *
 * @param filename
 *            name of project file to run
 */
protected void configureProject(String filename) throws BuildException {
    project = new Project();
    project.init();
    File antFile = new File(System.getProperty("root"), filename);
    File depsFolder = new File(System.getProperty("root"), "target/antDeps");
    project.setUserProperty("deps.dir", depsFolder.getAbsolutePath());
    project.setUserProperty("ant.file", antFile.getAbsolutePath());
    antTestListener = new AntTestListener(Project.MSG_ERR);
    project.addBuildListener(antTestListener);
    ProjectHelper.configureProject(project, antFile);
}
Also used : Project(org.apache.tools.ant.Project) File(java.io.File)

Example 29 with Project

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

the class GridToolsSelfTest method testAntGarTaskWithDoubleP2PDescriptor.

/**
 * @throws Exception If failed.
 */
public void testAntGarTaskWithDoubleP2PDescriptor() throws Exception {
    String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir");
    String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir");
    String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_2";
    String metaDirName = baseDirName + File.separator + "META-INF";
    String garFileName = baseDirName + ".gar";
    String garDescrDirName = U.resolveIgnitePath(GridTestProperties.getProperty("ant.gar.descriptor.dir")).getAbsolutePath() + File.separator + "ignite.xml";
    // Make base and META-INF dir.
    boolean mkdir = new File(baseDirName).mkdirs();
    assert mkdir;
    mkdir = new File(metaDirName).mkdirs();
    assert mkdir;
    // Make Gar file
    U.copy(new File(garDescrDirName), new File(metaDirName + File.separator + "ignite.xml"), true);
    // Copy files to basedir
    U.copy(new File(srcDirName), new File(baseDirName), true);
    IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask();
    Project garProject = new Project();
    garProject.setName("Gar test project");
    garTask.setDestFile(new File(garFileName));
    garTask.setDescrdir(new File(garDescrDirName));
    garTask.setBasedir(new File(baseDirName));
    garTask.setProject(garProject);
    try {
        garTask.execute();
        assert false;
    } catch (BuildException e) {
        if (log().isInfoEnabled())
            log().info(e.getMessage());
    }
}
Also used : Project(org.apache.tools.ant.Project) IgniteDeploymentGarAntTask(org.apache.ignite.util.antgar.IgniteDeploymentGarAntTask) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 30 with Project

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

the class GridToolsSelfTest method testCorrectAntGarTask.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TypeMayBeWeakened" })
public void testCorrectAntGarTask() throws Exception {
    String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir");
    String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir");
    String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_0";
    String metaDirName = baseDirName + File.separator + "META-INF";
    String garFileName = baseDirName + ".gar";
    String garDescDirName = U.resolveIgnitePath(GridTestProperties.getProperty("ant.gar.descriptor.dir")).getAbsolutePath() + File.separator + "ignite.xml";
    // Make base and META-INF dir.
    boolean mkdir = new File(baseDirName).mkdirs();
    assert mkdir;
    mkdir = new File(metaDirName).mkdirs();
    assert mkdir;
    // Make Gar file
    U.copy(new File(garDescDirName), new File(metaDirName + File.separator + "ignite.xml"), true);
    // Copy files to basedir
    U.copy(new File(srcDirName), new File(baseDirName), true);
    IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask();
    Project garProject = new Project();
    garProject.setName("Gar test project");
    garTask.setDestFile(new File(garFileName));
    garTask.setBasedir(new File(baseDirName));
    garTask.setProject(garProject);
    garTask.execute();
    File garFile = new File(garFileName);
    assert garFile.exists();
    boolean res = checkStructure(garFile, true);
    assert res;
}
Also used : Project(org.apache.tools.ant.Project) IgniteDeploymentGarAntTask(org.apache.ignite.util.antgar.IgniteDeploymentGarAntTask) File(java.io.File) ZipFile(java.util.zip.ZipFile)

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