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 72KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843
  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.File;
  14. import java.io.IOException;
  15. import java.util.ArrayList;
  16. import java.util.HashSet;
  17. import java.util.Hashtable;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. import java.util.Set;
  21. import org.aspectj.ajde.Ajde;
  22. import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
  23. import org.aspectj.ajdt.internal.core.builder.AjState;
  24. import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
  25. import org.aspectj.asm.AsmManager;
  26. import org.aspectj.asm.IElementHandleProvider;
  27. import org.aspectj.asm.IHierarchy;
  28. import org.aspectj.asm.IProgramElement;
  29. import org.aspectj.asm.IRelationship;
  30. import org.aspectj.asm.IRelationshipMap;
  31. import org.aspectj.asm.internal.JDTLikeHandleProvider;
  32. import org.aspectj.asm.internal.Relationship;
  33. import org.aspectj.bridge.IMessage;
  34. import org.aspectj.bridge.IMessageHandler;
  35. import org.aspectj.bridge.IMessageHolder;
  36. import org.aspectj.tools.ajc.Ajc;
  37. import org.aspectj.util.FileUtil;
  38. import org.aspectj.weaver.LintMessage;
  39. /**
  40. * The superclass knows all about talking through Ajde to the compiler.
  41. * The superclass isn't in charge of knowing how to simulate overlays
  42. * for incremental builds, that is in here. As is the ability to
  43. * generate valid build configs based on a directory structure. To
  44. * support this we just need access to a sandbox directory - this
  45. * sandbox is managed by the superclass (it only assumes all builds occur
  46. * in <sandboxDir>/<projectName>/ )
  47. *
  48. * The idea is you can initialize multiple projects in the sandbox and
  49. * they can all be built independently, hopefully exploiting
  50. * incremental compilation. Between builds you can alter the contents
  51. * of a project using the alter() method that overlays some set of
  52. * new files onto the current set (adding new files/changing existing
  53. * ones) - you can then drive a new build and check it behaves as
  54. * expected.
  55. */
  56. public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementalAjdeInteractionTestbed {
  57. /*
  58. A.aj
  59. package pack;
  60. public aspect A {
  61. pointcut p() : call(* C.method
  62. before() : p() { // line 7
  63. }
  64. }
  65. C.java
  66. package pack;
  67. public class C {
  68. public void method1() {
  69. method2(); // line 6
  70. }
  71. public void method2() { }
  72. public void method3() {
  73. method2(); // line 13
  74. }
  75. }*/
  76. public void testDontLoseAdviceMarkers_pr134471() {
  77. try {
  78. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=false;
  79. configureBuildStructureModel(true);
  80. initialiseProject("P4");
  81. build("P4");
  82. Ajc.dumpAJDEStructureModel("after full build where advice is applying");
  83. // should be 4 relationship entries
  84. // In inc1 the first advised line is 'commented out'
  85. alter("P4","inc1");
  86. build("P4");
  87. checkWasntFullBuild();
  88. Ajc.dumpAJDEStructureModel("after inc build where first advised line is gone");
  89. // should now be 2 relationship entries
  90. // This will be the line 6 entry in C.java
  91. IProgramElement codeElement = findCode(checkForNode("pack","C",true));
  92. // This will be the line 7 entry in A.java
  93. IProgramElement advice = findAdvice(checkForNode("pack","A",true));
  94. IRelationshipMap asmRelMap = AsmManager.getDefault().getRelationshipMap();
  95. assertEquals("There should be two relationships in the relationship map",
  96. 2,asmRelMap.getEntries().size());
  97. for (Iterator iter = asmRelMap.getEntries().iterator(); iter.hasNext();) {
  98. String sourceOfRelationship = (String) iter.next();
  99. IProgramElement ipe = AsmManager.getDefault().getHierarchy()
  100. .findElementForHandle(sourceOfRelationship);
  101. assertNotNull("expected to find IProgramElement with handle "
  102. + sourceOfRelationship + " but didn't",ipe);
  103. if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) {
  104. assertEquals("expected source of relationship to be " +
  105. advice.toString() + " but found " +
  106. ipe.toString(),advice,ipe);
  107. } else if (ipe.getKind().equals(IProgramElement.Kind.CODE)) {
  108. assertEquals("expected source of relationship to be " +
  109. codeElement.toString() + " but found " +
  110. ipe.toString(),codeElement,ipe);
  111. } else {
  112. fail("found unexpected relationship source " + ipe
  113. + " with kind " + ipe.getKind()+" when looking up handle: "+sourceOfRelationship);
  114. }
  115. List relationships = asmRelMap.get(ipe);
  116. assertNotNull("expected " + ipe.getName() +" to have some " +
  117. "relationships",relationships);
  118. for (Iterator iterator = relationships.iterator(); iterator.hasNext();) {
  119. Relationship rel = (Relationship) iterator.next();
  120. List targets = rel.getTargets();
  121. for (Iterator iterator2 = targets.iterator(); iterator2.hasNext();) {
  122. String t = (String) iterator2.next();
  123. IProgramElement link = AsmManager.getDefault().getHierarchy().findElementForHandle(t);
  124. if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) {
  125. assertEquals("expected target of relationship to be " +
  126. codeElement.toString() + " but found " +
  127. link.toString(),codeElement,link);
  128. } else if (ipe.getKind().equals(IProgramElement.Kind.CODE)) {
  129. assertEquals("expected target of relationship to be " +
  130. advice.toString() + " but found " +
  131. link.toString(),advice,link);
  132. } else {
  133. fail("found unexpected relationship source " + ipe.getName()
  134. + " with kind " + ipe.getKind());
  135. }
  136. }
  137. }
  138. }
  139. } finally {
  140. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=true;
  141. configureBuildStructureModel(false);
  142. }
  143. }
  144. // Compile a single simple project
  145. public void testTheBasics() {
  146. initialiseProject("P1");
  147. build("P1"); // This first build will be batch
  148. build("P1");
  149. checkWasntFullBuild();
  150. checkCompileWeaveCount(0,0);
  151. }
  152. // source code doesnt matter, we are checking invalid path handling
  153. public void testInvalidAspectpath_pr121395() {
  154. initialiseProject("P1");
  155. File f = new File("foo.jar");
  156. Set s = new HashSet();
  157. s.add(f);
  158. configureAspectPath(s);
  159. build("P1"); // This first build will be batch
  160. checkForError("invalid aspectpath entry");
  161. }
  162. /**
  163. * Build a project containing a resource - then mark the resource readOnly(), then
  164. * do an inc-compile, it will report an error about write access to the resource
  165. * in the output folder being denied
  166. */
  167. /*public void testProblemCopyingResources_pr138171() {
  168. initialiseProject("PR138171");
  169. File f=getProjectRelativePath("PR138171","res.txt");
  170. Map m = new HashMap();
  171. m.put("res.txt",f);
  172. AjdeInteractionTestbed.MyProjectPropertiesAdapter.getInstance().setSourcePathResources(m);
  173. build("PR138171");
  174. File f2 = getProjectOutputRelativePath("PR138171","res.txt");
  175. boolean successful = f2.setReadOnly();
  176. alter("PR138171","inc1");
  177. AjdeInteractionTestbed.MyProjectPropertiesAdapter.getInstance().setSourcePathResources(m);
  178. build("PR138171");
  179. List msgs = MyTaskListManager.getErrorMessages();
  180. assertTrue("there should be one message but there are "+(msgs==null?0:msgs.size())+":\n"+msgs,msgs!=null && msgs.size()==1);
  181. IMessage msg = (IMessage)msgs.get(0);
  182. String exp = "unable to copy resource to output folder: 'res.txt'";
  183. assertTrue("Expected message to include this text ["+exp+"] but it does not: "+msg,msg.toString().indexOf(exp)!=-1);
  184. }*/
  185. // Make simple changes to a project, adding a class
  186. public void testSimpleChanges() {
  187. initialiseProject("P1");
  188. build("P1"); // This first build will be batch
  189. alter("P1","inc1"); // adds a single class
  190. build("P1");
  191. checkCompileWeaveCount(1,-1);
  192. build("P1");
  193. checkCompileWeaveCount(0,-1);
  194. }
  195. // Make simple changes to a project, adding a class and an aspect
  196. public void testAddingAnAspect() {
  197. initialiseProject("P1");
  198. build("P1"); // build 1, weave 1
  199. alter("P1","inc1"); // adds a class
  200. alter("P1","inc2"); // adds an aspect
  201. build("P1"); // build 1,
  202. long timeTakenForFullBuildAndWeave = getTimeTakenForBuild();
  203. checkWasFullBuild(); // it *will* be a full build under the new
  204. // "back-to-the-source strategy
  205. checkCompileWeaveCount(5,3); // we compile X and A (the delta) find out that
  206. // an aspect has changed, go back to the source
  207. // and compile X,A,C, then weave them all.
  208. build("P1");
  209. long timeTakenForSimpleIncBuild = getTimeTakenForBuild();
  210. // I don't think this test will have timing issues as the times should be *RADICALLY* different
  211. // On my config, first build time is 2093ms and the second is 30ms
  212. assertTrue("Should not take longer for the trivial incremental build! first="+timeTakenForFullBuildAndWeave+
  213. "ms second="+timeTakenForSimpleIncBuild+"ms",
  214. timeTakenForSimpleIncBuild<timeTakenForFullBuildAndWeave);
  215. }
  216. public void testBuildingTwoProjectsInTurns() {
  217. configureBuildStructureModel(true);
  218. initialiseProject("P1");
  219. initialiseProject("P2");
  220. build("P1");
  221. build("P2");
  222. build("P1");
  223. checkWasntFullBuild();
  224. build("P2");
  225. checkWasntFullBuild();
  226. }
  227. // public void testDeclareAtType_pr149293() {
  228. // configureBuildStructureModel(true);
  229. // initialiseProject("PR149293_1");
  230. // build("PR149293_1");
  231. // checkCompileWeaveCount(4,5);
  232. // assertNoErrors();
  233. // alter("PR149293_1","inc1");
  234. // build("PR149293_1");
  235. // assertNoErrors();
  236. // }
  237. /*
  238. public void testRefactoring_pr148285() {
  239. configureBuildStructureModel(true);
  240. initialiseProject("PR148285");
  241. build("PR148285");
  242. System.err.println("xxx");
  243. alter("PR148285","inc1");
  244. build("PR148285");
  245. }
  246. */
  247. /**
  248. * In order for this next test to run, I had to move the weaver/world pair we keep in the
  249. * AjBuildManager instance down into the state object - this makes perfect sense - otherwise
  250. * when reusing the state for another project we'd not be switching to the right weaver/world
  251. * for that project.
  252. */
  253. public void testBuildingTwoProjectsMakingSmallChanges() {
  254. configureBuildStructureModel(true);
  255. initialiseProject("P1");
  256. initialiseProject("P2");
  257. build("P1");
  258. build("P2");
  259. build("P1");
  260. checkWasntFullBuild();
  261. build("P2");
  262. checkWasntFullBuild();
  263. alter("P1","inc1"); // adds a class
  264. alter("P1","inc2"); // adds an aspect
  265. build("P1");
  266. checkWasFullBuild(); // adding an aspect makes us go back to the source
  267. }
  268. public void testPr134371() {
  269. initialiseProject("PR134371");
  270. build("PR134371");
  271. alter("PR134371","inc1");
  272. build("PR134371");
  273. assertTrue("There should be no exceptions handled:\n"+MyErrorHandler.getErrorMessages(),
  274. MyErrorHandler.getErrorMessages().isEmpty());
  275. }
  276. /**
  277. * Setup up two simple projects and build them in turn - check the
  278. * structure model is right after each build
  279. */
  280. public void testBuildingTwoProjectsAndVerifyingModel() {
  281. configureBuildStructureModel(true);
  282. initialiseProject("P1");
  283. initialiseProject("P2");
  284. build("P1");
  285. checkForNode("pkg","C",true);
  286. build("P2");
  287. checkForNode("pkg","C",false);
  288. build("P1");
  289. checkForNode("pkg","C",true);
  290. build("P2");
  291. checkForNode("pkg","C",false);
  292. }
  293. // Setup up two simple projects and build them in turn - check the
  294. // structure model is right after each build
  295. public void testBuildingTwoProjectsAndVerifyingStuff() {
  296. configureBuildStructureModel(true);
  297. initialiseProject("P1");
  298. initialiseProject("P2");
  299. build("P1");
  300. checkForNode("pkg","C",true);
  301. build("P2");
  302. checkForNode("pkg","C",false);
  303. build("P1");
  304. checkForNode("pkg","C",true);
  305. build("P2");
  306. checkForNode("pkg","C",false);
  307. }
  308. /**
  309. * Complex. Here we are testing that a state object records structural changes since
  310. * the last full build correctly. We build a simple project from scratch - this will
  311. * be a full build and so the structural changes since last build count should be 0.
  312. * We then alter a class, adding a new method and check structural changes is 1.
  313. */
  314. public void testStateManagement1() {
  315. File binDirectoryForP1 = new File(getFile("P1","bin"));
  316. initialiseProject("P1");
  317. build("P1"); // full build
  318. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirectoryForP1);
  319. assertTrue("There should be a state object for project P1",ajs!=null);
  320. assertTrue("Should be no structural changes as it was a full build but found: "+
  321. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  322. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  323. alter("P1","inc3"); // adds a method to the class C.java
  324. build("P1");
  325. checkWasntFullBuild();
  326. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("P1","bin")));
  327. assertTrue("There should be state for project P1",ajs!=null);
  328. checkWasntFullBuild();
  329. assertTrue("Should be one structural changes as it was a full build but found: "+
  330. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  331. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==1);
  332. }
  333. /**
  334. * Complex. Here we are testing that a state object records structural changes since
  335. * the last full build correctly. We build a simple project from scratch - this will
  336. * be a full build and so the structural changes since last build count should be 0.
  337. * We then alter a class, changing body of a method, not the structure and
  338. * check struc changes is still 0.
  339. */
  340. public void testStateManagement2() {
  341. File binDirectoryForP1 = new File(getFile("P1","bin"));
  342. initialiseProject("P1");
  343. alter("P1","inc3"); // need this change in here so 'inc4' can be applied without making
  344. // it a structural change
  345. build("P1"); // full build
  346. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirectoryForP1);
  347. assertTrue("There should be state for project P1",ajs!=null);
  348. assertTrue("Should be no struc changes as its a full build: "+
  349. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  350. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  351. alter("P1","inc4"); // changes body of main() method but does *not* change the structure of C.java
  352. build("P1");
  353. checkWasntFullBuild();
  354. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("P1","bin")));
  355. assertTrue("There should be state for project P1",ajs!=null);
  356. checkWasntFullBuild();
  357. assertTrue("Shouldn't be any structural changes but there were "+
  358. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  359. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  360. }
  361. /**
  362. * The C.java file modified in this test has an inner class - this means the inner class
  363. * has a this$0 field and <init>(C) ctor to watch out for when checking for structural changes
  364. *
  365. */
  366. public void testStateManagement3() {
  367. File binDirForInterproject1 = new File(getFile("interprojectdeps1","bin"));
  368. initialiseProject("interprojectdeps1");
  369. build("interprojectdeps1"); // full build
  370. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirForInterproject1);
  371. assertTrue("There should be state for project P1",ajs!=null);
  372. assertTrue("Should be no struc changes as its a full build: "+
  373. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  374. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  375. alter("interprojectdeps1","inc1"); // adds a space to C.java
  376. build("interprojectdeps1");
  377. checkWasntFullBuild();
  378. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("interprojectdeps1","bin")));
  379. assertTrue("There should be state for project interprojectdeps1",ajs!=null);
  380. checkWasntFullBuild();
  381. assertTrue("Shouldn't be any structural changes but there were "+
  382. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  383. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  384. }
  385. /**
  386. * The C.java file modified in this test has an inner class - which has two ctors - this checks
  387. * how they are mangled with an instance of C.
  388. *
  389. */
  390. public void testStateManagement4() {
  391. File binDirForInterproject2 = new File(getFile("interprojectdeps2","bin"));
  392. initialiseProject("interprojectdeps2");
  393. build("interprojectdeps2"); // full build
  394. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirForInterproject2);
  395. assertTrue("There should be state for project interprojectdeps2",ajs!=null);
  396. assertTrue("Should be no struc changes as its a full build: "+
  397. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  398. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  399. alter("interprojectdeps2","inc1"); // minor change to C.java
  400. build("interprojectdeps2");
  401. checkWasntFullBuild();
  402. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("interprojectdeps2","bin")));
  403. assertTrue("There should be state for project interprojectdeps1",ajs!=null);
  404. checkWasntFullBuild();
  405. assertTrue("Shouldn't be any structural changes but there were "+
  406. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  407. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  408. }
  409. /**
  410. * The C.java file modified in this test has an inner class - it has two ctors but
  411. * also a reference to C.this in it - which will give rise to an accessor being
  412. * created in C
  413. *
  414. */
  415. public void testStateManagement5() {
  416. File binDirForInterproject3 = new File(getFile("interprojectdeps3","bin"));
  417. initialiseProject("interprojectdeps3");
  418. build("interprojectdeps3"); // full build
  419. AjState ajs = IncrementalStateManager.findStateManagingOutputLocation(binDirForInterproject3);
  420. assertTrue("There should be state for project interprojectdeps3",ajs!=null);
  421. assertTrue("Should be no struc changes as its a full build: "+
  422. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  423. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  424. alter("interprojectdeps3","inc1"); // minor change to C.java
  425. build("interprojectdeps3");
  426. checkWasntFullBuild();
  427. ajs = IncrementalStateManager.findStateManagingOutputLocation(new File(getFile("interprojectdeps3","bin")));
  428. assertTrue("There should be state for project interprojectdeps1",ajs!=null);
  429. checkWasntFullBuild();
  430. assertTrue("Shouldn't be any structural changes but there were "+
  431. ajs.getNumberOfStructuralChangesSinceLastFullBuild(),
  432. ajs.getNumberOfStructuralChangesSinceLastFullBuild()==0);
  433. }
  434. /**
  435. * Now the most complex test. Create a dependancy between two projects. Building
  436. * one may affect whether the other does an incremental or full build. The
  437. * structural information recorded in the state object should be getting used
  438. * to control whether a full build is necessary...
  439. */
  440. public void testBuildingDependantProjects() {
  441. initialiseProject("P1");
  442. initialiseProject("P2");
  443. configureNewProjectDependency("P2","P1");
  444. build("P1");
  445. build("P2"); // now everything is consistent and compiled
  446. alter("P1","inc1"); // adds a second class
  447. build("P1");
  448. build("P2"); // although a second class was added - P2 can't be using it, so we don't full build here :)
  449. checkWasntFullBuild();
  450. alter("P1","inc3"); // structurally changes one of the classes
  451. build("P1");
  452. build("P2"); // build notices the structural change
  453. checkWasFullBuild();
  454. alter("P1","inc4");
  455. build("P1");
  456. build("P2"); // build sees a change but works out its not structural
  457. checkWasntFullBuild();
  458. }
  459. public void testPr85132() {
  460. initialiseProject("PR85132");
  461. build("PR85132");
  462. alter("PR85132","inc1");
  463. build("PR85132");
  464. }
  465. // parameterization of generic aspects
  466. public void testPr125405() {
  467. initialiseProject("PR125405");
  468. build("PR125405");
  469. checkCompileWeaveCount(1,1);
  470. alter("PR125405","inc1");
  471. build("PR125405");
  472. // "only abstract aspects can have type parameters"
  473. checkForError("only abstract aspects can have type parameters");
  474. alter("PR125405","inc2");
  475. build("PR125405");
  476. checkCompileWeaveCount(1,1);
  477. assertTrue("Should be no errors, but got "+MyTaskListManager.getErrorMessages(),MyTaskListManager.getErrorMessages().size()==0);
  478. }
  479. public void testPr128618() {
  480. initialiseProject("PR128618_1");
  481. initialiseProject("PR128618_2");
  482. configureNewProjectDependency("PR128618_2","PR128618_1");
  483. assertTrue("there should be no warning messages before we start",
  484. MyTaskListManager.getWarningMessages().isEmpty());
  485. build("PR128618_1");
  486. build("PR128618_2");
  487. List warnings = MyTaskListManager.getWarningMessages();
  488. assertTrue("Should be one warning, but there are #"+warnings.size(),warnings.size()==1);
  489. IMessage msg = (IMessage)(MyTaskListManager.getWarningMessages().get(0));
  490. assertEquals("warning should be against the FFDC.aj resource","FFDC.aj",msg.getSourceLocation().getSourceFile().getName());
  491. alter("PR128618_2","inc1");
  492. build("PR128618_2");
  493. checkWasntFullBuild();
  494. IMessage msg2 = (IMessage)(MyTaskListManager.getWarningMessages().get(0));
  495. assertEquals("warning should be against the FFDC.aj resource","FFDC.aj",msg2.getSourceLocation().getSourceFile().getName());
  496. assertFalse("a new warning message should have been generated", msg.equals(msg2));
  497. }
  498. public void testPr92837() {
  499. initialiseProject("PR92837");
  500. build("PR92837");
  501. alter("PR92837","inc1");
  502. build("PR92837");
  503. }
  504. public void testPr119570() {
  505. initialiseProject("PR119570");
  506. build("PR119570");
  507. assertTrue("Should be no errors, but got "+MyTaskListManager.getErrorMessages(),MyTaskListManager.getErrorMessages().size()==0);
  508. }
  509. public void testPr119570_2() {
  510. initialiseProject("PR119570_2");
  511. build("PR119570_2");
  512. List l = MyTaskListManager.getWarningMessages();
  513. assertTrue("Should be no warnings, but got "+l,l.size()==0);
  514. }
  515. // If you fiddle with the compiler options - you must manually reset the options at the end of the test
  516. public void testPr117209() {
  517. try {
  518. initialiseProject("pr117209");
  519. configureNonStandardCompileOptions("-proceedOnError");
  520. build("pr117209");
  521. checkCompileWeaveCount(6,6);
  522. } finally {
  523. MyBuildOptionsAdapter.reset();
  524. }
  525. }
  526. public void testPr114875() {
  527. initialiseProject("pr114875");
  528. build("pr114875");
  529. alter("pr114875","inc1");
  530. build("pr114875");
  531. checkWasFullBuild();
  532. alter("pr114875","inc2");
  533. build("pr114875");
  534. checkWasFullBuild(); // back to the source for an aspect change
  535. }
  536. public void testPr117882() {
  537. // AjdeInteractionTestbed.VERBOSE=true;
  538. // AjdeInteractionTestbed.configureBuildStructureModel(true);
  539. initialiseProject("PR117882");
  540. build("PR117882");
  541. checkWasFullBuild();
  542. alter("PR117882","inc1");
  543. build("PR117882");
  544. checkWasFullBuild(); // back to the source for an aspect
  545. // AjdeInteractionTestbed.VERBOSE=false;
  546. // AjdeInteractionTestbed.configureBuildStructureModel(false);
  547. }
  548. public void testPr117882_2() {
  549. // AjdeInteractionTestbed.VERBOSE=true;
  550. // AjdeInteractionTestbed.configureBuildStructureModel(true);
  551. initialiseProject("PR117882_2");
  552. build("PR117882_2");
  553. checkWasFullBuild();
  554. alter("PR117882_2","inc1");
  555. build("PR117882_2");
  556. checkWasFullBuild(); // back to the source...
  557. //checkCompileWeaveCount(1,4);
  558. //fullBuild("PR117882_2");
  559. //checkWasFullBuild();
  560. // AjdeInteractionTestbed.VERBOSE=false;
  561. // AjdeInteractionTestbed.configureBuildStructureModel(false);
  562. }
  563. public void testPr115251() {
  564. //AjdeInteractionTestbed.VERBOSE=true;
  565. initialiseProject("PR115251");
  566. build("PR115251");
  567. checkWasFullBuild();
  568. alter("PR115251","inc1");
  569. build("PR115251");
  570. checkWasFullBuild(); // back to the source
  571. }
  572. public void testPr157054() {
  573. configureBuildStructureModel(true);
  574. MyBuildOptionsAdapter.setNonStandardOptions("-showWeaveInfo");
  575. initialiseProject("PR157054");
  576. build("PR157054");
  577. checkWasFullBuild();
  578. List weaveMessages = MyTaskListManager.getWeavingMessages();
  579. assertTrue("Should be two weaving messages but there are "+weaveMessages.size(),weaveMessages.size()==2);
  580. alter("PR157054","inc1");
  581. build("PR157054");
  582. weaveMessages = MyTaskListManager.getWeavingMessages();
  583. assertTrue("Should be three weaving messages but there are "+weaveMessages.size(),weaveMessages.size()==3);
  584. checkWasntFullBuild();
  585. fullBuild("PR157054");
  586. weaveMessages = MyTaskListManager.getWeavingMessages();
  587. assertTrue("Should be three weaving messages but there are "+weaveMessages.size(),weaveMessages.size()==3);
  588. }
  589. /**
  590. * Checks we aren't leaking mungers across compiles (accumulating multiple instances of the same one that
  591. * all do the same thing). On the first compile the munger is added late on - so at the time we set
  592. * the count it is still zero. On the subsequent compiles we know about this extra one.
  593. */
  594. public void testPr141956_IncrementallyCompilingAtAj() {
  595. initialiseProject("PR141956");
  596. build("PR141956");
  597. assertTrue("Should be zero but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==0);
  598. alter("PR141956","inc1");
  599. build("PR141956");
  600. assertTrue("Should be two but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==2);
  601. alter("PR141956","inc1");
  602. build("PR141956");
  603. assertTrue("Should be two but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==2);
  604. alter("PR141956","inc1");
  605. build("PR141956");
  606. assertTrue("Should be two but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==2);
  607. alter("PR141956","inc1");
  608. build("PR141956");
  609. assertTrue("Should be two but reports "+EclipseFactory.debug_mungerCount,EclipseFactory.debug_mungerCount==2);
  610. }
  611. // public void testPr124399() {
  612. // AjdeInteractionTestbed.VERBOSE=true;
  613. // configureBuildStructureModel(true);
  614. // initialiseProject("PR124399");
  615. // build("PR124399");
  616. // checkWasFullBuild();
  617. // alter("PR124399","inc1");
  618. // build("PR124399");
  619. // checkWasntFullBuild();
  620. // }
  621. public void testPr121384() {
  622. // AjdeInteractionTestbed.VERBOSE=true;
  623. // AsmManager.setReporting("c:/foo.txt",true,true,true,false);
  624. MyBuildOptionsAdapter.setNonStandardOptions("-showWeaveInfo");
  625. configureBuildStructureModel(true);
  626. initialiseProject("pr121384");
  627. build("pr121384");
  628. checkWasFullBuild();
  629. alter("pr121384","inc1");
  630. build("pr121384");
  631. checkWasntFullBuild();
  632. }
  633. /* public void testPr111779() {
  634. super.VERBOSE=true;
  635. initialiseProject("PR111779");
  636. build("PR111779");
  637. alter("PR111779","inc1");
  638. build("PR111779");
  639. }
  640. */
  641. public void testPr93310_1() {
  642. initialiseProject("PR93310_1");
  643. build("PR93310_1");
  644. checkWasFullBuild();
  645. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR93310_1" + File.separatorChar + "src" + File.separatorChar + "pack" + File.separatorChar + "C2.java";
  646. (new File(fileC2)).delete();
  647. alter("PR93310_1","inc1");
  648. build("PR93310_1");
  649. checkWasFullBuild();
  650. int l = AjdeInteractionTestbed.MyStateListener.detectedDeletions.size();
  651. assertTrue("Expected one deleted file to be noticed, but detected: "+l,l==1);
  652. String name = (String)AjdeInteractionTestbed.MyStateListener.detectedDeletions.get(0);
  653. assertTrue("Should end with C2.java but is "+name,name.endsWith("C2.java"));
  654. }
  655. public void testPr93310_2() {
  656. initialiseProject("PR93310_2");
  657. build("PR93310_2");
  658. checkWasFullBuild();
  659. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR93310_2" + File.separatorChar + "src" + File.separatorChar + "pack" + File.separatorChar + "C2.java";
  660. (new File(fileC2)).delete();
  661. alter("PR93310_2","inc1");
  662. build("PR93310_2");
  663. checkWasFullBuild();
  664. int l = AjdeInteractionTestbed.MyStateListener.detectedDeletions.size();
  665. assertTrue("Expected one deleted file to be noticed, but detected: "+l,l==1);
  666. String name = (String)AjdeInteractionTestbed.MyStateListener.detectedDeletions.get(0);
  667. assertTrue("Should end with C2.java but is "+name,name.endsWith("C2.java"));
  668. }
  669. // Stage1: Compile two files, pack.A and pack.A1 - A1 sets a protected field in A.
  670. // Stage2: make the field private in class A > gives compile error
  671. // Stage3: Add a new aspect whilst there is a compile error !
  672. public void testPr113531() {
  673. initialiseProject("PR113531");
  674. build("PR113531");
  675. assertFalse("build should have compiled ok",
  676. MyTaskListManager.hasErrorMessages());
  677. alter("PR113531","inc1");
  678. build("PR113531");
  679. assertEquals("error message should be 'foo cannot be resolved' ",
  680. "foo cannot be resolved",
  681. ((IMessage)MyTaskListManager.getErrorMessages().get(0))
  682. .getMessage());
  683. alter("PR113531","inc2");
  684. build("PR113531");
  685. assertTrue("There should be no exceptions handled:\n"+MyErrorHandler.getErrorMessages(),
  686. MyErrorHandler.getErrorMessages().isEmpty());
  687. assertEquals("error message should be 'foo cannot be resolved' ",
  688. "foo cannot be resolved",
  689. ((IMessage)MyTaskListManager.getErrorMessages().get(0))
  690. .getMessage());
  691. }
  692. // Stage 1: Compile the 4 files, pack.A2 extends pack.A1 (aspects) where
  693. // A2 uses a protected field in A1 and pack.C2 extends pack.C1 (classes)
  694. // where C2 uses a protected field in C1
  695. // Stage 2: make the field private in class C1 ==> compile errors in C2
  696. // Stage 3: make the field private in aspect A1 whilst there's the compile
  697. // error.
  698. // There shouldn't be a BCExcpetion saying can't find delegate for pack.C2
  699. public void testPr119882() {
  700. initialiseProject("PR119882");
  701. build("PR119882");
  702. assertFalse("build should have compiled ok",MyTaskListManager.hasErrorMessages());
  703. alter("PR119882","inc1");
  704. build("PR119882");
  705. //fullBuild("PR119882");
  706. List errors = MyTaskListManager.getErrorMessages();
  707. assertTrue("Should be at least one error, but got none",errors.size()==1);
  708. assertEquals("error message should be 'i cannot be resolved' ",
  709. "i cannot be resolved",
  710. ((IMessage)errors.get(0))
  711. .getMessage());
  712. alter("PR119882","inc2");
  713. build("PR119882");
  714. assertTrue("There should be no exceptions handled:\n"+MyErrorHandler.getErrorMessages(),
  715. MyErrorHandler.getErrorMessages().isEmpty());
  716. assertEquals("error message should be 'i cannot be resolved' ",
  717. "i cannot be resolved",
  718. ((IMessage)errors.get(0))
  719. .getMessage());
  720. }
  721. public void testPr112736() {
  722. initialiseProject("PR112736");
  723. build("PR112736");
  724. checkWasFullBuild();
  725. String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR112736" + File.separatorChar + "src" + File.separatorChar + "pack" + File.separatorChar + "A.java";
  726. (new File(fileC2)).delete();
  727. alter("PR112736","inc1");
  728. build("PR112736");
  729. checkWasFullBuild();
  730. }
  731. /**
  732. * We have problems with multiple rewrites of a pointcut across incremental builds.
  733. */
  734. public void testPr113257() {
  735. initialiseProject("PR113257");
  736. build("PR113257");
  737. alter("PR113257","inc1");
  738. build("PR113257");
  739. checkWasFullBuild(); // back to the source
  740. alter("PR113257","inc1");
  741. build("PR113257");
  742. }
  743. public void testPr123612() {
  744. initialiseProject("PR123612");
  745. build("PR123612");
  746. alter("PR123612","inc1");
  747. build("PR123612");
  748. checkWasFullBuild(); // back to the source
  749. }
  750. //Bugzilla Bug 152257 - Incremental compiler doesn't handle exception declaration correctly
  751. public void testPr152257() {
  752. configureNonStandardCompileOptions("-XnoInline");
  753. initialiseProject("PR152257");
  754. build("PR152257");
  755. List errors = MyTaskListManager.getErrorMessages();
  756. assertTrue("Should be no warnings, but there are #"+errors.size(),errors.size()==0);
  757. checkWasFullBuild();
  758. alter("PR152257","inc1");
  759. build("PR152257");
  760. errors = MyTaskListManager.getErrorMessages();
  761. assertTrue("Should be no warnings, but there are #"+errors.size(),errors.size()==0);
  762. checkWasntFullBuild();
  763. }
  764. public void testPr128655() {
  765. configureNonStandardCompileOptions("-showWeaveInfo");
  766. initialiseProject("pr128655");
  767. build("pr128655");
  768. List firstBuildMessages = MyTaskListManager.getWeavingMessages();
  769. assertTrue("Should be at least one message about the dec @type, but there were none",firstBuildMessages.size()>0);
  770. alter("pr128655","inc1");
  771. build("pr128655");
  772. checkWasntFullBuild(); // back to the source
  773. List secondBuildMessages = MyTaskListManager.getWeavingMessages();
  774. // check they are the same
  775. for (int i = 0; i < firstBuildMessages.size(); i++) {
  776. IMessage m1 = (IMessage)firstBuildMessages.get(i);
  777. IMessage m2 = (IMessage)secondBuildMessages.get(i);
  778. if (!m1.toString().equals(m2.toString())) {
  779. System.err.println("Message during first build was: "+m1);
  780. System.err.println("Message during second build was: "+m1);
  781. fail("The two messages should be the same, but are not: \n"+m1+"!="+m2);
  782. }
  783. }
  784. }
  785. // Similar to above, but now the annotation is in the default package
  786. public void testPr128655_2() {
  787. configureNonStandardCompileOptions("-showWeaveInfo");
  788. initialiseProject("pr128655_2");
  789. build("pr128655_2");
  790. List firstBuildMessages = MyTaskListManager.getWeavingMessages();
  791. assertTrue("Should be at least one message about the dec @type, but there were none",firstBuildMessages.size()>0);
  792. alter("pr128655_2","inc1");
  793. build("pr128655_2");
  794. checkWasntFullBuild(); // back to the source
  795. List secondBuildMessages = MyTaskListManager.getWeavingMessages();
  796. // check they are the same
  797. for (int i = 0; i < firstBuildMessages.size(); i++) {
  798. IMessage m1 = (IMessage)firstBuildMessages.get(i);
  799. IMessage m2 = (IMessage)secondBuildMessages.get(i);
  800. if (!m1.toString().equals(m2.toString())) {
  801. System.err.println("Message during first build was: "+m1);
  802. System.err.println("Message during second build was: "+m1);
  803. fail("The two messages should be the same, but are not: \n"+m1+"!="+m2);
  804. }
  805. }
  806. }
  807. // test for comment #31 - NPE
  808. public void testPr129163() {
  809. configureBuildStructureModel(true);
  810. initialiseProject("PR129613");
  811. build("PR129613");
  812. alter("PR129613","inc1");
  813. build("PR129613");
  814. assertTrue("There should be no exceptions handled:\n"+MyErrorHandler.getErrorMessages(),
  815. MyErrorHandler.getErrorMessages().isEmpty());
  816. assertEquals("warning message should be 'no match for this type name: File [Xlint:invalidAbsoluteTypeName]' ",
  817. "no match for this type name: File [Xlint:invalidAbsoluteTypeName]",
  818. ((IMessage)MyTaskListManager.getWarningMessages().get(0))
  819. .getMessage());
  820. configureBuildStructureModel(false);
  821. }
  822. // test for comment #0 - adding a comment to a class file shouldn't
  823. // cause us to go back to source and recompile everything. To force this
  824. // to behave like AJDT we need to include the aspect in 'inc1' so that
  825. // when AjState looks at its timestamp it thinks the aspect has been modified.
  826. // The logic within CrosscuttingMembers should then work out correctly
  827. // that there haven't really been any changes within the aspect and so
  828. // we shouldn't go back to source.
  829. public void testPr129163_2() {
  830. // want to behave like AJDT
  831. configureBuildStructureModel(true);
  832. initialiseProject("pr129163_2");
  833. build("pr129163_2");
  834. checkWasFullBuild();
  835. alter("pr129163_2","inc1");
  836. build("pr129163_2");
  837. checkWasntFullBuild(); // shouldn't be a full build because the
  838. // aspect hasn't changed
  839. configureBuildStructureModel(false);
  840. }
  841. // test for comment #6 - simulates AJDT core builder test testBug99133a -
  842. // changing the contents of a method within a class shouldn't force a
  843. // full build of a dependant project. To force this to behave like AJDT
  844. // 'inc1' of the dependant project should just be a copy of 'base' so that
  845. // AjState thinks somethings changed within the dependant project and
  846. // we do a build. Similarly, 'inc1' of the project depended on should
  847. // include the aspect even though nothing's changed within it. This causes
  848. // AjState to think that the aspect has changed. Together its then up to
  849. // logic within CrosscuttingMembers and various equals methods to decide
  850. // correctly that we don't have to go back to source.
  851. public void testPr129163_3() {
  852. configureBuildStructureModel(true);
  853. initialiseProject("PR129163_4");
  854. build("PR129163_4");
  855. checkWasFullBuild(); // should be a full build because initializing project
  856. initialiseProject("PR129163_3");
  857. configureNewProjectDependency("PR129163_3","PR129163_4");
  858. build("PR129163_3");
  859. checkWasFullBuild(); // should be a full build because initializing project
  860. alter("PR129163_4","inc1");
  861. build("PR129163_4");
  862. checkWasntFullBuild(); // should be an incremental build because although
  863. // "inc1" includes the aspect A1.aj, it actually hasn't
  864. // changed so we shouldn't go back to source
  865. alter("PR129163_3","inc1");
  866. build("PR129163_3");
  867. checkWasntFullBuild(); // should be an incremental build because nothing has
  868. // changed within the class and no aspects have changed
  869. // within the running of the test
  870. configureBuildStructureModel(false);
  871. }
  872. public void testPr133117() {
  873. // System.gc();
  874. // System.exit();
  875. configureNonStandardCompileOptions("-Xlint:warning");
  876. initialiseProject("PR133117");
  877. build("PR133117");
  878. assertTrue("There should only be one xlint warning message reported:\n"
  879. +MyTaskListManager.getWarningMessages(),
  880. MyTaskListManager.getWarningMessages().size()==1);
  881. alter("PR133117","inc1");
  882. build("PR133117");
  883. List warnings = MyTaskListManager.getWarningMessages();
  884. List noGuardWarnings = new ArrayList();
  885. for (Iterator iter = warnings.iterator(); iter.hasNext();) {
  886. IMessage element = (IMessage) iter.next();
  887. if (element.getMessage().indexOf("Xlint:noGuardForLazyTjp") != -1) {
  888. noGuardWarnings.add(element);
  889. }
  890. }
  891. assertTrue("There should only be two Xlint:noGuardForLazyTjp warning message reported:\n"
  892. +noGuardWarnings,noGuardWarnings.size() == 2);
  893. }
  894. public void testPr131505() {
  895. configureNonStandardCompileOptions("-outxml");
  896. initialiseProject("PR131505");
  897. build("PR131505");
  898. checkWasFullBuild();
  899. String outputDir = getWorkingDir().getAbsolutePath() + File.separatorChar
  900. + "PR131505" + File.separatorChar + "bin";
  901. // aop.xml file shouldn't contain any aspects
  902. checkXMLAspectCount("PR131505","",0, outputDir);
  903. // add a new aspect A which should be included in the aop.xml file
  904. alter("PR131505","inc1");
  905. build("PR131505");
  906. checkWasFullBuild();
  907. checkXMLAspectCount("PR131505","",1, outputDir);
  908. checkXMLAspectCount("PR131505","A",1, outputDir);
  909. // make changes to the class file which shouldn't affect the contents
  910. // of the aop.xml file
  911. alter("PR131505","inc2");
  912. build("PR131505");
  913. checkWasntFullBuild();
  914. checkXMLAspectCount("PR131505","",1, outputDir);
  915. checkXMLAspectCount("PR131505","A",1, outputDir);
  916. // add another new aspect A1 which should also be included in the aop.xml file
  917. // ...there should be no duplicate entries in the file
  918. alter("PR131505","inc3");
  919. build("PR131505");
  920. checkWasFullBuild();
  921. checkXMLAspectCount("PR131505","",2, outputDir);
  922. checkXMLAspectCount("PR131505","A1",1, outputDir);
  923. checkXMLAspectCount("PR131505","A",1, outputDir);
  924. // delete aspect A1 which meanss that aop.xml file should only contain A
  925. File a1 = new File(getWorkingDir().getAbsolutePath()
  926. + File.separatorChar + "PR131505" + File.separatorChar + "A1.aj");
  927. a1.delete();
  928. build("PR131505");
  929. checkWasFullBuild();
  930. checkXMLAspectCount("PR131505","",1, outputDir);
  931. checkXMLAspectCount("PR131505","A1",0, outputDir);
  932. checkXMLAspectCount("PR131505","A",1, outputDir);
  933. // add another aspect called A which is in a different package, both A
  934. // and pkg.A should be included in the aop.xml file
  935. alter("PR131505","inc4");
  936. build("PR131505");
  937. checkWasFullBuild();
  938. checkXMLAspectCount("PR131505","",2, outputDir);
  939. checkXMLAspectCount("PR131505","A",1, outputDir);
  940. checkXMLAspectCount("PR131505","pkg.A",1, outputDir);
  941. }
  942. public void testPr136585() {
  943. initialiseProject("PR136585");
  944. build("PR136585");
  945. alter("PR136585","inc1");
  946. build("PR136585");
  947. assertTrue("There should be no errors reported:\n"+MyTaskListManager.getErrorMessages(),
  948. MyTaskListManager.getErrorMessages().isEmpty());
  949. }
  950. public void testPr133532() {
  951. initialiseProject("PR133532");
  952. build("PR133532");
  953. alter("PR133532","inc1");
  954. build("PR133532");
  955. alter("PR133532","inc2");
  956. build("PR133532");
  957. assertTrue("There should be no errors reported:\n"+MyTaskListManager.getErrorMessages(),
  958. MyTaskListManager.getErrorMessages().isEmpty());
  959. }
  960. public void testPr133532_2() {
  961. initialiseProject("pr133532_2");
  962. build("pr133532_2");
  963. alter("pr133532_2","inc2");
  964. build("pr133532_2");
  965. assertTrue("There should be no errors reported:\n"+MyTaskListManager.getErrorMessages(),
  966. MyTaskListManager.getErrorMessages().isEmpty());
  967. String decisions = AjdeInteractionTestbed.MyStateListener.getDecisions();
  968. String expect="Need to recompile 'A.aj'";
  969. assertTrue("Couldn't find build decision: '"+expect+"' in the list of decisions made:\n"+decisions,
  970. decisions.indexOf(expect)!=-1);
  971. }
  972. public void testPr133532_3() {
  973. initialiseProject("PR133532_3");
  974. build("PR133532_3");
  975. alter("PR133532_3","inc1");
  976. build("PR133532_3");
  977. assertTrue("There should be no errors reported:\n"+MyTaskListManager.getErrorMessages(),
  978. MyTaskListManager.getErrorMessages().isEmpty());
  979. }
  980. public void testPr134541() {
  981. initialiseProject("PR134541");
  982. build("PR134541");
  983. assertEquals("[Xlint:adviceDidNotMatch] should be associated with line 5",5,
  984. ((IMessage)MyTaskListManager.getWarningMessages().get(0)).getSourceLocation().getLine());
  985. alter("PR134541","inc1");
  986. build("PR134541");
  987. if (AsmManager.getDefault().getHandleProvider().dependsOnLocation())
  988. checkWasFullBuild(); // the line number has changed... but nothing structural about the code
  989. else
  990. checkWasntFullBuild(); // the line number has changed... but nothing structural about the code
  991. assertEquals("[Xlint:adviceDidNotMatch] should now be associated with line 7",7,
  992. ((IMessage)MyTaskListManager.getWarningMessages().get(0)).getSourceLocation().getLine());
  993. }
  994. public void testJDTLikeHandleProviderWithLstFile_pr141730() {
  995. IElementHandleProvider handleProvider = AsmManager.getDefault().getHandleProvider();
  996. AsmManager.getDefault().setHandleProvider(new JDTLikeHandleProvider());
  997. configureBuildStructureModel(true);
  998. try {
  999. // The JDTLike-handles should start with the name
  1000. // of the buildconfig file
  1001. initialiseProject("JDTLikeHandleProvider");
  1002. build("JDTLikeHandleProvider");
  1003. IHierarchy top = AsmManager.getDefault().getHierarchy();
  1004. IProgramElement pe = top.findElementForType("pkg","A");
  1005. String expectedHandle = "build<pkg*A.aj}A";
  1006. assertEquals("expected handle to be " + expectedHandle + ", but found "
  1007. + pe.getHandleIdentifier(),expectedHandle,pe.getHandleIdentifier());
  1008. } finally {
  1009. AsmManager.getDefault().setHandleProvider(handleProvider);
  1010. configureBuildStructureModel(false);
  1011. }
  1012. }
  1013. public void testMovingAdviceDoesntChangeHandles_pr141730() {
  1014. IElementHandleProvider handleProvider = AsmManager.getDefault().getHandleProvider();
  1015. AsmManager.getDefault().setHandleProvider(new JDTLikeHandleProvider());
  1016. configureBuildStructureModel(true);
  1017. try {
  1018. initialiseProject("JDTLikeHandleProvider");
  1019. build("JDTLikeHandleProvider");
  1020. checkWasFullBuild();
  1021. IHierarchy top = AsmManager.getDefault().getHierarchy();
  1022. IProgramElement pe = top.findElementForLabel(top.getRoot(),
  1023. IProgramElement.Kind.ADVICE,"before(): <anonymous pointcut>");
  1024. // add a line which shouldn't change the handle
  1025. alter("JDTLikeHandleProvider","inc1");
  1026. build("JDTLikeHandleProvider");
  1027. checkWasntFullBuild();
  1028. IHierarchy top2 = AsmManager.getDefault().getHierarchy();
  1029. IProgramElement pe2 = top.findElementForLabel(top2.getRoot(),
  1030. IProgramElement.Kind.ADVICE,"before(): <anonymous pointcut>");
  1031. assertEquals("expected advice to be on line " + pe.getSourceLocation().getLine() + 1
  1032. + " but was on " + pe2.getSourceLocation().getLine(),
  1033. pe.getSourceLocation().getLine()+1,pe2.getSourceLocation().getLine());
  1034. assertEquals("expected advice to have handle " + pe.getHandleIdentifier()
  1035. + " but found handle " + pe2.getHandleIdentifier(),
  1036. pe.getHandleIdentifier(),pe2.getHandleIdentifier());
  1037. } finally {
  1038. AsmManager.getDefault().setHandleProvider(handleProvider);
  1039. configureBuildStructureModel(false);
  1040. }
  1041. }
  1042. public void testSwappingAdviceAndHandles_pr141730() {
  1043. IElementHandleProvider handleProvider = AsmManager.getDefault().getHandleProvider();
  1044. AsmManager.getDefault().setHandleProvider(new JDTLikeHandleProvider());
  1045. configureBuildStructureModel(true);
  1046. try {
  1047. initialiseProject("JDTLikeHandleProvider");
  1048. build("JDTLikeHandleProvider");
  1049. IHierarchy top = AsmManager.getDefault().getHierarchy();
  1050. IProgramElement call = top.findElementForLabel(top.getRoot(),
  1051. IProgramElement.Kind.ADVICE, "after(): callPCD..");
  1052. IProgramElement exec = top.findElementForLabel(top.getRoot(),
  1053. IProgramElement.Kind.ADVICE, "after(): execPCD..");
  1054. // swap the two after advice statements over. This forces
  1055. // a full build which means 'after(): callPCD..' will now
  1056. // be the second after advice in the file and have the same
  1057. // handle as 'after(): execPCD..' originally did.
  1058. alter("JDTLikeHandleProvider","inc2");
  1059. build("JDTLikeHandleProvider");
  1060. checkWasFullBuild();
  1061. IHierarchy top2 = AsmManager.getDefault().getHierarchy();
  1062. IProgramElement newCall = top2.findElementForLabel(top2.getRoot(),
  1063. IProgramElement.Kind.ADVICE, "after(): callPCD..");
  1064. IProgramElement newExec = top2.findElementForLabel(top2.getRoot(),
  1065. IProgramElement.Kind.ADVICE, "after(): execPCD..");
  1066. assertEquals("after swapping places, expected 'after(): callPCD..' " +
  1067. "to be on line " + newExec.getSourceLocation().getLine() +
  1068. " but was on line " + call.getSourceLocation().getLine(),
  1069. newExec.getSourceLocation().getLine(),
  1070. call.getSourceLocation().getLine());
  1071. assertEquals("after swapping places, expected 'after(): callPCD..' " +
  1072. "to have handle " + exec.getHandleIdentifier() +
  1073. " (because was full build) but had " + newCall.getHandleIdentifier(),
  1074. exec.getHandleIdentifier(), newCall.getHandleIdentifier());
  1075. } finally {
  1076. AsmManager.getDefault().setHandleProvider(handleProvider);
  1077. configureBuildStructureModel(false);
  1078. }
  1079. }
  1080. public void testInitializerCountForJDTLikeHandleProvider_pr141730() {
  1081. IElementHandleProvider handleProvider = AsmManager.getDefault().getHandleProvider();
  1082. AsmManager.getDefault().setHandleProvider(new JDTLikeHandleProvider());
  1083. configureBuildStructureModel(true);
  1084. try {
  1085. initialiseProject("JDTLikeHandleProvider");
  1086. build("JDTLikeHandleProvider");
  1087. String expected = "build<pkg*A.aj[C|1";
  1088. IHierarchy top = AsmManager.getDefault().getHierarchy();
  1089. IProgramElement init = top.findElementForLabel(top.getRoot(),
  1090. IProgramElement.Kind.INITIALIZER, "...");
  1091. assertEquals("expected initializers handle to be " + expected + "," +
  1092. " but found " + init.getHandleIdentifier(true),
  1093. expected,init.getHandleIdentifier(true));
  1094. alter("JDTLikeHandleProvider","inc2");
  1095. build("JDTLikeHandleProvider");
  1096. checkWasFullBuild();
  1097. IHierarchy top2 = AsmManager.getDefault().getHierarchy();
  1098. IProgramElement init2 = top2.findElementForLabel(top2.getRoot(),
  1099. IProgramElement.Kind.INITIALIZER, "...");
  1100. assertEquals("expected initializers handle to still be " + expected + "," +
  1101. " but found " + init2.getHandleIdentifier(true),
  1102. expected,init2.getHandleIdentifier(true));
  1103. } finally {
  1104. AsmManager.getDefault().setHandleProvider(handleProvider);
  1105. configureBuildStructureModel(false);
  1106. }
  1107. }
  1108. // 134471 related tests perform incremental compilation and verify features of the structure model post compile
  1109. public void testPr134471_IncrementalCompilationAndModelUpdates() {
  1110. try {
  1111. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=false;
  1112. configureBuildStructureModel(true);
  1113. configureNonStandardCompileOptions("-showWeaveInfo -emacssym");
  1114. // Step1. Build the code, simple advice from aspect A onto class C
  1115. initialiseProject("PR134471");
  1116. build("PR134471");
  1117. // Step2. Quick check that the advice points to something...
  1118. IProgramElement nodeForTypeA = checkForNode("pkg","A",true);
  1119. IProgramElement nodeForAdvice = findAdvice(nodeForTypeA);
  1120. List relatedElements = getRelatedElements(nodeForAdvice,1);
  1121. // Step3. Check the advice applying at the first 'code' join point in pkg.C is from aspect pkg.A, line 7
  1122. IProgramElement programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true)));
  1123. int line = programElement.getSourceLocation().getLine();
  1124. assertTrue("advice should be at line 7 - but is at line "+line,line==7);
  1125. // Step4. Simulate the aspect being saved but with no change at all in it
  1126. alter("PR134471","inc1");
  1127. build("PR134471");
  1128. // Step5. Quick check that the advice points to something...
  1129. nodeForTypeA = checkForNode("pkg","A",true);
  1130. nodeForAdvice = findAdvice(nodeForTypeA);
  1131. relatedElements = getRelatedElements(nodeForAdvice,1);
  1132. // Step6. Check the advice applying at the first 'code' join point in pkg.C is from aspect pkg.A, line 7
  1133. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true)));
  1134. line = programElement.getSourceLocation().getLine();
  1135. assertTrue("advice should be at line 7 - but is at line "+line,line==7);
  1136. } finally {
  1137. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=true;
  1138. }
  1139. }
  1140. // now the advice moves down a few lines - hopefully the model will notice... see discussion in 134471
  1141. public void testPr134471_MovingAdvice() {
  1142. configureBuildStructureModel(true);
  1143. configureNonStandardCompileOptions("-showWeaveInfo -emacssym");
  1144. // Step1. build the project
  1145. initialiseProject("PR134471_2");
  1146. build("PR134471_2");
  1147. // Step2. confirm advice is from correct location
  1148. IProgramElement programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true)));
  1149. int line = programElement.getSourceLocation().getLine();
  1150. assertTrue("advice should be at line 7 - but is at line "+line,line==7);
  1151. // Step3. No structural change to the aspect but the advice has moved down a few lines... (change in source location)
  1152. alter("PR134471_2","inc1");
  1153. build("PR134471_2");
  1154. if (AsmManager.getDefault().getHandleProvider().dependsOnLocation())
  1155. checkWasFullBuild(); // the line number has changed... but nothing structural about the code
  1156. else
  1157. checkWasntFullBuild(); // the line number has changed... but nothing structural about the code
  1158. //checkWasFullBuild(); // this is true whilst we consider sourcelocation in the type/shadow munger equals() method - have to until the handles are independent of location
  1159. // Step4. Check we have correctly realised the advice moved to line 11
  1160. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true)));
  1161. line = programElement.getSourceLocation().getLine();
  1162. assertTrue("advice should be at line 11 - but is at line "+line,line==11);
  1163. }
  1164. public void testAddingAndRemovingDecwWithStructureModel() {
  1165. configureBuildStructureModel(true);
  1166. initialiseProject("P3");
  1167. build("P3");
  1168. alter("P3","inc1");
  1169. build("P3");
  1170. assertTrue("There should be no exceptions handled:\n"+MyErrorHandler.getErrorMessages(),
  1171. MyErrorHandler.getErrorMessages().isEmpty());
  1172. alter("P3","inc2");
  1173. build("P3");
  1174. assertTrue("There should be no exceptions handled:\n"+MyErrorHandler.getErrorMessages(),
  1175. MyErrorHandler.getErrorMessages().isEmpty());
  1176. configureBuildStructureModel(false);
  1177. }
  1178. // same as first test with an extra stage that asks for C to be recompiled, it should still be advised...
  1179. public void testPr134471_IncrementallyRecompilingTheAffectedClass() {
  1180. try {
  1181. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=false;
  1182. configureBuildStructureModel(true);
  1183. configureNonStandardCompileOptions("-showWeaveInfo -emacssym");
  1184. // Step1. build the project
  1185. initialiseProject("PR134471");
  1186. build("PR134471");
  1187. // Step2. confirm advice is from correct location
  1188. IProgramElement programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true)));
  1189. int line = programElement.getSourceLocation().getLine();
  1190. assertTrue("advice should be at line 7 - but is at line "+line,line==7);
  1191. // Step3. No change to the aspect at all
  1192. alter("PR134471","inc1");
  1193. build("PR134471");
  1194. // Step4. Quick check that the advice points to something...
  1195. IProgramElement nodeForTypeA = checkForNode("pkg","A",true);
  1196. IProgramElement nodeForAdvice = findAdvice(nodeForTypeA);
  1197. List relatedElements = getRelatedElements(nodeForAdvice,1);
  1198. // Step5. No change to the file C but it should still be advised afterwards
  1199. alter("PR134471","inc2");
  1200. build("PR134471");
  1201. checkWasntFullBuild();
  1202. // Step6. confirm advice is from correct location
  1203. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true)));
  1204. line = programElement.getSourceLocation().getLine();
  1205. assertTrue("advice should be at line 7 - but is at line "+line,line==7);
  1206. } finally {
  1207. // see pr148027 AsmHierarchyBuilder.shouldAddUsesPointcut=true;
  1208. }
  1209. }
  1210. // similar to previous test but with 'declare warning' as well as advice
  1211. public void testPr134471_IncrementallyRecompilingAspectContainingDeclare() {
  1212. configureBuildStructureModel(true);
  1213. configureNonStandardCompileOptions("-showWeaveInfo -emacssym");
  1214. // Step1. build the project
  1215. initialiseProject("PR134471_3");
  1216. build("PR134471_3");
  1217. checkWasFullBuild();
  1218. // Step2. confirm declare warning is from correct location, decw matches line 7 in pkg.C
  1219. IProgramElement programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),7));
  1220. int line = programElement.getSourceLocation().getLine();
  1221. assertTrue("declare warning should be at line 10 - but is at line "+line,line==10);
  1222. // Step3. confirm advice is from correct location, advice matches line 6 in pkg.C
  1223. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),6));
  1224. line = programElement.getSourceLocation().getLine();
  1225. assertTrue("advice should be at line 7 - but is at line "+line,line==7);
  1226. // Step4. Move declare warning in the aspect
  1227. alter("PR134471_3","inc1");
  1228. build("PR134471_3");
  1229. if (AsmManager.getDefault().getHandleProvider().dependsOnLocation())
  1230. checkWasFullBuild(); // the line number has changed... but nothing structural about the code
  1231. else
  1232. checkWasntFullBuild(); // the line number has changed... but nothing structural about the code
  1233. //checkWasFullBuild();
  1234. // Step5. confirm declare warning is from correct location, decw (now at line 12) in pkg.A matches line 7 in pkg.C
  1235. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),7));
  1236. line = programElement.getSourceLocation().getLine();
  1237. assertTrue("declare warning should be at line 12 - but is at line "+line,line==12);
  1238. // Step6. Now just simulate 'resave' of the aspect, nothing has changed
  1239. alter("PR134471_3","inc2");
  1240. build("PR134471_3");
  1241. checkWasntFullBuild();
  1242. // Step7. confirm declare warning is from correct location, decw (now at line 12) in pkg.A matches line 7 in pkg.C
  1243. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),7));
  1244. line = programElement.getSourceLocation().getLine();
  1245. assertTrue("declare warning should be at line 12 - but is at line "+line,line==12);
  1246. configureBuildStructureModel(false);
  1247. }
  1248. // similar to previous test but with 'declare warning' as well as advice
  1249. public void testPr134471_IncrementallyRecompilingTheClassAffectedByDeclare() {
  1250. configureBuildStructureModel(true);
  1251. configureNonStandardCompileOptions("-showWeaveInfo -emacssym");
  1252. // Step1. build the project
  1253. initialiseProject("PR134471_3");
  1254. build("PR134471_3");
  1255. checkWasFullBuild();
  1256. // Step2. confirm declare warning is from correct location, decw matches line 7 in pkg.C
  1257. IProgramElement programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),7));
  1258. int line = programElement.getSourceLocation().getLine();
  1259. assertTrue("declare warning should be at line 10 - but is at line "+line,line==10);
  1260. // Step3. confirm advice is from correct location, advice matches line 6 in pkg.C
  1261. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),6));
  1262. line = programElement.getSourceLocation().getLine();
  1263. assertTrue("advice should be at line 7 - but is at line "+line,line==7);
  1264. // Step4. Move declare warning in the aspect
  1265. alter("PR134471_3","inc1");
  1266. build("PR134471_3");
  1267. if (AsmManager.getDefault().getHandleProvider().dependsOnLocation())
  1268. checkWasFullBuild(); // the line number has changed... but nothing structural about the code
  1269. else
  1270. checkWasntFullBuild(); // the line number has changed... but nothing structural about the code
  1271. //checkWasFullBuild();
  1272. // Step5. confirm declare warning is from correct location, decw (now at line 12) in pkg.A matches line 7 in pkg.C
  1273. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),7));
  1274. line = programElement.getSourceLocation().getLine();
  1275. assertTrue("declare warning should be at line 12 - but is at line "+line,line==12);
  1276. // Step6. Now just simulate 'resave' of the aspect, nothing has changed
  1277. alter("PR134471_3","inc2");
  1278. build("PR134471_3");
  1279. checkWasntFullBuild();
  1280. // Step7. confirm declare warning is from correct location, decw (now at line 12) in pkg.A matches line 7 in pkg.C
  1281. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),7));
  1282. line = programElement.getSourceLocation().getLine();
  1283. assertTrue("declare warning should be at line 12 - but is at line "+line,line==12);
  1284. // Step8. Now just simulate resave of the pkg.C type - no change at all... are relationships gonna be repaired OK?
  1285. alter("PR134471_3","inc3");
  1286. build("PR134471_3");
  1287. checkWasntFullBuild();
  1288. // Step9. confirm declare warning is from correct location, decw (now at line 12) in pkg.A matches line 7 in pkg.C
  1289. programElement = getFirstRelatedElement(findCode(checkForNode("pkg","C",true),7));
  1290. line = programElement.getSourceLocation().getLine();
  1291. assertTrue("declare warning should be at line 12 - but is at line "+line,line==12);
  1292. configureBuildStructureModel(false);
  1293. }
  1294. public void testDontLoseXlintWarnings_pr141556() {
  1295. configureNonStandardCompileOptions("-Xlint:warning");
  1296. initialiseProject("PR141556");
  1297. build("PR141556");
  1298. checkWasFullBuild();
  1299. String warningMessage = "can not build thisJoinPoint " +
  1300. "lazily for this advice since it has no suitable guard " +
  1301. "[Xlint:noGuardForLazyTjp]";
  1302. assertEquals("warning message should be '" + warningMessage + "'",
  1303. warningMessage,
  1304. ((IMessage)MyTaskListManager.getWarningMessages().get(0))
  1305. .getMessage());
  1306. // add a space to the Aspect but dont do a build
  1307. alter("PR141556","inc1");
  1308. // remove the space so that the Aspect is exactly as it was
  1309. alter("PR141556","inc2");
  1310. // build the project and we should not have lost the xlint warning
  1311. build("PR141556");
  1312. checkWasntFullBuild();
  1313. assertTrue("there should still be a warning message ",
  1314. !MyTaskListManager.getWarningMessages().isEmpty());
  1315. assertEquals("warning message should be '" + warningMessage + "'",
  1316. warningMessage,
  1317. ((IMessage)MyTaskListManager.getWarningMessages().get(0))
  1318. .getMessage());
  1319. }
  1320. public void testLintMessage_pr141564() {
  1321. configureNonStandardCompileOptions("-Xlint:warning");
  1322. initialiseProject("PR141556");
  1323. build("PR141556");
  1324. IMessageHandler handler = AjdeManager.getMessageHandler();
  1325. // the handler used to be an IMessageHolder (extended MessageHandler)
  1326. // which stored the messages, consequently we checked that none
  1327. // were being stored. Since we no longer stored any messages (fix
  1328. // for bug 141564) it was unnecessary to be an IMessageHolder as all the
  1329. // IMessageHolder methods in MessageHander used the list of stored
  1330. // messages. Therefore, rather than checking that the list of messages
  1331. // is empty we can check that we're an IMessageHandler but not an
  1332. // IMessageHolder.
  1333. assertFalse("expected the handler not to be an IMessageHolder but was ",
  1334. handler instanceof IMessageHolder);
  1335. List tasklistMessages = MyTaskListManager.getWarningMessages();
  1336. assertTrue("Should be one message but found "+tasklistMessages.size(),tasklistMessages.size()==1);
  1337. IMessage msg = (IMessage)tasklistMessages.get(0);
  1338. assertTrue("expected message to be a LintMessage but wasn't",
  1339. msg instanceof LintMessage);
  1340. assertTrue("expected message to be noGuardForLazyTjp xlint message but" +
  1341. " instead was " + ((LintMessage)msg).getKind().toString(),
  1342. ((LintMessage)msg).getLintKind().equals("noGuardForLazyTjp"));
  1343. assertTrue("expected message to be against file in project 'PR141556' but wasn't",
  1344. msg.getSourceLocation().getSourceFile().getAbsolutePath().indexOf("PR141556") != -1);
  1345. }
  1346. public void testAdviceDidNotMatch_pr152589() {
  1347. initialiseProject("PR152589");
  1348. build("PR152589");
  1349. List warnings = MyTaskListManager.getWarningMessages();
  1350. assertTrue("There should be no warnings:\n"+warnings,
  1351. warnings.isEmpty());
  1352. alter("PR152589","inc1");
  1353. build("PR152589");
  1354. if (AsmManager.getDefault().getHandleProvider().dependsOnLocation())
  1355. checkWasFullBuild(); // the line number has changed... but nothing structural about the code
  1356. else
  1357. checkWasntFullBuild(); // the line number has changed... but nothing structural about the code
  1358. // checkWasFullBuild();
  1359. warnings = MyTaskListManager.getWarningMessages();
  1360. assertTrue("There should be no warnings after adding a whitespace:\n"
  1361. +warnings,warnings.isEmpty());
  1362. }
  1363. // see comment #11 of bug 154054
  1364. public void testNoFullBuildOnChangeInSysOutInAdviceBody_pr154054() {
  1365. initialiseProject("PR154054");
  1366. build("PR154054");
  1367. alter("PR154054","inc1");
  1368. build("PR154054");
  1369. checkWasntFullBuild();
  1370. }
  1371. // change exception type in around advice, does it notice?
  1372. public void testShouldFullBuildOnExceptionChange_pr154054() {
  1373. initialiseProject("PR154054_2");
  1374. build("PR154054_2");
  1375. alter("PR154054_2","inc1");
  1376. build("PR154054_2");
  1377. checkWasFullBuild();
  1378. }
  1379. public void testPR158573() {
  1380. IElementHandleProvider handleProvider = AsmManager.getDefault().getHandleProvider();
  1381. AsmManager.getDefault().setHandleProvider(new JDTLikeHandleProvider());
  1382. initialiseProject("PR158573");
  1383. build("PR158573");
  1384. List warnings = MyTaskListManager.getWarningMessages();
  1385. assertTrue("There should be no warnings:\n"+warnings,warnings.isEmpty());
  1386. alter("PR158573","inc1");
  1387. build("PR158573");
  1388. checkWasntFullBuild();
  1389. warnings = MyTaskListManager.getWarningMessages();
  1390. assertTrue("There should be no warnings after changing the value of a " +
  1391. "variable:\n"+warnings,warnings.isEmpty());
  1392. AsmManager.getDefault().setHandleProvider(handleProvider);
  1393. }
  1394. /**
  1395. * If the user has specified that they want Java 6 compliance
  1396. * and kept the default classfile and source file level settings
  1397. * (also 6.0) then expect an error saying that we don't support
  1398. * java 6.
  1399. */
  1400. public void testPR164384_1() {
  1401. Hashtable javaOptions = new Hashtable();
  1402. javaOptions.put("org.eclipse.jdt.core.compiler.compliance","1.6");
  1403. javaOptions.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform","1.6");
  1404. javaOptions.put("org.eclipse.jdt.core.compiler.source","1.6");
  1405. MyBuildOptionsAdapter.setJavaOptionsMap(javaOptions);
  1406. initialiseProject("PR164384");
  1407. build("PR164384");
  1408. List errors = MyTaskListManager.getErrorMessages();
  1409. if (Ajde.getDefault().compilerIsJava6Compatible()) {
  1410. assertTrue("There should be no errros:\n"+errors,errors.isEmpty());
  1411. } else {
  1412. String expectedError = "Java 6.0 compliance level is unsupported";
  1413. String found = ((IMessage)errors.get(0)).getMessage();
  1414. assertEquals("Expected 'Java 6.0 compliance level is unsupported'" +
  1415. " error message but found " + found,expectedError,found);
  1416. // This is because the 'Java 6.0 compliance' error is an 'error'
  1417. // rather than an 'abort'. Aborts are really for compiler exceptions.
  1418. assertTrue("expected there to be more than the one compliance level" +
  1419. " error but only found that one",errors.size() > 1);
  1420. }
  1421. }
  1422. /**
  1423. * If the user has specified that they want Java 6 compliance
  1424. * and selected classfile and source file level settings to be
  1425. * 5.0 then expect an error saying that we don't support java 6.
  1426. */
  1427. public void testPR164384_2() {
  1428. Hashtable javaOptions = new Hashtable();
  1429. javaOptions.put("org.eclipse.jdt.core.compiler.compliance","1.6");
  1430. javaOptions.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform","1.5");
  1431. javaOptions.put("org.eclipse.jdt.core.compiler.source","1.5");
  1432. MyBuildOptionsAdapter.setJavaOptionsMap(javaOptions);
  1433. initialiseProject("PR164384");
  1434. build("PR164384");
  1435. List errors = MyTaskListManager.getErrorMessages();
  1436. if (Ajde.getDefault().compilerIsJava6Compatible()) {
  1437. assertTrue("There should be no errros:\n"+errors,errors.isEmpty());
  1438. } else {
  1439. String expectedError = "Java 6.0 compliance level is unsupported";
  1440. String found = ((IMessage)errors.get(0)).getMessage();
  1441. assertEquals("Expected 'Java 6.0 compliance level is unsupported'" +
  1442. " error message but found " + found,expectedError,found);
  1443. // This is because the 'Java 6.0 compliance' error is an 'error'
  1444. // rather than an 'abort'. Aborts are really for compiler exceptions.
  1445. assertTrue("expected there to be more than the one compliance level" +
  1446. " error but only found that one",errors.size() > 1);
  1447. }
  1448. }
  1449. /**
  1450. * If the user has specified that they want Java 6 compliance
  1451. * and set the classfile level to be 6.0 and source file level
  1452. * to be 5.0 then expect an error saying that we don't support
  1453. * java 6.
  1454. */
  1455. public void testPR164384_3() {
  1456. Hashtable javaOptions = new Hashtable();
  1457. javaOptions.put("org.eclipse.jdt.core.compiler.compliance","1.6");
  1458. javaOptions.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform","1.6");
  1459. javaOptions.put("org.eclipse.jdt.core.compiler.source","1.5");
  1460. MyBuildOptionsAdapter.setJavaOptionsMap(javaOptions);
  1461. initialiseProject("PR164384");
  1462. build("PR164384");
  1463. List errors = MyTaskListManager.getErrorMessages();
  1464. if (Ajde.getDefault().compilerIsJava6Compatible()) {
  1465. assertTrue("There should be no errros:\n"+errors,errors.isEmpty());
  1466. } else {
  1467. String expectedError = "Java 6.0 compliance level is unsupported";
  1468. String found = ((IMessage)errors.get(0)).getMessage();
  1469. assertEquals("Expected 'Java 6.0 compliance level is unsupported'" +
  1470. " error message but found " + found,expectedError,found);
  1471. // This is because the 'Java 6.0 compliance' error is an 'error'
  1472. // rather than an 'abort'. Aborts are really for compiler exceptions.
  1473. assertTrue("expected there to be more than the one compliance level" +
  1474. " error but only found that one",errors.size() > 1);
  1475. }
  1476. }
  1477. public void testPr168840() throws Exception {
  1478. initialiseProject("inpathTesting");
  1479. String inpathTestingDir = getWorkingDir() + File.separator + "inpathTesting";
  1480. String inpathDir = inpathTestingDir + File.separator + "injarBin" + File.separator + "pkg";
  1481. String expectedOutputDir = inpathTestingDir + File.separator + "bin";
  1482. // set up the inpath to have the directory on it's path
  1483. File f = new File(inpathDir);
  1484. Set s = new HashSet();
  1485. s.add(f);
  1486. configureInPath(s);
  1487. build("inpathTesting");
  1488. // the declare warning matches one place so expect one warning message
  1489. assertTrue("Expected there to be one warning message but found "
  1490. + MyTaskListManager.getWarningMessages().size() + ": " + MyTaskListManager.getWarningMessages(),
  1491. MyTaskListManager.getWarningMessages().size() == 1);
  1492. // copy over the updated version of the inpath class file
  1493. File from = new File(testdataSrcDir+File.separatorChar+"inpathTesting"
  1494. +File.separatorChar+"newInpathClass" + File.separatorChar + "InpathClass.class");
  1495. File destination = new File(inpathDir + File.separatorChar + "InpathClass.class");
  1496. FileUtil.copyFile(from,destination);
  1497. build("inpathTesting");
  1498. checkWasntFullBuild();
  1499. // the newly copied inpath class means the declare warning now matches two
  1500. // places, therefore expect two warning messages
  1501. assertTrue("Expected there to be two warning message but found "
  1502. + MyTaskListManager.getWarningMessages().size() + ": " + MyTaskListManager.getWarningMessages(),
  1503. MyTaskListManager.getWarningMessages().size() == 2);
  1504. }
  1505. // --- helper code ---
  1506. /**
  1507. * Retrieve program elements related to this one regardless of the relationship. A JUnit assertion is
  1508. * made that the number that the 'expected' number are found.
  1509. *
  1510. * @param programElement Program element whose related elements are to be found
  1511. * @param expected the number of expected related elements
  1512. */
  1513. private List/*IProgramElement*/ getRelatedElements(IProgramElement programElement,int expected) {
  1514. List relatedElements = getRelatedElements(programElement);
  1515. StringBuffer debugString = new StringBuffer();
  1516. if (relatedElements!=null) {
  1517. for (Iterator iter = relatedElements.iterator(); iter.hasNext();) {
  1518. String element = (String) iter.next();
  1519. debugString.append(AsmManager.getDefault().getHierarchy().findElementForHandle(element).toLabelString()).append("\n");
  1520. }
  1521. }
  1522. assertTrue("Should be "+expected+" element"+(expected>1?"s":"")+" related to this one '"+programElement+
  1523. "' but found :\n "+debugString,relatedElements!=null && relatedElements.size()==1);
  1524. return relatedElements;
  1525. }
  1526. private IProgramElement getFirstRelatedElement(IProgramElement programElement) {
  1527. List rels = getRelatedElements(programElement,1);
  1528. return AsmManager.getDefault().getHierarchy().findElementForHandle((String)rels.get(0));
  1529. }
  1530. private List/*IProgramElement*/ getRelatedElements(IProgramElement advice) {
  1531. List output = null;
  1532. IRelationshipMap map = AsmManager.getDefault().getRelationshipMap();
  1533. List/*IRelationship*/ rels = (List)map.get(advice);
  1534. if (rels==null) fail("Did not find any related elements!");
  1535. for (Iterator iter = rels.iterator(); iter.hasNext();) {
  1536. IRelationship element = (IRelationship) iter.next();
  1537. List/*String*/ targets = element.getTargets();
  1538. if (output==null) output = new ArrayList();
  1539. output.addAll(targets);
  1540. }
  1541. return output;
  1542. }
  1543. private IProgramElement findAdvice(IProgramElement ipe) {
  1544. return findAdvice(ipe,1);
  1545. }
  1546. private IProgramElement findAdvice(IProgramElement ipe,int whichOne) {
  1547. if (ipe.getKind()==IProgramElement.Kind.ADVICE) {
  1548. whichOne=whichOne-1;
  1549. if (whichOne==0) return ipe;
  1550. }
  1551. List kids = ipe.getChildren();
  1552. for (Iterator iter = kids.iterator(); iter.hasNext();) {
  1553. IProgramElement kid = (IProgramElement) iter.next();
  1554. IProgramElement found = findAdvice(kid,whichOne);
  1555. if (found!=null) return found;
  1556. }
  1557. return null;
  1558. }
  1559. /**
  1560. * Finds the first 'code' program element below the element supplied - will return null if there aren't any
  1561. */
  1562. private IProgramElement findCode(IProgramElement ipe) {
  1563. return findCode(ipe,-1);
  1564. }
  1565. /**
  1566. * Searches a hierarchy of program elements for a 'code' element at the specified line number, a line number
  1567. * of -1 means just return the first one you find
  1568. */
  1569. private IProgramElement findCode(IProgramElement ipe,int linenumber) {
  1570. if (ipe.getKind()==IProgramElement.Kind.CODE) {
  1571. if (linenumber==-1 || ipe.getSourceLocation().getLine()==linenumber) return ipe;
  1572. }
  1573. List kids = ipe.getChildren();
  1574. for (Iterator iter = kids.iterator(); iter.hasNext();) {
  1575. IProgramElement kid = (IProgramElement) iter.next();
  1576. IProgramElement found = findCode(kid,linenumber);
  1577. if (found!=null) return found;
  1578. }
  1579. return null;
  1580. }
  1581. // other possible tests:
  1582. // - memory usage (freemem calls?)
  1583. // - relationship map
  1584. // ---------------------------------------------------------------------------------------------------
  1585. private IProgramElement checkForNode(String packageName,String typeName,boolean shouldBeFound) {
  1586. IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForType(packageName,typeName);
  1587. if (shouldBeFound) {
  1588. if (ipe==null) printModel();
  1589. assertTrue("Should have been able to find '"+packageName+"."+typeName+"' in the asm",ipe!=null);
  1590. } else {
  1591. if (ipe!=null) printModel();
  1592. assertTrue("Should have NOT been able to find '"+packageName+"."+typeName+"' in the asm",ipe==null);
  1593. }
  1594. return ipe;
  1595. }
  1596. private void printModel() {
  1597. try {
  1598. AsmManager.dumptree(AsmManager.getDefault().getHierarchy().getRoot(),0);
  1599. } catch (IOException e) {
  1600. e.printStackTrace();
  1601. }
  1602. }
  1603. private static void log(String msg) {
  1604. if (VERBOSE) System.out.println(msg);
  1605. }
  1606. private File getProjectRelativePath(String p,String filename) {
  1607. File projDir = new File(getWorkingDir(),p);
  1608. return new File(projDir,filename);
  1609. }
  1610. private File getProjectOutputRelativePath(String p,String filename) {
  1611. File projDir = new File(getWorkingDir(),p);
  1612. return new File(projDir,"bin"+File.separator+filename);
  1613. }
  1614. private void assertNoErrors() {
  1615. assertTrue("Should be no errors, but got "+MyTaskListManager.getErrorMessages(),MyTaskListManager.getErrorMessages().size()==0);
  1616. }
  1617. }