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.

AjcTaskTester2.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 AJC2 ant task.
  20. */
  21. public class AjcTaskTester2 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/ajc2.xml"</code>.
  27. */
  28. public String getAntFile() {
  29. return "tests/ant/etc/ajc2.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. ////// End tests ////////////////////////////////////////////////
  61. /**
  62. * Make the build dir -- e.g. call {@link #makeBuildDir}
  63. */
  64. protected void beforeEveryTask() {
  65. makeBuildDir();
  66. }
  67. /**
  68. * Assert classes and clear build dir.
  69. *
  70. * @see #checkClasses()
  71. * @see #clearBuildDir()
  72. */
  73. protected void afterEveryTask() {
  74. checkClasses();
  75. clearBuildDir();
  76. }
  77. /**
  78. * Expect the classes found in
  79. * <code>classNamesWithoutExtensions</code>
  80. *
  81. * @param classNamesWithoutExtensions Array of class names without
  82. * extensions we want to see.
  83. * @see #wantClasses(List)
  84. */
  85. protected void wantClasses(String[] classNamesWithoutExtensions) {
  86. List list = new Vector();
  87. for (int i = 0; i < classNamesWithoutExtensions.length; i++) {
  88. list.add(classNamesWithoutExtensions[i]);
  89. }
  90. wantClasses(list);
  91. }
  92. /**
  93. * Expect the classes found in
  94. * <code>classNamesWithoutExtensions</code>
  95. *
  96. * @param classNamesWithoutExtensions String of class names without
  97. * extensions we want to see separated
  98. * by <code> </code>, <code>,</code>, or
  99. * <code>;</code>.
  100. * @see #wantClasses(List)
  101. */
  102. protected void wantClasses(String classNamesWithoutExtensions) {
  103. StringTokenizer tok = new StringTokenizer(classNamesWithoutExtensions, ",;");
  104. List list = new Vector();
  105. while (tok.hasMoreTokens()) {
  106. list.add(tok.nextToken());
  107. }
  108. wantClasses(list);
  109. }
  110. /**
  111. * Expected each class name found in
  112. * <code>classNamesWithoutExtensions</code>.
  113. *
  114. * @param classNamesWithoutExtensions List of class names without
  115. * exntensions.
  116. * @see #want(Object)
  117. */
  118. protected void wantClasses(List classNamesWithoutExtensions) {
  119. Iterator iter = classNamesWithoutExtensions.iterator();
  120. while (iter.hasNext()) {
  121. String className = iter.next() + "";
  122. className = className.replace('.', '/').replace('\\', '/');
  123. want(className + ".class");
  124. }
  125. }
  126. /**
  127. * Assert that all classes in {@link #wants} were found.
  128. */
  129. protected void checkClasses() {
  130. Iterator iter = wants.iterator();
  131. while (iter.hasNext()) {
  132. String className = iter.next() + "";
  133. File file = new File(buildDir, className);
  134. if (file != null && file.exists()) {
  135. have(className);
  136. }
  137. }
  138. }
  139. /**
  140. * Create a new build dir.
  141. */
  142. protected void init() {
  143. buildDir = new File(project.getBaseDir(), TEST_CLASSES);
  144. }
  145. /**
  146. * Make a new build dir using ANT.
  147. */
  148. protected void makeBuildDir() {
  149. try {
  150. Mkdir mkdir = (Mkdir)project.createTask("mkdir");
  151. mkdir.setDir(buildDir);
  152. mkdir.execute();
  153. } catch (BuildException be) {
  154. be.printStackTrace();
  155. }
  156. }
  157. /**
  158. * Clear the build dir using ANT.
  159. */
  160. protected void clearBuildDir() {
  161. try {
  162. Delete delete = (Delete)project.createTask("delete");
  163. FileSet fileset = new FileSet();
  164. fileset.setDir(buildDir);
  165. fileset.setIncludes("**");
  166. delete.addFileset(fileset);
  167. delete.execute();
  168. } catch (BuildException be) {
  169. be.printStackTrace();
  170. }
  171. }
  172. /**
  173. * Invoke {@link #runTests(String[])} on a
  174. * new instanceof {@link #AjcTaskTester2}.
  175. *
  176. * @param args Command line arguments.
  177. */
  178. public static void main(String[] args) {
  179. new AjcTaskTester2().runTests(args);
  180. }
  181. }