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

runant.pl 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (c) 2001-2002 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. my $onnetware = 0;
  51. if ($^O eq "NetWare")
  52. {
  53. $onnetware = 1;
  54. }
  55. #ISSUE: what java wants to split up classpath varies from platform to platform
  56. #and perl is not too hot at hinting which box it is on.
  57. #here I assume ":" 'cept on win32, dos, and netware. Add extra tests here as needed.
  58. my $s=":";
  59. if(($^O eq "MSWin32") || ($^O eq "dos") || ($^O eq "cygwin") ||
  60. ($onnetware == 1))
  61. {
  62. $s=";";
  63. }
  64. #build up standard classpath
  65. my $localpath=$ENV{CLASSPATH};
  66. if ($localpath eq "")
  67. {
  68. print "warning: no initial classpath\n" if ($debug);
  69. $localpath="";
  70. }
  71. if ($onnetware == 1)
  72. {
  73. # avoid building a command line bigger than 512 characters - make localpath
  74. # only include the "extra" stuff, and add in the system classpath as an expanded
  75. # variable.
  76. $localpath="";
  77. }
  78. #add jar files. I am sure there is a perl one liner to do this.
  79. my $jarpattern="$HOME/lib/*.jar";
  80. my @jarfiles =glob($jarpattern);
  81. print "jarfiles=@jarfiles\n" if ($debug);
  82. my $jar;
  83. foreach $jar (@jarfiles )
  84. {
  85. $localpath.="$s$jar";
  86. }
  87. #if Java home is defined, look for tools.jar & classes.zip and add to classpath
  88. my $JAVA_HOME = $ENV{JAVA_HOME};
  89. if ($JAVA_HOME ne "")
  90. {
  91. my $tools="$JAVA_HOME/lib/tools.jar";
  92. if (-e "$tools")
  93. {
  94. $localpath .= "$s$tools";
  95. }
  96. my $classes="$JAVA_HOME/lib/classes.zip";
  97. if (-e $classes)
  98. {
  99. $localpath .= "$s$classes";
  100. }
  101. }
  102. else
  103. {
  104. print "\n\nWarning: JAVA_HOME environment variable is not set.\n".
  105. "If the build fails because sun.* classes could not be found\n".
  106. "you will need to set the JAVA_HOME environment variable\n".
  107. "to the installation directory of java\n";
  108. }
  109. #set JVM options and Ant arguments, if any
  110. my @ANT_OPTS=split(" ", $ENV{ANT_OPTS});
  111. my @ANT_ARGS=split(" ", $ENV{ANT_ARGS});
  112. #jikes
  113. if($ENV{JIKESPATH} ne "")
  114. {
  115. push @ANT_OPTS, "-Djikes.class.path=$ENV{JIKESPATH}";
  116. }
  117. #construct arguments to java
  118. my @ARGS;
  119. if ($onnetware == 1)
  120. {
  121. # make classpath literally $CLASSPATH; and then the contents of $localpath
  122. # this is to avoid pushing us over the 512 character limit
  123. # even skip the ; - that is already in $localpath
  124. push @ARGS, "-classpath", "\$CLASSPATH$localpath";
  125. }
  126. else
  127. {
  128. push @ARGS, "-classpath", "$localpath";
  129. }
  130. push @ARGS, "-Dant.home=$HOME";
  131. push @ARGS, @ANT_OPTS;
  132. push @ARGS, "org.apache.tools.ant.Main", @ANT_ARGS;
  133. push @ARGS, @ARGV;
  134. print "\n $JAVACMD @ARGS\n\n" if ($debug);
  135. my $returnValue = system $JAVACMD, @ARGS;
  136. if ($returnValue eq 0)
  137. {
  138. exit 0;
  139. }
  140. else
  141. {
  142. # only 0 and 1 are widely recognized as exit values
  143. # so change the exit value to 1
  144. exit 1;
  145. }