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.

BuildModuleTests.java 11KB

21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package org.aspectj.build;
  2. /* *******************************************************************
  3. * Copyright (c) 1999-2001 Xerox Corporation,
  4. * 2002 Palo Alto Research Center, Incorporated (PARC).
  5. * All rights reserved.
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Public License v1.0
  8. * which accompanies this distribution and is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. *
  11. * Contributors:
  12. * Xerox/PARC initial implementation
  13. * ******************************************************************/
  14. // default package
  15. import org.aspectj.internal.tools.ant.taskdefs.Checklics;
  16. import org.aspectj.internal.tools.build.Builder;
  17. import org.aspectj.internal.tools.build.Util;
  18. import org.aspectj.internal.tools.build.UtilsTest;
  19. import org.aspectj.internal.build.BuildModuleTest;
  20. import org.aspectj.internal.build.ModulesTest;
  21. import java.io.File;
  22. import java.io.FileFilter;
  23. import java.util.ArrayList;
  24. import java.util.Arrays;
  25. import java.util.Collections;
  26. import java.util.List;
  27. import java.util.StringTokenizer;
  28. import junit.framework.*;
  29. /**
  30. * Master suite for build module
  31. * and test of all source directories for correct licenses and known file types.
  32. */
  33. public class BuildModuleTests extends TestCase {
  34. /** if true, then replace old headers with new first */
  35. private static final boolean replacing = false; // XXX never to enable again...
  36. /** replace commented out below - if any replace failed, halt all */
  37. private static boolean replaceFailed = false;
  38. private static final String BASE_DIR = ".." + File.separator;
  39. private static final String[] JDT_SOURCE_DIRS = new String[] {};
  40. public static Test suite() {
  41. TestSuite suite = new TestSuite("Build module tests");
  42. suite.addTestSuite(BuildModuleTests.class);
  43. suite.addTestSuite(BuildModuleTest.class);
  44. suite.addTestSuite(ModulesTest.class);
  45. suite.addTestSuite(UtilsTest.class);
  46. return suite;
  47. }
  48. /** @return String tag of license if not default */
  49. public static String getLicense(String module) {
  50. return null; // use permissive default
  51. }
  52. final static List<String> SOURCE_NAMES = Collections.unmodifiableList(
  53. Arrays.asList(new String[]{"src", "testsrc", "java5-src", "java5-testsrc", "aspectj-src"}));
  54. /**
  55. * @param moduleDir
  56. * @return
  57. */
  58. private static File[] findSourceRoots(File moduleDir) {
  59. ArrayList<File> result = new ArrayList<>();
  60. for (String name: SOURCE_NAMES) {
  61. File srcDir = new File(moduleDir, name);
  62. if (srcDir.canRead() && srcDir.isDirectory()) {
  63. result.add(srcDir);
  64. }
  65. }
  66. return (File[]) result.toArray(new File[0]);
  67. }
  68. public BuildModuleTests(String name) { super(name); }
  69. public void testSuffixList() {
  70. if (!UnknownFileCheck.STATIC_ERRORS.isEmpty()) {
  71. fail("" + UnknownFileCheck.STATIC_ERRORS);
  72. }
  73. }
  74. public void testLicense_ajbrowser() {
  75. checkLicense("ajbrowser");
  76. }
  77. public void testLicense_ajde() {
  78. checkLicense("ajde");
  79. }
  80. public void testLicense_aspectj5rt() {
  81. checkLicense("aspectj5rt");
  82. }
  83. public void testLicense_asm() {
  84. checkLicense("asm");
  85. }
  86. public void testLicense_bridge() {
  87. checkLicense("bridge");
  88. }
  89. public void testLicense_build() {
  90. checkLicense("build");
  91. }
  92. public void testLicense_org_aspectj_ajdt_core() {
  93. checkLicense("org.aspectj.ajdt.core");
  94. }
  95. public void testLicense_org_aspectj_lib() {
  96. checkLicense("org.aspectj.lib");
  97. }
  98. public void testLicense_org_eclipse_jdt_core() {
  99. final String mod = "org.eclipse.jdt.core";
  100. final String pre = BASE_DIR + mod + File.separator;
  101. for (int i = 0; i < JDT_SOURCE_DIRS.length; i++) {
  102. checkSourceDirectory(new File(pre + JDT_SOURCE_DIRS[i]), mod);
  103. }
  104. }
  105. public void testLicense_runtime() {
  106. checkLicense("runtime");
  107. }
  108. public void testLicense_taskdefs() {
  109. checkLicense("taskdefs");
  110. }
  111. public void testLicense_testing() {
  112. checkLicense("testing");
  113. }
  114. public void testLicense_testing_client() {
  115. checkLicense("testing-client");
  116. }
  117. public void testLicense_testing_drivers() {
  118. checkLicense("testing-drivers");
  119. }
  120. public void testLicense_testing_util() {
  121. checkLicense("testing-util");
  122. }
  123. public void testLicense_util() {
  124. checkLicense("util");
  125. }
  126. public void testLicense_weaver() {
  127. String module = "weaver";
  128. // skip (testdata) packages fluffy, reflect
  129. checkSourceDirectory(new File(Util.path(new String[] {"..", module, "src"})), module);
  130. checkSourceDirectory(new File(Util.path(new String[] {"..", module, "testsrc", "org"})), module);
  131. }
  132. public void testLicense_ajdoc() {
  133. checkLicense("ajdoc");
  134. }
  135. public void testLicense_loadtime() {
  136. checkLicense("loadtime");
  137. }
  138. public void testLicense_loadtime5() {
  139. checkLicense("loadtime5");
  140. }
  141. public void testLicense_weaver5() {
  142. checkLicense("weaver5");
  143. }
  144. void checkLicense(String module) {
  145. File moduleDir = new File(Util.path("..", module));
  146. File[] srcDirs = findSourceRoots(moduleDir);
  147. for (int i = 0; i < srcDirs.length; i++) {
  148. checkSourceDirectory(srcDirs[i], module);
  149. }
  150. }
  151. void checkSourceDirectory(File srcDir, String module) {
  152. final String label = "source dir " + srcDir + " (module " + module + ")";
  153. assertTrue(label, (srcDir.exists() && srcDir.isDirectory()));
  154. String license = getLicense(module);
  155. // if (replacing) {
  156. // if (replacing && true) {
  157. // throw new Error("replacing done - code left for other replaces");
  158. // }
  159. // assertTrue("aborting - replace failed", !replaceFailed);
  160. // // do the replace
  161. // int fails = Checklics.runDirect(moduleDir.getPath(), "replace-headers");
  162. // replaceFailed = (0 != fails);
  163. // assertTrue(!replaceFailed);
  164. // license = Checklics.CPL_IBM_PARC_XEROX_TAG;
  165. // }
  166. int fails = Checklics.runDirect(srcDir.getPath(), license, true);
  167. if (0 != fails) {
  168. if (replacing) {
  169. BuildModuleTests.replaceFailed = true;
  170. }
  171. assertTrue(label + " fails", !BuildModuleTests.replaceFailed);
  172. }
  173. // separate check to verify all file types (suffixes) are known
  174. if (!"testsrc".equals(srcDir.getName())) {
  175. ArrayList<File> unknownFiles = new ArrayList<>();
  176. UnknownFileCheck.SINGLETON.unknownFiles(srcDir, unknownFiles);
  177. if (!unknownFiles.isEmpty()) {
  178. String s = "unknown files (see readme-build-module.html to "
  179. + "update Builder.properties resource patterns): ";
  180. fail(s + unknownFiles);
  181. }
  182. }
  183. }
  184. /**
  185. * Check tree for files not managed by the build system
  186. * (either source files or managed as resources).
  187. * This should pick up situations where new kinds of resources are added
  188. * to the tree without updating the build script patterns to pick them
  189. * up.
  190. * @see Builder#BINARY_SOURCE_PATTERN
  191. * @see Builder#RESOURCE_PATTERN
  192. * @see org.aspectj.util.FileUtil#SOURCE_SUFFIXES
  193. */
  194. static class UnknownFileCheck implements FileFilter {
  195. private static final UnknownFileCheck SINGLETON = new UnknownFileCheck();
  196. private static final ArrayList<String> STATIC_ERRORS = new ArrayList<>();
  197. // Builder.BINARY_SOURCE_PATTERN and Builder.RESOURCE_PATTERN
  198. public static final List<String> KNOWN_SUFFIXES;
  199. static {
  200. List<String> suffixes = new ArrayList<>();
  201. // sources from org.aspectj.util.FileUtil.SOURCE_SUFFIXES
  202. suffixes.add(".aj");
  203. suffixes.add(".java");
  204. // just because we know...
  205. suffixes.add(".html");
  206. // others from Builder
  207. final String input = Builder.BINARY_SOURCE_PATTERN
  208. + "," + Builder.RESOURCE_PATTERN;
  209. StringTokenizer st = new StringTokenizer(input, ",");
  210. while (st.hasMoreTokens()) {
  211. String token = st.nextToken().trim();
  212. if (0 == token.length()) {
  213. continue;
  214. }
  215. if (token.startsWith("**/*.")) {
  216. token = token.substring(4);
  217. } else if (token.startsWith("*.")) {
  218. token = token.substring(1);
  219. } else {
  220. String s = input + " at \"" + token + "\"";
  221. STATIC_ERRORS.add("unable to read pattern: " + s);
  222. }
  223. suffixes.add(token);
  224. }
  225. KNOWN_SUFFIXES = Collections.unmodifiableList(suffixes);
  226. }
  227. private UnknownFileCheck() {
  228. }
  229. /**
  230. * Return true if input File file is a valid path to a directory
  231. * or to a file
  232. * which is not hidden (starts with .)
  233. * and does not have a known suffix.
  234. * Caller is responsible for pruning CVS directories
  235. * @return true iff unknown or a directory
  236. */
  237. public boolean accept(File file) {
  238. if (null == file) {
  239. return false;
  240. }
  241. if (file.isDirectory()) {
  242. return file.canRead();
  243. }
  244. String name = file.getName();
  245. if ("CVS".equals(name) || name.startsWith(".")) {
  246. return false;
  247. }
  248. // to do not accepting uppercase suffixes...
  249. for (String suffix: KNOWN_SUFFIXES) {
  250. if (name.endsWith(suffix)) {
  251. return false;
  252. }
  253. }
  254. return true;
  255. }
  256. void unknownFiles(File dir, ArrayList<File> results) {
  257. File[] files = dir.listFiles(this);
  258. for (int j = 0; j < files.length; j++) {
  259. File file = files[j];
  260. if (file.isDirectory()) {
  261. String name = file.getName();
  262. if (!("CVS".equals(name))) {
  263. unknownFiles(file, results);
  264. }
  265. } else {
  266. results.add(file);
  267. }
  268. }
  269. }
  270. }
  271. }