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 jvc compiler from microsoft.
  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 Jvc extends DefaultCompilerAdapter {
  30. /**
  31. * Run the compilation.
  32. *
  33. * @exception BuildException if the compilation has problems.
  34. */
  35. public boolean execute() throws BuildException {
  36. attributes.log("Using jvc compiler", Project.MSG_VERBOSE);
  37. Path classpath = new Path(project);
  38. // jvc doesn't support bootclasspath dir (-bootclasspath)
  39. // so we'll emulate it for compatibility and convenience.
  40. if (bootclasspath != null) {
  41. classpath.append(bootclasspath);
  42. }
  43. if (includeJavaRuntime) {
  44. // jvc doesn't support an extension dir (-extdir)
  45. // so we'll emulate it for compatibility and convenience.
  46. classpath.addExtdirs(extdirs);
  47. }
  48. classpath.append(getCompileClasspath());
  49. // jvc has no option for source-path so we
  50. // will add it to classpath.
  51. if (compileSourcepath != null) {
  52. classpath.append(compileSourcepath);
  53. } else {
  54. classpath.append(src);
  55. }
  56. Commandline cmd = new Commandline();
  57. String exec = getJavac().getExecutable();
  58. cmd.setExecutable(exec == null ? "jvc" : exec);
  59. if (destDir != null) {
  60. cmd.createArgument().setValue("/d");
  61. cmd.createArgument().setFile(destDir);
  62. }
  63. // Add the Classpath before the "internal" one.
  64. cmd.createArgument().setValue("/cp:p");
  65. cmd.createArgument().setPath(classpath);
  66. boolean msExtensions = true;
  67. String mse = getProject().getProperty("build.compiler.jvc.extensions");
  68. if (mse != null) {
  69. msExtensions = Project.toBoolean(mse);
  70. }
  71. if (msExtensions) {
  72. // Enable MS-Extensions and ...
  73. cmd.createArgument().setValue("/x-");
  74. // ... do not display a Message about this.
  75. cmd.createArgument().setValue("/nomessage");
  76. }
  77. // Do not display Logo
  78. cmd.createArgument().setValue("/nologo");
  79. if (debug) {
  80. cmd.createArgument().setValue("/g");
  81. }
  82. if (optimize) {
  83. cmd.createArgument().setValue("/O");
  84. }
  85. if (verbose) {
  86. cmd.createArgument().setValue("/verbose");
  87. }
  88. addCurrentCompilerArgs(cmd);
  89. int firstFileName = cmd.size();
  90. logAndAddFilesToCompile(cmd);
  91. return
  92. executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
  93. }
  94. }