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

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