mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
rerun java test configuration on make completed without errors
(cherry picked from commit 7058066)
This commit is contained in:
@@ -23,8 +23,11 @@ import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.testDiscovery.JavaAutoRunManager;
|
||||
import com.intellij.execution.testframework.*;
|
||||
import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction;
|
||||
import com.intellij.execution.testframework.autotest.AbstractAutoTestManager;
|
||||
import com.intellij.execution.testframework.autotest.ToggleAutoTestAction;
|
||||
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil;
|
||||
import com.intellij.execution.testframework.sm.runner.SMRunnerConsolePropertiesProvider;
|
||||
import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties;
|
||||
@@ -167,7 +170,12 @@ public abstract class JavaTestFrameworkRunnableState<T extends
|
||||
rerunFailedTestsAction.setModelProvider(() -> viewer);
|
||||
|
||||
final DefaultExecutionResult result = new DefaultExecutionResult(consoleView, handler);
|
||||
result.setRestartActions(rerunFailedTestsAction);
|
||||
result.setRestartActions(rerunFailedTestsAction, new ToggleAutoTestAction() {
|
||||
@Override
|
||||
public AbstractAutoTestManager getAutoTestManager(Project project) {
|
||||
return JavaAutoRunManager.getInstance(project);
|
||||
}
|
||||
});
|
||||
|
||||
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, runnerSettings);
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.execution.testDiscovery;
|
||||
|
||||
import com.intellij.execution.testframework.autotest.AbstractAutoTestManager;
|
||||
import com.intellij.execution.testframework.autotest.AutoTestWatcher;
|
||||
import com.intellij.openapi.compiler.CompilationStatusListener;
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.compiler.CompilerManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StoragePathMacros;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@State(
|
||||
name = "JavaAutoRunManager",
|
||||
storages = {@Storage(StoragePathMacros.WORKSPACE_FILE)}
|
||||
)
|
||||
public class JavaAutoRunManager extends AbstractAutoTestManager {
|
||||
@NotNull
|
||||
public static JavaAutoRunManager getInstance(Project project) {
|
||||
return ServiceManager.getService(project, JavaAutoRunManager.class);
|
||||
}
|
||||
|
||||
public JavaAutoRunManager(@NotNull Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected AutoTestWatcher createWatcher(Project project) {
|
||||
return new AutoTestWatcher() {
|
||||
private boolean myHasErrors = false;
|
||||
|
||||
private CompilationStatusListener myStatusListener;
|
||||
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
if (myStatusListener == null) {
|
||||
myStatusListener = new CompilationStatusListener() {
|
||||
@Override
|
||||
public void compilationFinished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
|
||||
if (errors == 0) {
|
||||
restartAllAutoTests(0);
|
||||
}
|
||||
myHasErrors = errors == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void automakeCompilationFinished(int errors, int warnings, CompileContext compileContext) {
|
||||
compilationFinished(false, errors, warnings, compileContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileGenerated(String outputRoot, String relativePath) {
|
||||
int a = 1;
|
||||
}
|
||||
};
|
||||
|
||||
CompilerManager.getInstance(project).addCompilationStatusListener(myStatusListener, project);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate() {
|
||||
if (myStatusListener != null) {
|
||||
CompilerManager.getInstance(project).removeCompilationStatusListener(myStatusListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpToDate(int modificationStamp) {
|
||||
return !myHasErrors;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
package com.intellij.execution;
|
||||
|
||||
import com.intellij.AppTopics;
|
||||
import com.intellij.execution.testframework.autotest.AutoTestWatcher;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
@@ -42,7 +43,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class DelayedDocumentWatcher {
|
||||
public class DelayedDocumentWatcher implements AutoTestWatcher {
|
||||
|
||||
// All instance fields are be accessed from EDT
|
||||
private final Project myProject;
|
||||
+260
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.execution.testframework.autotest;
|
||||
|
||||
import com.intellij.execution.ExecutionManager;
|
||||
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||
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;
|
||||
import com.intellij.execution.process.ProcessListener;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.runners.ExecutionUtil;
|
||||
import com.intellij.execution.ui.RunContentDescriptor;
|
||||
import com.intellij.execution.ui.RunContentManager;
|
||||
import com.intellij.ide.DataManager;
|
||||
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.PersistentStateComponent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.ui.content.Content;
|
||||
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;
|
||||
|
||||
public abstract class AbstractAutoTestManager implements PersistentStateComponent<AbstractAutoTestManager.State> {
|
||||
protected static final String AUTO_TEST_MANAGER_DELAY = "auto.test.manager.delay";
|
||||
protected static final int AUTO_TEST_MANAGER_DELAY_DEFAULT = 3000;
|
||||
private static final Key<ProcessListener> ON_TERMINATION_RESTARTER_KEY = Key.create("auto.test.manager.on.termination.restarter");
|
||||
private final Project myProject;
|
||||
private final Set<RunProfile> myEnabledRunProfiles = ContainerUtil.newHashSet();
|
||||
protected int myDelayMillis;
|
||||
private AutoTestWatcher myWatcher;
|
||||
|
||||
public AbstractAutoTestManager(@NotNull Project project) {
|
||||
myProject = project;
|
||||
myDelayMillis = PropertiesComponent.getInstance(project).getInt(AUTO_TEST_MANAGER_DELAY, AUTO_TEST_MANAGER_DELAY_DEFAULT);
|
||||
myWatcher = createWatcher(project);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ExecutionEnvironment getCurrentEnvironment(@NotNull Content content) {
|
||||
JComponent component = content.getComponent();
|
||||
if (component == null) {
|
||||
return null;
|
||||
}
|
||||
return LangDataKeys.EXECUTION_ENVIRONMENT.getData(DataManager.getInstance().getDataContext(component));
|
||||
}
|
||||
|
||||
private static void clearRestarterListener(@NotNull ProcessHandler processHandler) {
|
||||
ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler, null);
|
||||
if (restarterListener != null) {
|
||||
processHandler.removeProcessListener(restarterListener);
|
||||
ON_TERMINATION_RESTARTER_KEY.set(processHandler, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void restart(@NotNull RunContentDescriptor descriptor) {
|
||||
descriptor.setActivateToolWindowWhenAdded(false);
|
||||
descriptor.setReuseToolWindowActivation(true);
|
||||
ExecutionUtil.restart(descriptor);
|
||||
}
|
||||
|
||||
public static void saveConfigurationState(State state, RunProfile profile) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<RunConfiguration> loadConfigurations(State state, Project project) {
|
||||
List<RunConfiguration> configurations = ContainerUtil.newArrayList();
|
||||
RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
|
||||
List<RunConfigurationDescriptor> descriptors = ContainerUtil.notNullize(state.myEnabledRunConfigurations);
|
||||
for (RunConfigurationDescriptor descriptor : descriptors) {
|
||||
if (descriptor.myType != null && descriptor.myName != null) {
|
||||
RunnerAndConfigurationSettings settings = runManager.findConfigurationByTypeAndName(descriptor.myType,
|
||||
descriptor.myName);
|
||||
RunConfiguration configuration = settings != null ? settings.getConfiguration() : null;
|
||||
if (configuration != null) {
|
||||
configurations.add(configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
return configurations;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract AutoTestWatcher createWatcher(Project project);
|
||||
|
||||
public void setAutoTestEnabled(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment environment, boolean enabled) {
|
||||
Content content = descriptor.getAttachedContent();
|
||||
if (content != null) {
|
||||
if (enabled) {
|
||||
myEnabledRunProfiles.add(environment.getRunProfile());
|
||||
myWatcher.activate();
|
||||
}
|
||||
else {
|
||||
myEnabledRunProfiles.remove(environment.getRunProfile());
|
||||
if (!hasEnabledAutoTests()) {
|
||||
myWatcher.deactivate();
|
||||
}
|
||||
ProcessHandler processHandler = descriptor.getProcessHandler();
|
||||
if (processHandler != null) {
|
||||
clearRestarterListener(processHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasEnabledAutoTests() {
|
||||
RunContentManager contentManager = ExecutionManager.getInstance(myProject).getContentManager();
|
||||
for (RunContentDescriptor descriptor : contentManager.getAllDescriptors()) {
|
||||
if (isAutoTestEnabledForDescriptor(descriptor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAutoTestEnabled(@NotNull RunContentDescriptor descriptor) {
|
||||
return isAutoTestEnabledForDescriptor(descriptor);
|
||||
}
|
||||
|
||||
private boolean isAutoTestEnabledForDescriptor(@NotNull RunContentDescriptor descriptor) {
|
||||
Content content = descriptor.getAttachedContent();
|
||||
if (content != null) {
|
||||
ExecutionEnvironment environment = getCurrentEnvironment(content);
|
||||
return environment != null && myEnabledRunProfiles.contains(environment.getRunProfile());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void restartAllAutoTests(int modificationStamp) {
|
||||
RunContentManager contentManager = ExecutionManager.getInstance(myProject).getContentManager();
|
||||
boolean active = false;
|
||||
for (RunContentDescriptor descriptor : contentManager.getAllDescriptors()) {
|
||||
if (isAutoTestEnabledForDescriptor(descriptor)) {
|
||||
restartAutoTest(descriptor, modificationStamp, myWatcher);
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
if (!active) {
|
||||
myWatcher.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
private void restartAutoTest(@NotNull RunContentDescriptor descriptor,
|
||||
int modificationStamp,
|
||||
@NotNull AutoTestWatcher documentWatcher) {
|
||||
ProcessHandler processHandler = descriptor.getProcessHandler();
|
||||
if (processHandler != null && !processHandler.isProcessTerminated()) {
|
||||
scheduleRestartOnTermination(descriptor, processHandler, modificationStamp, documentWatcher);
|
||||
}
|
||||
else {
|
||||
restart(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleRestartOnTermination(@NotNull final RunContentDescriptor descriptor,
|
||||
@NotNull final ProcessHandler processHandler,
|
||||
final int modificationStamp,
|
||||
@NotNull final AutoTestWatcher watcher) {
|
||||
ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler);
|
||||
if (restarterListener != null) {
|
||||
clearRestarterListener(processHandler);
|
||||
}
|
||||
restarterListener = new ProcessAdapter() {
|
||||
@Override
|
||||
public void processTerminated(ProcessEvent event) {
|
||||
clearRestarterListener(processHandler);
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
if (isAutoTestEnabledForDescriptor(descriptor) && watcher.isUpToDate(modificationStamp)) {
|
||||
restart(descriptor);
|
||||
}
|
||||
}, ModalityState.any());
|
||||
}
|
||||
};
|
||||
ON_TERMINATION_RESTARTER_KEY.set(processHandler, restarterListener);
|
||||
processHandler.addProcessListener(restarterListener);
|
||||
}
|
||||
|
||||
int getDelay() {
|
||||
return myDelayMillis;
|
||||
}
|
||||
|
||||
void setDelay(int delay) {
|
||||
myDelayMillis = delay;
|
||||
myWatcher.deactivate();
|
||||
myWatcher = createWatcher(myProject);
|
||||
if (hasEnabledAutoTests()) {
|
||||
myWatcher.activate();
|
||||
}
|
||||
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) {
|
||||
saveConfigurationState(state, profile);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(State state) {
|
||||
List<RunConfiguration> configurations = loadConfigurations(state, myProject);
|
||||
myEnabledRunProfiles.clear();
|
||||
myEnabledRunProfiles.addAll(configurations);
|
||||
if (!configurations.isEmpty()) {
|
||||
myWatcher.activate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class State {
|
||||
@Tag("enabled-run-configurations")
|
||||
@AbstractCollection(surroundWithTag = false)
|
||||
List<AutoTestManager.RunConfigurationDescriptor> myEnabledRunConfigurations = ContainerUtil.newArrayList();
|
||||
}
|
||||
|
||||
@Tag("run-configuration")
|
||||
static class RunConfigurationDescriptor {
|
||||
@Attribute("type")
|
||||
String myType;
|
||||
|
||||
@Attribute("name")
|
||||
String myName;
|
||||
}
|
||||
}
|
||||
+6
-226
@@ -16,42 +16,11 @@
|
||||
package com.intellij.execution.testframework.autotest;
|
||||
|
||||
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;
|
||||
import com.intellij.execution.process.ProcessListener;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.runners.ExecutionUtil;
|
||||
import com.intellij.execution.ui.RunContentDescriptor;
|
||||
import com.intellij.execution.ui.RunContentManager;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.scratch.ScratchFileService;
|
||||
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.*;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
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
|
||||
@@ -60,16 +29,7 @@ import java.util.Set;
|
||||
name = "AutoTestManager",
|
||||
storages = {@Storage(StoragePathMacros.WORKSPACE_FILE)}
|
||||
)
|
||||
public class AutoTestManager implements PersistentStateComponent<AutoTestManager.State> {
|
||||
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<ProcessListener> ON_TERMINATION_RESTARTER_KEY = Key.create("auto.test.manager.on.termination.restarter");
|
||||
|
||||
private final Project myProject;
|
||||
private int myDelayMillis;
|
||||
private DelayedDocumentWatcher myDocumentWatcher;
|
||||
private final Set<RunProfile> myEnabledRunProfiles = ContainerUtil.newHashSet();
|
||||
public class AutoTestManager extends AbstractAutoTestManager {
|
||||
|
||||
@NotNull
|
||||
public static AutoTestManager getInstance(Project project) {
|
||||
@@ -77,198 +37,18 @@ public class AutoTestManager implements PersistentStateComponent<AutoTestManager
|
||||
}
|
||||
|
||||
public AutoTestManager(@NotNull Project project) {
|
||||
myProject = project;
|
||||
myDelayMillis = PropertiesComponent.getInstance(project).getInt(AUTO_TEST_MANAGER_DELAY, AUTO_TEST_MANAGER_DELAY_DEFAULT);
|
||||
myDocumentWatcher = createWatcher();
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
private DelayedDocumentWatcher createWatcher() {
|
||||
return new DelayedDocumentWatcher(myProject, myDelayMillis, modificationStamp -> restartAllAutoTests(modificationStamp), file -> {
|
||||
protected AutoTestWatcher createWatcher(Project project) {
|
||||
return new DelayedDocumentWatcher(project, myDelayMillis, this::restartAllAutoTests, file -> {
|
||||
if (ScratchFileService.getInstance().getRootType(file) != null) {
|
||||
return false;
|
||||
}
|
||||
// Vladimir.Krivosheev - I don't know, why AutoTestManager checks it, but old behavior is preserved
|
||||
return FileEditorManager.getInstance(myProject).isFileOpen(file);
|
||||
return FileEditorManager.getInstance(project).isFileOpen(file);
|
||||
});
|
||||
}
|
||||
|
||||
public void setAutoTestEnabled(@NotNull RunContentDescriptor descriptor, @NotNull ExecutionEnvironment environment, boolean enabled) {
|
||||
Content content = descriptor.getAttachedContent();
|
||||
if (content != null) {
|
||||
if (enabled) {
|
||||
myEnabledRunProfiles.add(environment.getRunProfile());
|
||||
myDocumentWatcher.activate();
|
||||
}
|
||||
else {
|
||||
myEnabledRunProfiles.remove(environment.getRunProfile());
|
||||
if (!hasEnabledAutoTests()) {
|
||||
myDocumentWatcher.deactivate();
|
||||
}
|
||||
ProcessHandler processHandler = descriptor.getProcessHandler();
|
||||
if (processHandler != null) {
|
||||
clearRestarterListener(processHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasEnabledAutoTests() {
|
||||
RunContentManager contentManager = ExecutionManager.getInstance(myProject).getContentManager();
|
||||
for (RunContentDescriptor descriptor : contentManager.getAllDescriptors()) {
|
||||
if (isAutoTestEnabledForDescriptor(descriptor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAutoTestEnabled(@NotNull RunContentDescriptor descriptor) {
|
||||
return isAutoTestEnabledForDescriptor(descriptor);
|
||||
}
|
||||
|
||||
private boolean isAutoTestEnabledForDescriptor(@NotNull RunContentDescriptor descriptor) {
|
||||
Content content = descriptor.getAttachedContent();
|
||||
if (content != null) {
|
||||
ExecutionEnvironment environment = getCurrentEnvironment(content);
|
||||
return environment != null && myEnabledRunProfiles.contains(environment.getRunProfile());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ExecutionEnvironment getCurrentEnvironment(@NotNull Content content) {
|
||||
JComponent component = content.getComponent();
|
||||
if (component == null) {
|
||||
return null;
|
||||
}
|
||||
return LangDataKeys.EXECUTION_ENVIRONMENT.getData(DataManager.getInstance().getDataContext(component));
|
||||
}
|
||||
|
||||
private static void clearRestarterListener(@NotNull ProcessHandler processHandler) {
|
||||
ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler, null);
|
||||
if (restarterListener != null) {
|
||||
processHandler.removeProcessListener(restarterListener);
|
||||
ON_TERMINATION_RESTARTER_KEY.set(processHandler, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void restartAllAutoTests(int modificationStamp) {
|
||||
RunContentManager contentManager = ExecutionManager.getInstance(myProject).getContentManager();
|
||||
boolean active = false;
|
||||
for (RunContentDescriptor descriptor : contentManager.getAllDescriptors()) {
|
||||
if (isAutoTestEnabledForDescriptor(descriptor)) {
|
||||
restartAutoTest(descriptor, modificationStamp, myDocumentWatcher);
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
if (!active) {
|
||||
myDocumentWatcher.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
else {
|
||||
restart(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
restarterListener = new ProcessAdapter() {
|
||||
@Override
|
||||
public void processTerminated(ProcessEvent event) {
|
||||
clearRestarterListener(processHandler);
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
if (isAutoTestEnabledForDescriptor(descriptor) && documentWatcher.isUpToDate(modificationStamp)) {
|
||||
restart(descriptor);
|
||||
}
|
||||
}, ModalityState.any());
|
||||
}
|
||||
};
|
||||
ON_TERMINATION_RESTARTER_KEY.set(processHandler, restarterListener);
|
||||
processHandler.addProcessListener(restarterListener);
|
||||
}
|
||||
|
||||
private static void restart(@NotNull RunContentDescriptor descriptor) {
|
||||
descriptor.setActivateToolWindowWhenAdded(false);
|
||||
descriptor.setReuseToolWindowActivation(true);
|
||||
ExecutionUtil.restart(descriptor);
|
||||
}
|
||||
|
||||
int getDelay() {
|
||||
return myDelayMillis;
|
||||
}
|
||||
|
||||
void setDelay(int delay) {
|
||||
myDelayMillis = delay;
|
||||
myDocumentWatcher.deactivate();
|
||||
myDocumentWatcher = createWatcher();
|
||||
if (hasEnabledAutoTests()) {
|
||||
myDocumentWatcher.activate();
|
||||
}
|
||||
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<RunConfiguration> configurations = ContainerUtil.newArrayList();
|
||||
RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myProject);
|
||||
List<RunConfigurationDescriptor> descriptors = ContainerUtil.notNullize(state.myEnabledRunConfigurations);
|
||||
for (RunConfigurationDescriptor descriptor : descriptors) {
|
||||
if (descriptor.myType != null && descriptor.myName != null) {
|
||||
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<RunConfigurationDescriptor> myEnabledRunConfigurations = ContainerUtil.newArrayList();
|
||||
}
|
||||
|
||||
@Tag("run-configuration")
|
||||
static class RunConfigurationDescriptor {
|
||||
@Attribute("type")
|
||||
String myType;
|
||||
|
||||
@Attribute("name")
|
||||
String myName;
|
||||
}
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.execution.testframework.autotest;
|
||||
|
||||
public interface AutoTestWatcher {
|
||||
void activate();
|
||||
void deactivate();
|
||||
|
||||
boolean isUpToDate(int modificationStamp);
|
||||
}
|
||||
+6
-2
@@ -32,7 +32,7 @@ public class ToggleAutoTestAction extends ToggleAction {
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
RunContentDescriptor descriptor = e.getData(LangDataKeys.RUN_CONTENT_DESCRIPTOR);
|
||||
return project != null && descriptor != null && AutoTestManager.getInstance(project).isAutoTestEnabled(descriptor);
|
||||
return project != null && descriptor != null && getAutoTestManager(project).isAutoTestEnabled(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,7 +41,11 @@ public class ToggleAutoTestAction extends ToggleAction {
|
||||
RunContentDescriptor descriptor = e.getData(LangDataKeys.RUN_CONTENT_DESCRIPTOR);
|
||||
ExecutionEnvironment environment = e.getData(LangDataKeys.EXECUTION_ENVIRONMENT);
|
||||
if (project != null && descriptor != null && environment != null) {
|
||||
AutoTestManager.getInstance(project).setAutoTestEnabled(descriptor, environment, state);
|
||||
getAutoTestManager(project).setAutoTestEnabled(descriptor, environment, state);
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractAutoTestManager getAutoTestManager(Project project) {
|
||||
return AutoTestManager.getInstance(project);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,6 +443,9 @@
|
||||
<applicationService serviceInterface="com.intellij.codeInsight.TestFrameworks"
|
||||
serviceImplementation="com.intellij.codeInsight.TestFrameworksImpl"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.execution.testDiscovery.JavaAutoRunManager"
|
||||
serviceImplementation="com.intellij.execution.testDiscovery.JavaAutoRunManager"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.ide.util.TreeClassChooserFactory"
|
||||
serviceImplementation="com.intellij.ide.util.TreeClassChooserFactoryImpl"/>
|
||||
<projectService serviceInterface="com.intellij.psi.JavaPsiFacade"
|
||||
|
||||
Reference in New Issue
Block a user