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

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