1 2 25 26 package org.aspectj.ajde; 27 28 import java.io.PrintStream ; 29 import java.util.HashMap ; 30 import java.util.List ; 31 import java.util.Vector ; 32 33 import org.aspectj.ajde.internal.*; 34 import org.aspectj.ajde.ui.*; 35 import org.aspectj.asm.StructureModelManager; 36 import org.aspectj.compiler.Version; 37 38 44 public class Ajde { 45 46 private static final Ajde INSTANCE = new Ajde(); 47 private static final String NOT_INITIALIZED_MESSAGE = "Ajde is not initialized."; 48 private static boolean isInitialized = false; 49 private BuildManager buildManager; 50 private EditorManager editorManager; 51 private StructureViewManager structureViewManager; 52 private StructureSearchManager structureSearchManager; 53 private BuildConfigManager configurationManager ; 54 private ProjectPropertiesAdapter projectProperties; 55 private TaskListManager taskListManager; 56 private IdeUIAdapter ideUIAdapter; 57 private ErrorHandler errorHandler; 58 private PrintStream logPrintStream = null; 59 60 63 protected Ajde() { 64 configurationManager = new LstBuildConfigManager(); 65 } 66 67 71 public static void init( 72 EditorAdapter editorAdapter, 73 TaskListManager taskListManager, 74 BuildProgressMonitor compileProgressMonitor, 75 ProjectPropertiesAdapter projectProperties, 76 BuildOptionsAdapter buildOptionsAdapter, 77 StructureViewNodeFactory structureViewNodeFactory, 78 IdeUIAdapter ideUIAdapter, 79 ErrorHandler errorHandler) { 80 try { 81 INSTANCE.projectProperties = projectProperties; 82 INSTANCE.errorHandler = errorHandler; 83 INSTANCE.taskListManager = taskListManager; 84 INSTANCE.editorManager = new EditorManager(editorAdapter); 85 INSTANCE.buildManager = new AspectJBuildManager( 86 taskListManager, 87 compileProgressMonitor, 88 buildOptionsAdapter); 89 90 INSTANCE.buildManager.addListener(INSTANCE.BUILD_STATUS_LISTENER); 91 INSTANCE.configurationManager.addListener(INSTANCE.STRUCTURE_UPDATE_CONFIG_LISTENER); 92 INSTANCE.ideUIAdapter = ideUIAdapter; 93 94 INSTANCE.structureSearchManager = new StructureSearchManager(); 95 INSTANCE.structureViewManager = new StructureViewManager(structureViewNodeFactory); 96 97 isInitialized = true; 98 } catch (Throwable t) { 99 System.err.println("AJDE ERROR: could not initialize Ajde."); 100 t.printStackTrace(); 101 } 102 } 103 104 107 public static Ajde getDefault() { 108 if (!isInitialized) throw new RuntimeException (NOT_INITIALIZED_MESSAGE); 109 return INSTANCE; 110 } 111 112 115 public void setConfigurationManager(BuildConfigManager configurationManager) { 116 this.configurationManager = configurationManager; 117 } 118 119 public BuildManager getBuildManager() { 120 return buildManager; 121 } 122 123 public EditorManager getEditorManager() { 124 return editorManager; 125 } 126 127 public StructureViewManager getStructureViewManager() { 128 return structureViewManager; 129 } 130 131 public StructureSearchManager getStructureSearchManager() { 132 return structureSearchManager; 133 } 134 135 public BuildConfigManager getConfigurationManager() { 136 return configurationManager; 137 } 138 139 public ProjectPropertiesAdapter getProjectProperties() { 140 return projectProperties; 141 } 142 143 public TaskListManager getTaskListManager() { 144 return taskListManager; 145 } 146 147 public IdeUIAdapter getIdeUIAdapter() { 148 return ideUIAdapter; 149 } 150 151 public void setIdeUIAdapter(IdeUIAdapter ideUIAdapter) { 152 this.ideUIAdapter = ideUIAdapter; 153 } 154 155 public ErrorHandler getErrorHandler() { 156 return errorHandler; 157 } 158 159 public String getVersion() { 160 return Version.text; 161 } 162 163 public void enableLogging(PrintStream logPrintStream) { 164 this.logPrintStream = logPrintStream; 165 } 166 167 public void disableLogging() { 168 this.logPrintStream = null; 169 } 170 171 176 public StructureModelManager getStructureModelManager() { 177 return StructureModelManager.INSTANCE; 178 } 179 180 public void logEvent(String message) { 181 if (logPrintStream != null) { 182 logPrintStream.println("<AJDE> " + message); 183 } 184 } 185 186 private final BuildConfigListener STRUCTURE_UPDATE_CONFIG_LISTENER = new BuildConfigListener() { 187 public void currConfigChanged(String configFilePath) { 188 if (configFilePath != null) Ajde.getDefault().getStructureModelManager().readStructureModel(configFilePath); 189 } 190 191 public void configsListUpdated(List configsList) { } 192 }; 193 194 private final BuildListener BUILD_STATUS_LISTENER = new BuildListener() { 195 196 199 public void compileStarted(String buildConfig) { 200 String configFilePath = projectProperties.getDefaultBuildConfigFile(); 201 if (buildConfig.equals(configFilePath)) { 202 configurationManager.writePaths(configFilePath, projectProperties.getProjectSourceFiles()); 203 logEvent("wrote default build config: " + configFilePath); 204 } 205 } 206 207 210 public void compileFinished(String buildConfig, int buildTime, boolean succeeded, boolean warnings) { 211 String configFilePath = projectProperties.getDefaultBuildConfigFile(); 212 if (!succeeded) { 213 StructureModelManager.INSTANCE.fireModelUpdated(); 214 } 215 } 216 217 220 public void compileAborted(String buildConfigFile, String message) { } 221 }; 222 } 223 224 225 | Popular Tags |