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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.io.FileNotFoundException;
  15. import java.io.FileOutputStream;
  16. import java.io.IOException;
  17. import java.util.Collection;
  18. import java.util.Hashtable;
  19. import java.util.Iterator;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.Set;
  23. import org.aspectj.ajdt.internal.compiler.CompilationResultDestinationManager;
  24. import org.aspectj.weaver.CompressingDataOutputStream;
  25. /**
  26. * Central point for all things incremental... - keeps track of the state recorded for each different config file - allows limited
  27. * interaction with these states
  28. *
  29. * - records dependency/change info for particular classpaths > this will become what JDT keeps in its 'State' object when its
  30. * finished
  31. */
  32. public class IncrementalStateManager {
  33. // FIXME asc needs an API through Ajde for trashing its contents
  34. // FIXME asc needs some memory mgmt (softrefs?) to recover memory
  35. // SECRETAPI will consume more memory, so turn on at your own risk ;) Set to 'true' when memory usage is understood
  36. public static boolean recordIncrementalStates = false;
  37. public static boolean debugIncrementalStates = false;
  38. private static Hashtable<String, AjState> incrementalStates = new Hashtable<>();
  39. public static void recordSuccessfulBuild(String buildConfig, AjState state) {
  40. if (!recordIncrementalStates) {
  41. return;
  42. }
  43. incrementalStates.put(buildConfig, state);
  44. // persist();
  45. }
  46. /**
  47. * Store states on disk
  48. */
  49. public static void persist() {
  50. // check serialization works
  51. Set<Map.Entry<String, AjState>> entries = incrementalStates.entrySet();
  52. for (Map.Entry<String, AjState> entry : entries) {
  53. System.out.println("Name " + entry.getKey());
  54. File f = new File("n:/temp/foo.ajstate");
  55. try {
  56. AjState state = (AjState) entry.getValue();
  57. CompressingDataOutputStream dos = new CompressingDataOutputStream(new FileOutputStream(f));
  58. state.write(dos);
  59. dos.close();
  60. } catch (FileNotFoundException e) {
  61. throw new RuntimeException(e);
  62. } catch (IOException e) {
  63. throw new RuntimeException(e);
  64. }
  65. }
  66. }
  67. public static boolean removeIncrementalStateInformationFor(String buildConfig) {
  68. return incrementalStates.remove(buildConfig) != null;
  69. }
  70. public static void clearIncrementalStates() {
  71. for (AjState element : incrementalStates.values()) {
  72. element.wipeAllKnowledge();
  73. }
  74. incrementalStates.clear();
  75. // AsmManager.getDefault().createNewStructureModel(); // forget what you know...
  76. }
  77. public static Set getConfigFilesKnown() {
  78. return incrementalStates.keySet();
  79. }
  80. public static AjState retrieveStateFor(String configFile) {
  81. return (AjState) incrementalStates.get(configFile);
  82. }
  83. // now, managing changes to entries on a classpath
  84. public static AjState findStateManagingOutputLocation(File location) {
  85. Collection<AjState> allStates = incrementalStates.values();
  86. if (debugIncrementalStates) {
  87. System.err.println("> findStateManagingOutputLocation(" + location + ") has " + allStates.size()
  88. + " states to look through");
  89. }
  90. for (AjState element : allStates) {
  91. AjBuildConfig ajbc = element.getBuildConfig();
  92. if (ajbc == null) {
  93. // FIXME asc why can it ever be null?
  94. if (debugIncrementalStates) {
  95. System.err.println(" No build configuration for state " + element);
  96. }
  97. continue;
  98. }
  99. File outputDir = ajbc.getOutputDir();
  100. if (outputDir != null && outputDir.equals(location)) {
  101. if (debugIncrementalStates) {
  102. System.err.println("< findStateManagingOutputLocation(" + location + ") returning " + element);
  103. }
  104. return element;
  105. }
  106. CompilationResultDestinationManager outputManager = ajbc.getCompilationResultDestinationManager();
  107. if (outputManager != null) {
  108. List outputDirs = outputManager.getAllOutputLocations();
  109. for (Object o : outputDirs) {
  110. File dir = (File) o;
  111. if (dir.equals(location)) {
  112. if (debugIncrementalStates) {
  113. System.err.println("< findStateManagingOutputLocation(" + location + ") returning " + element);
  114. }
  115. return element;
  116. }
  117. }
  118. }
  119. if (outputDir == null && outputManager == null) {
  120. // FIXME why can it ever be null? due to using outjar?
  121. if (debugIncrementalStates) {
  122. System.err.println(" output directory and output location manager for " + ajbc + " are null");
  123. }
  124. continue;
  125. }
  126. }
  127. if (debugIncrementalStates) {
  128. System.err.println("< findStateManagingOutputLocation(" + location + ") returning null");
  129. }
  130. return null;
  131. }
  132. // FIXME asc needs a persistence mechanism for storing/loading all state info
  133. // FIXME asc needs to understand two config files might point at the same output dir... what to do about this?
  134. }