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.8 kB

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