From c08f713b3cdbc623c3ab427d978bf75b31801f9b Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Thu, 13 Jul 2006 11:03:32 +0000 Subject: [PATCH] Add extra diags on the error message by printing out java.home git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@421585 13f79535-47bb-0310-9956-ffa450edef68 --- .../compilers/CompilerAdapterFactory.java | 5 +++- .../tools/ant/taskdefs/compilers/Javac12.java | 26 ++++++++++--------- .../apache/tools/ant/util/JavaEnvUtils.java | 8 ++++++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java b/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java index a6d73747b..b4ee605ae 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java @@ -110,7 +110,10 @@ public final class CompilerAdapterFactory { + " is not on the " + "classpath.\n" + "Perhaps JAVA_HOME does not" - + " point to the JDK"); + + " point to the JDK.\n" + + "It is currently set to \"" + + JavaEnvUtils.getJavaHome() + + "\""); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java index d34348840..f1bbd76e0 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java @@ -23,6 +23,8 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.JavaEnvUtils; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.taskdefs.LogOutputStream; import org.apache.tools.ant.types.Commandline; @@ -34,6 +36,7 @@ import org.apache.tools.ant.types.Commandline; * @since Ant 1.3 */ public class Javac12 extends DefaultCompilerAdapter { + protected static final String CLASSIC_COMPILER_CLASSNAME = "sun.tools.javac.Main"; /** * Run the compilation. @@ -48,7 +51,7 @@ public class Javac12 extends DefaultCompilerAdapter { try { // Create an instance of the compiler, redirecting output to // the project log - Class c = Class.forName("sun.tools.javac.Main"); + Class c = Class.forName(CLASSIC_COMPILER_CLASSNAME); Constructor cons = c.getConstructor(new Class[] {OutputStream.class, String.class}); @@ -63,11 +66,15 @@ public class Javac12 extends DefaultCompilerAdapter { new Object[] {cmd.getArguments()}); return ok.booleanValue(); } catch (ClassNotFoundException ex) { - throw new BuildException("Cannot use classic compiler, as it is " - + "not available. A common solution is " - + "to set the environment variable" - + " JAVA_HOME to your jdk directory.", - location); + throw new BuildException("Cannot use classic compiler , as it is " + + "not available. \n" + + " A common solution is " + + "to set the environment variable" + + " JAVA_HOME to your jdk directory.\n" + + "It is currently set to \"" + + JavaEnvUtils.getJavaHome() + + "\"", + location); } catch (Exception ex) { if (ex instanceof BuildException) { throw (BuildException) ex; @@ -76,12 +83,7 @@ public class Javac12 extends DefaultCompilerAdapter { ex, location); } } finally { - try { - logstr.close(); - } catch (IOException e) { - // plain impossible - throw new BuildException(e); - } + FileUtils.close(logstr); } } } diff --git a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java index bbebbc6ce..df70b339d 100644 --- a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java +++ b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java @@ -414,4 +414,12 @@ public final class JavaEnvUtils { } return script; } + + /** + * Return the value of ${java.home} + * @return the java home value. + */ + public static String getJavaHome() { + return JAVA_HOME; + } }