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.

IncrementalStateManager.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.ajdt.internal.core.builder;
  13. import java.io.File;
  14. import java.util.Collection;
  15. import java.util.Hashtable;
  16. import java.util.Iterator;
  17. import java.util.Set;
  18. import org.aspectj.asm.AsmManager;
  19. /**
  20. * Central point for all things incremental...
  21. * - keeps track of the state recorded for each different config file
  22. * - allows limited interaction with these states
  23. *
  24. * - records dependency/change info for particular classpaths
  25. * > this will become what JDT keeps in its 'State' object when its finished
  26. */
  27. public class IncrementalStateManager {
  28. // FIXME asc needs an API through Ajde for trashing its contents
  29. // FIXME asc needs some memory mgmt (softrefs?) to recover memory
  30. // SECRETAPI will consume more memory, so turn on at your own risk ;) Set to 'true' when memory usage is understood
  31. public static boolean recordIncrementalStates = false;
  32. public static boolean debugIncrementalStates = false;
  33. private static Hashtable incrementalStates = new Hashtable();
  34. public static void recordSuccessfulBuild(String buildConfig, AjState state) {
  35. if (!recordIncrementalStates) return;
  36. incrementalStates.put(buildConfig,state);
  37. }
  38. public static boolean removeIncrementalStateInformationFor(String buildConfig) {
  39. return incrementalStates.remove(buildConfig)!=null;
  40. }
  41. public static void clearIncrementalStates() {
  42. for (Iterator iter = incrementalStates.values().iterator(); iter.hasNext();) {
  43. AjState element = (AjState) iter.next();
  44. element.wipeAllKnowledge();
  45. }
  46. incrementalStates.clear();
  47. AsmManager.getDefault().createNewASM(null); // forget what you know...
  48. }
  49. public static Set getConfigFilesKnown() {
  50. return incrementalStates.keySet();
  51. }
  52. public static AjState retrieveStateFor(String configFile) {
  53. return (AjState)incrementalStates.get(configFile);
  54. }
  55. // now, managing changes to entries on a classpath
  56. public static AjState findStateManagingOutputLocation(File location) {
  57. Collection allStates = incrementalStates.values();
  58. if (debugIncrementalStates) System.err.println("> findStateManagingOutputLocation("+location+") has "+allStates.size()+" states to look through");
  59. for (Iterator iter = allStates.iterator(); iter.hasNext();) {
  60. AjState element = (AjState) iter.next();
  61. AjBuildConfig ajbc = element.getBuildConfig();
  62. if (ajbc==null) {
  63. // FIXME asc why can it ever be null?
  64. if (debugIncrementalStates) System.err.println(" No build configuration for state "+element);
  65. continue;
  66. }
  67. File outputDir = ajbc.getOutputDir();
  68. if (outputDir == null) {
  69. // FIXME why can it ever be null? due to using outjar?
  70. if (debugIncrementalStates) System.err.println(" output directory for "+ajbc+" is null");
  71. continue;
  72. }
  73. if (outputDir.equals(location)) {
  74. if (debugIncrementalStates) System.err.println("< findStateManagingOutputLocation("+location+") returning "+element);
  75. return element;
  76. }
  77. }
  78. if (debugIncrementalStates) System.err.println("< findStateManagingOutputLocation("+location+") returning null");
  79. return null;
  80. }
  81. // FIXME asc needs a persistence mechanism for storing/loading all state info
  82. // FIXME asc needs to understand two config files might point at the same output dir... what to do about this?
  83. }