5713N/A#!/usr/bin/python
5713N/A# Licensed to the Apache Software Foundation (ASF) under one or more
5713N/A# contributor license agreements. See the NOTICE file distributed with
5713N/A# this work for additional information regarding copyright ownership.
5713N/A# The ASF licenses this file to You under the Apache License, Version 2.0
5713N/A# (the "License"); you may not use this file except in compliance with
5713N/A# the License. You may obtain a copy of the License at
5713N/A#
5713N/A# http://www.apache.org/licenses/LICENSE-2.0
5713N/A#
5713N/A# Unless required by applicable law or agreed to in writing, software
5713N/A# distributed under the License is distributed on an "AS IS" BASIS,
5713N/A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5713N/A# See the License for the specific language governing permissions and
5713N/A# limitations under the License.
5713N/A#
5713N/A
5713N/A"""
5713N/A
5713N/A runant.py
5713N/A
5713N/A This script is a translation of the runant.pl written by Steve Loughran.
5713N/A It runs ant with/out arguments, it should be quite portable (thanks to
5713N/A the python os library)
5713N/A This script has been tested with Python2.0/Win2K
5713N/A
5713N/A created: 2001-04-11
5713N/A author: Pierre Dittgen pierre.dittgen@criltelecom.com
5713N/A
5713N/A Assumptions:
5713N/A
5713N/A - the "java" executable/script is on the command path
5713N/A"""
5713N/Aimport os, os.path, string, sys
5713N/A
5713N/A# Change it to 1 to get extra debug information
5713N/Adebug = 0
5713N/A
5713N/A#######################################################################
5713N/A
5713N/A# If ANT_HOME is not set default to script's parent directory
5713N/Aif os.environ.has_key('ANT_HOME'):
5713N/A ANT_HOME = os.environ['ANT_HOME']
5713N/Aelse:
5713N/A ANT_HOME = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
5713N/A
5713N/A# set ANT_LIB location
5713N/AANT_LIB = os.path.join(ANT_HOME, 'lib')
5713N/A
5713N/A# set JAVACMD (check variables JAVACMD and JAVA_HOME)
5713N/AJAVACMD = None
5713N/Aif not os.environ.has_key('JAVACMD'):
5713N/A if os.environ.has_key('JAVA_HOME'):
5713N/A if not os.path.exists(os.environ['JAVA_HOME']):
5713N/A print "Warning: JAVA_HOME is not defined correctly."
5713N/A else:
5713N/A JAVACMD = os.path.join(os.environ['JAVA_HOME'], 'bin', 'java')
5713N/A else:
5713N/A print "Warning: JAVA_HOME not set."
5713N/Aelse:
5713N/A JAVACMD = os.environ['JAVACMD']
5713N/Aif not JAVACMD:
5713N/A JAVACMD = 'java'
5713N/A
5713N/Alauncher_jar = os.path.join(ANT_LIB, 'ant-launcher.jar')
5713N/Aif not os.path.exists(launcher_jar):
5713N/A print 'Warning: Unable to locate ant-launcher.jar. Expected to find it in %s' % \
5713N/A ANT_LIB
5713N/A
5713N/A# Build up standard classpath (LOCALCLASSPATH)
5713N/ALOCALCLASSPATH = launcher_jar
5713N/Aif os.environ.has_key('LOCALCLASSPATH'):
5713N/A LOCALCLASSPATH += os.pathsep + os.environ['LOCALCLASSPATH']
5713N/A
5713N/AANT_OPTS = ""
5713N/Aif os.environ.has_key('ANT_OPTS'):
5713N/A ANT_OPTS = os.environ['ANT_OPTS']
5713N/A
5713N/AOPTS = ""
5713N/Aif os.environ.has_key('JIKESPATH'):
5713N/A OPTS = '-Djikes.class.path=\"%s\"' % os.environ['JIKESPATH']
5713N/A
5713N/AANT_ARGS = ""
5713N/Aif os.environ.has_key('ANT_ARGS'):
5713N/A ANT_ARGS = os.environ['ANT_ARGS']
5713N/A
5713N/ACLASSPATH = ""
5713N/Aif os.environ.has_key('CLASSPATH'):
5713N/A CLASSPATH = "-lib " + os.environ['CLASSPATH']
5713N/A
5713N/A# Builds the commandline
5713N/Acmdline = ('%s %s -classpath %s -Dant.home=%s %s ' + \
5713N/A 'org.apache.tools.ant.launch.Launcher %s %s %s') \
5713N/A % (JAVACMD, ANT_OPTS, LOCALCLASSPATH, ANT_HOME, OPTS, ANT_ARGS, \
5713N/A CLASSPATH, string.join(sys.argv[1:], ' '))
5713N/A
5713N/Aif debug:
5713N/A print '\n%s\n\n' % (cmdline)
5713N/Asys.stdout.flush()
5713N/A
5713N/A# Run the biniou!
5713N/Aos.system(cmdline)