1 /* *******************************************************************
2 * Copyright (c) 2005 Contributors.
4 * This program and the accompanying materials are made available
5 * under the terms of the Eclipse Public License v 2.0
6 * which accompanies this distribution and is available at
7 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
10 * Andy Clement initial implementation
11 * ******************************************************************/
12 package org.aspectj.ajdt.internal.core.builder;
15 import java.io.FileNotFoundException;
16 import java.io.FileOutputStream;
17 import java.io.IOException;
18 import java.util.Collection;
19 import java.util.Hashtable;
20 import java.util.List;
24 import org.aspectj.ajdt.internal.compiler.CompilationResultDestinationManager;
25 import org.aspectj.weaver.CompressingDataOutputStream;
28 * Central point for all things incremental... - keeps track of the state recorded for each different config file - allows limited
29 * interaction with these states
31 * - records dependency/change info for particular classpaths > this will become what JDT keeps in its 'State' object when it's
34 public class IncrementalStateManager {
36 // FIXME asc needs an API through Ajde for trashing its contents
37 // FIXME asc needs some memory mgmt (softrefs?) to recover memory
38 // SECRETAPI will consume more memory, so turn on at your own risk ;) Set to 'true' when memory usage is understood
39 public static boolean recordIncrementalStates = false;
40 public static boolean debugIncrementalStates = false;
41 private static Hashtable<String, AjState> incrementalStates = new Hashtable<>();
43 public static void recordSuccessfulBuild(String buildConfig, AjState state) {
44 if (!recordIncrementalStates) {
47 incrementalStates.put(buildConfig, state);
52 * Store states on disk
54 public static void persist() {
55 // check serialization works
56 Set<Map.Entry<String, AjState>> entries = incrementalStates.entrySet();
57 for (Map.Entry<String, AjState> entry : entries) {
58 System.out.println("Name " + entry.getKey());
59 File f = new File("n:/temp/foo.ajstate");
61 AjState state = (AjState) entry.getValue();
62 CompressingDataOutputStream dos = new CompressingDataOutputStream(new FileOutputStream(f));
65 } catch (FileNotFoundException e) {
66 throw new RuntimeException(e);
67 } catch (IOException e) {
68 throw new RuntimeException(e);
73 public static boolean removeIncrementalStateInformationFor(String buildConfig) {
74 return incrementalStates.remove(buildConfig) != null;
77 public static void clearIncrementalStates() {
78 for (AjState element : incrementalStates.values()) {
79 element.wipeAllKnowledge();
81 incrementalStates.clear();
82 // AsmManager.getDefault().createNewStructureModel(); // forget what you know...
85 public static Set getConfigFilesKnown() {
86 return incrementalStates.keySet();
89 public static AjState retrieveStateFor(String configFile) {
90 return (AjState) incrementalStates.get(configFile);
93 // now, managing changes to entries on a classpath
95 public static AjState findStateManagingOutputLocation(File location) {
96 Collection<AjState> allStates = incrementalStates.values();
97 if (debugIncrementalStates) {
98 System.err.println("> findStateManagingOutputLocation(" + location + ") has " + allStates.size()
99 + " states to look through");
101 for (AjState element : allStates) {
102 AjBuildConfig ajbc = element.getBuildConfig();
104 // FIXME asc why can it ever be null?
105 if (debugIncrementalStates) {
106 System.err.println(" No build configuration for state " + element);
110 File outputDir = ajbc.getOutputDir();
111 if (outputDir != null && outputDir.equals(location)) {
112 if (debugIncrementalStates) {
113 System.err.println("< findStateManagingOutputLocation(" + location + ") returning " + element);
117 CompilationResultDestinationManager outputManager = ajbc.getCompilationResultDestinationManager();
118 if (outputManager != null) {
119 List<File> outputDirs = outputManager.getAllOutputLocations();
120 for (Object o : outputDirs) {
122 if (dir.equals(location)) {
123 if (debugIncrementalStates) {
124 System.err.println("< findStateManagingOutputLocation(" + location + ") returning " + element);
130 if (outputDir == null && outputManager == null) {
131 // FIXME why can it ever be null? due to using outjar?
132 if (debugIncrementalStates) {
133 System.err.println(" output directory and output location manager for " + ajbc + " are null");
139 if (debugIncrementalStates) {
140 System.err.println("< findStateManagingOutputLocation(" + location + ") returning null");
145 // FIXME asc needs a persistence mechanism for storing/loading all state info
146 // FIXME asc needs to understand two config files might point at the same output dir... what to do about this?