2 # Copyright 2001,2003-2004 The Apache Software Foundation
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
21 This script is a translation of the runant.pl written by Steve Loughran.
22 It runs ant with/out arguments, it should be quite portable (thanks to
23 the python os library)
24 This script has been tested with Python2.0/Win2K
27 author: Pierre Dittgen pierre.dittgen@criltelecom.com
31 - the "java" executable/script is on the command path
33 import os
, os
.path
, string
, sys
35 # Change it to 1 to get extra debug information
38 #######################################################################
40 # If ANT_HOME is not set default to script's parent directory
41 if os
.environ
.has_key('ANT_HOME'):
42 ANT_HOME
= os
.environ
['ANT_HOME']
44 ANT_HOME
= os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(sys
.argv
[0])))
46 # set ANT_LIB location
47 ANT_LIB
= os
.path
.join(ANT_HOME
, 'lib')
49 # set JAVACMD (check variables JAVACMD and JAVA_HOME)
51 if not os
.environ
.has_key('JAVACMD'):
52 if os
.environ
.has_key('JAVA_HOME'):
53 if not os
.path
.exists(os
.environ
['JAVA_HOME']):
54 print "Warning: JAVA_HOME is not defined correctly."
56 JAVACMD
= os
.path
.join(os
.environ
['JAVA_HOME'], 'bin', 'java')
58 print "Warning: JAVA_HOME not set."
60 JAVACMD
= os
.environ
['JAVACMD']
64 launcher_jar
= os
.path
.join(ANT_LIB
, 'ant-launcher.jar')
65 if not os
.path
.exists(launcher_jar
):
66 print 'Unable to locate ant-launcher.jar. Expected to find it in %s' % \
69 # Build up standard classpath (LOCALCLASSPATH)
70 LOCALCLASSPATH
= launcher_jar
71 if os
.environ
.has_key('LOCALCLASSPATH'):
72 LOCALCLASSPATH
+= os
.pathsep
+ os
.environ
['LOCALCLASSPATH']
75 if os
.environ
.has_key('ANT_OPTS'):
76 ANT_OPTS
= os
.environ
['ANT_OPTS']
79 if os
.environ
.has_key('JIKESPATH'):
80 OPTS
= '-Djikes.class.path=\"%s\"' % os
.environ
['JIKESPATH']
83 if os
.environ
.has_key('ANT_ARGS'):
84 ANT_ARGS
= os
.environ
['ANT_ARGS']
87 if os
.environ
.has_key('CLASSPATH'):
88 CLASSPATH
= os
.environ
['CLASSPATH']
90 # Builds the commandline
91 cmdline
= ('%s %s -classpath %s -Dant.home=%s %s ' + \
92 'org.apache.tools.ant.launch.Launcher %s -lib %s %s') \
93 % (JAVACMD
, ANT_OPTS
, LOCALCLASSPATH
, ANT_HOME
, OPTS
, ANT_ARGS
, \
94 CLASSPATH
, string
.join(sys
.argv
[1:], ' '))
97 print '\n%s\n\n' % (cmdline
)