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.

AjdocTaskTester.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 Ajdoc ant task.
  20. */
  21. public class AjdocTaskTester extends AntTaskTester {
  22. /** todo correlate with basedir, local.properties in test-ant-task */
  23. protected final static String TEST_DOCDIR
  24. = "test-docs";
  25. protected final static String TEST_SOURCES = "../src";
  26. protected File docDir = null;
  27. /**
  28. * We use <code>"tests/ant/etc/ajc.xml"</code>.
  29. */
  30. public String getAntFile() {
  31. return "tests/ant/etc/ajdoc.xml";
  32. }
  33. /**
  34. * Put {@link #TEST_DOCDIR} and {@link #TEST_SOURCES}
  35. * into the user properties.
  36. */
  37. protected Map getUserProperties() {
  38. Map userProps = new HashMap();
  39. // these are in local.properties per test-ant-tasks.xml
  40. //userProps.put("ajdoc.relative.doc.dir", TEST_DOCDIR );
  41. //userProps.put("ajdoc.relative.src.dir", TEST_SOURCES);
  42. return userProps;
  43. }
  44. ////// Begin tests //////////////////////////////////////////////
  45. public void test_stylesheetfile() {
  46. avoid(STYLESHEET_CSS);
  47. wantFiles("One.html");
  48. wantFiles("mystylesheet.css");
  49. }
  50. public void test_helpfile() {
  51. avoid(HELP_DOC_HTML);
  52. wantFiles("One.html");
  53. wantFiles("myhelp.html");
  54. }
  55. public void test_nodeprecatedlist_no() {
  56. wantFiles("One.html");
  57. }
  58. public void test_nodeprecatedlist_yes() {
  59. avoid(DEPRECATED_LIST_HTML);
  60. wantFiles("One.html");
  61. }
  62. public void test_nodeprecated_no() { wantFiles("One.html"); }
  63. public void test_nodeprecated_yes() { wantFiles("One.html"); }
  64. public void test_use_no() {
  65. wantFiles("One.html");
  66. }
  67. public void test_use_yes() {
  68. wantFiles("One.html");
  69. wantFiles("class-use/One.html");
  70. }
  71. public void test_standard_no() {
  72. wantFiles("One.html");
  73. }
  74. public void test_standard_yes() {
  75. wantFiles("One.html");
  76. }
  77. public void test_author_no() { wantFiles("One.html"); }
  78. public void test_author_yes() { wantFiles("One.html"); }
  79. public void test_public_no() { wantFiles("One.html"); }
  80. public void test_public_yes() { wantFiles("One.html"); }
  81. public void test_package_no() { wantFiles("One.html"); }
  82. public void test_package_yes() { wantFiles("One.html"); }
  83. public void test_protected_no() { wantFiles("One.html"); }
  84. public void test_protected_yes() { wantFiles("One.html"); }
  85. public void test_private_no() { wantFiles("One.html"); }
  86. public void test_private_yes() { wantFiles("One.html"); }
  87. public void test_splitindex_no() {
  88. wantFiles("One.html");
  89. }
  90. public void test_splitindex_yes() {
  91. avoid(INDEX_ALL_HTML);
  92. wantFiles("One.html");
  93. }
  94. public void test_windowtitle() {
  95. wantFiles("One.html");
  96. }
  97. public void test_doctitle() {
  98. wantFiles("One.html");
  99. }
  100. public void test_bottom() {
  101. wantFiles("One.html");
  102. }
  103. public void test_footer() {
  104. wantFiles("One.html");
  105. }
  106. public void test_header() {
  107. wantFiles("One.html");
  108. }
  109. public void test_nohelp_no() {
  110. wantFiles("One.html");
  111. }
  112. public void test_nohelp_yes() {
  113. avoid(HELP_DOC_HTML);
  114. wantFiles("One.html");
  115. }
  116. public void test_noindex_no() {
  117. wantFiles("One.html");
  118. }
  119. public void test_noindex_yes() {
  120. avoid(INDEX_ALL_HTML);
  121. wantFiles("One.html");
  122. }
  123. public void test_notree_no() {
  124. wantFiles("One.html");
  125. }
  126. public void test_notree_yes() {
  127. avoid(OVERVIEW_TREE_HTML);
  128. wantFiles("One.html");
  129. }
  130. public void test985() {
  131. wantFiles("p1/One.html,p1/pp1/One.html");
  132. wantFiles("p2/Two.html,p2/pp2/Two.html");
  133. }
  134. public void test986() {
  135. wantFiles("p1/One.html,p1/pp1/One.html");
  136. }
  137. public void test987() {
  138. wantFiles("p1/One.html");
  139. wantFiles("p2/Two.html");
  140. }
  141. public void test988() {
  142. wantFiles("p1/One.html");
  143. }
  144. public void test989() {
  145. wantFiles("p1/One.html,p1/pp1/One.html");
  146. wantFiles("p2/Two.html,p2/pp2/Two.html");
  147. }
  148. public void test990() {
  149. wantFiles("p1/One.html,p1/pp1/One.html");
  150. wantFiles("p2/Two.html,p2/pp2/Two.html");
  151. }
  152. public void test991() {
  153. wantFiles("p1/One.html,p1/pp1/One.html");
  154. wantFiles("p2/Two.html");
  155. }
  156. public void test992() {
  157. wantFiles("p1/One.html,p2/Two.html");
  158. }
  159. public void test993() {
  160. wantFiles("p1/One.html,p1/pp1/One.html");
  161. }
  162. public void test994() {
  163. wantFiles("p1/One.html,p1/pp1/One.html");
  164. }
  165. public void test995() {
  166. wantFiles("p1/One.html");
  167. }
  168. public void test996() {
  169. wantFiles("One.html,Two.html");
  170. }
  171. public void test997() {
  172. wantFiles("One.html");
  173. }
  174. public void test998() {
  175. wantFiles("One.html,Two.html");
  176. }
  177. public void test999() {
  178. wantFiles("One.html");
  179. }
  180. ////// End tests ////////////////////////////////////////////////
  181. private final static int OVERVIEW_TREE_HTML = 0x000001;
  182. private final static int INDEX_ALL_HTML = 0x000002;
  183. private final static int DEPRECATED_LIST_HTML = 0x000004;
  184. private final static int ALLCLASSES_FRAME_HTML = 0x000008;
  185. private final static int INDEX_HTML = 0x000010;
  186. private final static int PACKAGES_HTML = 0x000020;
  187. private final static int OVERVIEW_SUMMARY_HTML = 0x000040;
  188. private final static int PACKAGE_LIST = 0x000080;
  189. private final static int HELP_DOC_HTML = 0x000100;
  190. private final static int STYLESHEET_CSS = 0x000200;
  191. private final static int ALL = 0x0003ff;
  192. private final static int TOP = ((ALL<<1)|1)&~ALL;
  193. private final static String[] FILES = new String[] {
  194. "overview-tree.html",
  195. "index-all.html",
  196. "deprecated-list.html",
  197. "allclasses-frame.html",
  198. "index.html",
  199. "packages.html",
  200. "overview-summary.html",
  201. "package-list",
  202. "help-doc.html",
  203. "stylesheet.css",
  204. };
  205. private void wantFiles(int mods) {
  206. mods &= (ALL | TOP);
  207. for (int c = 0; mods != 0x1; c++, mods >>= 0x1) {
  208. if ((mods & 0x1) == 0x1) {
  209. wantFiles(FILES[c]);
  210. } else {
  211. avoidFiles(FILES[c]);
  212. }
  213. }
  214. }
  215. private int MODS = ALL;
  216. private void avoid(int mods) {
  217. MODS &= ~mods;
  218. }
  219. /**
  220. * Make the doc dir -- e.g. call {@link #makeDocDir}
  221. */
  222. protected void beforeEveryTask() {
  223. makeDocDir();
  224. wantFiles(MODS);
  225. }
  226. /**
  227. * Assert classes and clear doc dir.
  228. *
  229. * @see #checkDocs()
  230. * @see #clearDocDir()
  231. */
  232. protected void afterEveryTask() {
  233. checkDocs();
  234. clearDocDir();
  235. MODS = ALL;
  236. }
  237. protected void avoidFiles(String filesWithoutHtmlExtensions) {
  238. List list = new ArrayList();
  239. for (StringTokenizer tok =
  240. new StringTokenizer(filesWithoutHtmlExtensions, " ,;");
  241. tok.hasMoreTokens();) {
  242. list.add(tok.nextToken());
  243. }
  244. avoidFiles(list);
  245. }
  246. protected void avoidFiles(List filesWithoutHtmlExtensions) {
  247. for (Iterator iter = filesWithoutHtmlExtensions.iterator(); iter.hasNext();) {
  248. dont(iter.next()+"");
  249. }
  250. }
  251. protected void wantFiles(String filesWithoutHtmlExtensions) {
  252. List list = new ArrayList();
  253. for (StringTokenizer tok =
  254. new StringTokenizer(filesWithoutHtmlExtensions, " ,;");
  255. tok.hasMoreTokens();) {
  256. list.add(tok.nextToken());
  257. }
  258. wantFiles(list);
  259. }
  260. protected void wantFiles(List filesWithoutHtmlExtensions) {
  261. for (Iterator iter = filesWithoutHtmlExtensions.iterator(); iter.hasNext();) {
  262. want(iter.next()+"");
  263. }
  264. }
  265. protected void checkDocs() {
  266. for (Iterator iter = wants.iterator(); iter.hasNext();) {
  267. String filename = iter.next() + "";
  268. File file = new File(docDir, filename);
  269. if (file != null && file.exists()) {
  270. have(filename);
  271. } else {
  272. //System.err.println("westodo expected " + file.getPath());
  273. }
  274. }
  275. for (Iterator iter = donts.iterator(); iter.hasNext();) {
  276. String filename = iter.next() + "";
  277. File file = new File(docDir, filename);
  278. if (file != null && file.exists()) {
  279. have(filename);
  280. } else {
  281. //System.err.println("westodo avoiding " + file.getPath());
  282. }
  283. }
  284. }
  285. /**
  286. * Create a new doc dir.
  287. */
  288. protected void init() {
  289. docDir = new File(project.getBaseDir(), TEST_DOCDIR);
  290. }
  291. /**
  292. * Make a new doc dir using ANT.
  293. */
  294. protected void makeDocDir() {
  295. try {
  296. Mkdir mkdir = (Mkdir)project.createTask("mkdir");
  297. mkdir.setDir(docDir);
  298. mkdir.execute();
  299. } catch (BuildException be) {
  300. be.printStackTrace();
  301. }
  302. }
  303. /**
  304. * Clear the build dir using ANT.
  305. */
  306. protected void clearDocDir() {
  307. try {
  308. Delete delete = (Delete)project.createTask("delete");
  309. FileSet fileset = new FileSet();
  310. fileset.setDir(docDir);
  311. fileset.setIncludes("**");
  312. delete.addFileset(fileset);
  313. delete.execute();
  314. } catch (BuildException be) {
  315. be.printStackTrace();
  316. }
  317. }
  318. /**
  319. * Invoke {@link #runTests(String[])} on a
  320. * new instanceof {@link #AjdocTaskTester}.
  321. *
  322. * @param args Command line arguments.
  323. */
  324. public static void main(String[] args) {
  325. new AjdocTaskTester().runTests(args);
  326. }
  327. }