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.pl 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/perl
  2. #######################################################################
  3. #
  4. # runant.pl
  5. #
  6. # wrapper script for invoking ant in a platform with Perl installed
  7. # this may include cgi-bin invocation, which is considered somewhat daft.
  8. # (slo: that should be a separate file which can be derived from this
  9. # and returns the XML formatted output)
  10. #
  11. # the code is not totally portable due to classpath and directory splitting
  12. # issues. oops. (NB, use File::Spec::Functions will help and the code is
  13. # structured for the catfile() call, but because of perl version funnies
  14. # the code is not included.
  15. #
  16. # created: 2000-8-24
  17. # last modified: 2000-8-24
  18. # author: Steve Loughran steve_l@sourceforge.net
  19. #######################################################################
  20. #
  21. # Assumptions:
  22. #
  23. # - the "java" executable/script is on the command path
  24. # - ANT_HOME has been set
  25. # - target platform uses ":" as classpath separator or perl indicates it is dos/win32
  26. # - target platform uses "/" as directory separator.
  27. #be fussy about variables
  28. use strict;
  29. #platform specifics (disabled)
  30. #use File::Spec::Functions;
  31. #turn warnings on during dev; generates a few spurious uninitialised var access warnings
  32. #use warnings;
  33. #and set $debug to 1 to turn on trace info
  34. my $debug=0;
  35. #######################################################################
  36. #
  37. # check to make sure environment is setup
  38. #
  39. my $HOME = $ENV{ANT_HOME};
  40. if ($HOME eq "")
  41. {
  42. die "\n\nANT_HOME *MUST* be set!\n\n";
  43. }
  44. my $JAVACMD = $ENV{JAVACMD};
  45. $JAVACMD = "java" if $JAVACMD eq "";
  46. #ISSUE: what java wants to split up classpath varies from platform to platform
  47. #and perl is not too hot at hinting which box it is on.
  48. #here I assume ":" 'cept on win32 and dos. Add extra tests here as needed.
  49. my $s=":";
  50. if(($^O eq "MSWin32") || ($^O eq "dos") || ($^O eq "cygwin"))
  51. {
  52. $s=";";
  53. }
  54. #build up standard classpath
  55. my $localpath=$ENV{CLASSPATH};
  56. if ($localpath eq "")
  57. {
  58. print "warning: no initial classpath\n" if ($debug);
  59. $localpath="";
  60. }
  61. #add jar files. I am sure there is a perl one liner to do this.
  62. my $jarpattern="$HOME/lib/*.jar";
  63. my @jarfiles =glob($jarpattern);
  64. print "jarfiles=@jarfiles\n" if ($debug);
  65. my $jar;
  66. foreach $jar (@jarfiles )
  67. {
  68. $localpath.="$s$jar";
  69. }
  70. #if Java home is defined, look for tools.jar & classes.zip and add to classpath
  71. my $JAVA_HOME = $ENV{JAVA_HOME};
  72. if ($JAVA_HOME ne "")
  73. {
  74. my $tools="$JAVA_HOME/lib/tools.jar";
  75. if (-e "$tools")
  76. {
  77. $localpath .= "$s$tools";
  78. }
  79. my $classes="$JAVA_HOME/lib/classes.zip";
  80. if (-e $classes)
  81. {
  82. $localpath .= "$s$classes";
  83. }
  84. }
  85. else
  86. {
  87. print "\n\nWarning: JAVA_HOME environment variable is not set.\n".
  88. "If the build fails because sun.* classes could not be found\n".
  89. "you will need to set the JAVA_HOME environment variable\n".
  90. "to the installation directory of java\n";
  91. }
  92. #set JVM options and Ant arguments, if any
  93. my @ANT_OPTS=split(" ", $ENV{ANT_OPTS});
  94. my @ANT_ARGS=split(" ", $ENV{ANT_ARGS});
  95. #jikes
  96. if($ENV{JIKESPATH} ne "")
  97. {
  98. push @ANT_OPTS, "-Djikes.class.path=$ENV{JIKESPATH}";
  99. }
  100. #construct arguments to java
  101. my @ARGS;
  102. push @ARGS, "-classpath", "$localpath", "-Dant.home=$HOME";
  103. push @ARGS, @ANT_OPTS;
  104. push @ARGS, "org.apache.tools.ant.Main", @ANT_ARGS;
  105. push @ARGS, @ARGV;
  106. print "\n $JAVACMD @ARGS\n\n" if ($debug);
  107. my $returnValue = system $JAVACMD, @ARGS;
  108. if ($returnValue eq 0)
  109. {
  110. exit 0;
  111. }
  112. else
  113. {
  114. # only 0 and 1 are widely recognized as exit values
  115. # so change the exit value to 1
  116. exit 1;
  117. }