From cbef49e344857a1cf7c35737b67d3c732f901710 Mon Sep 17 00:00:00 2001 From: glennm Date: Tue, 17 Jul 2001 14:54:13 +0000 Subject: [PATCH] Look for java.home/../bin/javadoc(.exe) before falling back on plain old javadoc. Just looking in the java.home directory tree isn't sufficient, as it may give incorrect results on Windows (thanks to Connor for the info.). git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269351 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/Javadoc.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java index dd636ee41..22b906409 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -734,8 +734,7 @@ public class Javadoc extends Task { } Commandline toExecute = (Commandline)cmd.clone(); - toExecute.setExecutable(System.getProperty("java.home") + - "/../bin/javadoc"); + toExecute.setExecutable( getJavadocExecutableName() ); // ------------------------------------------------ general javadoc arguments if (classpath == null) @@ -1143,5 +1142,31 @@ public class Javadoc extends Task { private File createTempFile() { return new File("javadoc" + (new Random(System.currentTimeMillis())).nextLong()); } + + 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" : ""; + + // Look for javadoc 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 javadoc is somewhere on the + // PATH. + File jdocExecutable = new File( System.getProperty("java.home") + + "/../bin/javadoc" + extension ); + + if (jdocExecutable.exists()) + { + return jdocExecutable.getAbsolutePath(); + } + else + { + log( "Unable to locate " + jdocExecutable.getAbsolutePath() + + ". Using \"javadoc\" instead.", Project.MSG_VERBOSE ); + return "javadoc"; + } + } }