You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AjcCompilerAdapter.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* *******************************************************************
  2. * Copyright (c) 2000-2001 Xerox Corporation.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Xerox/PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.tools.ant.taskdefs;
  13. import org.apache.tools.ant.taskdefs.Javac;
  14. import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
  15. import org.apache.tools.ant.BuildException;
  16. import org.apache.tools.ant.types.Path;
  17. import java.io.File;
  18. /**
  19. * Partial implementation of CompilerAdapter for ajc task.
  20. * The Javac interface does not support argfiles which are
  21. * typically necessary to compile under ajc, so this
  22. * implementation is not documented, recommended, or supported.
  23. * See Apache request for enhancement
  24. * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7542">
  25. * 7542</a>.
  26. * @see CompilerAdapter
  27. */
  28. public class AjcCompilerAdapter implements CompilerAdapter {
  29. // Cannot extend Ajc because CompilerAdapter.execute() returns boolean.
  30. Ajc10 ajc = null;
  31. /** @see CompilerAdapter */
  32. public void setJavac(Javac javac) {
  33. if (null == javac) {
  34. throw new IllegalArgumentException("null javac");
  35. }
  36. Object task = javac.getProject().createTask("ajc");
  37. String err = null;
  38. if (null == task) {
  39. err = "ajc not defined - put ajc taskdef library on classpath";
  40. } else if (!(task instanceof Ajc10)) {
  41. String name = task.getClass().getName();
  42. err = "Wrong class for Ajc task - ";
  43. if (name.equals(Ajc10.class.getName())) {
  44. err = err + "second class loader - put ajc taskdef library "
  45. + "only on system classpath via ant/lib";
  46. } else {
  47. err = err + name;
  48. }
  49. }
  50. if (null != err) {
  51. throw new Error(err);
  52. }
  53. Ajc10 tempAjc = (Ajc10) task;
  54. Path srcDir = javac.getSrcdir();
  55. if (null != srcDir) {
  56. tempAjc.setSrcdir(srcDir);
  57. }
  58. File destDir = javac.getDestdir();
  59. if (null != destDir) {
  60. tempAjc.setDestdir(destDir.getPath());
  61. }
  62. Path classpath = javac.getClasspath();
  63. if (null != classpath) {
  64. tempAjc.setClasspath(classpath);
  65. }
  66. Path bootclasspath = javac.getBootclasspath();
  67. if (null != bootclasspath) {
  68. tempAjc.setBootclasspath(bootclasspath);
  69. }
  70. Path extDirs = javac.getExtdirs();
  71. if (null != extDirs) {
  72. tempAjc.setExtdirs(extDirs);
  73. }
  74. tempAjc.setFailonerror(javac.getFailonerror());
  75. tempAjc.setDeprecation(javac.getDeprecation()); // XXX unsupported
  76. tempAjc.setEncoding(javac.getEncoding());
  77. tempAjc.setDebug(javac.getDebug()); // XXX unsupported
  78. tempAjc.setOptimize(javac.getOptimize()); // XXX unsupported
  79. tempAjc.setDepend(javac.getDepend()?"on":"off"); // XXX unsupported
  80. tempAjc.setVerbose(javac.getVerbose());
  81. String target = javac.getTarget();
  82. if (null != target) {
  83. tempAjc.setTarget(target);
  84. }
  85. tempAjc.setIncludeantruntime(javac.getIncludeantruntime()); // XXX unsupported
  86. File[] files = javac.getFileList();
  87. if (null != files) {
  88. for (int i = 0; i < files.length; i++) {
  89. tempAjc.backdoorSetFile(files[i]);
  90. }
  91. }
  92. ajc = tempAjc;
  93. }
  94. /**
  95. * Run the compiler.
  96. * @see CompilerAdapter#execute()
  97. * @throws BuildException if setJavac(Javac) was not called before each call of this
  98. */
  99. public boolean execute() throws BuildException {
  100. if (null == ajc) {
  101. throw new BuildException("setJavac(Javac) not completed");
  102. }
  103. ajc.execute();
  104. ajc = null; // enforce one-shot
  105. return true;
  106. }
  107. }