X-Git-Url: https://git.jetbrains.org/?p=idea%2Fcommunity.git;a=blobdiff_plain;f=platform%2FtestRunner%2Fsrc%2Fcom%2Fintellij%2Fexecution%2Ftestframework%2Fautotest%2FAutoTestManager.java;h=f817967cf63fd6a684219c3299919e94847d19d9;hp=7a9b062290828fd2c800da66fed8eb9a6c0aa0d6;hb=a9629a157512b06751aa203b41dd0638d3be43a8;hpb=61ead5131db764000ec2ff43e3d91f64f8cfc0ef diff --git a/platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java b/platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java index 7a9b06229082..f817967cf63f 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java @@ -15,8 +15,10 @@ */ package com.intellij.execution.testframework.autotest; -import com.intellij.execution.DelayedDocumentWatcher; -import com.intellij.execution.ExecutionManager; +import com.intellij.execution.*; +import com.intellij.execution.configurations.RunConfiguration; +import com.intellij.execution.configurations.RunProfile; +import com.intellij.execution.impl.RunManagerImpl; import com.intellij.execution.process.ProcessAdapter; import com.intellij.execution.process.ProcessEvent; import com.intellij.execution.process.ProcessHandler; @@ -31,7 +33,7 @@ import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.components.*; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; @@ -39,24 +41,35 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.content.Content; import com.intellij.util.Consumer; +import com.intellij.util.ObjectUtils; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.xmlb.annotations.AbstractCollection; +import com.intellij.util.xmlb.annotations.Attribute; +import com.intellij.util.xmlb.annotations.Tag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.List; +import java.util.Set; /** * @author yole */ -public class AutoTestManager { +@State( + name = "AutoTestManager", + storages = {@Storage(StoragePathMacros.WORKSPACE_FILE)} +) +public class AutoTestManager implements PersistentStateComponent { private static final String AUTO_TEST_MANAGER_DELAY = "auto.test.manager.delay"; private static final int AUTO_TEST_MANAGER_DELAY_DEFAULT = 3000; private static final Key ON_TERMINATION_RESTARTER_KEY = Key.create("auto.test.manager.on.termination.restarter"); - private static final Key EXECUTION_ENVIRONMENT_KEY = Key.create("auto.test.manager.execution.environment"); private final Project myProject; private int myDelayMillis; private DelayedDocumentWatcher myDocumentWatcher; + private final Set myEnabledRunProfiles = ContainerUtil.newHashSet(); @NotNull public static AutoTestManager getInstance(Project project) { @@ -92,11 +105,11 @@ public class AutoTestManager { Content content = descriptor.getAttachedContent(); if (content != null) { if (enabled) { - EXECUTION_ENVIRONMENT_KEY.set(content, environment); + myEnabledRunProfiles.add(environment.getRunProfile()); myDocumentWatcher.activate(); } else { - EXECUTION_ENVIRONMENT_KEY.set(content, null); + myEnabledRunProfiles.remove(environment.getRunProfile()); if (!hasEnabledAutoTests()) { myDocumentWatcher.deactivate(); } @@ -122,19 +135,11 @@ public class AutoTestManager { return isAutoTestEnabledForDescriptor(descriptor); } - private static boolean isAutoTestEnabledForDescriptor(@NotNull RunContentDescriptor descriptor) { + private boolean isAutoTestEnabledForDescriptor(@NotNull RunContentDescriptor descriptor) { Content content = descriptor.getAttachedContent(); if (content != null) { - ExecutionEnvironment watched = EXECUTION_ENVIRONMENT_KEY.get(content); - if (watched != null) { - ExecutionEnvironment current = getCurrentEnvironment(content); - boolean result = current != null && equals(current, watched); - if (!result) { - // let GC do its work - EXECUTION_ENVIRONMENT_KEY.set(content, null); - } - return result; - } + ExecutionEnvironment environment = getCurrentEnvironment(content); + return environment != null && myEnabledRunProfiles.contains(environment.getRunProfile()); } return false; } @@ -148,13 +153,6 @@ public class AutoTestManager { return LangDataKeys.EXECUTION_ENVIRONMENT.getData(DataManager.getInstance().getDataContext(component)); } - private static boolean equals(@NotNull ExecutionEnvironment env1, @NotNull ExecutionEnvironment env2) { - return env1.getRunProfile() == env2.getRunProfile() && - env1.getRunner() == env2.getRunner() && - env1.getExecutor() == env2.getExecutor() && - env1.getExecutionTarget() == env2.getExecutionTarget(); - } - private static void clearRestarterListener(@NotNull ProcessHandler processHandler) { ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler, null); if (restarterListener != null) { @@ -177,9 +175,9 @@ public class AutoTestManager { } } - private static void restartAutoTest(@NotNull RunContentDescriptor descriptor, - int modificationStamp, - @NotNull DelayedDocumentWatcher documentWatcher) { + private void restartAutoTest(@NotNull RunContentDescriptor descriptor, + int modificationStamp, + @NotNull DelayedDocumentWatcher documentWatcher) { ProcessHandler processHandler = descriptor.getProcessHandler(); if (processHandler != null && !processHandler.isProcessTerminated()) { scheduleRestartOnTermination(descriptor, processHandler, modificationStamp, documentWatcher); @@ -189,10 +187,10 @@ public class AutoTestManager { } } - private static void scheduleRestartOnTermination(@NotNull final RunContentDescriptor descriptor, - @NotNull final ProcessHandler processHandler, - final int modificationStamp, - @NotNull final DelayedDocumentWatcher documentWatcher) { + private void scheduleRestartOnTermination(@NotNull final RunContentDescriptor descriptor, + @NotNull final ProcessHandler processHandler, + final int modificationStamp, + @NotNull final DelayedDocumentWatcher documentWatcher) { ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler); if (restarterListener != null) { clearRestarterListener(processHandler); @@ -234,4 +232,51 @@ public class AutoTestManager { } PropertiesComponent.getInstance(myProject).setValue(AUTO_TEST_MANAGER_DELAY, myDelayMillis, AUTO_TEST_MANAGER_DELAY_DEFAULT); } + + @Nullable + @Override + public State getState() { + State state = new State(); + for (RunProfile profile : myEnabledRunProfiles) { + RunConfiguration runConfiguration = ObjectUtils.tryCast(profile, RunConfiguration.class); + if (runConfiguration != null) { + RunConfigurationDescriptor descriptor = new RunConfigurationDescriptor(); + descriptor.myType = runConfiguration.getType().getId(); + descriptor.myName = runConfiguration.getName(); + state.myEnabledRunConfigurations.add(descriptor); + } + } + return state; + } + + @Override + public void loadState(State state) { + List configurations = ContainerUtil.newArrayList(); + RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myProject); + for (RunConfigurationDescriptor descriptor : state.myEnabledRunConfigurations) { + RunnerAndConfigurationSettings settings = runManager.findConfigurationByTypeAndName(descriptor.myType, + descriptor.myName); + RunConfiguration configuration = settings != null ? settings.getConfiguration() : null; + if (configuration != null) { + configurations.add(configuration); + } + } + myEnabledRunProfiles.clear(); + myEnabledRunProfiles.addAll(configurations); + } + + static class State { + @Tag("enabled-run-configurations") + @AbstractCollection(surroundWithTag = false) + List myEnabledRunConfigurations = ContainerUtil.newArrayList(); + } + + @Tag("run-configuration") + static class RunConfigurationDescriptor { + @Attribute("type") + String myType; + + @Attribute("name") + String myName; + } }