From 1ca56f13c4f3bf5a4a3d264131da2ddfc729c063 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 18 Jul 2001 10:07:02 +0000 Subject: [PATCH] Apply the same magic uses to locate the javadoc command to CommandlineJava (and with thus to ). Suggested by: Jesse Glick Also, add .exe on OS/2 as well. This still doesn't work for IBM's JDK 1.3 on AIX (java is in JAVA_HOME/jre/sh and javac in JAVA_HOME/sh) - need to find out what java.home points to and where javadoc is, before we can fix that. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269357 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/Javadoc.java | 10 +++++--- .../tools/ant/types/CommandlineJava.java | 25 ++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java index 22b906409..64efe93de 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -1145,10 +1145,12 @@ public class Javadoc extends Task { private String getJavadocExecutableName() { - // This is the most common extension case - exe for windows, nothing - // for *nix. - String extension = (System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0) ? - ".exe" : ""; + // This is the most common extension case - exe for windows and OS/2, + // nothing for *nix. + String os = System.getProperty("os.name").toLowerCase(); + boolean dosBased = + os.indexOf("windows") >= 0 || os.indexOf("os/2") >= 0; + String extension = dosBased? ".exe" : ""; // Look for javadoc in the java.home/../bin directory. Unfortunately // on Windows java.home doesn't always refer to the correct location, diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index c614094e7..2239888b7 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -128,7 +128,7 @@ public class CommandlineJava implements Cloneable { } public CommandlineJava() { - setVm("java"); + setVm(getJavaExecutableName()); setVmversion(org.apache.tools.ant.Project.getJavaVersion()); } @@ -254,4 +254,27 @@ public class CommandlineJava implements Cloneable { javaCommand.clearArgs(); } + private String getJavaExecutableName() { + // This is the most common extension case - exe for windows and OS/2, + // nothing for *nix. + String os = System.getProperty("os.name").toLowerCase(); + boolean dosBased = + os.indexOf("windows") >= 0 || os.indexOf("os/2") >= 0; + String extension = dosBased? ".exe" : ""; + + // Look for java in the java.home/../bin directory. Unfortunately + // on Windows java.home doesn't always refer to the correct location, + // so we need to fall back to assuming java is somewhere on the + // PATH. + java.io.File jExecutable = + new java.io.File(System.getProperty("java.home") + + "/../bin/java" + extension ); + + if (jExecutable.exists()) { + return jExecutable.getAbsolutePath(); + } else { + return "java"; + } + } + }