You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

runant.py 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/python
  2. """
  3. runant.py
  4. This script is a translation of the runant.pl written by Steve Loughran.
  5. It runs ant with/out arguments, it should be quite portable (thanks to
  6. the python os library)
  7. This script has been tested with Python2.0/Win2K
  8. created: 2001-04-11
  9. author: Pierre Dittgen pierre.dittgen@criltelecom.com
  10. Assumptions:
  11. - the "java" executable/script is on the command path
  12. - ANT_HOME has been set
  13. """
  14. import os, os.path, string, sys
  15. # Change it to 1 to get extra debug information
  16. debug = 0
  17. #######################################################################
  18. #
  19. # check to make sure environment is setup
  20. #
  21. if not os.environ.has_key('ANT_HOME'):
  22. print '\n\nANT_HOME *MUST* be set!\n\n'
  23. sys.exit(1)
  24. else:
  25. ANT_HOME = os.environ['ANT_HOME']
  26. if not os.environ.has_key('JAVACMD'):
  27. JAVACMD = 'java'
  28. else:
  29. JAVACMD = os.environ['JAVACMD']
  30. # Sets the separator char for CLASSPATH
  31. SEPARATOR = ':'
  32. if os.name == 'dos' or os.name == 'nt':
  33. SEPARATOR = ';'
  34. # Build up standard classpath
  35. localpath = ''
  36. if os.environ.has_key('CLASSPATH'):
  37. localpath = os.environ['CLASSPATH']
  38. else:
  39. if debug:
  40. print 'Warning: no initial classpath\n'
  41. # Add jar files
  42. LIBDIR = os.path.join(ANT_HOME, 'lib')
  43. jarfiles = []
  44. for file in os.listdir(LIBDIR):
  45. if file[-4:] == '.jar':
  46. jarfiles.append(os.path.join(LIBDIR,file))
  47. if debug:
  48. print 'Jar files:'
  49. for jar in jarfiles:
  50. print jar
  51. localpath = localpath + SEPARATOR + string.join(jarfiles, SEPARATOR)
  52. # If JAVA_HOME is defined, look for tools.jar & classes.zip
  53. # and add to classpath
  54. if os.environ.has_key('JAVA_HOME') and os.environ['JAVA_HOME'] != '':
  55. JAVA_HOME = os.environ['JAVA_HOME']
  56. TOOLS = os.path.join(JAVA_HOME, os.path.join('lib', 'tools.jar'))
  57. if os.path.exists(TOOLS):
  58. localpath = localpath + SEPARATOR + TOOLS
  59. CLASSES = os.path.join(JAVA_HOME, os.path.join('lib', 'classes.zip'))
  60. if os.path.exists(CLASSES):
  61. localpath = localpath + SEPARATOR + CLASSES
  62. else:
  63. print '\n\nWarning: JAVA_HOME environment variable is not set.\n', \
  64. 'If the build fails because sun.* classes could not be found\n', \
  65. 'you will need to set the JAVA_HOME environment variable\n', \
  66. 'to the installation directory of java\n'
  67. # Jikes
  68. ANT_OPTS = []
  69. if os.environ.has_key('ANT_OPTS'):
  70. ANT_OPTS = string.split(os.environ['ANT_OPTS'])
  71. if os.environ.has_key('JIKESPATH'):
  72. ANT_OPTS.append('-Djikes.class.path=' + os.environ['JIKESPATH'])
  73. # Builds the commandline
  74. cmdline = '%s -classpath %s -Dant.home=%s %s org.apache.tools.ant.Main %s' \
  75. % (JAVACMD, localpath, ANT_HOME, string.join(ANT_OPTS,' '), \
  76. string.join(sys.argv[1:], ' '))
  77. if debug:
  78. print '\n%s\n\n' % (cmdline)
  79. # Run the biniou!
  80. os.system(cmdline)