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.

AjdocOutputChecker.java 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /********************************************************************
  2. * Copyright (c) 2005 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - iniital version
  10. *******************************************************************/
  11. package org.aspectj.tools.ajdoc;
  12. import java.io.BufferedReader;
  13. import java.io.File;
  14. import java.io.FileReader;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. /**
  18. * Helper class to check whether the ajdoc contains the expected
  19. * information.
  20. */
  21. public class AjdocOutputChecker {
  22. /**
  23. * Checks whether the given html file contains the required String.
  24. *
  25. * @param htmlFile
  26. * @param requiredString
  27. * @return true if the file contains the given string or
  28. * false otherwise (or if the file is null or not an html file)
  29. * @throws Exception
  30. */
  31. public static boolean containsString(File htmlFile,
  32. String requiredString) throws Exception {
  33. if ((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html")) {
  34. return false;
  35. }
  36. BufferedReader reader = new BufferedReader(new FileReader(htmlFile));
  37. String line = reader.readLine();
  38. while (line != null) {
  39. if (line.indexOf(requiredString) != -1) {
  40. reader.close();
  41. return true;
  42. }
  43. line = reader.readLine();
  44. }
  45. reader.close();
  46. return false;
  47. }
  48. /**
  49. * Returns those strings from the given array which aren't in the html file.
  50. *
  51. * @param htmlFile
  52. * @param an array of requiredStrings
  53. * @return a List of those strings not found
  54. * @throws Exception
  55. */
  56. public static List<String> getMissingStringsInFile(File htmlFile, String[] requiredStrings) throws Exception {
  57. List<String> missingStrings = new ArrayList<String>();
  58. for (int i = 0; i < requiredStrings.length; i++) {
  59. String string = requiredStrings[i];
  60. if (!containsString(htmlFile, string)) {
  61. missingStrings.add(string);
  62. }
  63. }
  64. return missingStrings;
  65. }
  66. /**
  67. * Checks whether the section of the html file contains the
  68. * required String
  69. *
  70. * @param htmlFile
  71. * @param requiredString
  72. * @param sectionHeader
  73. * @return true if the file contains the given string within the
  74. * required section or false otherwise (or if the file is null or
  75. * not an html file)
  76. * @throws Exception
  77. */
  78. public static boolean containsStringWithinSection(File htmlFile,
  79. String requiredString, String sectionHeader) throws Exception {
  80. if ((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html")) {
  81. return false;
  82. }
  83. BufferedReader reader = new BufferedReader(new FileReader(htmlFile));
  84. String line = reader.readLine();
  85. while (line != null) {
  86. if (line.indexOf(sectionHeader) != -1) {
  87. String nextLine = reader.readLine();
  88. while (nextLine != null &&
  89. (nextLine.indexOf("========") == -1)) {
  90. if (nextLine.indexOf(requiredString) != -1) {
  91. reader.close();
  92. return true;
  93. }
  94. nextLine = reader.readLine();
  95. }
  96. reader.close();
  97. return false;
  98. }
  99. line = reader.readLine();
  100. }
  101. reader.close();
  102. return false;
  103. }
  104. /**
  105. * Returns those strings from the given array which aren't in the
  106. * ajdoc html file
  107. *
  108. * @param htmlFile
  109. * @param an array of requiredStrings
  110. * @param sectionHeader
  111. * @return List of those requiredStrings not found
  112. * @throws Exception
  113. */
  114. public static List /*String*/ getMissingStringsInSection(File htmlFile,
  115. String[] requiredStrings, String sectionHeader) throws Exception {
  116. List missingStrings = new ArrayList();
  117. for (int i = 0; i < requiredStrings.length; i++) {
  118. String string = requiredStrings[i];
  119. if (!containsStringWithinSection(htmlFile,string,sectionHeader)) {
  120. missingStrings.add(string);
  121. }
  122. }
  123. return missingStrings;
  124. }
  125. /**
  126. * Returns whether the class data section has the expected
  127. * relationship and target i.e. have the relationships been
  128. * applied to the type.
  129. *
  130. * @param the ajdoc html file
  131. * @param the detail sectionHeader, for example "DECLARE DETAIL SUMMARY"
  132. * @param the source of the relationship, for example "Point()"
  133. * @param the relationship, for example HtmlDecorator.HtmlRelationshipKind.MATCHED_BY
  134. * @param the expected target, for example "HREF=\"../foo/Main.html#doIt()\""
  135. * @return true if the section contains the expected source/relationship/target,
  136. * false otherwise
  137. */
  138. public static boolean classDataSectionContainsRel(File htmlFile,
  139. HtmlDecorator.HtmlRelationshipKind relationship,
  140. String target) throws Exception {
  141. if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) {
  142. return false;
  143. }
  144. BufferedReader reader = new BufferedReader(new FileReader(htmlFile));
  145. String line = reader.readLine();
  146. while (line != null) {
  147. if (line.indexOf("START OF CLASS DATA") != -1) {
  148. // found the required class data section
  149. String subLine = reader.readLine();
  150. while(subLine != null
  151. && (subLine.indexOf("========") == -1)){
  152. int relIndex = subLine.indexOf(relationship.toString());
  153. int targetIndex = subLine.indexOf(target);
  154. if ((relIndex != -1) && (targetIndex != -1)) {
  155. reader.close();
  156. if (relIndex < targetIndex) {
  157. return true;
  158. }
  159. return false;
  160. }
  161. subLine = reader.readLine();
  162. }
  163. reader.close();
  164. return false;
  165. }
  166. line = reader.readLine();
  167. }
  168. reader.close();
  169. return false;
  170. }
  171. /**
  172. * Returns whether the supplied source has the expected
  173. * relationship and target within the given detail section
  174. *
  175. * @param the ajdoc html file
  176. * @param the detail sectionHeader, for example "DECLARE DETAIL SUMMARY"
  177. * @param the source of the relationship, for example "Point()"
  178. * @param the relationship, for example HtmlDecorator.HtmlRelationshipKind.MATCHED_BY
  179. * @param the expected target, for example "HREF=\"../foo/Main.html#doIt()\""
  180. * @return true if the section contains the expected source/relationship/target,
  181. * false otherwise
  182. */
  183. public static boolean detailSectionContainsRel(File htmlFile,
  184. String sectionHeader, String source,
  185. HtmlDecorator.HtmlRelationshipKind relationship,
  186. String target) throws Exception {
  187. if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) {
  188. return false;
  189. }
  190. if (sectionHeader.indexOf("DETAIL") == -1) {
  191. return false;
  192. }
  193. BufferedReader reader = new BufferedReader(new FileReader(htmlFile));
  194. String line = reader.readLine();
  195. while (line != null) {
  196. if (line.indexOf(sectionHeader) != -1) {
  197. // found the required main section
  198. String nextLine = reader.readLine();
  199. while (nextLine != null && (nextLine.indexOf("========") == -1)) {
  200. if (nextLine.indexOf("NAME=\""+source+"\"") != -1 || nextLine.indexOf("name=\""+source+"\"") != -1) {
  201. // found the required subsection
  202. String subLine = reader.readLine();
  203. while(subLine != null
  204. && (subLine.indexOf("========") == -1)
  205. && (subLine.indexOf("NAME") == -1 && subLine.indexOf("name") == -1)) {
  206. int relIndex = subLine.indexOf(relationship.toString());
  207. int targetIndex = subLine.indexOf(target);
  208. if ((relIndex != -1) && (targetIndex != -1)) {
  209. reader.close();
  210. if (relIndex < targetIndex) {
  211. return true;
  212. }
  213. return false;
  214. }
  215. subLine = reader.readLine();
  216. }
  217. reader.close();
  218. return false;
  219. }
  220. nextLine = reader.readLine();
  221. }
  222. reader.close();
  223. return false;
  224. }
  225. line = reader.readLine();
  226. }
  227. reader.close();
  228. return false;
  229. }
  230. /**
  231. * Returns whether the supplied source has the expected
  232. * relationship and target within the given summary section
  233. *
  234. * @param the ajdoc html file
  235. * @param the detail sectionHeader, for example "DECLARE SUMMARY"
  236. * @param the source of the relationship, for example "Point()"
  237. * @param the relationship, for example HtmlDecorator.HtmlRelationshipKind.MATCHED_BY
  238. * @param the expected target, for example "HREF=\"../foo/Main.html#doIt()\""
  239. * @return true if the section contains the expected source/relationship/target,
  240. * false otherwise
  241. */
  242. public static boolean summarySectionContainsRel(
  243. File htmlFile,
  244. String sectionHeader,
  245. String source,
  246. HtmlDecorator.HtmlRelationshipKind relationship,
  247. String target) throws Exception {
  248. if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) {
  249. return false;
  250. }
  251. if (sectionHeader.indexOf("SUMMARY") == -1) {
  252. return false;
  253. }
  254. BufferedReader reader = new BufferedReader(new FileReader(htmlFile));
  255. String line = reader.readLine();
  256. while (line != null) {
  257. if (line.indexOf(sectionHeader) != -1) {
  258. // found the required main section
  259. String nextLine = reader.readLine();
  260. while (nextLine != null && (nextLine.indexOf("========") == -1)) {
  261. if (nextLine.indexOf(source) != -1) {
  262. // found the required subsection
  263. String subLine = nextLine;
  264. while(subLine != null
  265. && (subLine.indexOf("========") == -1)
  266. && (subLine.indexOf("<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">") == -1)) {
  267. int relIndex = subLine.indexOf(relationship.toString());
  268. int targetIndex = subLine.indexOf(target);
  269. if ((relIndex != -1) && (targetIndex != -1)) {
  270. reader.close();
  271. if (relIndex < targetIndex) {
  272. return true;
  273. }
  274. return false;
  275. }
  276. subLine = reader.readLine();
  277. }
  278. reader.close();
  279. return false;
  280. }
  281. nextLine = reader.readLine();
  282. }
  283. reader.close();
  284. return false;
  285. }
  286. line = reader.readLine();
  287. }
  288. reader.close();
  289. return false;
  290. }
  291. }