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.

IncrementalTests.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM Corporation
  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://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * ******************************************************************/
  10. package org.aspectj.systemtest.incremental;
  11. import java.io.File;
  12. import java.util.List;
  13. import org.aspectj.ajdt.internal.core.builder.AbstractStateListener;
  14. import org.aspectj.ajdt.internal.core.builder.AjState;
  15. import org.aspectj.testing.XMLBasedAjcTestCase;
  16. import junit.framework.Test;
  17. public class IncrementalTests extends org.aspectj.testing.XMLBasedAjcTestCase {
  18. public static Test suite() {
  19. return XMLBasedAjcTestCase.loadSuite(IncrementalTests.class);
  20. }
  21. protected java.net.URL getSpecFile() {
  22. return getClassResource("incremental.xml");
  23. }
  24. protected void setUp() throws Exception {
  25. super.setUp();
  26. AjState.FORCE_INCREMENTAL_DURING_TESTING = true;
  27. }
  28. protected void tearDown() throws Exception {
  29. super.tearDown();
  30. AjState.FORCE_INCREMENTAL_DURING_TESTING = false;
  31. }
  32. public void test001() throws Exception {
  33. runTest("expect class added in initial incremental tests");
  34. nextIncrement(false);
  35. copyFileAndDoIncrementalBuild("src.20/main/Main.java","src/main/Main.java");
  36. assertAdded("main/Target.class");
  37. run("main.Main");
  38. }
  39. public void test002() throws Exception {
  40. runTest("expect class removed in initial incremental tests");
  41. nextIncrement(false);
  42. assertAdded("main/Target.class");
  43. copyFileAndDoIncrementalBuild("src.20/main/Main.java","src/main/Main.java");
  44. assertDeleted("main/Target.class");
  45. run("main.Main");
  46. }
  47. public void test003() throws Exception {
  48. runTest("expect class updated in initial incremental tests");
  49. long lastTime = nextIncrement(true);
  50. copyFileAndDoIncrementalBuild("src.20/main/Main.java","src/main/Main.java");
  51. assertUpdated("main/Main.class",lastTime);
  52. run("main.Main");
  53. }
  54. public void test004() throws Exception {
  55. runTest("add file with class");
  56. nextIncrement(false);
  57. copyFileAndDoIncrementalBuild("src.20/main/Target.java","src/main/Target.java");
  58. assertAdded("main/Target.class");
  59. long lastTime = nextIncrement(true);
  60. copyFileAndDoIncrementalBuild("src.30/main/Main.java","src/main/Main.java");
  61. assertUpdated("main/Main.class",lastTime);
  62. run("main.Main");
  63. }
  64. public void test005()throws Exception {
  65. runTest("delete source file before incremental compile");
  66. nextIncrement(false);
  67. MessageSpec messageSpec = new MessageSpec(null,newMessageList(new Message(6,"delete/Target.java",null,null)));
  68. deleteFileAndDoIncrementalBuild("src/delete/DeleteMe.java",messageSpec);
  69. nextIncrement(false);
  70. copyFileAndDoIncrementalBuild("src.30/delete/Target.java","src/delete/Target.java");
  71. run("delete.Main");
  72. }
  73. public void test006() throws Exception {
  74. runTest("do everything in default package (sourceroots)");
  75. nextIncrement(false);
  76. copyFileAndDoIncrementalBuild("changes/Target.20.java","src/Target.java");
  77. run("Target");
  78. long lastTime = nextIncrement(true);
  79. copyFileAndDoIncrementalBuild("changes/Main.30.java","src/Main.java");
  80. assertUpdated("Main.class",lastTime);
  81. nextIncrement(false);
  82. MessageSpec messageSpec = new MessageSpec(null,newMessageList(new Message(6,"Main.java",null,null)));
  83. deleteFileAndDoIncrementalBuild("src/Target.java",messageSpec);
  84. nextIncrement(false);
  85. copyFileAndDoIncrementalBuild("changes/Main.50.java","src/Main.java");
  86. run("Main");
  87. }
  88. public void test007() throws Exception {
  89. runTest("change sources in default package");
  90. nextIncrement(false);
  91. copyFileAndDoIncrementalBuild("changes/Main.20.java","src/Main.java");
  92. run("Main");
  93. }
  94. public void test008() throws Exception {
  95. runTest("change source");
  96. nextIncrement(false);
  97. copyFileAndDoIncrementalBuild("changes/Main.20.java","src/app/Main.java");
  98. run("app.Main");
  99. }
  100. /**
  101. * See bug report 85297. We plugged a hole so that we check whether the contents of
  102. * directories on the classpath have changed when deciding whether we can do an
  103. * incremental build or not - the implementation didn't allow for the output location
  104. * being on the classpath. This test verifies the fix is OK
  105. */
  106. public void testIncrementalOKWithOutputPathOnClasspath() throws Exception {
  107. class MyStateListener extends AbstractStateListener {
  108. public boolean pathChange = false;
  109. public void pathChangeDetected() {pathChange = true;}
  110. public void aboutToCompareClasspaths(List oldClasspath, List newClasspath) {}
  111. public void detectedClassChangeInThisDir(File f) {}
  112. public void buildSuccessful(boolean wasFullBuild) {}
  113. };
  114. MyStateListener sl = new MyStateListener();
  115. try {
  116. AjState.stateListener = sl;
  117. runTest("change source");
  118. nextIncrement(false);
  119. copyFileAndDoIncrementalBuild("changes/Main.20.java","src/app/Main.java");
  120. assertTrue("Did not expect a path change to be detected ",!sl.pathChange);
  121. run("app.Main");
  122. } finally {
  123. AjState.stateListener=null;
  124. }
  125. }
  126. public void test009() throws Exception {
  127. runTest("incrementally change only string literal, still expect advice");
  128. long lastTime = nextIncrement(true);
  129. copyFileAndDoIncrementalBuild("changes/Main.20.java","src/packageOne/Main.java");
  130. assertUpdated("packageOne/Main.class",lastTime);
  131. run("packageOne.Main",new String[] {"in longer packageOne.Main.main(..)",
  132. "before main packageOne.Main"},
  133. null);
  134. }
  135. public void test010() throws Exception {
  136. runTest("add aspect source file and check world is rewoven");
  137. nextIncrement(false);
  138. copyFileAndDoIncrementalBuild("changes/Detour.20.java","src/Detour.java");
  139. assertAdded("Detour.class");
  140. run("Main");
  141. }
  142. public void test011() throws Exception {
  143. runTest("make sure additional classes generated during weave are deleted with src class file");
  144. nextIncrement(false);
  145. assertTrue("AdviceOnIntroduced$AjcClosure1.class exists",
  146. new File(ajc.getSandboxDirectory(),"AdviceOnIntroduced$AjcClosure1.class").exists());
  147. deleteFileAndDoIncrementalBuild("src/AdviceOnIntroduced.java");
  148. assertDeleted("AdviceOnIntroduced$AjcClosure1.class");
  149. }
  150. public void test012() throws Exception {
  151. runTest("incremental with aspect-driven full rebuild");
  152. nextIncrement(false);
  153. MessageSpec messageSpec = new MessageSpec(newMessageList(new Message(3,"Main.java",null,null)),null);
  154. copyFileAndDoIncrementalBuild("changes/Aspect.20.java","src/Aspect.java",messageSpec);
  155. run("Main");
  156. }
  157. public void testIncrementalResourceAdditionToInPath() throws Exception {
  158. runTest("incremental with addition of resource to inpath directory");
  159. RunResult result = run("Hello");
  160. assertTrue("Should have been advised", result.getStdOut().contains("World"));
  161. nextIncrement(false);
  162. assertFalse("Resource file should not exist yet",new File(ajc.getSandboxDirectory(),"AResourceFile.txt").exists());
  163. copyFileAndDoIncrementalBuild("changes/AResourceFile.txt", "indir/AResourceFile.txt");
  164. // resources are *NOT* copied from inpath directories
  165. assertFalse("Resource file should not exist yet",new File(ajc.getSandboxDirectory(),"AResourceFile.txt").exists());
  166. }
  167. public void testAdditionOfResourceToInJar() throws Exception {
  168. runTest("incremental with addition of resource to inpath jar");
  169. nextIncrement(true);
  170. assertFalse("Resource file should not exist yet",new File(ajc.getSandboxDirectory(),"AResourceFile.txt").exists());
  171. copyFileAndDoIncrementalBuild("changes/MyJar.20.jar", "MyJar.jar");
  172. // resources *are* copied from inpath jars
  173. assertAdded("AResourceFile.txt");
  174. }
  175. public void testRemovalOfResourceFromInJar() throws Exception {
  176. runTest("incremental with removal of resource from inpath jar");
  177. nextIncrement(true);
  178. assertAdded("AResourceFile.txt");
  179. copyFileAndDoIncrementalBuild("changes/MyJar.20.jar", "MyJar.jar");
  180. // resources *are* copied from inpath jars
  181. assertDeleted("AResourceFile.txt");
  182. }
  183. public void testAdditionOfClassToInPathJar() throws Exception {
  184. runTest("incremental with addition of class to inpath jar");
  185. nextIncrement(true);
  186. assertFalse("Hello2.class should not exist yet",new File(ajc.getSandboxDirectory(),"Hello2.class").exists());
  187. copyFileAndDoIncrementalBuild("changes/MyJar.20.jar", "MyJar.jar");
  188. assertAdded("Hello2.class");
  189. }
  190. public void testRemovalOfClassFromInPathJar() throws Exception {
  191. runTest("incremental with removal of class from inpath jar");
  192. nextIncrement(true);
  193. assertAdded("Hello2.class");
  194. copyFileAndDoIncrementalBuild("changes/MyJar.20.jar", "MyJar.jar");
  195. assertDeleted("Hello2.class");
  196. }
  197. public void testAdditionOfClassToInJarJar() throws Exception {
  198. runTest("incremental with addition of class to injar jar");
  199. nextIncrement(true);
  200. assertFalse("Hello2.class should not exist yet",new File(ajc.getSandboxDirectory(),"Hello2.class").exists());
  201. copyFileAndDoIncrementalBuild("changes/MyJar.20.jar", "MyJar.jar");
  202. assertAdded("Hello2.class");
  203. }
  204. public void testRemovalOfClassFromInJarJar() throws Exception {
  205. runTest("incremental with removal of class from injar jar");
  206. nextIncrement(true);
  207. assertAdded("Hello2.class");
  208. copyFileAndDoIncrementalBuild("changes/MyJar.20.jar", "MyJar.jar");
  209. assertDeleted("Hello2.class");
  210. }
  211. public void testAdditionOfClassToInPathDir() throws Exception {
  212. runTest("incremental with addition of class to inpath dir");
  213. nextIncrement(true);
  214. assertFalse("Hello2.class should not exist yet",new File(ajc.getSandboxDirectory(),"Hello2.class").exists());
  215. copyFileAndDoIncrementalBuild("changes/Hello2.20.class", "indir/Hello2.class");
  216. assertAdded("Hello2.class");
  217. }
  218. public void testRemovalOfClassFromInPathDir() throws Exception {
  219. runTest("incremental with removal of class from inpath dir");
  220. nextIncrement(true);
  221. assertAdded("Hello2.class");
  222. deleteFileAndDoIncrementalBuild("indir/Hello2.class");
  223. assertDeleted("Hello2.class");
  224. }
  225. public void testUpdateOfClassInInPathDir() throws Exception {
  226. runTest("incremental with update of class in inpath dir");
  227. nextIncrement(true);
  228. RunResult before = run("Hello");
  229. assertTrue("Should say hello",before.getStdOut().startsWith("hello"));
  230. copyFileAndDoIncrementalBuild("changes/Hello.20.class", "indir/Hello.class");
  231. RunResult after = run("Hello");
  232. assertTrue("Should say updated hello",after.getStdOut().startsWith("updated hello"));
  233. }
  234. public void testUsesPointcutRelsWhenReferringToPCTIn2ndFile_pr90806() throws Exception {
  235. runTest("NPE in genHandleIdentifier");
  236. nextIncrement(true);
  237. copyFileAndDoIncrementalBuild("changes/X.20.aj","src/X.aj");
  238. }
  239. public void testPersistingDeow_pr84033() throws Exception {
  240. runTest("incremental declare error persists after fix");
  241. copyFileAndDoIncrementalBuild("changes/Aspect.20.java", "src/pack/Aspect.java");
  242. nextIncrement(true);
  243. RunResult before = run("pack.Main");
  244. }
  245. public void testIncrementalUpdateOfBodyInAroundAdvice_pr154054() throws Exception {
  246. runTest("incremental update of body in around advice");
  247. nextIncrement(true);
  248. RunResult before = run("MyClass");
  249. assertTrue("value should be 13 but was " + before.getStdOut(),
  250. before.getStdOut().startsWith("13"));
  251. // update value added to proceed
  252. copyFileAndDoIncrementalBuild("changes/MyAspect.20.aj","src/MyAspect.aj");
  253. RunResult after = run("MyClass");
  254. assertTrue("value should be 14 but was " + after.getStdOut(),
  255. after.getStdOut().startsWith("14"));
  256. }
  257. public void testIncrementalUpdateOfBodyInAroundAdviceWithString_pr154054() throws Exception {
  258. runTest("incremental update of body in around advice with string");
  259. nextIncrement(true);
  260. RunResult before = run("MyClass");
  261. assertTrue("expected 'Fred and George' in output but found " + before.getStdOut(),
  262. before.getStdOut().startsWith("Fred and George"));
  263. // update value added to proceed
  264. copyFileAndDoIncrementalBuild("changes/MyAspect.30.aj","src/MyAspect.aj");
  265. RunResult after = run("MyClass");
  266. assertTrue("expected 'Fred and Harry' in output but found " + after.getStdOut(),
  267. after.getStdOut().startsWith("Fred and Harry"));
  268. }
  269. }