1. /*
  2. * Copyright 2000,2002-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs;
  18. import java.io.File;
  19. import java.io.FileWriter;
  20. import java.io.IOException;
  21. import java.io.PrintWriter;
  22. import java.util.Random;
  23. import org.apache.tools.ant.BuildException;
  24. import org.apache.tools.ant.Project;
  25. /**
  26. * Encapsulates a Jikes compiler, by directly executing an external
  27. * process.
  28. *
  29. * <p><strong>As of Ant 1.2, this class is considered to be dead code
  30. * by the Ant developers and is unmaintained. Don't use
  31. * it.</strong></p>
  32. *
  33. * @deprecated merged into the class Javac.
  34. */
  35. public class Jikes {
  36. protected JikesOutputParser jop;
  37. protected String command;
  38. protected Project project;
  39. /**
  40. * Constructs a new Jikes object.
  41. * @param jop - Parser to send jike's output to
  42. * @param command - name of jikes executable
  43. */
  44. protected Jikes(JikesOutputParser jop, String command, Project project) {
  45. super();
  46. System.err.println("As of Ant 1.2 released in October 2000, "
  47. + "the Jikes class");
  48. System.err.println("is considered to be dead code by the Ant "
  49. + "developers and is unmaintained.");
  50. System.err.println("Don\'t use it!");
  51. this.jop = jop;
  52. this.command = command;
  53. this.project = project;
  54. }
  55. /**
  56. * Do the compile with the specified arguments.
  57. * @param args - arguments to pass to process on command line
  58. */
  59. protected void compile(String[] args) {
  60. String[] commandArray = null;
  61. File tmpFile = null;
  62. try {
  63. String myos = System.getProperty("os.name");
  64. // Windows has a 32k limit on total arg size, so
  65. // create a temporary file to store all the arguments
  66. // There have been reports that 300 files could be compiled
  67. // so 250 is a conservative approach
  68. if (myos.toLowerCase().indexOf("windows") >= 0
  69. && args.length > 250) {
  70. PrintWriter out = null;
  71. try {
  72. String tempFileName = "jikes"
  73. + (new Random(System.currentTimeMillis())).nextLong();
  74. tmpFile = new File(tempFileName);
  75. out = new PrintWriter(new FileWriter(tmpFile));
  76. for (int i = 0; i < args.length; i++) {
  77. out.println(args[i]);
  78. }
  79. out.flush();
  80. commandArray = new String[] {command,
  81. "@" + tmpFile.getAbsolutePath()};
  82. } catch (IOException e) {
  83. throw new BuildException("Error creating temporary file",
  84. e);
  85. } finally {
  86. if (out != null) {
  87. try {
  88. out.close();
  89. } catch (Throwable t) {
  90. // ignore
  91. }
  92. }
  93. }
  94. } else {
  95. commandArray = new String[args.length + 1];
  96. commandArray[0] = command;
  97. System.arraycopy(args, 0, commandArray, 1, args.length);
  98. }
  99. // We assume, that everything jikes writes goes to
  100. // standard output, not to standard error. The option
  101. // -Xstdout that is given to Jikes in Javac.doJikesCompile()
  102. // should guarantee this. At least I hope so. :)
  103. try {
  104. Execute exe = new Execute(jop);
  105. exe.setAntRun(project);
  106. exe.setWorkingDirectory(project.getBaseDir());
  107. exe.setCommandline(commandArray);
  108. exe.execute();
  109. } catch (IOException e) {
  110. throw new BuildException("Error running Jikes compiler", e);
  111. }
  112. } finally {
  113. if (tmpFile != null) {
  114. tmpFile.delete();
  115. }
  116. }
  117. }
  118. }