From 7bf41207e0b3bef0fe3f8d1a88ca7b872e69f0e9 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Tue, 22 Aug 2006 23:04:54 +0000 Subject: [PATCH] change error code of the launcher. We could change it from 2, its now in a constant where we can tune it. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@433793 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 +- .../org/apache/tools/ant/launch/Launcher.java | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index a50c9d627..7bb216fa4 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -94,7 +94,7 @@ Changes that could break older environments: * now optionally supports the sftp protocol, you may need a newer jsch.jar. Bugzilla Report 39373. -* Ant launcher program prints errors to stderr, and exits with a -1 exit code +* Ant launcher program prints errors to stderr, and exits with a 2 exit code value if, for any reason, it cannot actually start Ant proper. This will only affect programs/scripts that called the launcher and which did not want to receive an error if ant itself would not start diff --git a/src/main/org/apache/tools/ant/launch/Launcher.java b/src/main/org/apache/tools/ant/launch/Launcher.java index 2bdc2a6f3..a1149b685 100644 --- a/src/main/org/apache/tools/ant/launch/Launcher.java +++ b/src/main/org/apache/tools/ant/launch/Launcher.java @@ -19,7 +19,6 @@ package org.apache.tools.ant.launch; import java.net.URL; import java.net.URLClassLoader; import java.net.MalformedURLException; -import java.io.UnsupportedEncodingException; import java.io.File; import java.util.StringTokenizer; import java.util.List; @@ -89,6 +88,11 @@ public class Launcher { */ private static final String JAVA_CLASS_PATH = "java.class.path"; + /** + * Exit code on trouble + */ + protected static final int EXIT_CODE_ERROR = 2; + /** * Entry point for starting command line Ant. * @@ -98,21 +102,20 @@ public class Launcher { int exitCode; try { Launcher launcher = new Launcher(); - exitCode=launcher.run(args); + exitCode = launcher.run(args); } catch (LaunchException e) { - exitCode=-1; + exitCode = EXIT_CODE_ERROR; System.err.println(e.getMessage()); } catch (Throwable t) { - exitCode=-1; + exitCode = EXIT_CODE_ERROR; t.printStackTrace(System.err); } - if(exitCode!=0) { + if (exitCode != 0) { System.exit(exitCode); } } - - + /** * Add a CLASSPATH or -lib to lib path urls. * @@ -300,10 +303,10 @@ public class Launcher { File mainJar = Locator.getClassSource(mainClass); System.err.println( "Location of this class " + mainJar); - exitCode=-1; + exitCode = EXIT_CODE_ERROR; } catch (Throwable t) { t.printStackTrace(System.err); - exitCode=-1; + exitCode = EXIT_CODE_ERROR; } return exitCode;