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 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/usr/bin/perl
  2. #
  3. # Copyright 2000-2004 The Apache Software Foundation
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. #######################################################################
  18. #
  19. # runant.pl
  20. #
  21. # wrapper script for invoking ant in a platform with Perl installed
  22. # this may include cgi-bin invocation, which is considered somewhat daft.
  23. # (slo: that should be a separate file which can be derived from this
  24. # and returns the XML formatted output)
  25. #
  26. # the code is not totally portable due to classpath and directory splitting
  27. # issues. oops. (NB, use File::Spec::Functions will help and the code is
  28. # structured for the catfile() call, but because of perl version funnies
  29. # the code is not included.
  30. #
  31. # created: 2000-8-24
  32. # author: Steve Loughran steve_l@sourceforge.net
  33. #######################################################################
  34. #
  35. # Assumptions:
  36. #
  37. # - the "java" executable/script is on the command path
  38. # - ANT_HOME has been set
  39. # - target platform uses ":" as classpath separator or perl indicates it is dos/win32
  40. # - target platform uses "/" as directory separator.
  41. #be fussy about variables
  42. use strict;
  43. #platform specifics (disabled)
  44. #use File::Spec::Functions;
  45. #turn warnings on during dev; generates a few spurious uninitialised var access warnings
  46. #use warnings;
  47. #and set $debug to 1 to turn on trace info
  48. my $debug=1;
  49. #######################################################################
  50. #
  51. # check to make sure environment is setup
  52. #
  53. my $HOME = $ENV{ANT_HOME};
  54. if ($HOME eq "")
  55. {
  56. die "\n\nANT_HOME *MUST* be set!\n\n";
  57. }
  58. my $JAVACMD = $ENV{JAVACMD};
  59. $JAVACMD = "java" if $JAVACMD eq "";
  60. my $onnetware = 0;
  61. if ($^O eq "NetWare")
  62. {
  63. $onnetware = 1;
  64. }
  65. my $oncygwin = ($^O eq "cygwin");
  66. #ISSUE: what java wants to split up classpath varies from platform to platform
  67. #and perl is not too hot at hinting which box it is on.
  68. #here I assume ":" 'cept on win32, dos, and netware. Add extra tests here as needed.
  69. my $s=":";
  70. if(($^O eq "MSWin32") || ($^O eq "dos") || ($^O eq "cygwin") ||
  71. ($onnetware == 1))
  72. {
  73. $s=";";
  74. }
  75. #build up standard classpath
  76. my $localpath = "$HOME/lib/ant-launcher.jar";
  77. #set JVM options and Ant arguments, if any
  78. my @ANT_OPTS=split(" ", $ENV{ANT_OPTS});
  79. my @ANT_ARGS=split(" ", $ENV{ANT_ARGS});
  80. #jikes
  81. if($ENV{JIKESPATH} ne "")
  82. {
  83. push @ANT_OPTS, "-Djikes.class.path=$ENV{JIKESPATH}";
  84. }
  85. #construct arguments to java
  86. my @ARGS;
  87. push @ARGS, @ANT_OPTS;
  88. my $CYGHOME = "";
  89. my $classpath=$ENV{CLASSPATH};
  90. if ($oncygwin == 1) {
  91. $localpath = `cygpath --path --windows $localpath`;
  92. chomp ($localpath);
  93. if (! $classpath eq "")
  94. {
  95. $classpath = `cygpath --path --windows "$classpath"`;
  96. chomp ($classpath);
  97. }
  98. $HOME = `cygpath --path --windows $HOME`;
  99. chomp ($HOME);
  100. $CYGHOME = `cygpath --path --windows $ENV{HOME}`;
  101. chomp ($CYGHOME);
  102. }
  103. push @ARGS, "-classpath", "$localpath";
  104. push @ARGS, "-Dant.home=$HOME";
  105. if ( ! $CYGHOME eq "" )
  106. {
  107. push @ARGS, "-Dcygwin.user.home=\"$CYGHOME\""
  108. }
  109. push @ARGS, "org.apache.tools.ant.launch.Launcher", @ANT_ARGS;
  110. push @ARGS, @ARGV;
  111. if (! $classpath eq "")
  112. {
  113. if ($onnetware == 1)
  114. {
  115. # make classpath literally $CLASSPATH
  116. # this is to avoid pushing us over the 512 character limit
  117. # even skip the ; - that is already in $localpath
  118. push @ARGS, "-lib", "\$CLASSPATH";
  119. }
  120. else
  121. {
  122. push @ARGS, "-lib", "$classpath";
  123. }
  124. }
  125. print "\n $JAVACMD @ARGS\n\n" if ($debug);
  126. my $returnValue = system $JAVACMD, @ARGS;
  127. if ($returnValue eq 0)
  128. {
  129. exit 0;
  130. }
  131. else
  132. {
  133. # only 0 and 1 are widely recognized as exit values
  134. # so change the exit value to 1
  135. exit 1;
  136. }