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

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