IDEA-122208 Previous errors are sometimes stuck in errors view

This commit is contained in:
Eugene Zhuravlev
2014-03-21 17:25:05 +04:00
parent d4878138fd
commit 2f2c69874c
8 changed files with 40 additions and 15 deletions
@@ -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);
@@ -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<Key<?>> CONTENT_ID_KEY = Key.create("CONTENT_ID");
private static final Key<Key<?>> SESSION_ID_KEY = Key.create("SESSION_ID");
private static final String APP_ICON_ID = "compiler";
private Key<Key<?>> myContentIdKey = CONTENT_ID_KEY;
private final Key<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<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);
}
}
@@ -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);
}
@@ -164,7 +164,7 @@ public class BuildArtifactsBeforeRunTaskProvider extends BeforeRunTaskProvider<B
public boolean executeTask(DataContext context,
RunConfiguration configuration,
ExecutionEnvironment env,
final ExecutionEnvironment env,
final BuildArtifactsBeforeRunTask task) {
final Ref<Boolean> result = Ref.create(false);
final Semaphore finished = new Semaphore();
@@ -195,7 +195,9 @@ public class BuildArtifactsBeforeRunTaskProvider extends BeforeRunTaskProvider<B
public void run() {
final CompilerManager manager = CompilerManager.getInstance(myProject);
finished.down();
manager.make(ArtifactCompileScope.createArtifactsScope(myProject, artifacts), compilerFilter, callback);
final CompileScope scope = ArtifactCompileScope.createArtifactsScope(myProject, artifacts);
ExecutionEnvironment.EXECUTION_SESSION_ID_KEY.set(scope, ExecutionEnvironment.EXECUTION_SESSION_ID_KEY.get(env));
manager.make(scope, compilerFilter, callback);
}
}, ModalityState.NON_MODAL);
@@ -34,6 +34,7 @@ import java.util.Set;
* and invoke various types of compilations (make, compile, rebuild)
*/
public abstract class CompilerManager {
@Deprecated
public static final Key<Key> CONTENT_ID_KEY = Key.create("COMPILATION_CONTENT_ID_CUSTOM_KEY");
public static final NotificationGroup NOTIFICATION_GROUP = NotificationGroup.logOnlyGroup("Compiler");
@@ -152,6 +152,7 @@ public class CompileStepBeforeRun extends BeforeRunTaskProvider<CompileStepBefor
if (!myProject.isDisposed()) {
scope.putUserData(RUN_CONFIGURATION, configuration);
scope.putUserData(RUN_CONFIGURATION_TYPE_ID, configuration.getType().getId());
ExecutionEnvironment.EXECUTION_SESSION_ID_KEY.set(scope, ExecutionEnvironment.EXECUTION_SESSION_ID_KEY.get(env));
compilerManager.make(scope, callback);
}
else {
@@ -27,6 +27,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.DataKey;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.UserDataHolderBase;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -41,6 +42,8 @@ import static com.intellij.openapi.actionSystem.LangDataKeys.*;
public class ExecutionEnvironment extends UserDataHolderBase {
public static final Key<Key> EXECUTION_SESSION_ID_KEY = Key.create("EXECUTION_SESSION_ID_KEY");
private static final AtomicLong myIdHolder = new AtomicLong(1L);
@NotNull private final Project myProject;
@@ -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);