replace separate run configurations with corresponding test kind; run over change list to be restored

(cherry picked from commit 2f95663)
This commit is contained in:
Anna Kozlova
2016-06-15 16:08:41 +03:00
parent ce82e7d745
commit 5020982df5
28 changed files with 472 additions and 1056 deletions
@@ -1,253 +0,0 @@
/*
* 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.application.options.ModulesComboBox;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.MethodBrowser;
import com.intellij.execution.ui.*;
import com.intellij.ide.util.ClassFilter;
import com.intellij.openapi.fileTypes.PlainTextLanguage;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.psi.JavaCodeFragment;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.EditorTextFieldWithBrowseButton;
import com.intellij.ui.PanelWithAnchor;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import static java.awt.GridBagConstraints.*;
public class TestDiscoveryConfigurable<T extends TestDiscoveryConfiguration> extends SettingsEditor<T> implements PanelWithAnchor {
private final ConfigurationModuleSelector myModuleSelector;
// Fields
private JPanel myWholePanel = new JPanel(new BorderLayout());
private LabeledComponent<ModulesComboBox> myModule = new LabeledComponent<ModulesComboBox>();
private CommonJavaParametersPanel myCommonJavaParameters = new CommonJavaParametersPanel();
private JrePathEditor myJrePathEditor;
private LabeledComponent<EditorTextFieldWithBrowseButton> myClass = new LabeledComponent<EditorTextFieldWithBrowseButton>();
private LabeledComponent<EditorTextFieldWithBrowseButton> myMethod = new LabeledComponent<EditorTextFieldWithBrowseButton>();
private ComboBox myChangeLists = new ComboBox();
private JRadioButton myPositionRb = new JRadioButton("Tests for method:");
private JRadioButton myChangesRb = new JRadioButton("Tests for change list:");
private JComponent anchor;
public TestDiscoveryConfigurable(final Project project) {
myModule.setText(ExecutionBundle.message("application.configuration.use.classpath.and.jdk.of.module.label"));
myModule.setLabelLocation(BorderLayout.WEST);
myModule.setComponent(new ModulesComboBox());
myModuleSelector = new ConfigurationModuleSelector(project, getModulesComponent());
myCommonJavaParameters.setModuleContext(myModuleSelector.getModule());
myCommonJavaParameters.setHasModuleMacro();
myModule.getComponent().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myCommonJavaParameters.setModuleContext(myModuleSelector.getModule());
}
});
final JPanel panelWithSettings = new JPanel(new GridBagLayout());
final GridBagConstraints gc = new GridBagConstraints(0, RELATIVE, 1, 1, 1, 0, NORTHWEST, HORIZONTAL, JBUI.emptyInsets(), 0, 0);
panelWithSettings.add(myPositionRb, gc);
myClass.setText("Class:");
final ClassBrowser classBrowser = new ClassBrowser(project, "Choose Class") {
@Override
protected ClassFilter.ClassFilterWithScope getFilter() throws NoFilterException {
return new ClassFilter.ClassFilterWithScope() {
@Override
public GlobalSearchScope getScope() {
return GlobalSearchScope.allScope(project);
}
@Override
public boolean isAccepted(PsiClass aClass) {
return true;
}
};
}
@Override
protected PsiClass findClass(String className) {
return JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
}
};
final EditorTextFieldWithBrowseButton classComponent = new EditorTextFieldWithBrowseButton(project, true);
myClass.setComponent(classComponent);
classBrowser.setField(classComponent);
panelWithSettings.add(myClass, gc);
myMethod.setText("Method:");
final EditorTextFieldWithBrowseButton textFieldWithBrowseButton = new EditorTextFieldWithBrowseButton(project, true,
JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE,
PlainTextLanguage.INSTANCE.getAssociatedFileType());
myMethod.setComponent(textFieldWithBrowseButton);
final MethodBrowser methodBrowser = new MethodBrowser(project) {
protected Condition<PsiMethod> getFilter(final PsiClass testClass) {
return method -> method.getContainingClass() == testClass;
}
@Override
protected String getClassName() {
return myClass.getComponent().getText().trim();
}
@Override
protected ConfigurationModuleSelector getModuleSelector() {
return myModuleSelector;
}
};
methodBrowser.setField(textFieldWithBrowseButton);
methodBrowser.installCompletion(textFieldWithBrowseButton.getChildComponent());
panelWithSettings.add(myMethod, gc);
panelWithSettings.add(myChangesRb, gc);
panelWithSettings.add(myChangeLists, gc);
ButtonGroup gr = new ButtonGroup();
gr.add(myPositionRb);
gr.add(myChangesRb);
final ActionListener l = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateComponents();
}
};
myPositionRb.addActionListener(l);
myChangesRb.addActionListener(l);
final List<LocalChangeList> changeLists = ChangeListManager.getInstance(project).getChangeLists();
final DefaultComboBoxModel model = new DefaultComboBoxModel();
model.addElement("All");
for (LocalChangeList changeList : changeLists) {
model.addElement(changeList.getName());
}
myChangeLists.setModel(model);
ChangeListManager changeListManager = ChangeListManager.getInstance(project);
if (changeListManager.getAffectedFiles().isEmpty()) {
myChangesRb.setEnabled(false);
}
myWholePanel.add(panelWithSettings, BorderLayout.NORTH);
myWholePanel.add(myCommonJavaParameters, BorderLayout.CENTER);
final JPanel classpathPanel = new JPanel(new BorderLayout());
myWholePanel.add(classpathPanel, BorderLayout.SOUTH);
classpathPanel.add(myModule, BorderLayout.NORTH);
myJrePathEditor = new JrePathEditor(DefaultJreSelector.fromModuleDependencies(getModulesComponent(), false));
classpathPanel.add(myJrePathEditor, BorderLayout.CENTER);
UIUtil.setEnabled(myCommonJavaParameters.getProgramParametersComponent(), false, true);
setAnchor(myModule.getLabel());
myJrePathEditor.setAnchor(myModule.getLabel());
myCommonJavaParameters.setAnchor(myModule.getLabel());
}
private void updateComponents() {
myClass.setEnabled(myPositionRb.isSelected());
myMethod.setEnabled(myPositionRb.isSelected());
myChangeLists.setEnabled(myChangesRb.isSelected());
}
public void applyEditorTo(final TestDiscoveryConfiguration configuration) {
applyHelpersTo(configuration);
configuration.setAlternativeJrePath(myJrePathEditor.getJrePathOrName());
configuration.setAlternativeJrePathEnabled(myJrePathEditor.isAlternativeJreSelected());
configuration.setPosition(myPositionRb.isSelected() ? Pair.create(myClass.getComponent().getText().trim(),
myMethod.getComponent().getText().trim()) : null);
if (myChangesRb.isSelected()) {
final Object selectedItem = myChangeLists.getSelectedItem();
configuration.setChangeList("All".equals(selectedItem) ? null : (String)selectedItem);
}
else {
configuration.setChangeList(null);
}
myCommonJavaParameters.applyTo(configuration);
}
public void resetEditorFrom(final TestDiscoveryConfiguration configuration) {
myCommonJavaParameters.reset(configuration);
getModuleSelector().reset(configuration);
myJrePathEditor
.setPathOrName(configuration.getAlternativeJrePath(), configuration.isAlternativeJrePathEnabled());
final Pair<String, String> position = configuration.getPosition();
if (position != null) {
myPositionRb.setSelected(true);
myClass.getComponent().setText(position.first);
myMethod.getComponent().setText(position.second);
}
else if (myChangesRb.isEnabled()) {
myChangesRb.setSelected(true);
}
else {
myPositionRb.setSelected(true);
}
final String changeList = configuration.getChangeList();
if (changeList != null) {
myChangeLists.setSelectedItem(changeList);
}
else if (myChangesRb.isEnabled()) {
myChangeLists.setSelectedIndex(0);
}
updateComponents();
}
public ModulesComboBox getModulesComponent() {
return myModule.getComponent();
}
public ConfigurationModuleSelector getModuleSelector() {
return myModuleSelector;
}
@Override
public JComponent getAnchor() {
return anchor;
}
@Override
public void setAnchor(JComponent anchor) {
this.anchor = anchor;
}
@NotNull
public JComponent createEditor() {
return myWholePanel;
}
private void applyHelpersTo(final TestDiscoveryConfiguration currentState) {
myCommonJavaParameters.applyTo(currentState);
getModuleSelector().applyTo(currentState);
}
}
@@ -1,234 +0,0 @@
/*
* Copyright 2000-2015 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.diagnostic.logging.LogConfigurationPanel;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.Executor;
import com.intellij.execution.JavaRunConfigurationExtensionManager;
import com.intellij.execution.JavaTestConfigurationBase;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.JavaRunConfigurationModule;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.options.SettingsEditorGroup;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
public abstract class TestDiscoveryConfiguration extends JavaTestConfigurationBase {
private String myChangeList;
private Pair<String, String> myPosition;
protected JavaTestConfigurationBase myDelegate;
public TestDiscoveryConfiguration(String name,
@NotNull JavaRunConfigurationModule configurationModule,
@NotNull ConfigurationFactory factory,
JavaTestConfigurationBase delegate) {
super(name, configurationModule, factory);
myDelegate = delegate;
}
@Override
public void setVMParameters(String value) {
myDelegate.setVMParameters(value);
}
@Override
public String getVMParameters() {
return myDelegate.getVMParameters();
}
@Override
public boolean isAlternativeJrePathEnabled() {
return myDelegate.isAlternativeJrePathEnabled();
}
@Override
public void setAlternativeJrePathEnabled(boolean enabled) {
myDelegate.setAlternativeJrePathEnabled(enabled);
}
@Override
@Nullable
public String getAlternativeJrePath() {
return myDelegate.getAlternativeJrePath();
}
@Override
public void setAlternativeJrePath(String path) {
myDelegate.setAlternativeJrePath(path);
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
if (myPosition == null &&
myChangeList != null && ChangeListManager.getInstance(getProject()).findChangeList(myChangeList) == null) {
throw new RuntimeConfigurationException("Change list " + myChangeList + " doesn't exist");
}
if (myPosition != null) {
if (StringUtil.isEmptyOrSpaces(myPosition.first)) {
throw new RuntimeConfigurationException("No class specified");
}
if (StringUtil.isEmptyOrSpaces(myPosition.second)) {
throw new RuntimeConfigurationException("No method specified");
}
}
JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);
}
@Override
public Collection<Module> getValidModules() {
return Arrays.asList(ModuleManager.getInstance(getProject()).getModules());
}
@NotNull
@Override
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
SettingsEditorGroup<TestDiscoveryConfiguration> group = new SettingsEditorGroup<TestDiscoveryConfiguration>();
group.addEditor(ExecutionBundle.message("run.configuration.configuration.tab.title"),
new TestDiscoveryConfigurable<TestDiscoveryConfiguration>(getProject()));
JavaRunConfigurationExtensionManager.getInstance().appendEditors(this, group);
group.addEditor(ExecutionBundle.message("logs.tab.title"), new LogConfigurationPanel<TestDiscoveryConfiguration>());
return group;
}
@Override
public void readExternal(Element element) throws InvalidDataException {
myDelegate.readExternal(element);
super.readExternal(element);
readModule(element);
final String classQName = element.getAttributeValue("class");
final String methodName = element.getAttributeValue("method");
myPosition = classQName != null && methodName != null ? Pair.create(classQName, methodName) : null;
myChangeList = element.getAttributeValue("changeList");
if ("All".equals(myChangeList)) {
myChangeList = null;
}
}
@Override
public void setModule(Module module) {
super.setModule(module);
myDelegate.setModule(module);
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
myDelegate.writeExternal(element);
super.writeExternal(element);
writeModule(element);
if (myPosition != null) {
element.setAttribute("class", myPosition.first);
element.setAttribute("method", myPosition.second);
}
element.setAttribute("changeList", myChangeList == null ? "All" : myChangeList);
}
@Nullable
@Override
public String getRunClass() {
return null;
}
@Nullable
@Override
public String getPackage() {
return "";
}
@Override
public void setProgramParameters(@Nullable String value) {
myDelegate.setProgramParameters(value);
}
@Override
@Nullable
public String getProgramParameters() {
return myDelegate.getProgramParameters();
}
@Override
public void setWorkingDirectory(@Nullable String value) {
myDelegate.setWorkingDirectory(value);
}
@Override
@Nullable
public String getWorkingDirectory() {
return myDelegate.getWorkingDirectory();
}
@Override
public void setEnvs(@NotNull Map<String, String> envs) {
myDelegate.setEnvs(envs);
}
@Override
@NotNull
public Map<String, String> getEnvs() {
return myDelegate.getEnvs();
}
@Override
public void setPassParentEnvs(boolean passParentEnvs) {
myDelegate.setPassParentEnvs(passParentEnvs);
}
@Override
public boolean isPassParentEnvs() {
return myDelegate.isPassParentEnvs();
}
@Override
public SMTRunnerConsoleProperties createTestConsoleProperties(Executor executor) {
return myDelegate.createTestConsoleProperties(executor);
}
public void setPosition(Pair<String, String> position) {
myPosition = position;
}
public void setChangeList(String changeList) {
myChangeList = changeList;
}
public Pair<String, String> getPosition() {
return myPosition;
}
public String getChangeList() {
return myChangeList;
}
}
@@ -16,9 +16,7 @@
package com.intellij.execution.testDiscovery;
import com.intellij.codeInsight.TestFrameworks;
import com.intellij.execution.JavaExecutionUtil;
import com.intellij.execution.Location;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.*;
import com.intellij.execution.actions.ConfigurationContext;
import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.execution.configurations.ModuleBasedConfiguration;
@@ -45,13 +43,17 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
public abstract class TestDiscoveryConfigurationProducer extends JavaRunConfigurationProducerBase<TestDiscoveryConfiguration> {
public abstract class TestDiscoveryConfigurationProducer extends JavaRunConfigurationProducerBase<JavaTestConfigurationBase> {
protected TestDiscoveryConfigurationProducer(ConfigurationType type) {
super(type);
}
protected abstract void setPosition(JavaTestConfigurationBase configuration, PsiLocation<PsiMethod> position);
protected abstract Pair<String, String> getPosition(JavaTestConfigurationBase configuration);
@Override
protected boolean setupConfigurationFromContext(final TestDiscoveryConfiguration configuration,
protected boolean setupConfigurationFromContext(final JavaTestConfigurationBase configuration,
ConfigurationContext configurationContext,
Ref<PsiElement> ref) {
if (!Registry.is("testDiscovery.enabled")) {
@@ -61,8 +63,9 @@ public abstract class TestDiscoveryConfigurationProducer extends JavaRunConfigur
assert contextLocation != null;
final Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
if (location == null) return false;
final Pair<String, String> position = getPosition(location);
if (position != null) {
final PsiMethod sourceMethod = getSourceMethod(location);
final Pair<String, String> position = getPosition(sourceMethod);
if (sourceMethod != null && position != null) {
try {
final Project project = configuration.getProject();
final TestDiscoveryIndex testDiscoveryIndex = TestDiscoveryIndex.getInstance(project);
@@ -71,7 +74,7 @@ public abstract class TestDiscoveryConfigurationProducer extends JavaRunConfigur
ContainerUtil.filter(testsByMethodName, s -> s.startsWith(configuration.getFrameworkPrefix())).isEmpty()) {
return false;
}
configuration.setPosition(position);
setPosition(configuration, new PsiLocation<PsiMethod>(sourceMethod));
configuration.setName("Tests for " + StringUtil.getShortName(position.first) + "." + position.second);
final RunnerAndConfigurationSettings template =
@@ -111,11 +114,11 @@ public abstract class TestDiscoveryConfigurationProducer extends JavaRunConfigur
}
@Override
protected Module findModule(TestDiscoveryConfiguration configuration, Module contextModule) {
protected Module findModule(JavaTestConfigurationBase configuration, Module contextModule) {
return null;
}
private static Pair<String, String> getPosition(Location location) {
private static PsiMethod getSourceMethod(Location location) {
final PsiElement psiElement = location.getPsiElement();
final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(psiElement, PsiMethod.class);
if (psiMethod != null) {
@@ -125,18 +128,27 @@ public abstract class TestDiscoveryConfigurationProducer extends JavaRunConfigur
if (testFramework != null) {
return null;
}
final String qualifiedName = containingClass.getQualifiedName();
if (qualifiedName != null) {
return Pair.create(qualifiedName, psiMethod.getName());
}
return psiMethod;
}
}
return null;
}
private static Pair<String, String> getPosition(PsiMethod method) {
if (method == null) {
return null;
}
final PsiClass containingClass = method.getContainingClass();
final String qualifiedName = containingClass.getQualifiedName();
if (qualifiedName != null) {
return Pair.create(qualifiedName, method.getName());
}
return null;
}
@Override
public boolean isConfigurationFromContext(TestDiscoveryConfiguration configuration, ConfigurationContext configurationContext) {
final Pair<String, String> position = getPosition(configurationContext.getLocation());
return position != null && position.equals(configuration.getPosition());
public boolean isConfigurationFromContext(JavaTestConfigurationBase configuration, ConfigurationContext configurationContext) {
final Pair<String, String> position = getPosition(getSourceMethod(configurationContext.getLocation()));
return position != null && position.equals(getPosition(configuration));
}
}