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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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.util.ArrayList;
  15. import java.util.Hashtable;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.Set;
  20. import junit.framework.TestCase;
  21. import org.aspectj.ajde.Ajde;
  22. import org.aspectj.ajde.BuildOptionsAdapter;
  23. import org.aspectj.ajde.BuildProgressMonitor;
  24. import org.aspectj.ajde.ErrorHandler;
  25. import org.aspectj.ajde.OutputLocationManager;
  26. import org.aspectj.ajde.ProjectPropertiesAdapter;
  27. import org.aspectj.ajde.TaskListManager;
  28. import org.aspectj.ajde.internal.AspectJBuildManager;
  29. import org.aspectj.ajdt.internal.core.builder.AbstractStateListener;
  30. import org.aspectj.ajdt.internal.core.builder.AjState;
  31. import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
  32. import org.aspectj.asm.AsmManager;
  33. import org.aspectj.bridge.IMessage;
  34. import org.aspectj.bridge.IMessageHandler;
  35. import org.aspectj.bridge.ISourceLocation;
  36. import org.aspectj.bridge.IMessage.Kind;
  37. import org.aspectj.tools.ajc.Ajc;
  38. /**
  39. * This class uses Ajde in the same way that an IDE (e.g. AJDT) does.
  40. *
  41. * The build is driven through 'build(projectName,configFile)' but the
  42. * build can be configured by the methods beginning 'configure***'.
  43. * Information about what happened during a build is accessible
  44. * through the get*, was*, print* public methods...
  45. *
  46. * There are many methods across the multiple listeners that communicate
  47. * info with Ajde - not all are implemented. Those that are are
  48. * task tagged DOESSOMETHING :)
  49. */
  50. public class AjdeInteractionTestbed extends TestCase {
  51. public static boolean VERBOSE = false; // do you want the gory details?
  52. public static String testdataSrcDir = "../tests/multiIncremental";
  53. protected static File sandboxDir;
  54. private static boolean buildModel;
  55. // Methods for configuring the build
  56. public static void configureBuildStructureModel(boolean b) { buildModel = b;}
  57. public static void configureNewProjectDependency(String fromProject, String projectItDependsOn) {
  58. MyProjectPropertiesAdapter.addDependancy(fromProject,projectItDependsOn);
  59. }
  60. public static void configureNonStandardCompileOptions(String options) {
  61. MyBuildOptionsAdapter.setNonStandardOptions(options);
  62. }
  63. public static void configureAspectPath(Set aspectpath) {
  64. MyProjectPropertiesAdapter.setAspectpath(aspectpath);
  65. }
  66. public static void configureOutputLocationManager(OutputLocationManager mgr) {
  67. MyProjectPropertiesAdapter.setOutputLocationManager(mgr);
  68. }
  69. public static void configureResourceMap(Map resourcesMap) {
  70. MyProjectPropertiesAdapter.setSourcePathResources(resourcesMap);
  71. }
  72. // End of methods for configuring the build
  73. protected File getWorkingDir() { return sandboxDir; }
  74. protected void setUp() throws Exception {
  75. super.setUp();
  76. if (AjState.stateListener==null) AjState.stateListener=MyStateListener.getInstance();
  77. MyStateListener.reset();
  78. MyBuildProgressMonitor.reset();
  79. MyTaskListManager.reset();
  80. MyProjectPropertiesAdapter.reset();
  81. // Create a sandbox in which to work
  82. sandboxDir = Ajc.createEmptySandbox();
  83. }
  84. protected void tearDown() throws Exception {
  85. super.tearDown();
  86. AjState.stateListener=null;
  87. }
  88. /** Drives a build */
  89. public boolean build(String projectName,String configFile) {
  90. return AjdeManager.build(projectName,configFile);
  91. }
  92. public boolean fullBuild(String projectName,String configFile) {
  93. return AjdeManager.fullBuild(projectName,configFile);
  94. }
  95. /** Looks after communicating with the singleton Ajde instance */
  96. public static class AjdeManager {
  97. static {
  98. Ajde.init(null,
  99. MyTaskListManager.getInstance(),
  100. MyBuildProgressMonitor.getInstance(),
  101. MyProjectPropertiesAdapter.getInstance(),
  102. MyBuildOptionsAdapter.getInstance(),
  103. null,null,
  104. MyErrorHandler.getInstance());
  105. MyStateListener sl = MyStateListener.getInstance();
  106. AjState.stateListener = sl;
  107. }
  108. /**
  109. * Builds a specified project using a specified config file. Subsequent
  110. * calls to build the same project should result in incremental builds.
  111. */
  112. private static boolean build(String projectName,String configFile) {
  113. pause(1000); // delay to allow previous runs build stamps to be OK
  114. lognoln("Building project '"+projectName+"'");
  115. // Ajde.getDefault().enableLogging(System.out);
  116. //Ajde.getDefault().getBuildManager().setReportInfoMessages(true);
  117. // Configure the necessary providers and listeners for this compile
  118. MyBuildProgressMonitor.reset();
  119. MyTaskListManager.reset();
  120. MyStateListener.reset();
  121. // MyBuildOptionsAdapter.reset(); needs manually resetting in a test
  122. MyProjectPropertiesAdapter.setActiveProject(projectName);
  123. AsmManager.attemptIncrementalModelRepairs=true;
  124. IncrementalStateManager.recordIncrementalStates=true;
  125. Ajde.getDefault().getBuildManager().setBuildModelMode(buildModel);
  126. // Do the compile
  127. Ajde.getDefault().getBuildManager().build(getFile(projectName,configFile));
  128. // Wait for it to complete
  129. while (!MyBuildProgressMonitor.hasFinished()) {
  130. lognoln(".");
  131. pause(100);
  132. }
  133. log("");
  134. // What happened?
  135. if (MyTaskListManager.hasErrorMessages()) {
  136. System.err.println("Build errors:");
  137. for (Iterator iter = MyTaskListManager.getErrorMessages().iterator(); iter.hasNext();) {
  138. IMessage element = (IMessage) iter.next();
  139. System.err.println(element);
  140. }
  141. System.err.println("---------");
  142. }
  143. log("Build finished, time taken = "+MyBuildProgressMonitor.getTimeTaken()+"ms");
  144. return true;
  145. }
  146. private static boolean fullBuild(String projectName,String configFile) {
  147. pause(1000); // delay to allow previous runs build stamps to be OK
  148. lognoln("Building project '"+projectName+"'");
  149. // Ajde.getDefault().enableLogging(System.out);
  150. //Ajde.getDefault().getBuildManager().setReportInfoMessages(true);
  151. // Configure the necessary providers and listeners for this compile
  152. MyBuildProgressMonitor.reset();
  153. MyTaskListManager.reset();
  154. MyStateListener.reset();
  155. MyProjectPropertiesAdapter.setActiveProject(projectName);
  156. //AsmManager.attemptIncrementalModelRepairs=true;
  157. //IncrementalStateManager.recordIncrementalStates=true;
  158. Ajde.getDefault().getBuildManager().setBuildModelMode(buildModel);
  159. // Do the compile
  160. Ajde.getDefault().getBuildManager().buildFresh(getFile(projectName,configFile));
  161. // Wait for it to complete
  162. while (!MyBuildProgressMonitor.hasFinished()) {
  163. lognoln(".");
  164. pause(100);
  165. }
  166. log("");
  167. // What happened?
  168. if (MyTaskListManager.hasErrorMessages()) {
  169. System.err.println("Build errors:");
  170. for (Iterator iter = MyTaskListManager.getErrorMessages().iterator(); iter.hasNext();) {
  171. IMessage element = (IMessage) iter.next();
  172. System.err.println(element);
  173. }
  174. System.err.println("---------");
  175. }
  176. log("Build finished, time taken = "+MyBuildProgressMonitor.getTimeTaken()+"ms");
  177. return true;
  178. }
  179. private static void pause(int millis) {
  180. try {
  181. Thread.sleep(millis);
  182. } catch (InterruptedException ie) {}
  183. }
  184. public static void setMessageHandler(IMessageHandler handler) {
  185. Ajde.getDefault().setMessageHandler(handler);
  186. }
  187. public static IMessageHandler getMessageHandler() {
  188. AspectJBuildManager buildManager = (AspectJBuildManager) Ajde.getDefault().getBuildManager();
  189. return buildManager.getCompilerAdapter().getMessageHandler();
  190. }
  191. // public static boolean lastCompileDefaultedToBatch() {
  192. // return MyTaskListManager.defaultedToBatch();
  193. // }
  194. }
  195. // Methods for querying what happened during a build and accessing information
  196. // about the build:
  197. /**
  198. * Helper method for dumping info about which files were compiled and
  199. * woven during the last build.
  200. */
  201. public String printCompiledAndWovenFiles() {
  202. StringBuffer sb = new StringBuffer();
  203. if (getCompiledFiles().size()==0 && getWovenClasses().size()==0)
  204. sb.append("No files were compiled or woven\n");
  205. for (Iterator iter = getCompiledFiles().iterator(); iter.hasNext();) {
  206. Object element = (Object) iter.next();
  207. sb.append("compiled: "+element+"\n");
  208. }
  209. for (Iterator iter = getWovenClasses().iterator(); iter.hasNext();) {
  210. Object element = (Object) iter.next();
  211. sb.append("woven: "+element+"\n");
  212. }
  213. return sb.toString();
  214. }
  215. /**
  216. * Summary report on what happened in the most recent build
  217. */
  218. public void printBuildReport() {
  219. System.out.println("\n============== BUILD REPORT =================");
  220. System.out.println("Build took: "+getTimeTakenForBuild()+"ms");
  221. List compiled=getCompiledFiles();
  222. System.out.println("Compiled: "+compiled.size()+" files");
  223. for (Iterator iter = compiled.iterator(); iter.hasNext();) {
  224. System.out.println(" :"+iter.next());
  225. }
  226. List woven=getWovenClasses();
  227. System.out.println("Wove: "+woven.size()+" files");
  228. for (Iterator iter = woven.iterator(); iter.hasNext();) {
  229. System.out.println(" :"+iter.next());
  230. }
  231. if (wasFullBuild()) System.out.println("It was a batch (full) build");
  232. System.out.println("=============================================");
  233. }
  234. public boolean wasFullBuild() {
  235. // alternatives: statelistener is debug interface, progressmonitor is new proper interface (see pr145689)
  236. // return MyBuildProgressMonitor.wasFullBuild();
  237. return MyStateListener.wasFullBuild();
  238. }
  239. public long getTimeTakenForBuild() {
  240. return MyBuildProgressMonitor.getTimeTaken();
  241. }
  242. public List getCompiledFiles() {
  243. return MyBuildProgressMonitor.getCompiledFiles();
  244. }
  245. public List getWovenClasses() {
  246. return MyBuildProgressMonitor.getWovenClasses();
  247. }
  248. // Infrastructure below here
  249. private static void log(String msg) {
  250. if (VERBOSE) System.out.println(msg);
  251. }
  252. private static void lognoln(String msg) {
  253. if (VERBOSE) System.out.print(msg);
  254. }
  255. /** Return the *full* path to this file which is taken relative to the project dir*/
  256. protected static String getFile(String projectName, String path) {
  257. return new File(sandboxDir,projectName+File.separatorChar + path).getAbsolutePath();
  258. }
  259. // Helper classes that communicate with Ajde
  260. static class MyErrorHandler implements ErrorHandler {
  261. static MyErrorHandler _instance = new MyErrorHandler();
  262. private List errorMessages = new ArrayList();
  263. private MyErrorHandler() {}
  264. public static ErrorHandler getInstance() {
  265. return _instance;
  266. }
  267. public void handleWarning(String message) {
  268. log("ErrorHandler.handleWarning("+message+")");
  269. }
  270. public void handleError(String message) {
  271. log("ErrorHandler.handleWarning("+message+")");
  272. errorMessages.add(message);
  273. }
  274. public void handleError(String message, Throwable t) {
  275. log("ErrorHandler.handleError("+message+","+t+")");
  276. if (VERBOSE) t.printStackTrace();
  277. errorMessages.add(message+","+t+")");
  278. }
  279. public static List/*String*/ getErrorMessages() {
  280. return _instance.errorMessages;
  281. }
  282. }
  283. // -----------------
  284. static class MyProjectPropertiesAdapter implements ProjectPropertiesAdapter {
  285. private final static boolean VERBOSE = false;
  286. static MyProjectPropertiesAdapter _instance = new MyProjectPropertiesAdapter();
  287. private MyProjectPropertiesAdapter() {}
  288. public static MyProjectPropertiesAdapter getInstance() {
  289. return _instance;
  290. }
  291. public static void reset() {
  292. _instance.aspectPath=null;
  293. _instance.sourcePathResources=null;
  294. }
  295. private String projectName = null;
  296. private String classPath = "";
  297. private Set aspectPath = null;
  298. private Map sourcePathResources = null;
  299. private OutputLocationManager outputLocationManager = null;
  300. public static void setActiveProject(String n) {
  301. _instance.projectName = n;
  302. }
  303. private static Hashtable dependants = new Hashtable();
  304. public static void addDependancy(String project, String projectItDependsOn) {
  305. List l = (List)dependants.get(project);
  306. if (l == null) {
  307. List ps = new ArrayList();
  308. ps.add(projectItDependsOn);
  309. dependants.put(project,ps);
  310. } else {
  311. l.add(projectItDependsOn);
  312. }
  313. }
  314. public static void setSourcePathResources(Map m) {
  315. _instance.sourcePathResources = m;
  316. }
  317. public void setClasspath(String path) {
  318. this.classPath = path;
  319. }
  320. public static void setAspectpath(Set path) {
  321. _instance.aspectPath = path;
  322. }
  323. // interface impl below
  324. // DOESSOMETHING
  325. public String getProjectName() {
  326. log("MyProjectProperties.getProjectName() [returning "+projectName+"]");
  327. return projectName;
  328. }
  329. // DOESSOMETHING
  330. public String getRootProjectDir() {
  331. String dir = testdataSrcDir+File.separatorChar+projectName;
  332. log("MyProjectProperties.getRootProjectDir() [returning "+dir+"]");
  333. return dir;
  334. }
  335. public List getBuildConfigFiles() {
  336. log("MyProjectProperties.getBuildConfigFiles()");
  337. return null;
  338. }
  339. public String getDefaultBuildConfigFile() {
  340. log("MyProjectProperties.getDefaultBuildConfigFile()");
  341. return null;
  342. }
  343. public String getLastActiveBuildConfigFile() {
  344. log("MyProjectProperties.getLastActiveBuildConfigFile()");
  345. return null;
  346. }
  347. public List getProjectSourceFiles() {
  348. log("MyProjectProperties.getProjectSourceFiles()");
  349. return null;
  350. }
  351. public String getProjectSourcePath() {
  352. log("MyProjectProperties.getProjectSourcePath()");
  353. return null;
  354. }
  355. // DOESSOMETHING
  356. public String getClasspath() {
  357. log("MyProjectProperties.getClasspath()");
  358. String cp =
  359. new File(testdataSrcDir) + File.pathSeparator +
  360. System.getProperty("sun.boot.class.path") +
  361. File.pathSeparator + "../runtime/bin" +
  362. File.pathSeparator + this.classPath +
  363. File.pathSeparator + System.getProperty("aspectjrt.path") +
  364. File.pathSeparator + "../lib/junit/junit.jar" +
  365. "c:/batik/batik-1.6/lib/batik-util.jar;"+
  366. "c:/batik/batik-1.6/lib/batik-awt-util.jar;"+
  367. "c:/batik/batik-1.6/lib/batik-dom.jar;"+
  368. "c:/batik/batik-1.6/lib/batik-svggen.jar;"+
  369. File.pathSeparator+".."+File.separator+"lib" + File.separator+"test"+File.separator+"aspectjrt.jar";
  370. // look at dependant projects
  371. List projects = (List)dependants.get(projectName);
  372. if (projects!=null) {
  373. for (Iterator iter = projects.iterator(); iter.hasNext();) {
  374. cp = getFile((String)iter.next(),"bin")+File.pathSeparator+cp;
  375. }
  376. }
  377. //System.err.println("For project "+projectName+" getClasspath() returning "+cp);
  378. return cp;
  379. }
  380. public String getOutputPath() {
  381. String dir = getFile(projectName,"bin");
  382. log("MyProjectProperties.getOutputPath() [returning "+dir+"]");
  383. return dir;
  384. }
  385. public static void setOutputLocationManager(OutputLocationManager mgr) {
  386. _instance.outputLocationManager = mgr;
  387. }
  388. public OutputLocationManager getOutputLocationManager() {
  389. return this.outputLocationManager;
  390. }
  391. public String getBootClasspath() {
  392. log("MyProjectProperties.getBootClasspath()");
  393. return null;
  394. }
  395. public String getClassToExecute() {
  396. log("MyProjectProperties.getClassToExecute()");
  397. return null;
  398. }
  399. public String getExecutionArgs() {
  400. log("MyProjectProperties.getExecutionArgs()");
  401. return null;
  402. }
  403. public String getVmArgs() {
  404. log("MyProjectProperties.getVmArgs()");
  405. return null;
  406. }
  407. public Set getInJars() {
  408. log("MyProjectProperties.getInJars()");
  409. return null;
  410. }
  411. public Set getInpath() {
  412. log("MyProjectProperties.getInPath()");
  413. return null;
  414. }
  415. public Map getSourcePathResources() {
  416. log("MyProjectProperties.getSourcePathResources()");
  417. return sourcePathResources;
  418. }
  419. public String getOutJar() {
  420. log("MyProjectProperties.getOutJar()");
  421. return null;
  422. }
  423. public Set getSourceRoots() {
  424. log("MyProjectProperties.getSourceRoots()");
  425. return null;
  426. }
  427. public Set getAspectPath() {
  428. log("MyProjectProperties.getAspectPath("+aspectPath+")");
  429. return aspectPath;
  430. }
  431. public static void log(String s) {
  432. if (VERBOSE) System.out.println(s);
  433. }
  434. }
  435. // -----------------------
  436. static class MyBuildProgressMonitor implements BuildProgressMonitor {
  437. public static boolean VERBOSE = false;
  438. private static MyBuildProgressMonitor _instance = new MyBuildProgressMonitor();
  439. private MyBuildProgressMonitor() {}
  440. private List compiledFiles=new ArrayList();
  441. private List wovenClasses=new ArrayList();
  442. public static BuildProgressMonitor getInstance() {
  443. return _instance;
  444. }
  445. public static void reset() {
  446. _instance.finished = false;
  447. _instance.wasFullBuild=true;
  448. _instance.compiledFiles.clear();
  449. _instance.wovenClasses.clear();
  450. }
  451. public static boolean hasFinished() {
  452. return _instance.finished;
  453. }
  454. public static List getCompiledFiles() { return _instance.compiledFiles;}
  455. public static List getWovenClasses() { return _instance.wovenClasses; }
  456. //---
  457. private long starttime = 0;
  458. private long totaltimetaken = 0;
  459. private boolean finished = false;
  460. private boolean wasFullBuild = true;
  461. public void start(String configFile) {
  462. starttime = System.currentTimeMillis();
  463. log("BuildProgressMonitor.start("+configFile+")");
  464. }
  465. public void setProgressText(String text) {
  466. log("BuildProgressMonitor.setProgressText("+text+")");
  467. if (text.startsWith("compiled: ")) {
  468. compiledFiles.add(text.substring(10));
  469. } else if (text.startsWith("woven class ")) {
  470. wovenClasses.add(text.substring(12));
  471. } else if (text.startsWith("woven aspect ")) {
  472. wovenClasses.add(text.substring(13));
  473. }
  474. }
  475. public void setProgressBarVal(int newVal) {
  476. log("BuildProgressMonitor.setProgressBarVal("+newVal+")");
  477. }
  478. public void incrementProgressBarVal() {
  479. log("BuildProgressMonitor.incrementProgressBarVal()");
  480. }
  481. public void setProgressBarMax(int maxVal) {
  482. log("BuildProgressMonitor.setProgressBarMax("+maxVal+")");
  483. }
  484. public int getProgressBarMax() {
  485. log("BuildProgressMonitor.getProgressBarMax() [returns 100]");
  486. return 100;
  487. }
  488. public void finish(boolean b) {
  489. log("BuildProgressMonitor.finish()");
  490. _instance.finished=true;
  491. _instance.wasFullBuild = b;
  492. _instance.totaltimetaken=(System.currentTimeMillis()-starttime);
  493. }
  494. public static long getTimeTaken() {
  495. return _instance.totaltimetaken;
  496. }
  497. public static void log(String s) {
  498. if (VERBOSE) System.out.println(s);
  499. }
  500. public static boolean wasFullBuild() {
  501. return _instance.wasFullBuild;
  502. }
  503. }
  504. // ----
  505. static class MyTaskListManager implements TaskListManager {
  506. private static final String CANT_BUILD_INCREMENTAL_INDICATION = "Unable to perform incremental build";
  507. private static final String DOING_BATCH_BUILD_INDICATION = "Performing batch build for config";
  508. private final static boolean VERBOSE = false;
  509. static MyTaskListManager _instance = new MyTaskListManager();
  510. private MyTaskListManager() {}
  511. private boolean receivedNonIncrementalBuildMessage = false;
  512. private boolean receivedBatchBuildMessage = false;
  513. private List errorMessages = new ArrayList();
  514. private List warningMessages = new ArrayList();
  515. private List weavingMessages = new ArrayList();
  516. public static void reset() {
  517. _instance.receivedNonIncrementalBuildMessage=false;
  518. _instance.receivedBatchBuildMessage=false;
  519. _instance.errorMessages.clear();
  520. _instance.warningMessages.clear();
  521. _instance.weavingMessages.clear();
  522. }
  523. // public static boolean defaultedToBatch() {
  524. // return _instance.receivedNonIncrementalBuildMessage;
  525. // }
  526. //
  527. // public static boolean didBatchBuild() {
  528. // return _instance.receivedBatchBuildMessage;
  529. // }
  530. public static boolean hasErrorMessages() {
  531. return !_instance.errorMessages.isEmpty();
  532. }
  533. public static List/*IMessage*/ getErrorMessages() {
  534. return _instance.errorMessages;
  535. }
  536. public static List/*IMessage*/ getWarningMessages() {
  537. return _instance.warningMessages;
  538. }
  539. public static List/*IMessage*/ getWeavingMessages() {
  540. return _instance.weavingMessages;
  541. }
  542. public static TaskListManager getInstance() {
  543. return _instance;
  544. }
  545. public void addSourcelineTask(String message, ISourceLocation sourceLocation, Kind kind) {
  546. log("TaskListManager.addSourcelineTask("+message+","+sourceLocation+","+kind+")");
  547. }
  548. // DOESSOMETHING
  549. public void addSourcelineTask(IMessage message) {
  550. // if (message.getKind()==IMessage.INFO) {
  551. // if (message.getMessage().startsWith(CANT_BUILD_INCREMENTAL_INDICATION)) _instance.receivedNonIncrementalBuildMessage=true;
  552. // if (message.getMessage().startsWith(DOING_BATCH_BUILD_INDICATION)) _instance.receivedBatchBuildMessage=true;
  553. // }
  554. if (message.getKind()==IMessage.ERROR) errorMessages.add(message);
  555. if (message.getKind()==IMessage.WARNING) warningMessages.add(message);
  556. if (message.getKind()==IMessage.WEAVEINFO) weavingMessages.add(message);
  557. log("TaskListManager.addSourcelineTask("+message+")");
  558. }
  559. public boolean hasWarning() {
  560. log("TaskListManager.hasWarning() [returning "+(warningMessages.size()==0)+"]");
  561. return warningMessages.size()==0;
  562. }
  563. public void addProjectTask(String message, Kind kind) {
  564. log("TaskListManager.addProjectTask("+message+","+kind+")");
  565. }
  566. public void clearTasks() {
  567. log("TaskListManager.clearTasks()");
  568. }
  569. public static void log(String s) {
  570. if (VERBOSE) System.out.println(s);
  571. }
  572. }
  573. // ----
  574. static class MyBuildOptionsAdapter implements BuildOptionsAdapter {
  575. static MyBuildOptionsAdapter _instance = new MyBuildOptionsAdapter();
  576. private MyBuildOptionsAdapter() {}
  577. public static void setNonStandardOptions(String options) {
  578. _instance.nonstandardoptions = options;
  579. }
  580. private String nonstandardoptions=null;
  581. public static void reset() {
  582. _instance.nonstandardoptions=null;
  583. }
  584. public static BuildOptionsAdapter getInstance() {
  585. return _instance;
  586. }
  587. public Map getJavaOptionsMap() {
  588. Hashtable ht = new Hashtable();
  589. ht.put("org.eclipse.jdt.core.compiler.compliance","1.5");
  590. ht.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform","1.5");
  591. return ht;
  592. }
  593. public boolean getUseJavacMode() {
  594. return false;
  595. }
  596. public String getWorkingOutputPath() {
  597. return null;
  598. }
  599. public boolean getPreprocessMode() {
  600. return false;
  601. }
  602. public String getCharacterEncoding() {
  603. return null;
  604. }
  605. public boolean getSourceOnePointFourMode() {
  606. return false;
  607. }
  608. // DOESSOMETHING
  609. public boolean getIncrementalMode() {
  610. return true;
  611. }
  612. public boolean getLenientSpecMode() {
  613. return false;
  614. }
  615. public boolean getStrictSpecMode() {
  616. return false;
  617. }
  618. public boolean getPortingMode() {
  619. return false;
  620. }
  621. public String getNonStandardOptions() {
  622. return nonstandardoptions;
  623. }
  624. public String getComplianceLevel() {
  625. return null;
  626. }
  627. public String getSourceCompatibilityLevel() {
  628. return "1.5";
  629. }
  630. public Set getWarnings() {
  631. return null;
  632. }
  633. public Set getDebugLevel() {
  634. return null;
  635. }
  636. public boolean getNoImportError() {
  637. return false;
  638. }
  639. public boolean getPreserveAllLocals() {
  640. return false;
  641. }
  642. }
  643. static class MyStateListener extends AbstractStateListener {
  644. private static MyStateListener _instance = new MyStateListener();
  645. private MyStateListener() {reset();}
  646. public static MyStateListener getInstance() { return _instance;}
  647. public static boolean informedAboutKindOfBuild;
  648. public static boolean fullBuildOccurred;
  649. public static List detectedDeletions = new ArrayList();
  650. public static StringBuffer decisions = new StringBuffer();
  651. public static void reset() {
  652. informedAboutKindOfBuild=false;
  653. decisions = new StringBuffer();
  654. fullBuildOccurred=false;
  655. if (detectedDeletions!=null) detectedDeletions.clear();
  656. }
  657. public boolean pathChange = false;
  658. public void pathChangeDetected() {pathChange = true;}
  659. public void aboutToCompareClasspaths(List oldClasspath, List newClasspath) {}
  660. public void detectedClassChangeInThisDir(File f) {}
  661. public void detectedAspectDeleted(File f) {
  662. detectedDeletions.add(f.toString());
  663. }
  664. public void buildSuccessful(boolean wasFullBuild) {
  665. informedAboutKindOfBuild= true;
  666. fullBuildOccurred=wasFullBuild;
  667. }
  668. public static String getDecisions() {
  669. return decisions.toString();
  670. }
  671. public static boolean wasFullBuild() {
  672. if (!informedAboutKindOfBuild) throw new RuntimeException("I never heard about what kind of build it was!!");
  673. return fullBuildOccurred;
  674. }
  675. // not needed just yet...
  676. // public void recordInformation(String s) { decisions.append(s).append("\n");}
  677. public void recordDecision(String s) {
  678. decisions.append(s).append("\n");
  679. }
  680. };
  681. }