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.

MultiProjectIncrementalTests.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.systemtest.incremental.tools;
  13. import java.io.DataOutputStream;
  14. import java.io.File;
  15. import java.io.FileOutputStream;
  16. import java.io.IOException;
  17. import java.util.ArrayList;
  18. import java.util.HashSet;
  19. import java.util.Iterator;
  20. import java.util.List;
  21. import java.util.Set;
  22. import org.aspectj.ajdt.internal.core.builder.AjState;
  23. import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
  24. import org.aspectj.asm.AsmManager;
  25. import org.aspectj.asm.IProgramElement;
  26. import org.aspectj.bridge.IMessage;
  27. import org.aspectj.testing.util.FileUtil;
  28. /**
  29. * The superclass knows all about talking through Ajde to the compiler.
  30. * The superclass isn't in charge of knowing how to simulate overlays
  31. * for incremental builds, that is in here. As is the ability to
  32. * generate valid build configs based on a directory structure. To
  33. * support this we just need access to a sandbox directory - this
  34. * sandbox is managed by the superclass (it only assumes all builds occur
  35. * in <sandboxDir>/<projectName>/ )
  36. *
  37. * The idea is you can initialize multiple projects in the sandbox and
  38. * they can all be built independently, hopefully exploiting
  39. * incremental compilation. Between builds you can alter the contents
  40. * of a project using the alter() method that overlays some set of
  41. * new files onto the current set (adding new files/changing existing
  42. * ones) - you can then drive a new build and check it behaves as
  43. * expected.
  44. */
  45. public class MultiProjectIncrementalTests extends AjdeInteractionTestbed {
  46. public static boolean VERBOSE = false;
  47. protected void setUp() throws Exception {
  48. super.setUp();
  49. AjdeInteractionTestbed.VERBOSE = VERBOSE;
  50. }
  51. // Compile a single simple project
  52. public void testTheBasics() {
  53. initialiseProject("P1");
  54. build("P1"); // This first build will be batch
  55. build("P1");
  56. checkWasntFullBuild();
  57. checkCompileWeaveCount(0,0);
  58. }
  59. // source code doesnt matter, we are checking invalid path handling
  60. public void testInvalidAspectpath_pr121395() {
  61. initialiseProject("P1");
  62. File f = new File("foo.jar");
  63. Set s = new HashSet();
  64. s.add(f);
  65. configureAspectPath(s);
  66. build("P1"); // This first build will be batch
  67. checkForError("invalid aspectpath entry");
  68. }
  69. // Make simple changes to a project, adding a class
  70. public void testSimpleChanges() {
  71. initialiseProject("P1");
  72. build("P1"); // This first build will be batch
  73. alter("P1","inc1"); // adds a single class
  74. build("P1");
  75. checkCompileWeaveCount(1,-1);
  76. build("P1");
  77. checkCompileWeaveCount(0,-1);
  78. }
  79. // Make simple changes to a project, adding a class and an aspect
  80. public void testAddingAnAspect() {
  81. initialiseProject("P1");
  82. build("P1"); // build 1, weave 1
  83. alter("P1","inc1"); // adds a class
  84. alter("P1","inc2"); // adds an aspect
  85. build("P1"); // build 1,
  86. long timeTakenForFullBuildAndWeave = getTimeTakenForBuild();
  87. checkWasFullBuild(); // it *will* be a full build under the new
  88. // "back-to-the-source strategy
  89. checkCompileWeaveCount(5,3); // we compile X and A (the delta) find out that
  90. // an aspect has changed, go back to the source
  91. // and compile X,A,C, then weave them all.
  92. build("P1");
  93. long timeTakenForSimpleIncBuild = getTimeTakenForBuild();
  94. // I don't think this test will have timing issues as the times should be *RADICALLY* different
  95. // On my config, first build time is 2093ms and the second is 30ms
  96. assertTrue("Should not take longer for the trivial incremental build! first="+timeTakenForFullBuildAndWeave+
  97. "ms second="+timeTakenForSimpleIncBuild+"ms",
  98. timeTakenForSimpleIncBuild<timeTakenForFullBuildAndWeave);
  99. }
  100. public void testBuildingTwoProjectsInTurns() {
  101. configureBuildStructureModel(true);
  102. initialiseProject("P1");
  103. initialiseProject("P2");
  104. build("P1");
  105. build("P2");
  106. build("P1");
  107. checkWasntFullBuild();
  108. build("P2");
  109. checkWasntFullBuild();
  110. }
  111. /**
  112. * In order for this next test to run, I had to move the weaver/world pair we keep in the
  113. * AjBuildManager instance down into the state object - this makes perfect sense - otherwise
  114. * when reusing the state for another project we'd not be switching to the right weaver/world
  115. * for that project.
  116. */
  117. public void testBuildingTwoProjectsMakingSmallChanges() {
  118. configureBuildStructureModel(true);
  119. initialiseProject("P1");
  120. initialiseProject("P2");
  121. build("P1");
  122. build("P2");
  123. build("P1");
  124. checkWasntFullBuild();
  125. build("P2");
  126. checkWasntFullBuild();
  127. alter("P1","inc1"); // adds a class
  128. alter("P1","inc2"); // adds an aspect
  129. build("P1");
  130. checkWasFullBuild(); // adding an aspect makes us go back to the source
  131. }
  132. /**
  133. * Setup up two simple projects and build them in turn - check the
  134. * structure model is right after each build
  135. */
  136. public void testBuildingTwoProjectsAndVerifyingModel() {
  137. configureBuildStructureModel(true);
  138. initialiseProject("P1");
  139. initialiseProject("P2");
  140. build("P1");
  141. checkForNode("pkg","C",true);
  142. build("P2");
  143. checkForNode("pkg","C",false);
  144. build("P1");
  145. checkForNode("pkg","C",true);
  146. build("P2");
  147. checkForNode("pkg","C",false);
  148. }
  149. // Setup up two simple projects and build them in turn - check the
  150. // structure model is right after each build
  151. public void testBuildingTwoProjectsAndVerifyingStuff() {
  152. configureBuildStructureModel(true);
  153. initialiseProject("P1");
  154. initialiseProject("P2");
  155. build("P1");
  156. checkForNode("pkg","C",true);
  157. build("P2");
  158. checkForNode("pkg","C",false);
  159. build("P1");
  160. checkForNode("pkg","C",true);
  161. build("P2");
  162. checkForNode("pkg","C",false);
  163. }
  164. /**
  165. * Complex. Here we are testing that a state object records structural changes since
  166. * the last full build correctly. We build a simple project from scratch - this will
  167. * be a full build and so the structural changes since last build count should be 0.
  168. * We then alter a class, adding a new method and check structural changes is 1.
  169. */
  170. public void testStateManagement1() {
  171. File binDirectoryForP1 = new File(getFile("P1","bin"));
  172. initialiseProject("P1");
  173. build("P1"); // full build
  174. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirectoryForP1);
  175. assertTrue("There should be a state object for project P1",ajs!=null);
  176. assertTrue("Should be no structural changes as it was a full build but found: "+
  177. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  178. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  179. alter("P1","inc3"); // adds a method to the class C.java
  180. build("P1");
  181. checkWasntFullBuild();
  182. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("P1","bin")));
  183. assertTrue("There should be state for project P1",ajs!=null);
  184. checkWasntFullBuild();
  185. assertTrue("Should be one structural changes as it was a full build but found: "+
  186. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  187. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==1);
  188. }
  189. /**
  190. * Complex. Here we are testing that a state object records structural changes since
  191. * the last full build correctly. We build a simple project from scratch - this will
  192. * be a full build and so the structural changes since last build count should be 0.
  193. * We then alter a class, changing body of a method, not the structure and
  194. * check struc changes is still 0.
  195. */
  196. public void testStateManagement2() {
  197. File binDirectoryForP1 = new File(getFile("P1","bin"));
  198. initialiseProject("P1");
  199. alter("P1","inc3"); // need this change in here so 'inc4' can be applied without making
  200. // it a structural change
  201. build("P1"); // full build
  202. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirectoryForP1);
  203. assertTrue("There should be state for project P1",ajs!=null);
  204. assertTrue("Should be no struc changes as its a full build: "+
  205. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  206. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  207. alter("P1","inc4"); // changes body of main() method but does *not* change the structure of C.java
  208. build("P1");
  209. checkWasntFullBuild();
  210. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("P1","bin")));
  211. assertTrue("There should be state for project P1",ajs!=null);
  212. checkWasntFullBuild();
  213. assertTrue("Shouldn't be any structural changes but there were "+
  214. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  215. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  216. }
  217. /**
  218. * Now the most complex test. Create a dependancy between two projects. Building
  219. * one may affect whether the other does an incremental or full build. The
  220. * structural information recorded in the state object should be getting used
  221. * to control whether a full build is necessary...
  222. */
  223. public void testBuildingDependantProjects() {
  224. initialiseProject("P1");
  225. initialiseProject("P2");
  226. configureNewProjectDependency("P2","P1");
  227. build("P1");
  228. build("P2"); // now everything is consistent and compiled
  229. alter("P1","inc1"); // adds a second class
  230. build("P1");
  231. build("P2"); // although a second class was added - P2 can't be using it, so we don't full build here :)
  232. checkWasntFullBuild();
  233. alter("P1","inc3"); // structurally changes one of the classes
  234. build("P1");
  235. build("P2"); // build notices the structural change
  236. checkWasFullBuild();
  237. alter("P1","inc4");
  238. build("P1");
  239. build("P2"); // build sees a change but works out its not structural
  240. checkWasntFullBuild();
  241. }
  242. public void testPr85132() {
  243. initialiseProject("PR85132");
  244. build("PR85132");
  245. alter("PR85132","inc1");
  246. build("PR85132");
  247. }
  248. // parameterization of generic aspects
  249. public void testPr125405() {
  250. initialiseProject("PR125405");
  251. build("PR125405");
  252. checkCompileWeaveCount(1,1);
  253. alter("PR125405","inc1");
  254. build("PR125405");
  255. // "only abstract aspects can have type parameters"
  256. checkForError("only abstract aspects can have type parameters");
  257. alter("PR125405","inc2");
  258. build("PR125405");
  259. checkCompileWeaveCount(2,1);
  260. assertTrue("Should be no errors, but got "+MyTaskListManager.getErrorMessages(),MyTaskListManager.getErrorMessages().size()==0);
  261. }
  262. public void testPr92837() {
  263. initialiseProject("PR92837");
  264. build("PR92837");
  265. alter("PR92837","inc1");
  266. build("PR92837");
  267. }
  268. public void testPr119570() {
  269. initialiseProject("PR119570");
  270. build("PR119570");
  271. assertTrue("Should be no errors, but got "+MyTaskListManager.getErrorMessages(),MyTaskListManager.getErrorMessages().size()==0);
  272. }
  273. public void testPr119570_2() {
  274. initialiseProject("PR119570_2");
  275. build("PR119570_2");
  276. List l = MyTaskListManager.getWarningMessages();
  277. assertTrue("Should be no warnings, but got "+l,l.size()==0);
  278. }
  279. // If you fiddle with the compiler options - you must manually reset the options at the end of the test
  280. public void testPr117209() {
  281. try {
  282. initialiseProject("pr117209");
  283. configureNonStandardCompileOptions("-proceedOnError");
  284. build("pr117209");
  285. checkCompileWeaveCount(6,6);
  286. } finally {
  287. MyBuildOptionsAdapter.reset();
  288. }
  289. }
  290. public void testPr114875() {
  291. initialiseProject("pr114875");
  292. build("pr114875");
  293. alter("pr114875","inc1");
  294. build("pr114875");
  295. checkWasFullBuild();
  296. alter("pr114875","inc2");
  297. build("pr114875");
  298. checkWasFullBuild(); // back to the source for an aspect change
  299. }
  300. public void testPr117882() {
  301. // AjdeInteractionTestbed.VERBOSE=true;
  302. // AjdeInteractionTestbed.configureBuildStructureModel(true);
  303. initialiseProject("PR117882");
  304. build("PR117882");
  305. checkWasFullBuild();
  306. alter("PR117882","inc1");
  307. build("PR117882");
  308. checkWasFullBuild(); // back to the source for an aspect
  309. // AjdeInteractionTestbed.VERBOSE=false;
  310. // AjdeInteractionTestbed.configureBuildStructureModel(false);
  311. }
  312. public void testPr117882_2() {
  313. // AjdeInteractionTestbed.VERBOSE=true;
  314. // AjdeInteractionTestbed.configureBuildStructureModel(true);
  315. initialiseProject("PR117882_2");
  316. build("PR117882_2");
  317. checkWasFullBuild();
  318. alter("PR117882_2","inc1");
  319. build("PR117882_2");
  320. checkWasFullBuild(); // back to the source...
  321. //checkCompileWeaveCount(1,4);
  322. //fullBuild("PR117882_2");
  323. //checkWasFullBuild();
  324. // AjdeInteractionTestbed.VERBOSE=false;
  325. // AjdeInteractionTestbed.configureBuildStructureModel(false);
  326. }
  327. public void testPr115251() {
  328. //AjdeInteractionTestbed.VERBOSE=true;
  329. initialiseProject("PR115251");
  330. build("PR115251");
  331. checkWasFullBuild();
  332. alter("PR115251","inc1");
  333. build("PR115251");
  334. checkWasFullBuild(); // back to the source
  335. }
  336. // public void testPr124399() {
  337. // AjdeInteractionTestbed.VERBOSE=true;
  338. // configureBuildStructureModel(true);
  339. // initialiseProject("PR124399");
  340. // build("PR124399");
  341. // checkWasFullBuild();
  342. // alter("PR124399","inc1");
  343. // build("PR124399");
  344. // checkWasntFullBuild();
  345. // }
  346. public void testPr121384() {
  347. // AjdeInteractionTestbed.VERBOSE=true;
  348. // AsmManager.setReporting("c:/foo.txt",true,true,true,false);
  349. MyBuildOptionsAdapter.setNonStandardOptions("-showWeaveInfo");
  350. configureBuildStructureModel(true);
  351. initialiseProject("pr121384");
  352. build("pr121384");
  353. checkWasFullBuild();
  354. alter("pr121384","inc1");
  355. build("pr121384");
  356. checkWasntFullBuild();
  357. }
  358. /* public void testPr111779() {
  359. super.VERBOSE=true;
  360. initialiseProject("PR111779");
  361. build("PR111779");
  362. alter("PR111779","inc1");
  363. build("PR111779");
  364. }
  365. */
  366. public void testPr93310_1() {
  367. initialiseProject("PR93310_1");
  368. build("PR93310_1");
  369. checkWasFullBuild();
  370. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR93310_1" + File.separatorChar + "src" + File.separatorChar + "pack" + File.separatorChar + "C2.java";
  371. (new File(fileC2)).delete();
  372. alter("PR93310_1","inc1");
  373. build("PR93310_1");
  374. checkWasFullBuild();
  375. int l = AjdeInteractionTestbed.MyStateListener.detectedDeletions.size();
  376. assertTrue("Expected one deleted file to be noticed, but detected: "+l,l==1);
  377. String name = (String)AjdeInteractionTestbed.MyStateListener.detectedDeletions.get(0);
  378. assertTrue("Should end with C2.java but is "+name,name.endsWith("C2.java"));
  379. }
  380. public void testPr93310_2() {
  381. initialiseProject("PR93310_2");
  382. build("PR93310_2");
  383. checkWasFullBuild();
  384. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR93310_2" + File.separatorChar + "src" + File.separatorChar + "pack" + File.separatorChar + "C2.java";
  385. (new File(fileC2)).delete();
  386. alter("PR93310_2","inc1");
  387. build("PR93310_2");
  388. checkWasFullBuild();
  389. int l = AjdeInteractionTestbed.MyStateListener.detectedDeletions.size();
  390. assertTrue("Expected one deleted file to be noticed, but detected: "+l,l==1);
  391. String name = (String)AjdeInteractionTestbed.MyStateListener.detectedDeletions.get(0);
  392. assertTrue("Should end with C2.java but is "+name,name.endsWith("C2.java"));
  393. }
  394. // Stage1: Compile two files, pack.A and pack.A1 - A1 sets a protected field in A.
  395. // Stage2: make the field private in class A > gives compile error
  396. // Stage3: Add a new aspect whilst there is a compile error !
  397. public void testPr113531() {
  398. initialiseProject("PR113531");
  399. build("PR113531");
  400. assertFalse("build should have compiled ok",
  401. MyTaskListManager.hasErrorMessages());
  402. alter("PR113531","inc1");
  403. build("PR113531");
  404. assertEquals("error message should be 'foo cannot be resolved' ",
  405. "foo cannot be resolved",
  406. ((IMessage)MyTaskListManager.getErrorMessages().get(0))
  407. .getMessage());
  408. alter("PR113531","inc2");
  409. build("PR113531");
  410. assertTrue("There should be no exceptions handled:\n"+MyErrorHandler.getErrorMessages(),
  411. MyErrorHandler.getErrorMessages().isEmpty());
  412. assertEquals("error message should be 'foo cannot be resolved' ",
  413. "foo cannot be resolved",
  414. ((IMessage)MyTaskListManager.getErrorMessages().get(0))
  415. .getMessage());
  416. }
  417. public void testPr112736() {
  418. AjdeInteractionTestbed.VERBOSE = true;
  419. initialiseProject("PR112736");
  420. build("PR112736");
  421. checkWasFullBuild();
  422. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR112736" + File.separatorChar + "src" + File.separatorChar + "pack" + File.separatorChar + "A.java";
  423. (new File(fileC2)).delete();
  424. alter("PR112736","inc1");
  425. build("PR112736");
  426. checkWasFullBuild();
  427. }
  428. /**
  429. * We have problems with multiple rewrites of a pointcut across incremental builds.
  430. */
  431. public void testPr113257() {
  432. initialiseProject("PR113257");
  433. build("PR113257");
  434. alter("PR113257","inc1");
  435. build("PR113257");
  436. checkWasFullBuild(); // back to the source
  437. alter("PR113257","inc1");
  438. build("PR113257");
  439. }
  440. public void testPr123612() {
  441. initialiseProject("PR123612");
  442. build("PR123612");
  443. alter("PR123612","inc1");
  444. build("PR123612");
  445. checkWasFullBuild(); // back to the source
  446. }
  447. // other possible tests:
  448. // - memory usage (freemem calls?)
  449. // - relationship map
  450. // ---------------------------------------------------------------------------------------------------
  451. /**
  452. * Check we compiled/wove the right number of files, passing '-1' indicates you don't care about
  453. * that number.
  454. */
  455. private void checkCompileWeaveCount(int expCompile,int expWoven) {
  456. if (expCompile!=-1 && getCompiledFiles().size()!=expCompile)
  457. fail("Expected compilation of "+expCompile+" files but compiled "+getCompiledFiles().size()+
  458. "\n"+printCompiledAndWovenFiles());
  459. if (expWoven!=-1 && getWovenClasses().size()!=expWoven)
  460. fail("Expected weaving of "+expWoven+" files but wove "+getWovenClasses().size()+
  461. "\n"+printCompiledAndWovenFiles());
  462. }
  463. private void checkWasntFullBuild() {
  464. assertTrue("Shouldn't have been a full (batch) build",!wasFullBuild());
  465. }
  466. private void checkWasFullBuild() {
  467. assertTrue("Should have been a full (batch) build",wasFullBuild());
  468. }
  469. private void checkForNode(String packageName,String typeName,boolean shouldBeFound) {
  470. IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForType(packageName,typeName);
  471. if (shouldBeFound) {
  472. if (ipe==null) printModel();
  473. assertTrue("Should have been able to find '"+packageName+"."+typeName+"' in the asm",ipe!=null);
  474. } else {
  475. if (ipe!=null) printModel();
  476. assertTrue("Should have NOT been able to find '"+packageName+"."+typeName+"' in the asm",ipe==null);
  477. }
  478. }
  479. private void printModel() {
  480. try {
  481. AsmManager.dumptree(AsmManager.getDefault().getHierarchy().getRoot(),0);
  482. } catch (IOException e) {
  483. e.printStackTrace();
  484. }
  485. }
  486. public void build(String projectName) {
  487. constructUpToDateLstFile(projectName,"build.lst");
  488. build(projectName,"build.lst");
  489. if (AjdeInteractionTestbed.VERBOSE) printBuildReport();
  490. }
  491. public void fullBuild(String projectName) {
  492. constructUpToDateLstFile(projectName,"build.lst");
  493. fullBuild(projectName,"build.lst");
  494. if (AjdeInteractionTestbed.VERBOSE) printBuildReport();
  495. }
  496. private void constructUpToDateLstFile(String pname,String configname) {
  497. File projectBase = new File(sandboxDir,pname);
  498. File toConstruct = new File(projectBase,configname);
  499. List filesForCompilation = new ArrayList();
  500. collectUpFiles(projectBase,projectBase,filesForCompilation);
  501. try {
  502. FileOutputStream fos = new FileOutputStream(toConstruct);
  503. DataOutputStream dos = new DataOutputStream(fos);
  504. for (Iterator iter = filesForCompilation.iterator(); iter.hasNext();) {
  505. String file = (String) iter.next();
  506. dos.writeBytes(file+"\n");
  507. }
  508. dos.close();
  509. } catch (IOException ioe) {
  510. ioe.printStackTrace();
  511. }
  512. }
  513. public void checkForError(String anError) {
  514. List messages = MyTaskListManager.getErrorMessages();
  515. for (Iterator iter = messages.iterator(); iter.hasNext();) {
  516. IMessage element = (IMessage) iter.next();
  517. if (element.getMessage().indexOf(anError)!=-1) return;
  518. }
  519. fail("Didn't find the error message:\n'"+anError+"'.\nErrors that occurred:\n"+MyTaskListManager.getErrorMessages());
  520. }
  521. private void collectUpFiles(File location,File base,List collectionPoint) {
  522. String contents[] = location.list();
  523. if (contents==null) return;
  524. for (int i = 0; i < contents.length; i++) {
  525. String string = contents[i];
  526. File f = new File(location,string);
  527. if (f.isDirectory()) {
  528. collectUpFiles(f,base,collectionPoint);
  529. } else if (f.isFile() && (f.getName().endsWith(".aj") || f.getName().endsWith(".java"))) {
  530. String fileFound;
  531. try {
  532. fileFound = f.getCanonicalPath();
  533. String toRemove = base.getCanonicalPath();
  534. if (!fileFound.startsWith(toRemove)) throw new RuntimeException("eh? "+fileFound+" "+toRemove);
  535. collectionPoint.add(fileFound.substring(toRemove.length()+1));//+1 captures extra separator
  536. } catch (IOException e) {
  537. e.printStackTrace();
  538. }
  539. }
  540. }
  541. }
  542. /**
  543. * Fill in the working directory with the project base files,
  544. * from the 'base' folder.
  545. */
  546. protected void initialiseProject(String p) {
  547. File projectSrc=new File(testdataSrcDir+File.separatorChar+p+File.separatorChar+"base");
  548. File destination=new File(getWorkingDir(),p);
  549. if (!destination.exists()) {destination.mkdir();}
  550. copy(projectSrc,destination);//,false);
  551. }
  552. /*
  553. * Applies an overlay onto the project being tested - copying
  554. * the contents of the specified overlay directory.
  555. */
  556. private void alter(String projectName,String overlayDirectory) {
  557. File projectSrc =new File(testdataSrcDir+File.separatorChar+projectName+
  558. File.separatorChar+overlayDirectory);
  559. File destination=new File(getWorkingDir(),projectName);
  560. copy(projectSrc,destination);
  561. }
  562. /**
  563. * Copy the contents of some directory to another location - the
  564. * copy is recursive.
  565. */
  566. private void copy(File from, File to) {
  567. String contents[] = from.list();
  568. if (contents==null) return;
  569. for (int i = 0; i < contents.length; i++) {
  570. String string = contents[i];
  571. File f = new File(from,string);
  572. File t = new File(to,string);
  573. if (f.isDirectory() && !f.getName().startsWith("inc")) {
  574. t.mkdir();
  575. copy(f,t);
  576. } else if (f.isFile()) {
  577. StringBuffer sb = new StringBuffer();
  578. //if (VERBOSE) System.err.println("Copying "+f+" to "+t);
  579. FileUtil.copyFile(f,t,sb);
  580. if (sb.length()!=0) { System.err.println(sb.toString());}
  581. }
  582. }
  583. }
  584. private static void log(String msg) {
  585. if (VERBOSE) System.out.println(msg);
  586. }
  587. }