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.

BuildCancellingTest.java 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /********************************************************************
  2. * Copyright (c) 2004 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Andy Clement Initial version
  11. * Helen Hawkins Converted to new interface (bug 148190)
  12. * ******************************************************************/
  13. package org.aspectj.ajde.core.tests;
  14. import org.aspectj.ajde.core.AjdeCoreTestCase;
  15. import org.aspectj.ajde.core.TestBuildProgressMonitor;
  16. import org.aspectj.ajde.core.TestCompilerConfiguration;
  17. /**
  18. * It is now possible to cancel the compiler during either the compilation or
  19. * weaving phases - this testcase verifies a few cases, making sure the process
  20. * stops when expected. It can check the disk contents, but it doesn't right
  21. * now.
  22. *
  23. * Two different .lst files are used during these tests: LoadsaCode.lst and
  24. * EvenMoreCode.lst which contain mixes of aspects and classes
  25. *
  26. * Here are some things to think about that will help you understand what is on
  27. * the disk when we cancel the compiler.
  28. *
  29. * There are 3 important phases worth remembering : - Compile all the types -
  30. * Weave all the aspects - Weave all the classes
  31. *
  32. * Each of those steps goes through all the types. This means during the 'weave
  33. * all the aspects' step we are jumping over classes and during the 'weave all
  34. * the classes ' step we are jumping over aspects. Why is this important?
  35. *
  36. *
  37. * We only write bytes out during the 'weave all the classes ' phase and it is
  38. * even during that phase that we write out the bytes for aspects. This means if
  39. * you cancel during compilation or during the weaving of aspects - there will
  40. * be nothing on the disk. If you cancel whilst in the 'weave all the classes '
  41. * phase then the disk will contain anything finished with by the cancellation
  42. * point.
  43. */
  44. public class BuildCancellingTest extends AjdeCoreTestCase {
  45. private final boolean debugTests = false;
  46. private TestBuildProgressMonitor programmableBPM;
  47. private TestCompilerConfiguration compilerConfig;
  48. private String[] loadsaCode = { "A1.aj", "A2.aj", "HW.java", "A3.aj",
  49. "A4.aj" };
  50. private String[] evenMoreCode = { "A1.aj", "Cl1.java", "A2.aj", "Cl2.java",
  51. "HW.java", "A3.aj", "Cl3.java", "A4.aj" };
  52. protected void setUp() throws Exception {
  53. super.setUp();
  54. initialiseProject("BuildCancelling");
  55. programmableBPM = (TestBuildProgressMonitor) getCompiler()
  56. .getBuildProgressMonitor();
  57. compilerConfig = (TestCompilerConfiguration) getCompiler()
  58. .getCompilerConfiguration();
  59. }
  60. protected void tearDown() throws Exception {
  61. super.tearDown();
  62. programmableBPM = null;
  63. compilerConfig = null;
  64. }
  65. /**
  66. * After first compilation message, get it to cancel, there should be one
  67. * more warning message about cancelling the compile and their should be
  68. * nothing on the disk.
  69. */
  70. public void testCancelFirstCompile() {
  71. if (debugTests)
  72. System.out
  73. .println("\n\n\ntestCancelFirstCompile: Building with LoadsaCode");
  74. compilerConfig.setProjectSourceFiles(getSourceFileList(loadsaCode));
  75. programmableBPM.cancelOn("compiled:", 1); // Force a cancel after the
  76. // first compile occurs
  77. doBuild(true);
  78. assertTrue("Should have cancelled after first compile?:"
  79. + programmableBPM.numCompiledMessages,
  80. programmableBPM.numCompiledMessages == 1);
  81. // Comment out to check the disk contents
  82. // assertTrue("As weaving was cancelled, no files should have been
  83. // written out, but I found:"+wovenClassesFound(),
  84. // wovenClassesFound()==0);
  85. boolean expectedCancelMessageFound = checkFor("Compilation cancelled as requested");
  86. if (!expectedCancelMessageFound)
  87. dumpTaskData(); // Useful for debugging
  88. assertTrue(
  89. "Failed to get warning message about compilation being cancelled!",
  90. expectedCancelMessageFound);
  91. }
  92. /**
  93. * After third compilation message, get it to cancel, there should be one
  94. * more warning message about cancelling the compile and their should be
  95. * nothing on the disk.
  96. */
  97. public void testCancelThirdCompile() {
  98. if (debugTests)
  99. System.out
  100. .println("\n\n\ntestCancelThirdCompile: Building with LoadsaCode");
  101. compilerConfig.setProjectSourceFiles(getSourceFileList(loadsaCode));
  102. programmableBPM.cancelOn("compiled:", 3); // Force a cancel after the
  103. // third compile occurs
  104. doBuild(true);
  105. assertTrue("Should have cancelled after third compile?:"
  106. + programmableBPM.numCompiledMessages,
  107. programmableBPM.numCompiledMessages == 3);
  108. // Comment out to check the disk contents
  109. // assertTrue("As weaving was cancelled, no files should have been
  110. // written out, but I found:"+wovenClassesFound(),
  111. // wovenClassesFound()==0);
  112. boolean expectedCancelMessageFound = checkFor("Compilation cancelled as requested");
  113. if (!expectedCancelMessageFound)
  114. dumpTaskData(); // Useful for debugging
  115. assertTrue(
  116. "Failed to get warning message about compilation being cancelled!",
  117. expectedCancelMessageFound);
  118. }
  119. /**
  120. * After first weave aspect message, get it to cancel, there should be one
  121. * more warning message about cancelling the weave and their should be
  122. * nothing on the disk.
  123. */
  124. public void testCancelFirstAspectWeave() {
  125. if (debugTests)
  126. System.out
  127. .println("\n\n\ntestCancelFirstAspectWeave: Building with LoadsaCode");
  128. compilerConfig.setProjectSourceFiles(getSourceFileList(loadsaCode));
  129. programmableBPM.cancelOn("woven aspect ", 1); // Force a cancel after
  130. // the first weave
  131. // aspect occurs
  132. doBuild(true);
  133. assertTrue("Should have cancelled after first aspect weave?:"
  134. + programmableBPM.numWovenAspectMessages,
  135. programmableBPM.numWovenAspectMessages == 1);
  136. // Comment out to check the disk contents
  137. // assertTrue("As weaving was cancelled, no files should have been
  138. // written out?:"+wovenClassesFound(),
  139. // wovenClassesFound()==0);
  140. boolean expectedCancelMessageFound = checkFor("Weaving cancelled as requested");
  141. if (!expectedCancelMessageFound)
  142. dumpTaskData(); // Useful for debugging
  143. assertTrue(
  144. "Failed to get warning message about weaving being cancelled!",
  145. expectedCancelMessageFound);
  146. }
  147. /**
  148. * After third weave aspect message, get it to cancel, there should be one
  149. * more warning message about cancelling the weave and their should be
  150. * nothing on the disk.
  151. */
  152. public void testCancelThirdAspectWeave() {
  153. if (debugTests)
  154. System.out
  155. .println("\n\n\ntestCancelThirdAspectWeave: Building with LoadsaCode");
  156. compilerConfig.setProjectSourceFiles(getSourceFileList(loadsaCode));
  157. // Force a cancel after the third weave occurs.
  158. // This should leave two class files on disk - I think?
  159. programmableBPM.cancelOn("woven aspect ", 3);
  160. doBuild(true);
  161. assertTrue("Should have cancelled after third weave?:"
  162. + programmableBPM.numWovenAspectMessages,
  163. programmableBPM.numWovenAspectMessages == 3);
  164. // Comment out to check disk contents
  165. // assertTrue("As weaving was cancelled, no files should have been
  166. // written out?:"+wovenClassesFound(),
  167. // wovenClassesFound()==0);
  168. boolean expectedCancelMessageFound = checkFor("Weaving cancelled as requested");
  169. if (!expectedCancelMessageFound)
  170. dumpTaskData(); // Useful for debugging
  171. assertTrue(
  172. "Failed to get warning message about weaving being cancelled!",
  173. expectedCancelMessageFound);
  174. }
  175. /**
  176. * After first weave class message, get it to cancel, there should be one
  177. * more warning message about cancelling the weave and their should be
  178. * nothing on the disk.
  179. *
  180. * EvenMoreCode.lst contains: A1.aj Cl1.java A2.aj Cl2.java HW.java A3.aj
  181. * Cl3.java A4.aj
  182. *
  183. */
  184. public void testCancelFirstClassWeave() {
  185. if (debugTests)
  186. System.out
  187. .println("testCancelFirstClassWeave: Building with EvenMoreCode");
  188. compilerConfig.setProjectSourceFiles(getSourceFileList(evenMoreCode));
  189. programmableBPM.cancelOn("woven class", 1);
  190. doBuild(true);
  191. // Should just be A1 on the disk - uncomment this line to verify that!
  192. // (and uncomment diskContents())
  193. // assertTrue("Incorrect disk contents found",diskContents("A1"));
  194. assertTrue("Should have cancelled after first class weave?:"
  195. + programmableBPM.numWovenClassMessages,
  196. programmableBPM.numWovenClassMessages == 1);
  197. boolean expectedCancelMessageFound = checkFor("Weaving cancelled as requested");
  198. if (!expectedCancelMessageFound)
  199. dumpTaskData(); // Useful for debugging
  200. assertTrue(
  201. "Failed to get warning message about weaving being cancelled!",
  202. expectedCancelMessageFound);
  203. }
  204. /**
  205. * After first weave aspect message, get it to cancel, there should be one
  206. * more warning message about cancelling the weave and their should be
  207. * nothing on the disk.
  208. *
  209. * EvenMoreCode.lst contains: A1.aj Cl1.java A2.aj Cl2.java HW.java A3.aj
  210. * Cl3.java A4.aj
  211. *
  212. */
  213. public void testCancelSecondClassWeave() {
  214. if (debugTests)
  215. System.out
  216. .println("testCancelSecondClassWeave: Building with EvenMoreCode");
  217. compilerConfig.setProjectSourceFiles(getSourceFileList(evenMoreCode));
  218. programmableBPM.cancelOn("woven class", 2);
  219. doBuild(true);
  220. // Uncomment this line to verify disk contents(and uncomment
  221. // diskContents())
  222. // assertTrue("Incorrect disk contents found",diskContents("A1 Cl1
  223. // A2"));
  224. assertTrue("Should have cancelled after first class weave?:"
  225. + programmableBPM.numWovenClassMessages,
  226. programmableBPM.numWovenClassMessages == 2);
  227. boolean expectedCancelMessageFound = checkFor("Weaving cancelled as requested");
  228. if (!expectedCancelMessageFound)
  229. dumpTaskData(); // Useful for debugging
  230. assertTrue(
  231. "Failed to get warning message about weaving being cancelled!",
  232. expectedCancelMessageFound);
  233. }
  234. }