| Method from org.apache.tools.ant.Main Detail: |
protected void addBuildListeners(Project project) {
// Add the default listener
project.addBuildListener(createLogger());
for (int i = 0; i < listeners.size(); i++) {
String className = (String) listeners.elementAt(i);
BuildListener listener =
(BuildListener) ClasspathUtils.newInstance(className,
Main.class.getClassLoader(), BuildListener.class);
project.setProjectReference(listener);
project.addBuildListener(listener);
}
}
Adds the listeners specified in the command line arguments,
along with the default listener, to the specified project. |
protected void exit(int exitCode) {
System.exit(exitCode);
}
This operation is expected to call System#exit(int) , which
is what the base version does.
However, it is possible to do something else. |
public static synchronized String getAntVersion() throws BuildException {
if (antVersion == null) {
try {
Properties props = new Properties();
InputStream in =
Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt");
props.load(in);
in.close();
StringBuffer msg = new StringBuffer();
msg.append("Apache Ant version ");
msg.append(props.getProperty("VERSION"));
msg.append(" compiled on ");
msg.append(props.getProperty("DATE"));
antVersion = msg.toString();
} catch (IOException ioe) {
throw new BuildException("Could not load the version information:"
+ ioe.getMessage());
} catch (NullPointerException npe) {
throw new BuildException("Could not load the version information.");
}
}
return antVersion;
}
Returns the Ant version information, if available. Once the information
has been loaded once, it's cached and returned from the cache on future
calls. |
public static void main(String[] args) {
start(args, null, null);
}
Command line entry point. This method kicks off the building
of a project object and executes a build using either a given
target or the default target. |
public static void start(String[] args,
Properties additionalUserProperties,
ClassLoader coreLoader) {
Main m = new Main();
m.startAnt(args, additionalUserProperties, coreLoader);
}
Creates a new instance of this class using the
arguments specified, gives it any extra user properties which have been
specified, and then runs the build using the classloader provided. |
public void startAnt(String[] args,
Properties additionalUserProperties,
ClassLoader coreLoader) {
try {
Diagnostics.validateVersion();
processArgs(args);
} catch (Throwable exc) {
handleLogfile();
printMessage(exc);
exit(1);
return;
}
if (additionalUserProperties != null) {
for (Enumeration e = additionalUserProperties.keys();
e.hasMoreElements();) {
String key = (String) e.nextElement();
String property = additionalUserProperties.getProperty(key);
definedProps.put(key, property);
}
}
// expect the worst
int exitCode = 1;
try {
try {
runBuild(coreLoader);
exitCode = 0;
} catch (ExitStatusException ese) {
exitCode = ese.getStatus();
if (exitCode != 0) {
throw ese;
}
}
} catch (BuildException be) {
if (err != System.err) {
printMessage(be);
}
} catch (Throwable exc) {
exc.printStackTrace();
printMessage(exc);
} finally {
handleLogfile();
}
exit(exitCode);
}
|