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.

AjcTaskTester.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Common Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/cpl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. import java.io.*;
  14. import java.util.*;
  15. import org.apache.tools.ant.*;
  16. import org.apache.tools.ant.taskdefs.*;
  17. import org.apache.tools.ant.types.*;
  18. /**
  19. * Tests the AJC ant task.
  20. */
  21. public class AjcTaskTester extends AntTaskTester {
  22. protected final static String TEST_CLASSES = "test-classes";
  23. protected final static String TEST_SOURCES = "../src";
  24. protected File buildDir = null;
  25. /**
  26. * We use <code>"tests/ant/etc/ajc.xml"</code>.
  27. */
  28. public String getAntFile() {
  29. return "tests/ant/etc/ajc.xml";
  30. }
  31. /**
  32. * Put {@link #TEST_CLASSES} and {@link #TEST_SOURCES}
  33. * into the user properties.
  34. */
  35. protected Map getUserProperties() {
  36. Map userProps = new HashMap();
  37. userProps.put("ant.test.classes", TEST_CLASSES);
  38. userProps.put("ant.test.sources", TEST_SOURCES);
  39. return userProps;
  40. }
  41. ////// Begin tests //////////////////////////////////////////////
  42. public void test1() { wantClasses("One"); }
  43. public void test2() { wantClasses("One,Two"); }
  44. public void test3() { wantClasses("One,Two,Three"); }
  45. public void test4() { wantClasses("One"); }
  46. public void test4b() { wantClasses("One"); }
  47. public void test5() { wantClasses("One,Two"); }
  48. public void test5b() { wantClasses("One,Two"); }
  49. public void test6() { wantClasses("One,Two,Three"); }
  50. public void test6b() { wantClasses("One,Two,Three"); }
  51. public void test8() { wantClasses("One"); }
  52. public void test9() { wantClasses("One"); }
  53. public void test10() { wantClasses("One"); }
  54. public void test11() { wantClasses("One"); }
  55. public void test12() { wantClasses(""); }
  56. public void test13() { wantClasses("One"); }
  57. public void fail1(BuildException be) {}
  58. public void fail2(BuildException be) {}
  59. public void fail3(BuildException be) {}
  60. public void test1_fork() { wantClasses("One"); }
  61. public void test2_fork() { wantClasses("One,Two"); }
  62. public void test3_fork() { wantClasses("One,Two,Three"); }
  63. public void test4_fork() { wantClasses("One"); }
  64. public void test4b_fork() { wantClasses("One"); }
  65. public void test5_fork() { wantClasses("One,Two"); }
  66. public void test5b_fork() { wantClasses("One,Two"); }
  67. public void test6_fork() { wantClasses("One,Two,Three"); }
  68. public void test6b_fork() { wantClasses("One,Two,Three"); }
  69. public void test8_fork() { wantClasses("One"); }
  70. public void test9_fork() { wantClasses("One"); }
  71. public void test10_fork() { wantClasses("One"); }
  72. public void test11_fork() { wantClasses("One"); }
  73. public void test12_fork() { wantClasses(""); }
  74. public void test13_fork() { wantClasses("One"); }
  75. public void fail1_fork(BuildException be) {}
  76. public void fail2_fork(BuildException be) {}
  77. public void fail3_fork(BuildException be) {}
  78. ////// End tests ////////////////////////////////////////////////
  79. /**
  80. * Make the build dir -- e.g. call {@link #makeBuildDir}
  81. */
  82. protected void beforeEveryTask() {
  83. makeBuildDir();
  84. }
  85. /**
  86. * Assert classes and clear build dir.
  87. *
  88. * @see #checkClasses()
  89. * @see #clearBuildDir()
  90. */
  91. protected void afterEveryTask() {
  92. checkClasses();
  93. clearBuildDir();
  94. }
  95. /**
  96. * Expect the classes found in
  97. * <code>classNamesWithoutExtensions</code>
  98. *
  99. * @param classNamesWithoutExtensions Array of class names without
  100. * extensions we want to see.
  101. * @see #wantClasses(List)
  102. */
  103. protected void wantClasses(String[] classNamesWithoutExtensions) {
  104. List list = new Vector();
  105. for (int i = 0; i < classNamesWithoutExtensions.length; i++) {
  106. list.add(classNamesWithoutExtensions[i]);
  107. }
  108. wantClasses(list);
  109. }
  110. /**
  111. * Expect the classes found in
  112. * <code>classNamesWithoutExtensions</code>
  113. *
  114. * @param classNamesWithoutExtensions String of class names without
  115. * extensions we want to see separated
  116. * by <code> </code>, <code>,</code>, or
  117. * <code>;</code>.
  118. * @see #wantClasses(List)
  119. */
  120. protected void wantClasses(String classNamesWithoutExtensions) {
  121. StringTokenizer tok = new StringTokenizer(classNamesWithoutExtensions, " ,;");
  122. List list = new Vector();
  123. while (tok.hasMoreTokens()) {
  124. list.add(tok.nextToken());
  125. }
  126. wantClasses(list);
  127. }
  128. /**
  129. * Expected each class name found in
  130. * <code>classNamesWithoutExtensions</code>.
  131. *
  132. * @param classNamesWithoutExtensions List of class names without
  133. * exntensions.
  134. * @see #want(Object)
  135. */
  136. protected void wantClasses(List classNamesWithoutExtensions) {
  137. Iterator iter = classNamesWithoutExtensions.iterator();
  138. while (iter.hasNext()) {
  139. String className = iter.next() + "";
  140. className = className.replace('.', '/').replace('\\', '/');
  141. want(className + ".class");
  142. }
  143. }
  144. /**
  145. * Assert that all classes in {@link #wants} were found.
  146. */
  147. protected void checkClasses() {
  148. Iterator iter = wants.iterator();
  149. while (iter.hasNext()) {
  150. String className = iter.next() + "";
  151. File file = new File(buildDir, className);
  152. if (file != null && file.exists()) {
  153. have(className);
  154. }
  155. }
  156. }
  157. /**
  158. * Create a new build dir.
  159. */
  160. protected void init() {
  161. buildDir = new File(project.getBaseDir(), TEST_CLASSES);
  162. }
  163. /**
  164. * Make a new build dir using ANT.
  165. */
  166. protected void makeBuildDir() {
  167. try {
  168. Mkdir mkdir = (Mkdir)project.createTask("mkdir");
  169. mkdir.setDir(buildDir);
  170. mkdir.execute();
  171. } catch (BuildException be) {
  172. be.printStackTrace();
  173. }
  174. }
  175. /**
  176. * Clear the build dir using ANT.
  177. */
  178. protected void clearBuildDir() {
  179. try {
  180. Delete delete = (Delete)project.createTask("delete");
  181. FileSet fileset = new FileSet();
  182. fileset.setDir(buildDir);
  183. fileset.setIncludes("**");
  184. delete.addFileset(fileset);
  185. delete.execute();
  186. } catch (BuildException be) {
  187. be.printStackTrace();
  188. }
  189. }
  190. /**
  191. * Invoke {@link #runTests(String[])} on a
  192. * new instanceof {@link #AjcTaskTester}.
  193. *
  194. * @param args Command line arguments.
  195. */
  196. public static void main(String[] args) {
  197. new AjcTaskTester().runTests(args);
  198. }
  199. }