runant.pl 4.1 KB

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