From 466f07f27207d84ce2963ae97e68c65b4c30d7f0 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 4 May 2012 15:37:53 +0200 Subject: [PATCH] drop saved fs state and force fs rescan on roots changed event --- .../compiler/server/BuildManager.java | 10 ++++---- .../jetbrains/jps/cmdline/BuildSession.java | 25 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 7410fa63d04e..ceadac438ea4 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -241,6 +241,7 @@ public class BuildManager implements ApplicationComponent{ } public void clearState(Project project) { + myGlobals = null; final String projectPath = getProjectPath(project); synchronized (myProjectDataMap) { final ProjectData data = myProjectDataMap.get(projectPath); @@ -260,10 +261,6 @@ public class BuildManager implements ApplicationComponent{ return vFile != null ? vFile.getPath() : null; } - private void clearGlobalsCache() { - myGlobals = null; - } - private void runAutoMake() { if (ApplicationManager.getApplication().isUnitTestMode()) { return; @@ -778,7 +775,10 @@ public class BuildManager implements ApplicationComponent{ @Override public void rootsChanged(final ModuleRootEvent event) { - clearGlobalsCache(); + final Object source = event.getSource(); + if (source instanceof Project) { + clearState((Project)source); + } } }); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java index f6adf474c8ae..423decc28335 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java @@ -199,13 +199,13 @@ final class BuildSession implements Runnable, CanceledStatus { pd = new ProjectDescriptor(project, fsState, projectTimestamps, dataManager, BuildLoggingManager.DEFAULT); myProjectDescriptor = pd; - loadFsState(myProjectDescriptor, dataStorageRoot, myInitialFSDelta); - // free memory - myInitialFSDelta = null; - // ensure events from controller are processed after FSState initialization - myEventsProcessor.startProcessing(); - try { + loadFsState(myProjectDescriptor, dataStorageRoot, myInitialFSDelta); + // free memory + myInitialFSDelta = null; + // ensure events from controller are processed after FSState initialization + myEventsProcessor.startProcessing(); + for (int attempt = 0; attempt < 2; attempt++) { if (forceCleanCaches && modules.isEmpty() && paths.isEmpty()) { // if compilation scope is the whole project and cache rebuild is forced, use PROJECT_REBUILD for faster compilation @@ -313,10 +313,6 @@ final class BuildSession implements Runnable, CanceledStatus { private static void saveFsState(File dataStorageRoot, BuildFSState state, long lastEventOrdinal) { final File file = new File(dataStorageRoot, FS_STATE_FILE); - if (lastEventOrdinal < 0L) { - FileUtil.delete(file); - return; - } BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream(); try { @@ -370,6 +366,7 @@ final class BuildSession implements Runnable, CanceledStatus { finally { fs.close(); } + final DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes)); try { final long savedOrdinal = in.readLong(); @@ -387,14 +384,16 @@ final class BuildSession implements Runnable, CanceledStatus { finally { in.close(); } + return; // successfully initialized + } catch (FileNotFoundException ignored) { } - catch (IOException e) { - pd.fsState.clearAll(); - myLastEventOrdinal = initialEvent != null? initialEvent.getOrdinal() : 0L; + catch (Throwable e) { LOG.error(e); } + myLastEventOrdinal = initialEvent != null? initialEvent.getOrdinal() : 0L; + pd.fsState.clearAll(); } private void finishBuild(Throwable error, boolean hadBuildErrors, boolean markedUptodateFiles) {