1. /*
  2. * Copyright 2001-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.compilers;
  18. import org.apache.tools.ant.BuildException;
  19. import org.apache.tools.ant.Project;
  20. import org.apache.tools.ant.types.Commandline;
  21. import org.apache.tools.ant.types.Path;
  22. /**
  23. * The implementation of the jikes compiler.
  24. * This is primarily a cut-and-paste from the original javac task before it
  25. * was refactored.
  26. *
  27. * @since Ant 1.3
  28. */
  29. public class Jikes extends DefaultCompilerAdapter {
  30. /**
  31. * Performs a compile using the Jikes compiler from IBM.
  32. * Mostly of this code is identical to doClassicCompile()
  33. * However, it does not support all options like
  34. * bootclasspath, extdirs, deprecation and so on, because
  35. * there is no option in jikes and I don't understand
  36. * what they should do.
  37. *
  38. * It has been successfully tested with jikes >1.10
  39. */
  40. public boolean execute() throws BuildException {
  41. attributes.log("Using jikes compiler", Project.MSG_VERBOSE);
  42. Path classpath = new Path(project);
  43. // Jikes doesn't support bootclasspath dir (-bootclasspath)
  44. // so we'll emulate it for compatibility and convenience.
  45. if (bootclasspath != null) {
  46. classpath.append(bootclasspath);
  47. }
  48. // Jikes doesn't support an extension dir (-extdir)
  49. // so we'll emulate it for compatibility and convenience.
  50. classpath.addExtdirs(extdirs);
  51. if (bootclasspath == null || bootclasspath.size() == 0) {
  52. // no bootclasspath, therefore, get one from the java runtime
  53. includeJavaRuntime = true;
  54. } else {
  55. // there is a bootclasspath stated. By default, the
  56. // includeJavaRuntime is false. If the user has stated a
  57. // bootclasspath and said to include the java runtime, it's on
  58. // their head!
  59. }
  60. classpath.append(getCompileClasspath());
  61. // Jikes has no option for source-path so we
  62. // will add it to classpath.
  63. if (compileSourcepath != null) {
  64. classpath.append(compileSourcepath);
  65. } else {
  66. classpath.append(src);
  67. }
  68. // if the user has set JIKESPATH we should add the contents as well
  69. String jikesPath = System.getProperty("jikes.class.path");
  70. if (jikesPath != null) {
  71. classpath.append(new Path(project, jikesPath));
  72. }
  73. Commandline cmd = new Commandline();
  74. String exec = getJavac().getExecutable();
  75. cmd.setExecutable(exec == null ? "jikes" : exec);
  76. if (deprecation == true) {
  77. cmd.createArgument().setValue("-deprecation");
  78. }
  79. if (destDir != null) {
  80. cmd.createArgument().setValue("-d");
  81. cmd.createArgument().setFile(destDir);
  82. }
  83. cmd.createArgument().setValue("-classpath");
  84. cmd.createArgument().setPath(classpath);
  85. if (encoding != null) {
  86. cmd.createArgument().setValue("-encoding");
  87. cmd.createArgument().setValue(encoding);
  88. }
  89. if (debug) {
  90. cmd.createArgument().setValue("-g");
  91. }
  92. if (optimize) {
  93. cmd.createArgument().setValue("-O");
  94. }
  95. if (verbose) {
  96. cmd.createArgument().setValue("-verbose");
  97. }
  98. if (depend) {
  99. cmd.createArgument().setValue("-depend");
  100. }
  101. if (target != null) {
  102. cmd.createArgument().setValue("-target");
  103. cmd.createArgument().setValue(target);
  104. }
  105. /**
  106. * XXX
  107. * Perhaps we shouldn't use properties for these
  108. * three options (emacs mode, warnings and pedantic),
  109. * but include it in the javac directive?
  110. */
  111. /**
  112. * Jikes has the nice feature to print error
  113. * messages in a form readable by emacs, so
  114. * that emacs can directly set the cursor
  115. * to the place, where the error occurred.
  116. */
  117. String emacsProperty = project.getProperty("build.compiler.emacs");
  118. if (emacsProperty != null && Project.toBoolean(emacsProperty)) {
  119. cmd.createArgument().setValue("+E");
  120. }
  121. /**
  122. * Jikes issues more warnings that javac, for
  123. * example, when you have files in your classpath
  124. * that don't exist. As this is often the case, these
  125. * warning can be pretty annoying.
  126. */
  127. String warningsProperty =
  128. project.getProperty("build.compiler.warnings");
  129. if (warningsProperty != null) {
  130. attributes.log("!! the build.compiler.warnings property is "
  131. + "deprecated. !!", Project.MSG_WARN);
  132. attributes.log("!! Use the nowarn attribute instead. !!",
  133. Project.MSG_WARN);
  134. if (!Project.toBoolean(warningsProperty)) {
  135. cmd.createArgument().setValue("-nowarn");
  136. }
  137. } if (attributes.getNowarn()) {
  138. /*
  139. * FIXME later
  140. *
  141. * let the magic property win over the attribute for backwards
  142. * compatibility
  143. */
  144. cmd.createArgument().setValue("-nowarn");
  145. }
  146. /**
  147. * Jikes can issue pedantic warnings.
  148. */
  149. String pedanticProperty =
  150. project.getProperty("build.compiler.pedantic");
  151. if (pedanticProperty != null && Project.toBoolean(pedanticProperty)) {
  152. cmd.createArgument().setValue("+P");
  153. }
  154. /**
  155. * Jikes supports something it calls "full dependency
  156. * checking", see the jikes documentation for differences
  157. * between -depend and +F.
  158. */
  159. String fullDependProperty =
  160. project.getProperty("build.compiler.fulldepend");
  161. if (fullDependProperty != null
  162. && Project.toBoolean(fullDependProperty)) {
  163. cmd.createArgument().setValue("+F");
  164. }
  165. if (attributes.getSource() != null) {
  166. cmd.createArgument().setValue("-source");
  167. cmd.createArgument().setValue(attributes.getSource());
  168. }
  169. addCurrentCompilerArgs(cmd);
  170. int firstFileName = cmd.size();
  171. logAndAddFilesToCompile(cmd);
  172. return
  173. executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
  174. }
  175. }