in src/main/org/apache/tools/ant/Main.java [723:848]
private void runBuild(final ClassLoader coreLoader) throws BuildException {
if (!readyToRun) {
return;
}
final ArgumentProcessorRegistry processorRegistry = ArgumentProcessorRegistry.getInstance();
for (final ArgumentProcessor processor : processorRegistry.getProcessors()) {
final List<String> extraArgs = extraArguments.get(processor.getClass());
if (extraArgs != null) {
if (processor.handleArg(extraArgs)) {
return;
}
}
}
final Project project = new Project();
project.setCoreLoader(coreLoader);
Throwable error = null;
try {
addBuildListeners(project);
addInputHandler(project);
final PrintStream savedErr = System.err;
final PrintStream savedOut = System.out;
final InputStream savedIn = System.in;
try {
if (allowInput) {
project.setDefaultInputStream(System.in);
}
System.setIn(new DemuxInputStream(project));
System.setOut(new PrintStream(new DemuxOutputStream(project, false)));
System.setErr(new PrintStream(new DemuxOutputStream(project, true)));
if (!projectHelp) {
project.fireBuildStarted();
}
// set the thread priorities
if (threadPriority != null) {
try {
project.log("Setting Ant's thread priority to "
+ threadPriority, Project.MSG_VERBOSE);
Thread.currentThread().setPriority(threadPriority);
} catch (final SecurityException swallowed) {
//we cannot set the priority here.
project.log("A security manager refused to set the -nice value");
}
}
setProperties(project);
project.setKeepGoingMode(keepGoingMode);
if (proxy) {
//proxy setup if enabled
final ProxySetup proxySetup = new ProxySetup(project);
proxySetup.enableProxies();
}
for (final ArgumentProcessor processor : processorRegistry.getProcessors()) {
final List<String> extraArgs = extraArguments.get(processor.getClass());
if (extraArgs != null) {
processor.prepareConfigure(project, extraArgs);
}
}
ProjectHelper.configureProject(project, buildFile);
for (final ArgumentProcessor processor : processorRegistry.getProcessors()) {
final List<String> extraArgs = extraArguments.get(processor.getClass());
if (extraArgs != null) {
if (processor.handleArg(project, extraArgs)) {
return;
}
}
}
if (projectHelp) {
printDescription(project);
printTargets(project, msgOutputLevel > Project.MSG_INFO,
msgOutputLevel > Project.MSG_VERBOSE);
return;
}
// make sure that we have a target to execute
if (targets.isEmpty()) {
if (project.getDefaultTarget() != null) {
targets.addElement(project.getDefaultTarget());
}
}
project.executeTargets(targets);
} finally {
System.setOut(savedOut);
System.setErr(savedErr);
System.setIn(savedIn);
}
} catch (final RuntimeException | Error exc) {
error = exc;
throw exc;
} finally {
if (!projectHelp) {
try {
project.fireBuildFinished(error);
} catch (final Throwable t) {
// yes, I know it is bad style to catch Throwable,
// but if we don't, we lose valuable information
System.err.println("Caught an exception while logging the"
+ " end of the build. Exception was:");
t.printStackTrace(); //NOSONAR
if (error != null) {
System.err.println("There has been an error prior to"
+ " that:");
error.printStackTrace(); //NOSONAR
}
throw new BuildException(t); //NOSONAR
}
} else if (error != null) {
project.log(error.toString(), Project.MSG_ERR);
}
}
}