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.

Jikes.java 5.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. 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. package org.apache.tools.ant.taskdefs;
  19. import java.io.BufferedWriter;
  20. import java.io.File;
  21. import java.io.FileWriter;
  22. import java.io.IOException;
  23. import java.util.Locale;
  24. import org.apache.tools.ant.BuildException;
  25. import org.apache.tools.ant.Project;
  26. import org.apache.tools.ant.util.FileUtils;
  27. /**
  28. * Encapsulates a Jikes compiler, by directly executing an external
  29. * process.
  30. *
  31. * <p><strong>As of Ant 1.2, this class is considered to be dead code
  32. * by the Ant developers and is unmaintained. Don't use
  33. * it.</strong></p>
  34. *
  35. * @deprecated since 1.2.
  36. * Merged into the class Javac.
  37. */
  38. @Deprecated
  39. public class Jikes {
  40. // There have been reports that 300 files could be compiled
  41. // on a command line so 250 is a conservative approach
  42. private static final int MAX_FILES_ON_COMMAND_LINE = 250;
  43. // CheckStyle:VisibilityModifier OFF - bc
  44. protected JikesOutputParser jop;
  45. protected String command;
  46. protected Project project;
  47. // CheckStyle:VisibilityModifier ON
  48. /**
  49. * Constructs a new Jikes object.
  50. * @param jop Parser to send jike's output to
  51. * @param command name of jikes executable
  52. * @param project the current project
  53. */
  54. protected Jikes(JikesOutputParser jop, String command, Project project) {
  55. super();
  56. System.err.println("As of Ant 1.2 released in October 2000, "
  57. + "the Jikes class");
  58. System.err.println("is considered to be dead code by the Ant "
  59. + "developers and is unmaintained.");
  60. System.err.println("Don\'t use it!");
  61. this.jop = jop;
  62. this.command = command;
  63. this.project = project;
  64. }
  65. /**
  66. * Do the compile with the specified arguments.
  67. * @param args - arguments to pass to process on command line
  68. */
  69. protected void compile(String[] args) {
  70. String[] commandArray = null;
  71. File tmpFile = null;
  72. try {
  73. String myos = System.getProperty("os.name");
  74. // Windows has a 32k limit on total arg size, so
  75. // create a temporary file to store all the arguments
  76. if (myos.toLowerCase(Locale.ENGLISH).indexOf("windows") >= 0
  77. && args.length > MAX_FILES_ON_COMMAND_LINE) {
  78. BufferedWriter out = null;
  79. try {
  80. tmpFile = FileUtils.getFileUtils().createTempFile("jikes",
  81. "tmp", null, false, true);
  82. out = new BufferedWriter(new FileWriter(tmpFile));
  83. for (int i = 0; i < args.length; i++) {
  84. out.write(args[i]);
  85. out.newLine();
  86. }
  87. out.flush();
  88. commandArray = new String[] {command,
  89. "@" + tmpFile.getAbsolutePath()};
  90. } catch (IOException e) {
  91. throw new BuildException("Error creating temporary file",
  92. e);
  93. } finally {
  94. FileUtils.close(out);
  95. }
  96. } else {
  97. commandArray = new String[args.length + 1];
  98. commandArray[0] = command;
  99. System.arraycopy(args, 0, commandArray, 1, args.length);
  100. }
  101. // We assume, that everything jikes writes goes to
  102. // standard output, not to standard error. The option
  103. // -Xstdout that is given to Jikes in Javac.doJikesCompile()
  104. // should guarantee this. At least I hope so. :)
  105. try {
  106. Execute exe = new Execute(jop);
  107. exe.setAntRun(project);
  108. exe.setWorkingDirectory(project.getBaseDir());
  109. exe.setCommandline(commandArray);
  110. exe.execute();
  111. } catch (IOException e) {
  112. throw new BuildException("Error running Jikes compiler", e);
  113. }
  114. } finally {
  115. if (tmpFile != null) {
  116. if (!tmpFile.delete()) {
  117. tmpFile.deleteOnExit();
  118. }
  119. }
  120. }
  121. }
  122. }