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

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