From d3012bec8e30bd119c154a07bc14b6a1d05108fe Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 4 May 2012 19:47:47 +0200 Subject: [PATCH] clean info about removed sources only after they have been 'integrated' --- .../jps/incremental/CompileContext.java | 13 +---- .../jps/incremental/IncProjectBuilder.java | 50 ++++++++++++------- .../jps/incremental/ModuleLevelBuilder.java | 37 ++++++++++++-- .../org/jetbrains/jps/incremental/Utils.java | 3 +- 4 files changed, 66 insertions(+), 37 deletions(-) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java index dc71440c418e..178c70d6513d 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java @@ -259,17 +259,6 @@ public class CompileContext extends UserDataHolderBase implements MessageHandler } } - // clean mapping only after everything else is processed - final Map> map = Utils.CHUNK_PER_MODULE_REMOVED_SOURCES_KEY.get(this); - if (map != null) { - for (Map.Entry> entry : map.entrySet()) { - final SourceToOutputMapping mapping = dataManager.getSourceToOutputMap(entry.getKey(), isCompilingTests()); - for (String path : entry.getValue()) { - mapping.remove(path); - } - } - } - if (marked) { processMessage(UptoDateFilesSavedEvent.INSTANCE); } @@ -350,7 +339,7 @@ public class CompileContext extends UserDataHolderBase implements MessageHandler } public boolean hasRemovedSources() { - final Set removed = Utils.CHUNK_REMOVED_SOURCES_KEY.get(this); + final Map> removed = Utils.REMOVED_SOURCES_KEY.get(this); return removed != null && !removed.isEmpty(); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index c5db47f94d44..dc99c6ca0217 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -428,8 +428,29 @@ public class IncProjectBuilder { throw new ProjectBuildException(e); } finally { - Utils.CHUNK_REMOVED_SOURCES_KEY.set(context, null); - Utils.CHUNK_PER_MODULE_REMOVED_SOURCES_KEY.set(context, null); + + try { + // restore deleted paths that were not procesesd by 'integrate' + final Map> map = Utils.REMOVED_SOURCES_KEY.get(context); + if (map != null) { + final boolean forTests = context.isCompilingTests(); + for (Map.Entry> entry : map.entrySet()) { + final String moduleName = entry.getKey(); + final Collection paths = entry.getValue(); + if (paths != null) { + for (String path : paths) { + myProjectDescriptor.fsState.registerDeleted(moduleName, new File(path), forTests, null); + } + } + } + } + } + catch (IOException e) { + throw new ProjectBuildException(e); + } + + Utils.REMOVED_SOURCES_KEY.set(context, null); + if (doneSomething && GENERATE_CLASSPATH_INDEX) { final boolean forTests = context.isCompilingTests(); final Future future = SharedThreadPool.INSTANCE.submit(new Runnable() { @@ -485,8 +506,7 @@ public class IncProjectBuilder { private void processDeletedPaths(CompileContext context, ModuleChunk chunk) throws ProjectBuildException { try { // cleanup outputs - final Set allChunkRemovedSources = new HashSet(); - final Map> perModuleRemovedSources = new HashMap>(); + final Map> removedSources = new HashMap>(); for (Module module : chunk.getModules()) { final Collection deletedPaths = myProjectDescriptor.fsState.getAndClearDeletedPaths(module.getName(), @@ -494,11 +514,9 @@ public class IncProjectBuilder { if (deletedPaths.isEmpty()) { continue; } - allChunkRemovedSources.addAll(deletedPaths); - perModuleRemovedSources.put(module.getName(), deletedPaths); + removedSources.put(module.getName(), deletedPaths); - final SourceToOutputMapping sourceToOutputStorage = - context.getDataManager().getSourceToOutputMap(module.getName(), context.isCompilingTests()); + final SourceToOutputMapping sourceToOutputStorage = context.getDataManager().getSourceToOutputMap(module.getName(), context.isCompilingTests()); // actually delete outputs associated with removed paths for (String deletedSource : deletedPaths) { // deleting outputs corresponding to non-existing source @@ -539,26 +557,20 @@ public class IncProjectBuilder { } } } - if (!allChunkRemovedSources.isEmpty()) { - final Set currentData = Utils.CHUNK_REMOVED_SOURCES_KEY.get(context); - if (currentData != null) { - allChunkRemovedSources.addAll(currentData); - } - Utils.CHUNK_REMOVED_SOURCES_KEY.set(context, allChunkRemovedSources); - - final Map> existing = Utils.CHUNK_PER_MODULE_REMOVED_SOURCES_KEY.get(context); + if (!removedSources.isEmpty()) { + final Map> existing = Utils.REMOVED_SOURCES_KEY.get(context); if (existing != null) { for (Map.Entry> entry : existing.entrySet()) { - final Collection paths = perModuleRemovedSources.get(entry.getKey()); + final Collection paths = removedSources.get(entry.getKey()); if (paths != null) { paths.addAll(entry.getValue()); } else { - perModuleRemovedSources.put(entry.getKey(), entry.getValue()); + removedSources.put(entry.getKey(), entry.getValue()); } } } - Utils.CHUNK_PER_MODULE_REMOVED_SOURCES_KEY.set(context, perModuleRemovedSources); + Utils.REMOVED_SOURCES_KEY.set(context, removedSources); } } catch (IOException e) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleLevelBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleLevelBuilder.java index 0e41a0cec7fb..014c9ff487f3 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleLevelBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleLevelBuilder.java @@ -10,6 +10,7 @@ import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.messages.ProgressMessage; +import org.jetbrains.jps.incremental.storage.SourceToOutputMapping; import java.io.File; import java.io.IOException; @@ -65,7 +66,7 @@ public abstract class ModuleLevelBuilder extends Builder { try { boolean additionalPassRequired = false; - final Set removedPaths = getRemovedPaths(context); + final Set removedPaths = getRemovedPaths(context, chunk); final Mappings globalMappings = context.getDataManager().getMappings(); @@ -143,6 +144,9 @@ public abstract class ModuleLevelBuilder extends Builder { globalMappings.integrate(delta, removedPaths); + // save to remove everything that has been integrated + dropRemovedPaths(context, chunk); + return additionalPassRequired; } catch(RuntimeException e) { @@ -205,9 +209,34 @@ public abstract class ModuleLevelBuilder extends Builder { return allCompiledFiles; } - private static Set getRemovedPaths(CompileContext context) { - final Set removed = Utils.CHUNK_REMOVED_SOURCES_KEY.get(context); - return removed != null? removed : Collections.emptySet(); + private static Set getRemovedPaths(CompileContext context, ModuleChunk chunk) { + final Map> map = Utils.REMOVED_SOURCES_KEY.get(context); + if (map == null) { + return Collections.emptySet(); + } + final Set removed = new HashSet(); + for (Module module : chunk.getModules()) { + final Collection modulePaths = map.get(module.getName()); + if (modulePaths != null) { + removed.addAll(modulePaths); + } + } + return removed; + } + + private static void dropRemovedPaths(CompileContext context, ModuleChunk chunk) throws IOException { + final Map> map = Utils.REMOVED_SOURCES_KEY.get(context); + if (map != null) { + for (Module module : chunk.getModules()) { + final Collection paths = map.remove(module.getName()); + if (paths != null) { + final SourceToOutputMapping storage = context.getDataManager().getSourceToOutputMap(module.getName(), context.isCompilingTests()); + for (String path : paths) { + storage.remove(path); + } + } + } + } } private static class ModulesBasedFileFilter implements Mappings.DependentFilesFilter{ diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/Utils.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/Utils.java index 3557ffbf9688..829b53901b69 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/Utils.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/Utils.java @@ -15,8 +15,7 @@ import java.util.*; * Date: 10/20/11 */ public class Utils { - public static final Key> CHUNK_REMOVED_SOURCES_KEY = Key.create("_chunk_removed_sources_"); - public static final Key>> CHUNK_PER_MODULE_REMOVED_SOURCES_KEY = Key.create("_chunk_per_maodule_removed_sources_"); + public static final Key>> REMOVED_SOURCES_KEY = Key.create("_removed_sources_"); private static volatile File ourSystemRoot = new File(System.getProperty("user.home", ".jps-server")); private Utils() {