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.

AjdeInteractionTestbed.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /********************************************************************
  2. * Copyright (c) 2005 Contributors.All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Andy Clement initial implementation
  10. * Helen Hawkins Converted to new interface (bug 148190)
  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.Iterator;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import junit.framework.TestCase;
  22. import org.aspectj.ajde.core.AjCompiler;
  23. import org.aspectj.ajde.core.IBuildMessageHandler;
  24. import org.aspectj.ajde.core.ICompilerConfiguration;
  25. import org.aspectj.ajde.core.IOutputLocationManager;
  26. import org.aspectj.ajdt.internal.core.builder.AbstractStateListener;
  27. import org.aspectj.ajdt.internal.core.builder.AjState;
  28. import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
  29. import org.aspectj.asm.AsmManager;
  30. import org.aspectj.bridge.IMessage;
  31. import org.aspectj.tools.ajc.Ajc;
  32. /**
  33. * This class uses Ajde in the same way that an IDE (e.g. AJDT) does.
  34. *
  35. * The build is driven through 'doBuild(projectName)' but the build can be configured by the methods beginning 'configure***'.
  36. * Information about what happened during a build is accessible through the get*, was*, print* public methods...
  37. *
  38. */
  39. public class AjdeInteractionTestbed extends TestCase {
  40. public static boolean VERBOSE = false; // do you want the gory details?
  41. public static String testdataSrcDir = "../tests/multiIncremental";
  42. protected static File sandboxDir;
  43. private static boolean buildModel;
  44. // Methods for configuring the build
  45. public void configureNewProjectDependency(String fromProjectName, String projectItDependsOn) {
  46. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + fromProjectName);
  47. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).addDependancy(projectItDependsOn);
  48. }
  49. public void addSourceFolderForSourceFile(String projectName, File f, String sourceFolder) {
  50. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  51. ((MultiProjTestOutputLocationManager) ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration())
  52. .getOutputLocationManager()).setSourceFolderFor(f, sourceFolder);
  53. }
  54. public void setNextChangeResponse(String projName, int flags) {
  55. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projName);
  56. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).changed = flags;
  57. }
  58. public void setProjectEncoding(String projName, String encoding) {
  59. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projName);
  60. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setProjectEncoding(encoding);
  61. }
  62. public void addProjectSourceFileChanged(String projectName, File changedFile) {
  63. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  64. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).addProjectSourceFileChanged(changedFile);
  65. }
  66. public void addXmlConfigFile(String projectName, String xmlfile) {
  67. List<String> l = new ArrayList<String>();
  68. l.add(xmlfile);
  69. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  70. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setProjectXmlConfigFiles(l);
  71. }
  72. public void addClasspathEntry(String projectName, File classpathEntry) {
  73. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  74. MultiProjTestCompilerConfiguration config = ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration());
  75. config.setClasspath(config.getClasspath() + File.pathSeparator + classpathEntry.toString());
  76. }
  77. public void addClasspathEntryChanged(String projectName, String changedDir) {
  78. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  79. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).addClasspathEntryChanged(changedDir);
  80. }
  81. public void configureNonStandardCompileOptions(String projectName, String options) {
  82. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  83. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setNonStandardOptions(options);
  84. }
  85. public void configureAspectPath(String projectName, Set aspectpath) {
  86. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  87. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setAspectPath(aspectpath);
  88. }
  89. public void configureProcessor(String projectName, String processor) {
  90. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  91. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setProcessor(processor);
  92. }
  93. public void configureProcessorPath(String projectName, String processorPath) {
  94. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  95. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setProcessorPath(processorPath);
  96. }
  97. public void configureAspectPath(String projectName, File aspectpath) {
  98. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  99. Set<File> s = new HashSet<File>();
  100. s.add(aspectpath);
  101. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setAspectPath(s);
  102. }
  103. public void configureResourceMap(String projectName, Map resourcesMap) {
  104. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  105. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setSourcePathResources(resourcesMap);
  106. }
  107. public void configureJavaOptionsMap(String projectName, Map options) {
  108. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  109. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setJavaOptions(options);
  110. }
  111. public static void configureInPath(String projectName, Set<File> inpath) {
  112. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  113. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setInpath(inpath);
  114. }
  115. public static void configureInPath(String projectName, File inpath) {
  116. Set<File> s = new HashSet<File>();
  117. s.add(inpath);
  118. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  119. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setInpath(s);
  120. }
  121. public static void configureOutputLocationManager(String projectName, IOutputLocationManager mgr) {
  122. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  123. ((MultiProjTestCompilerConfiguration) compiler.getCompilerConfiguration()).setOutputLocationManager(mgr);
  124. }
  125. public void configureShowWeaveInfoMessages(String projectName, boolean showWeaveInfo) {
  126. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  127. IBuildMessageHandler handler = compiler.getMessageHandler();
  128. if (showWeaveInfo) {
  129. handler.dontIgnore(IMessage.WEAVEINFO);
  130. } else {
  131. handler.ignore(IMessage.WEAVEINFO);
  132. }
  133. }
  134. // End of methods for configuring the build
  135. public AjCompiler getCompilerForProjectWithName(String projectName) {
  136. return CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  137. }
  138. protected File getWorkingDir() {
  139. return sandboxDir;
  140. }
  141. protected void setUp() throws Exception {
  142. super.setUp();
  143. // need this line because otherwise reset in previous tests
  144. AsmManager.attemptIncrementalModelRepairs = true;
  145. if (AjState.stateListener == null) {
  146. AjState.stateListener = MyStateListener.getInstance();
  147. }
  148. MyStateListener.reset();
  149. // Create a sandbox in which to work
  150. sandboxDir = Ajc.createEmptySandbox();
  151. }
  152. protected void tearDown() throws Exception {
  153. super.tearDown();
  154. AjState.stateListener = null;
  155. CompilerFactory.clearCompilerMap();
  156. IncrementalStateManager.clearIncrementalStates();
  157. }
  158. /** Drives a build */
  159. public boolean doBuild(String projectName) {
  160. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  161. resetCompilerRecords(compiler);
  162. addSourceFilesToBuild(projectName, compiler);
  163. // addXmlConfigFilesToBuild(projectName, compiler);
  164. pause(1000); // delay to allow previous runs build stamps to be OK
  165. lognoln("Building project '" + projectName + "'");
  166. compiler.build();
  167. log("");
  168. checkForErrors(compiler);
  169. log("Build finished, time taken = "
  170. + ((MultiProjTestBuildProgressMonitor) compiler.getBuildProgressMonitor()).getTimeTaken() + "ms");
  171. return true;
  172. }
  173. // public AsmManager getStructureModelFor(String projectName) {
  174. // AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  175. // returnc compiler.getStructureModelFor(projectName)
  176. // }
  177. /** Drives a full build **/
  178. public boolean doFullBuild(String projectName) {
  179. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  180. resetCompilerRecords(compiler);
  181. addSourceFilesToBuild(projectName, compiler);
  182. addXmlConfigFilesToBuild(projectName, compiler);
  183. pause(1000); // delay to allow previous runs build stamps to be OK
  184. lognoln("Building project '" + projectName + "'");
  185. compiler.buildFresh();
  186. log("");
  187. checkForErrors(compiler);
  188. log("Build finished, time taken = "
  189. + ((MultiProjTestBuildProgressMonitor) compiler.getBuildProgressMonitor()).getTimeTaken() + "ms");
  190. return true;
  191. }
  192. /**
  193. * Clears any maps associated with the compiler
  194. */
  195. private void resetCompilerRecords(AjCompiler compiler) {
  196. ((MultiProjTestBuildProgressMonitor) compiler.getBuildProgressMonitor()).reset();
  197. ((MultiProjTestMessageHandler) compiler.getMessageHandler()).reset();
  198. }
  199. /**
  200. * Find the source files associated with the given project and add them to the list of projectSourceFiles in the
  201. * MultiProjTestCompilerConfiguration to be used in the subsequent build
  202. */
  203. private void addSourceFilesToBuild(String pname, AjCompiler compiler) {
  204. File projectBase = new File(sandboxDir, pname);
  205. ICompilerConfiguration icc = compiler.getCompilerConfiguration();
  206. List currentFiles = icc.getProjectSourceFiles();
  207. List<String> filesForCompilation = new ArrayList<String>();
  208. collectUpFiles(projectBase, projectBase, filesForCompilation);
  209. boolean changed = false;
  210. for (int i = 0; i < filesForCompilation.size(); i++) {
  211. if (!currentFiles.contains(filesForCompilation.get(i))) {
  212. changed = true;
  213. }
  214. }
  215. for (int i = 0; i < currentFiles.size(); i++) {
  216. if (!filesForCompilation.contains(currentFiles.get(i))) {
  217. changed = true;
  218. }
  219. }
  220. if (changed) {
  221. ((MultiProjTestCompilerConfiguration) icc).setProjectSourceFiles(filesForCompilation);
  222. }
  223. }
  224. private void addXmlConfigFilesToBuild(String pname, AjCompiler compiler) {
  225. File projectBase = new File(sandboxDir, pname);
  226. ICompilerConfiguration icc = compiler.getCompilerConfiguration();
  227. List<String> currentXmlFiles = icc.getProjectXmlConfigFiles();
  228. List<String> collector = new ArrayList<String>();
  229. collectUpXmlFiles(projectBase, projectBase, collector);
  230. boolean changed = false;
  231. for (int i = 0; i < collector.size(); i++) {
  232. if (!currentXmlFiles.contains(collector.get(i))) {
  233. changed = true;
  234. }
  235. }
  236. for (int i = 0; i < currentXmlFiles.size(); i++) {
  237. if (!collector.contains(currentXmlFiles.get(i))) {
  238. changed = true;
  239. }
  240. }
  241. if (changed) {
  242. ((MultiProjTestCompilerConfiguration) icc).setProjectXmlConfigFiles(collector);
  243. }
  244. }
  245. private void collectUpFiles(File location, File base, List<String> collectionPoint) {
  246. String contents[] = location.list();
  247. if (contents == null) {
  248. return;
  249. }
  250. for (int i = 0; i < contents.length; i++) {
  251. String string = contents[i];
  252. File f = new File(location, string);
  253. if (f.isDirectory()) {
  254. collectUpFiles(f, base, collectionPoint);
  255. } else if (f.isFile() && (f.getName().endsWith(".aj") || f.getName().endsWith(".java"))) {
  256. String fileFound;
  257. try {
  258. fileFound = f.getCanonicalPath();
  259. collectionPoint.add(fileFound);
  260. // String toRemove = base.getCanonicalPath();
  261. // if (!fileFound.startsWith(toRemove)) throw new RuntimeException("eh? "+fileFound+" "+toRemove);
  262. // collectionPoint.add(fileFound.substring(toRemove.length()+1));//+1 captures extra separator
  263. } catch (IOException e) {
  264. e.printStackTrace();
  265. }
  266. }
  267. }
  268. }
  269. private void collectUpXmlFiles(File location, File base, List<String> collectionPoint) {
  270. String contents[] = location.list();
  271. if (contents == null) {
  272. return;
  273. }
  274. for (int i = 0; i < contents.length; i++) {
  275. String string = contents[i];
  276. File f = new File(location, string);
  277. if (f.isDirectory()) {
  278. collectUpXmlFiles(f, base, collectionPoint);
  279. } else if (f.isFile() && f.getName().endsWith(".xml")) {
  280. String fileFound;
  281. try {
  282. fileFound = f.getCanonicalPath();
  283. collectionPoint.add(fileFound);
  284. } catch (IOException e) {
  285. e.printStackTrace();
  286. }
  287. }
  288. }
  289. }
  290. /**
  291. * Make sure no errors have been recorded
  292. */
  293. private void checkForErrors(AjCompiler compiler) {
  294. MultiProjTestMessageHandler handler = (MultiProjTestMessageHandler) compiler.getMessageHandler();
  295. if (handler.hasErrorMessages()) {
  296. System.err.println("Build errors:");
  297. for (Iterator<IMessage> iter = handler.getErrorMessages().iterator(); iter.hasNext();) {
  298. IMessage element = iter.next();
  299. System.err.println(element);
  300. }
  301. System.err.println("---------");
  302. }
  303. }
  304. public List<IMessage> getErrorMessages(String projectName) {
  305. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  306. return ((MultiProjTestMessageHandler) compiler.getMessageHandler()).getErrorMessages();
  307. }
  308. public List<IMessage> getWarningMessages(String projectName) {
  309. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  310. return ((MultiProjTestMessageHandler) compiler.getMessageHandler()).getWarningMessages();
  311. }
  312. public List<IMessage> getWeavingMessages(String projectName) {
  313. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  314. return ((MultiProjTestMessageHandler) compiler.getMessageHandler()).getWeavingMessages();
  315. }
  316. public List<IMessage> getCompilerErrorMessages(String projectName) {
  317. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  318. return ((MultiProjTestMessageHandler) compiler.getMessageHandler()).getCompilerErrors();
  319. }
  320. public void checkForError(String projectName, String anError) {
  321. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  322. List<IMessage> messages = ((MultiProjTestMessageHandler) compiler.getMessageHandler()).getErrorMessages();
  323. for (Iterator<IMessage> iter = messages.iterator(); iter.hasNext();) {
  324. IMessage element = iter.next();
  325. if (element.getMessage().indexOf(anError) != -1) {
  326. return;
  327. }
  328. }
  329. fail("Didn't find the error message:\n'" + anError + "'.\nErrors that occurred:\n" + messages);
  330. }
  331. private void pause(int millis) {
  332. try {
  333. Thread.sleep(millis);
  334. } catch (InterruptedException ie) {
  335. }
  336. }
  337. // Methods for querying what happened during a build and accessing information
  338. // about the build:
  339. /**
  340. * Helper method for dumping info about which files were compiled and woven during the last build.
  341. */
  342. public String printCompiledAndWovenFiles(String projectName) {
  343. StringBuffer sb = new StringBuffer();
  344. if (getCompiledFiles(projectName).size() == 0 && getWovenClasses(projectName).size() == 0) {
  345. sb.append("No files were compiled or woven\n");
  346. }
  347. for (Iterator iter = getCompiledFiles(projectName).iterator(); iter.hasNext();) {
  348. Object element = iter.next();
  349. sb.append("compiled: " + element + "\n");
  350. }
  351. for (Iterator iter = getWovenClasses(projectName).iterator(); iter.hasNext();) {
  352. Object element = iter.next();
  353. sb.append("woven: " + element + "\n");
  354. }
  355. return sb.toString();
  356. }
  357. /**
  358. * Summary report on what happened in the most recent build
  359. */
  360. public void printBuildReport(String projectName) {
  361. System.out.println("\n====== BUILD REPORT (Project " + projectName + ") ===========");
  362. System.out.println("Build took: " + getTimeTakenForBuild(projectName) + "ms");
  363. List<String> compiled = getCompiledFiles(projectName);
  364. System.out.println("Compiled: " + compiled.size() + " files");
  365. for (Iterator<String> iter = compiled.iterator(); iter.hasNext();) {
  366. System.out.println(" :" + iter.next());
  367. }
  368. List<String> woven = getWovenClasses(projectName);
  369. System.out.println("Wove: " + woven.size() + " files");
  370. for (Iterator<String> iter = woven.iterator(); iter.hasNext();) {
  371. System.out.println(" :" + iter.next());
  372. }
  373. if (wasFullBuild()) {
  374. System.out.println("It was a batch (full) build");
  375. }
  376. System.out.println("=============================================");
  377. }
  378. /**
  379. * Check we compiled/wove the right number of files, passing '-1' indicates you don't care about that number.
  380. */
  381. public void checkCompileWeaveCount(String projectName, int expCompile, int expWoven) {
  382. if (expCompile != -1 && getCompiledFiles(projectName).size() != expCompile) {
  383. fail("Expected compilation of " + expCompile + " files but compiled " + getCompiledFiles(projectName).size() + "\n"
  384. + printCompiledAndWovenFiles(projectName));
  385. }
  386. if (expWoven != -1 && getWovenClasses(projectName).size() != expWoven) {
  387. fail("Expected weaving of " + expWoven + " files but wove " + getWovenClasses(projectName).size() + "\n"
  388. + printCompiledAndWovenFiles(projectName));
  389. }
  390. }
  391. public void checkWasntFullBuild() {
  392. assertTrue("Shouldn't have been a full (batch) build", !wasFullBuild());
  393. }
  394. public void checkWasFullBuild() {
  395. assertTrue("Should have been a full (batch) build", wasFullBuild());
  396. }
  397. public boolean wasFullBuild() {
  398. // alternatives: statelistener is debug interface, progressmonitor is new proper interface (see pr145689)
  399. // return MyBuildProgressMonitor.wasFullBuild();
  400. return MyStateListener.wasFullBuild();
  401. }
  402. public long getTimeTakenForBuild(String projectName) {
  403. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  404. return ((MultiProjTestBuildProgressMonitor) compiler.getBuildProgressMonitor()).getTimeTaken();
  405. }
  406. public List<String> getCompiledFiles(String projectName) {
  407. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  408. return ((MultiProjTestBuildProgressMonitor) compiler.getBuildProgressMonitor()).getCompiledFiles();
  409. }
  410. public AsmManager getModelFor(String projectName) {
  411. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  412. return compiler.getModel();
  413. }
  414. public List<String> getWovenClasses(String projectName) {
  415. AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName);
  416. return ((MultiProjTestBuildProgressMonitor) compiler.getBuildProgressMonitor()).getWovenClasses();
  417. }
  418. // Infrastructure below here
  419. private static void log(String msg) {
  420. if (VERBOSE) {
  421. System.out.println(msg);
  422. }
  423. }
  424. private static void lognoln(String msg) {
  425. if (VERBOSE) {
  426. System.out.print(msg);
  427. }
  428. }
  429. /** Return the *full* path to this file which is taken relative to the project dir */
  430. protected static String getFile(String projectName, String path) {
  431. return new File(sandboxDir, projectName + File.separatorChar + path).getAbsolutePath();
  432. }
  433. static class MyStateListener extends AbstractStateListener {
  434. private static MyStateListener _instance = new MyStateListener();
  435. private MyStateListener() {
  436. reset();
  437. }
  438. public static MyStateListener getInstance() {
  439. return _instance;
  440. }
  441. public static boolean informedAboutKindOfBuild;
  442. public static boolean fullBuildOccurred;
  443. public static List<String> detectedDeletions = new ArrayList<String>();
  444. public static StringBuffer decisions = new StringBuffer();
  445. public static void reset() {
  446. informedAboutKindOfBuild = false;
  447. decisions = new StringBuffer();
  448. fullBuildOccurred = false;
  449. if (detectedDeletions != null) {
  450. detectedDeletions.clear();
  451. }
  452. }
  453. public boolean pathChange = false;
  454. public void pathChangeDetected() {
  455. pathChange = true;
  456. }
  457. public void aboutToCompareClasspaths(List oldClasspath, List newClasspath) {
  458. }
  459. public void detectedClassChangeInThisDir(File f) {
  460. recordDecision("Detected class change in this directory: " + f.toString());
  461. }
  462. public void detectedAspectDeleted(File f) {
  463. detectedDeletions.add(f.toString());
  464. }
  465. public void buildSuccessful(boolean wasFullBuild) {
  466. informedAboutKindOfBuild = true;
  467. fullBuildOccurred = wasFullBuild;
  468. }
  469. public static String getDecisions() {
  470. return decisions.toString();
  471. }
  472. public static boolean wasFullBuild() {
  473. if (!informedAboutKindOfBuild) {
  474. throw new RuntimeException("I never heard about what kind of build it was!!");
  475. }
  476. return fullBuildOccurred;
  477. }
  478. // not needed just yet...
  479. // public void recordInformation(String s) { decisions.append(s).append("\n");}
  480. public void recordDecision(String s) {
  481. decisions.append(s).append("\n");
  482. log(s);
  483. }
  484. };
  485. }