diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileContextImpl.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileContextImpl.java index a90138146a4d..32ff81f18f17 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileContextImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileContextImpl.java @@ -26,6 +26,7 @@ import com.intellij.compiler.CompilerMessageImpl; import com.intellij.compiler.CompilerWorkspaceConfiguration; import com.intellij.compiler.make.DependencyCache; import com.intellij.compiler.progress.CompilerTask; +import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.compiler.*; import com.intellij.openapi.compiler.Compiler; @@ -40,6 +41,7 @@ import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.vfs.VfsUtil; @@ -99,7 +101,13 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon myIsAnnotationProcessorsEnabled = CompilerConfiguration.getInstance(project).isAnnotationProcessorsEnabled(); if (compilerSession != null) { - compilerSession.setContentIdKey(compileScope.getUserData(CompilerManager.CONTENT_ID_KEY)); + final Key sessionId = ExecutionEnvironment.EXECUTION_SESSION_ID_KEY.get(compileScope); + if (sessionId != null) { + // in case compilation is started as a part of some execution session, + // all compilation tasks should have the same sessionId in order for successive task not to clean messages + // from previous compilation tasks run within this execution session + compilerSession.setSessionId(sessionId); + } } recalculateOutputDirs(); final CompilerWorkspaceConfiguration workspaceConfig = CompilerWorkspaceConfiguration.getInstance(myProject); diff --git a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java index d37e7c2dd672..57bd30ab9753 100644 --- a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java +++ b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java @@ -72,9 +72,12 @@ import java.util.concurrent.atomic.AtomicBoolean; public class CompilerTask extends Task.Backgroundable { private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.progress.CompilerProgressIndicator"); private static final Key> CONTENT_ID_KEY = Key.create("CONTENT_ID"); + private static final Key> SESSION_ID_KEY = Key.create("SESSION_ID"); private static final String APP_ICON_ID = "compiler"; - private Key> myContentIdKey = CONTENT_ID_KEY; - private final Key> myContentId = Key.create("compile_content"); + @NotNull + private final Key myContentId = Key.create("content_id"); + @NotNull + private Key mySessionId = myContentId; // by default sessionID should be unique, just as content ID private NewErrorTreeViewPanel myErrorTreeView; private final Object myMessageViewLock = new Object(); private final String myContentName; @@ -107,8 +110,13 @@ public class CompilerTask extends Task.Backgroundable { myCompilationStartedAutomatically = compilationStartedAutomatically; } - public void setContentIdKey(Key> contentIdKey) { - myContentIdKey = contentIdKey != null? contentIdKey : CONTENT_ID_KEY; + @NotNull + public Key getSessionId() { + return mySessionId; + } + + public void setSessionId(@NotNull Key sessionId) { + mySessionId = sessionId; } public String getProcessId() { @@ -189,7 +197,9 @@ public class CompilerTask extends Task.Backgroundable { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - if (myProject.isDisposed()) return; + if (myProject.isDisposed()) { + return; + } synchronized (myMessageViewLock) { // clear messages from the previous compilation if (myErrorTreeView == null) { @@ -410,7 +420,8 @@ public class CompilerTask extends Task.Backgroundable { final MessageView messageView = MessageView.SERVICE.getInstance(myProject); final Content content = ContentFactory.SERVICE.getInstance().createContent(component, myContentName, true); - content.putUserData(myContentIdKey, myContentId); + CONTENT_ID_KEY.set(content, myContentId); + SESSION_ID_KEY.set(content, mySessionId); messageView.getContentManager().addContent(content); myCloseListener.setContent(content, messageView.getContentManager()); removeAllContents(myProject, content); @@ -423,7 +434,7 @@ public class CompilerTask extends Task.Backgroundable { final MessageView messageView = MessageView.SERVICE.getInstance(myProject); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { - if (content.getUserData(myContentIdKey) != null) { + if (CONTENT_ID_KEY.get(content) == myContentId) { messageView.getContentManager().setSelectedContent(content); return; } @@ -442,7 +453,7 @@ public class CompilerTask extends Task.Backgroundable { if (content == notRemove) { continue; } - if (content.getUserData(myContentIdKey) != null) { // the content was added by me + if (CONTENT_ID_KEY.get(content) == myContentId || SESSION_ID_KEY.get(content) != mySessionId) { // the content was added by previous compilation messageView.getContentManager().removeContent(content, true); } } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompileScope.java b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompileScope.java index abf048489885..f79426895c91 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompileScope.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/compiler/ArtifactCompileScope.java @@ -17,7 +17,6 @@ package com.intellij.packaging.impl.compiler; import com.intellij.compiler.impl.ModuleCompileScope; import com.intellij.openapi.compiler.CompileScope; -import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; @@ -76,9 +75,6 @@ public class ArtifactCompileScope { boolean useCustomContentId, final boolean forceArtifactBuild) { baseScope.putUserData(ARTIFACTS_KEY, artifacts.toArray(new Artifact[artifacts.size()])); - if (useCustomContentId) { - baseScope.putUserData(CompilerManager.CONTENT_ID_KEY, ARTIFACTS_CONTENT_ID_KEY); - } if (forceArtifactBuild) { baseScope.putUserData(FORCE_ARTIFACT_BUILD, Boolean.TRUE); } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProvider.java b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProvider.java index e0342ebf23e6..873cd5510a9e 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProvider.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProvider.java @@ -164,7 +164,7 @@ public class BuildArtifactsBeforeRunTaskProvider extends BeforeRunTaskProvider result = Ref.create(false); final Semaphore finished = new Semaphore(); @@ -195,7 +195,9 @@ public class BuildArtifactsBeforeRunTaskProvider extends BeforeRunTaskProvider CONTENT_ID_KEY = Key.create("COMPILATION_CONTENT_ID_CUSTOM_KEY"); public static final NotificationGroup NOTIFICATION_GROUP = NotificationGroup.logOnlyGroup("Compiler"); diff --git a/java/execution/impl/src/com/intellij/compiler/options/CompileStepBeforeRun.java b/java/execution/impl/src/com/intellij/compiler/options/CompileStepBeforeRun.java index d397f0d1d005..749230ab4a39 100644 --- a/java/execution/impl/src/com/intellij/compiler/options/CompileStepBeforeRun.java +++ b/java/execution/impl/src/com/intellij/compiler/options/CompileStepBeforeRun.java @@ -152,6 +152,7 @@ public class CompileStepBeforeRun extends BeforeRunTaskProvider EXECUTION_SESSION_ID_KEY = Key.create("EXECUTION_SESSION_ID_KEY"); + private static final AtomicLong myIdHolder = new AtomicLong(1L); @NotNull private final Project myProject; diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java index 959ebd206b52..d80bbc500c4a 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java @@ -41,6 +41,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Trinity; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFileManager; @@ -141,6 +142,7 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom if (!activeTasks.isEmpty()) { final long finalId = id; + final Key executionSessionId = Key.create("execution_session_id"); ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { /** @noinspection SSBasedInspection*/ @Override @@ -156,6 +158,7 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom } ExecutionEnvironment taskEnvironment = new ExecutionEnvironmentBuilder(env).setContentToReuse(null).build(); taskEnvironment.setExecutionId(finalId); + ExecutionEnvironment.EXECUTION_SESSION_ID_KEY.set(taskEnvironment, executionSessionId); if (!provider.executeTask(projectContext, runConfiguration, taskEnvironment, task)) { if (onCancelRunnable != null) { SwingUtilities.invokeLater(onCancelRunnable);