Hello,

Attached is a patch for improved Cygwin support in the ant script.  I
found the current version has problems because it didn't convert all the
necessary variables to UNIX format paths before the body of the script
started building up the CLASSPATH.  The end result was a JAVA_HOME that
looked something like D:\/d/jdk1.3 preventing Ant from starting.  Rather
than just fix that one problem, I reworked the cygwin support to be more
robust and easier to maintain.

This patch makes the following improvements for cygwin support:
1. Test for cygwin is done only once at the top of the script rather than
each time  conditional logic for cygwin was needed.
2. Removed calls to cygpath in the middle of the script so now they're
localized at the top and bottom.
3. The variables ANT_HOME, JAVA_HOME and CLASSPATH can be set either using
Windows or UNIX path conventions before running Ant without getting
garbled variables or CLASSPATH.
4. Spaces in any existing CLASSPATH are handled correctly.  However, I
made no attempt at handling the case where Ant or Java is installed in a
directory with spaces.  If there is consensus that needs to be fixed, I'd
be willing to come up with a separate patch to handle that case.

-Bill Burton
--- /d/cvs/jakarta-ant/src/bin/ant      Thu Dec 21 00:13:35 2000
+++ ./ant       Thu Dec 21 01:21:21 2000
@@ -4,17 +4,20 @@
   . $HOME/.antrc
 fi
 
-# Cygwin support.
-if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ]; then
-
-  if [ ! "$ANT_HOME" = "" ]; then
-    ANT_HOME=`cygpath --path --unix $ANT_HOME`
-  fi
-
-  if [ ! "$JAVA_HOME" = "" ]; then
-    JAVA_HOME=`cygpath --path --unix $JAVA_HOME`
-  fi
-
+# Cygwin support.  $cygwin _must_ be set to either true or false.
+case "`uname`" in
+  CYGWIN*) cygwin=true ;;
+  *) cygwin=false ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin; then
+  [ -n "$ANT_HOME" ] &&
+    ANT_HOME=`cygpath --unix "$ANT_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
 fi
 
 if [ "$ANT_HOME" = "" ] ; then
@@ -76,10 +79,6 @@
 done
 
 if [ "$CLASSPATH" != "" ] ; then
-  # More Cygwin support
-  if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
-    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
-  fi
   LOCALCLASSPATH=$CLASSPATH:$LOCALCLASSPATH
 fi
 
@@ -107,9 +106,11 @@
   fi
 fi
 
-# More Cygwin support
-if [ "$OSTYPE" = "cygwin32" ] || [ "$OSTYPE" = "cygwin" ] ; then
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+  ANT_HOME=`cygpath --path --windows "$ANT_HOME"`
+  JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
   LOCALCLASSPATH=`cygpath --path --windows "$LOCALCLASSPATH"`
 fi
 
-$JAVACMD -classpath $LOCALCLASSPATH -Dant.home=${ANT_HOME} $ANT_OPTS 
org.apache.tools.ant.Main $@
+$JAVACMD -classpath "$LOCALCLASSPATH" -Dant.home="${ANT_HOME}" $ANT_OPTS 
org.apache.tools.ant.Main $@

Reply via email to