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);
}
}
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"));
}
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);
}
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());
}
}
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;
}
Aggregations