From 2004eba7ff5b0650d5f0d7fb07699ef1ce0a1fd5 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 22 Oct 2010 12:44:34 +0400 Subject: [PATCH] merge roots changes when commiting artifacts to avoid multiple roots changed events from WebProjectComponent --- .../impl/artifacts/ArtifactManagerImpl.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java index 162cc7927b58..6b6d04c3eed6 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java @@ -21,9 +21,11 @@ import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.components.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ex.ProjectRootManagerEx; import com.intellij.openapi.util.ModificationTracker; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.packaging.artifacts.*; import com.intellij.packaging.elements.*; import com.intellij.util.containers.ContainerUtil; @@ -294,9 +296,9 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo final List allArtifacts = artifactModel.getOriginalArtifacts(); - Set removed = new THashSet(myModel.myArtifactsList); - List added = new ArrayList(); - List> changed = new ArrayList>(); + final Set removed = new THashSet(myModel.myArtifactsList); + final List added = new ArrayList(); + final List> changed = new ArrayList>(); for (ArtifactImpl artifact : allArtifacts) { final boolean isAdded = !removed.remove(artifact); @@ -314,16 +316,20 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo myModel.setArtifactsList(allArtifacts); myModificationCount++; final ArtifactListener publisher = myProject.getMessageBus().syncPublisher(TOPIC); - for (ArtifactImpl artifact : removed) { - publisher.artifactRemoved(artifact); - } - //it's important to send 'removed' events before 'added'. Otherwise when artifacts are reloaded from xml artifact pointers will be damaged - for (ArtifactImpl artifact : added) { - publisher.artifactAdded(artifact); - } - for (Pair pair : changed) { - publisher.artifactChanged(pair.getFirst(), pair.getSecond()); - } + ProjectRootManagerEx.getInstanceEx(myProject).mergeRootsChangesDuring(new Runnable() { + public void run() { + for (ArtifactImpl artifact : removed) { + publisher.artifactRemoved(artifact); + } + //it's important to send 'removed' events before 'added'. Otherwise when artifacts are reloaded from xml artifact pointers will be damaged + for (ArtifactImpl artifact : added) { + publisher.artifactAdded(artifact); + } + for (Pair pair : changed) { + publisher.artifactChanged(pair.getFirst(), pair.getSecond()); + } + } + }); } finally { myInsideCommit = false;