use of org.apache.tools.ant.DefaultLogger 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;
}
use of org.apache.tools.ant.DefaultLogger 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.DefaultLogger in project hudson-2.x by hudson.
the class WindowsInstallerLink method doRestart.
public void doRestart(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
if (installationDir == null) {
// if the user reloads the page after Hudson has restarted,
// it comes back here. In such a case, don't let this restart Hudson.
// so just send them back to the top page
rsp.sendRedirect(req.getContextPath() + "/");
return;
}
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
rsp.forward(this, "_restart", req);
final File oldRoot = Hudson.getInstance().getRootDir();
// initiate an orderly shutdown after we finished serving this request
new Thread("terminator") {
public void run() {
try {
Thread.sleep(1000);
// let the service start after we close our sockets, to avoid conflicts
Runtime.getRuntime().addShutdownHook(new Thread("service starter") {
public void run() {
try {
if (!oldRoot.equals(installationDir)) {
LOGGER.info("Moving data");
Move mv = new Move();
Project p = new Project();
p.addBuildListener(createLogger());
mv.setProject(p);
FileSet fs = new FileSet();
fs.setDir(oldRoot);
// we can't really move the exploded war.
fs.setExcludes("war/**");
mv.addFileset(fs);
mv.setTodir(installationDir);
// plugins can also fail to move
mv.setFailOnError(false);
mv.execute();
}
LOGGER.info("Starting a Windows service");
StreamTaskListener task = StreamTaskListener.fromStdout();
int r = WindowsSlaveInstaller.runElevated(new File(installationDir, "hudson.exe"), "start", task, installationDir);
task.getLogger().println(r == 0 ? "Successfully started" : "start service failed. Exit code=" + r);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private DefaultLogger createLogger() {
DefaultLogger logger = new DefaultLogger();
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);
return logger;
}
});
System.exit(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
use of org.apache.tools.ant.DefaultLogger in project randomizedtesting by randomizedtesting.
the class AntBuildFileTestBase method setupProject.
protected void setupProject(File projectFile) {
try {
restoreSysout = System.out;
restoreSyserr = System.err;
output = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(output, true, "UTF-8");
System.setOut(ps);
System.setErr(ps);
project = new Project();
project.init();
project.setUserProperty(MagicNames.ANT_FILE, projectFile.getAbsolutePath());
ProjectHelper.configureProject(project, projectFile);
listener = new DefaultLogger();
listener.setMessageOutputLevel(Project.MSG_DEBUG);
listener.setErrorPrintStream(ps);
listener.setOutputPrintStream(ps);
getProject().addBuildListener(listener);
DefaultLogger console = new DefaultLogger();
console.setMessageOutputLevel(Project.MSG_INFO);
console.setErrorPrintStream(restoreSyserr);
console.setOutputPrintStream(restoreSysout);
getProject().addBuildListener(console);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.tools.ant.DefaultLogger in project Gargoyle by callakrsos.
the class AntJavaCompiler method parse.
/**
*
* build.xml파일을 파싱처리하여
* 빌드처리 준비상태로 처리한다.
* 이후 run 함수를 호출하여 빌드를 실행할 수 있다.
*
* @작성자 : KYJ
* @작성일 : 2017. 3. 7.
*/
public void parse() {
p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.setUserProperty("encoding", encoding.displayName());
p.init();
helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
if (baseDir != null && baseDir.exists())
p.setBaseDir(baseDir);
else
p.setBaseDir(buildFile.getParentFile());
//setting console
DefaultLogger consoleLogger = getLogger();
consoleLogger.setOutputPrintStream(new PrintStream(out));
consoleLogger.setErrorPrintStream(new PrintStream(err));
consoleLogger.setMessageOutputLevel(Project.MSG_VERBOSE);
p.addBuildListener(consoleLogger);
//parse build.xml
helper.parse(p, buildFile);
LOGGER.debug(" ##### base dir : " + p.getBaseDir());
LOGGER.debug(" ##### default target : " + p.getDefaultTarget());
//append build debugger.
BuildListener buildListener = getBuildListener();
if (buildListener != null)
p.addBuildListener(buildListener);
wasParse = true;
}
Aggregations