mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
-253
@@ -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);
|
||||
}
|
||||
}
|
||||
-234
@@ -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;
|
||||
}
|
||||
}
|
||||
+29
-17
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@
|
||||
<programRunner implementation="com.intellij.execution.junit.JUnitDebuggerRunner"/>
|
||||
<codeInsight.externalLibraryResolver implementation="com.intellij.execution.junit.codeInsight.JUnitExternalLibraryResolver"/>
|
||||
<junitListener implementation="com.intellij.junit4.JUnitTestDiscoveryListener"/>
|
||||
<configurationType implementation="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationType"/>
|
||||
<runConfigurationProducer implementation="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer"/>
|
||||
</extensions>
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ public class JUnitConfiguration extends JavaTestConfigurationBase {
|
||||
@NonNls public static final String TEST_DIRECTORY = "directory";
|
||||
@NonNls public static final String TEST_CATEGORY = "category";
|
||||
@NonNls public static final String TEST_METHOD = "method";
|
||||
@NonNls public static final String BY_SOURCE_POSITION = "source location";
|
||||
|
||||
//fork modes
|
||||
@NonNls public static final String FORK_NONE = "none";
|
||||
@@ -288,6 +289,11 @@ public class JUnitConfiguration extends JavaTestConfigurationBase {
|
||||
setGeneratedName();
|
||||
}
|
||||
|
||||
public void beFromSourcePosition(PsiLocation<PsiMethod> sourceLocation) {
|
||||
myData.setTestMethod(sourceLocation);
|
||||
myData.TEST_OBJECT = BY_SOURCE_POSITION;
|
||||
}
|
||||
|
||||
public void setMainClass(final PsiClass testClass) {
|
||||
final boolean shouldUpdateName = isGeneratedName();
|
||||
setModule(myData.setMainClass(testClass));
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.intellij.execution.junit;
|
||||
|
||||
import com.intellij.execution.JavaTestFrameworkDebuggerRunner;
|
||||
import com.intellij.execution.configurations.RunProfile;
|
||||
import com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -26,8 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class JUnitDebuggerRunner extends JavaTestFrameworkDebuggerRunner {
|
||||
@Override
|
||||
protected boolean validForProfile(@NotNull RunProfile profile) {
|
||||
return profile instanceof JUnitConfiguration ||
|
||||
profile instanceof JUnitTestDiscoveryConfiguration;
|
||||
return profile instanceof JUnitConfiguration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.configurations.ParametersList;
|
||||
import com.intellij.execution.configurations.RunnerSettings;
|
||||
import com.intellij.execution.configurations.RuntimeConfigurationException;
|
||||
import com.intellij.execution.junit.testDiscovery.TestBySource;
|
||||
import com.intellij.execution.junit2.TestProxy;
|
||||
import com.intellij.execution.junit2.segments.DeferredActionsQueue;
|
||||
import com.intellij.execution.junit2.segments.DeferredActionsQueueImpl;
|
||||
@@ -100,6 +101,9 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
|
||||
if (JUnitConfiguration.TEST_PATTERN.equals(id)) {
|
||||
return new TestsPattern(configuration, environment);
|
||||
}
|
||||
if (JUnitConfiguration.BY_SOURCE_POSITION.equals(id)) {
|
||||
return new TestBySource(configuration, environment);
|
||||
}
|
||||
LOG.error(MESSAGE + id);
|
||||
return null;
|
||||
}
|
||||
|
||||
-147
@@ -1,147 +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.junit.testDiscovery;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.Executor;
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
import com.intellij.execution.junit.JUnitConfigurationType;
|
||||
import com.intellij.execution.junit.TestObject;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoveryConfiguration;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoverySearchHelper;
|
||||
import com.intellij.execution.testframework.SearchForTestsTask;
|
||||
import com.intellij.execution.testframework.SourceScope;
|
||||
import com.intellij.execution.testframework.TestSearchScope;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.util.FunctionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class JUnitTestDiscoveryConfiguration extends TestDiscoveryConfiguration {
|
||||
|
||||
public JUnitTestDiscoveryConfiguration(String name, Project project, ConfigurationFactory factory) {
|
||||
super(name, new JavaRunConfigurationModule(project, false), factory,
|
||||
new JUnitConfiguration("", project, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
|
||||
return new JUnitTestDiscoveryRunnableState(environment);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RefactoringElementListener getRefactoringElementListener(PsiElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFrameworkPrefix() {
|
||||
return "j";
|
||||
}
|
||||
|
||||
private class JUnitTestDiscoveryRunnableState extends TestObject {
|
||||
public JUnitTestDiscoveryRunnableState(ExecutionEnvironment environment) {
|
||||
super(((JUnitConfiguration)myDelegate), environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestSearchScope getScope() {
|
||||
return getConfigurationModule().getModule() != null ? TestSearchScope.MODULE_WITH_DEPENDENCIES : TestSearchScope.WHOLE_PROJECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean forkPerModule() {
|
||||
return getConfigurationModule().getModule() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PsiElement retrievePsiElement(Object pattern) {
|
||||
if (pattern instanceof String) {
|
||||
final String className = StringUtil.getPackageName((String)pattern, ',');
|
||||
if (!pattern.equals(className)) {
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
|
||||
final SourceScope sourceScope = getSourceScope();
|
||||
final GlobalSearchScope globalSearchScope = sourceScope != null ? sourceScope.getGlobalSearchScope()
|
||||
: GlobalSearchScope.projectScope(getProject());
|
||||
return facade.findClass(className, globalSearchScope);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchForTestsTask createSearchingForTestsTask() {
|
||||
return new SearchForTestsTask(getProject(), myServerSocket) {
|
||||
|
||||
private Set<String> myPatterns;
|
||||
|
||||
@Override
|
||||
protected void search() throws ExecutionException {
|
||||
myPatterns = TestDiscoverySearchHelper.search(getProject(), getPosition(), getChangeList(), getFrameworkPrefix());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFound() {
|
||||
if (myPatterns != null) {
|
||||
try {
|
||||
addClassesListToJavaParameters(myPatterns, FunctionUtil.<String>id(), "", false, getJavaParameters());
|
||||
}
|
||||
catch (ExecutionException ignored) {}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaParameters createJavaParameters() throws ExecutionException {
|
||||
final JavaParameters javaParameters = super.createJavaParameters();
|
||||
createTempFiles(javaParameters);
|
||||
|
||||
createServerSocket(javaParameters);
|
||||
return javaParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String suggestActionName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringElementListener getListener(PsiElement element, JUnitConfiguration configuration) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfiguredByElement(JUnitConfiguration configuration,
|
||||
PsiClass testClass,
|
||||
PsiMethod testMethod,
|
||||
PsiPackage testPackage,
|
||||
PsiDirectory testDir) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-2
@@ -15,11 +15,30 @@
|
||||
*/
|
||||
package com.intellij.execution.junit.testDiscovery;
|
||||
|
||||
import com.intellij.execution.configurations.ConfigurationTypeUtil;
|
||||
import com.intellij.execution.JavaTestConfigurationBase;
|
||||
import com.intellij.execution.PsiLocation;
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
import com.intellij.execution.junit.JUnitConfigurationType;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoveryConfigurationProducer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
|
||||
public class JUnitTestDiscoveryConfigurationProducer extends TestDiscoveryConfigurationProducer {
|
||||
protected JUnitTestDiscoveryConfigurationProducer() {
|
||||
super(ConfigurationTypeUtil.findConfigurationType(JUnitTestDiscoveryConfigurationType.class));
|
||||
super(JUnitConfigurationType.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPosition(JavaTestConfigurationBase configuration, PsiLocation<PsiMethod> position) {
|
||||
((JUnitConfiguration)configuration).beFromSourcePosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, String> getPosition(JavaTestConfigurationBase configuration) {
|
||||
final JUnitConfiguration.Data data = ((JUnitConfiguration)configuration).getPersistentData();
|
||||
if (data.TEST_OBJECT.equals(JUnitConfiguration.BY_SOURCE_POSITION)) {
|
||||
return Pair.create(data.getMainClassName(), data.getMethodName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
-71
@@ -1,71 +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.junit.testDiscovery;
|
||||
|
||||
import com.intellij.execution.configuration.ConfigurationFactoryEx;
|
||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||
import com.intellij.execution.configurations.ConfigurationType;
|
||||
import com.intellij.execution.configurations.ModuleBasedConfiguration;
|
||||
import com.intellij.execution.configurations.RunConfiguration;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoveryConfiguration;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JUnitTestDiscoveryConfigurationType implements ConfigurationType {
|
||||
private final ConfigurationFactory myFactory;
|
||||
|
||||
public JUnitTestDiscoveryConfigurationType() {
|
||||
myFactory = new ConfigurationFactoryEx(this) {
|
||||
public RunConfiguration createTemplateConfiguration(Project project) {
|
||||
return new JUnitTestDiscoveryConfiguration("", project, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewConfigurationCreated(@NotNull RunConfiguration configuration) {
|
||||
((ModuleBasedConfiguration)configuration).onNewConfigurationCreated();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "JUnit Test Discovery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigurationTypeDescription() {
|
||||
return "Runs junit tests which passed changed code";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return AllIcons.RunConfigurations.Junit;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getId() {
|
||||
return "JUnitTestDiscovery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationFactory[] getConfigurationFactories() {
|
||||
return new ConfigurationFactory[] {myFactory};
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.junit.testDiscovery;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
import com.intellij.execution.junit.TestObject;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoverySearchHelper;
|
||||
import com.intellij.execution.testframework.SearchForTestsTask;
|
||||
import com.intellij.execution.testframework.SourceScope;
|
||||
import com.intellij.execution.testframework.TestSearchScope;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.util.FunctionUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
abstract class JUnitTestDiscoveryRunnableState extends TestObject {
|
||||
public JUnitTestDiscoveryRunnableState(JUnitConfiguration configuration, ExecutionEnvironment environment) {
|
||||
super(configuration, environment);
|
||||
}
|
||||
|
||||
protected abstract String getChangeList();
|
||||
protected abstract Pair<String, String> getPosition();
|
||||
|
||||
|
||||
@Override
|
||||
protected TestSearchScope getScope() {
|
||||
return getConfiguration().getConfigurationModule().getModule() != null ? TestSearchScope.MODULE_WITH_DEPENDENCIES : TestSearchScope.WHOLE_PROJECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean forkPerModule() {
|
||||
return getConfiguration().getConfigurationModule().getModule() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PsiElement retrievePsiElement(Object pattern) {
|
||||
if (pattern instanceof String) {
|
||||
final String className = StringUtil.getPackageName((String)pattern, ',');
|
||||
if (!pattern.equals(className)) {
|
||||
final Project project = getConfiguration().getProject();
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
|
||||
final SourceScope sourceScope = getSourceScope();
|
||||
final GlobalSearchScope globalSearchScope = sourceScope != null ? sourceScope.getGlobalSearchScope()
|
||||
: GlobalSearchScope.projectScope(project);
|
||||
return facade.findClass(className, globalSearchScope);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchForTestsTask createSearchingForTestsTask() {
|
||||
return new SearchForTestsTask(getConfiguration().getProject(), myServerSocket) {
|
||||
|
||||
private Set<String> myPatterns;
|
||||
|
||||
@Override
|
||||
protected void search() throws ExecutionException {
|
||||
myPatterns = TestDiscoverySearchHelper.search(getProject(), getPosition(), getChangeList(), getConfiguration().getFrameworkPrefix());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFound() {
|
||||
if (myPatterns != null) {
|
||||
try {
|
||||
addClassesListToJavaParameters(myPatterns, FunctionUtil.<String>id(), "", false, getJavaParameters());
|
||||
}
|
||||
catch (ExecutionException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaParameters createJavaParameters() throws ExecutionException {
|
||||
final JavaParameters javaParameters = super.createJavaParameters();
|
||||
createTempFiles(javaParameters);
|
||||
|
||||
createServerSocket(javaParameters);
|
||||
return javaParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String suggestActionName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringElementListener getListener(PsiElement element, JUnitConfiguration configuration) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfiguredByElement(JUnitConfiguration configuration,
|
||||
PsiClass testClass,
|
||||
PsiMethod testMethod,
|
||||
PsiPackage testPackage,
|
||||
PsiDirectory testDir) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.junit.testDiscovery;
|
||||
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
|
||||
public class TestBySource extends JUnitTestDiscoveryRunnableState {
|
||||
public TestBySource(JUnitConfiguration configuration,
|
||||
ExecutionEnvironment environment) {
|
||||
super(configuration, environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getChangeList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, String> getPosition() {
|
||||
final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
|
||||
return Pair.create(data.getMainClassName(), data.getMethodName());
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -42,6 +42,7 @@ import com.intellij.openapi.ui.*;
|
||||
import com.intellij.openapi.ui.ex.MessagesEx;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -71,8 +72,8 @@ public class JUnitConfigurable<T extends JUnitConfiguration> extends SettingsEdi
|
||||
new TIntArrayList(new int[]{1, 2}),
|
||||
new TIntArrayList(new int[]{3}),
|
||||
new TIntArrayList(new int[]{4}),
|
||||
new TIntArrayList(new int[]{5})
|
||||
);
|
||||
new TIntArrayList(new int[]{5}),
|
||||
new TIntArrayList(new int[]{1, 2}));
|
||||
private static final String[] FORK_MODE_ALL =
|
||||
{JUnitConfiguration.FORK_NONE, JUnitConfiguration.FORK_METHOD, JUnitConfiguration.FORK_KLASS};
|
||||
private static final String[] FORK_MODE = {JUnitConfiguration.FORK_NONE, JUnitConfiguration.FORK_METHOD};
|
||||
@@ -158,6 +159,9 @@ public class JUnitConfigurable<T extends JUnitConfiguration> extends SettingsEdi
|
||||
aModel.addElement(JUnitConfigurationModel.CLASS);
|
||||
aModel.addElement(JUnitConfigurationModel.METHOD);
|
||||
aModel.addElement(JUnitConfigurationModel.CATEGORY);
|
||||
if (Registry.is("testDiscovery.enabled")) {
|
||||
aModel.addElement(JUnitConfigurationModel.BY_SOURCE_POSITION);
|
||||
}
|
||||
myTypeChooser.setModel(aModel);
|
||||
myTypeChooser.setRenderer(new ListCellRendererWrapper<Integer>() {
|
||||
@Override
|
||||
@@ -181,6 +185,9 @@ public class JUnitConfigurable<T extends JUnitConfiguration> extends SettingsEdi
|
||||
case JUnitConfigurationModel.CATEGORY:
|
||||
setText("Category");
|
||||
break;
|
||||
case JUnitConfigurationModel.BY_SOURCE_POSITION:
|
||||
setText("Source location");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -359,7 +366,7 @@ public class JUnitConfigurable<T extends JUnitConfiguration> extends SettingsEdi
|
||||
myForkCb.setModel(getForkModelBasedOnRepeat());
|
||||
myForkCb.setSelectedItem(selectedItem != JUnitConfiguration.FORK_KLASS ? selectedItem : JUnitConfiguration.FORK_METHOD);
|
||||
}
|
||||
else if (selectedType == JUnitConfigurationModel.METHOD){
|
||||
else if (selectedType == JUnitConfigurationModel.METHOD || selectedType == JUnitConfigurationModel.BY_SOURCE_POSITION){
|
||||
myPackagePanel.setVisible(false);
|
||||
myScopesPanel.setVisible(false);
|
||||
myPattern.setVisible(false);
|
||||
|
||||
+3
-1
@@ -43,6 +43,7 @@ public class JUnitConfigurationModel {
|
||||
public static final int PATTERN = 3;
|
||||
public static final int DIR = 4;
|
||||
public static final int CATEGORY = 5;
|
||||
public static final int BY_SOURCE_POSITION = 6;
|
||||
|
||||
private static final List<String> ourTestObjects;
|
||||
|
||||
@@ -52,7 +53,8 @@ public class JUnitConfigurationModel {
|
||||
JUnitConfiguration.TEST_METHOD,
|
||||
JUnitConfiguration.TEST_PATTERN,
|
||||
JUnitConfiguration.TEST_DIRECTORY,
|
||||
JUnitConfiguration.TEST_CATEGORY);
|
||||
JUnitConfiguration.TEST_CATEGORY,
|
||||
JUnitConfiguration.BY_SOURCE_POSITION);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@
|
||||
<programRunner implementation="com.theoryinpractice.testng.configuration.TestNGDebuggerRunner"/>
|
||||
<runConfigurationProducer
|
||||
implementation="com.theoryinpractice.testng.configuration.testDiscovery.TestNGTestDiscoveryConfigurationProducer"/>
|
||||
<configurationType implementation="com.theoryinpractice.testng.configuration.testDiscovery.TestNGTestDiscoveryConfigurationType"/>
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="com.theoryinpractice.testng">
|
||||
<listener implementation="org.testng.TestNGTestDiscoveryListener"/>
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementAdapter;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.refactoring.listeners.UndoRefactoringElementListener;
|
||||
import com.theoryinpractice.testng.configuration.testDiscovery.TestNGTestDiscoveryRunnableState;
|
||||
import com.theoryinpractice.testng.model.TestData;
|
||||
import com.theoryinpractice.testng.model.TestNGConsoleProperties;
|
||||
import com.theoryinpractice.testng.model.TestNGTestObject;
|
||||
@@ -128,6 +129,10 @@ public class TestNGConfiguration extends JavaTestConfigurationBase {
|
||||
}
|
||||
|
||||
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
|
||||
final TestData data = getPersistantData();
|
||||
if (data.TEST_OBJECT.equals(TestType.SOURCE.getType()) || data.getChangeList() != null) {
|
||||
return new TestNGTestDiscoveryRunnableState(env, this);
|
||||
}
|
||||
return new TestNGRunnableState(env, this);
|
||||
}
|
||||
|
||||
@@ -439,4 +444,9 @@ public class TestNGConfiguration extends JavaTestConfigurationBase {
|
||||
.collect(Collectors.toSet());
|
||||
return groups.isEmpty() ? null : groups;
|
||||
}
|
||||
|
||||
public void beFromSourcePosition(PsiLocation<PsiMethod> position) {
|
||||
setMethodConfiguration(position);
|
||||
getPersistantData().TEST_OBJECT = TestType.SOURCE.getType();
|
||||
}
|
||||
}
|
||||
|
||||
+16
-50
@@ -243,7 +243,7 @@
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="3054c" layout-manager="GridLayoutManager" row-count="1" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="3054c" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -251,59 +251,25 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="5eaf8" class="javax.swing.JRadioButton" binding="groupTest">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Group"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="61e8b" class="javax.swing.JRadioButton" binding="classTest">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="C&lass"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2ab9d" class="javax.swing.JRadioButton" binding="methodTest">
|
||||
<constraints>
|
||||
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Method"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="dcd9c" class="javax.swing.JRadioButton" binding="packageTest">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="All in &package"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d8c06" class="javax.swing.JRadioButton" binding="suiteTest">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="S&uite"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="99b4d" class="com.intellij.ui.components.JBRadioButton" binding="patternTest">
|
||||
<constraints>
|
||||
<grid row="0" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Pattern"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="99645">
|
||||
<constraints>
|
||||
<grid row="0" column="6" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="fccce" class="javax.swing.JComboBox" binding="myTestKind">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="ec186" class="com.intellij.ui.components.JBLabel" binding="myTestLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Test kind:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
|
||||
+29
-54
@@ -49,6 +49,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.table.TableView;
|
||||
import com.intellij.util.IconUtil;
|
||||
@@ -71,6 +72,7 @@ import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends SettingsEditor<T> implements PanelWithAnchor {
|
||||
@@ -83,12 +85,8 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
private LabeledComponent<ModulesComboBox> moduleClasspath;
|
||||
private JrePathEditor alternateJDK;
|
||||
private final ConfigurationModuleSelector moduleSelector;
|
||||
private JRadioButton suiteTest;
|
||||
private JRadioButton packageTest;
|
||||
private JRadioButton classTest;
|
||||
private JRadioButton methodTest;
|
||||
private JRadioButton groupTest;
|
||||
private JRadioButton patternTest;
|
||||
private JComboBox<TestType> myTestKind;
|
||||
private JBLabel myTestLabel;
|
||||
private final TestNGConfigurationModel model;
|
||||
private LabeledComponent<EditorTextFieldWithBrowseButton> methodField;
|
||||
private LabeledComponent<EditorTextFieldWithBrowseButton> packageField;
|
||||
@@ -160,31 +158,21 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
});
|
||||
panel.add(editBtn, BorderLayout.EAST);
|
||||
|
||||
registerListener(new JRadioButton[]{packageTest, classTest, methodTest, groupTest, suiteTest, patternTest}, new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
ButtonModel buttonModel = (ButtonModel)e.getSource();
|
||||
if (buttonModel.isSelected()) {
|
||||
if (buttonModel == packageTest.getModel()) {
|
||||
model.setType(TestType.PACKAGE);
|
||||
}
|
||||
else if (buttonModel == classTest.getModel()) {
|
||||
model.setType(TestType.CLASS);
|
||||
}
|
||||
else if (buttonModel == methodTest.getModel()) {
|
||||
model.setType(TestType.METHOD);
|
||||
}
|
||||
else if (buttonModel == groupTest.getModel()) {
|
||||
model.setType(TestType.GROUP);
|
||||
}
|
||||
else if (buttonModel == suiteTest.getModel()) {
|
||||
model.setType(TestType.SUITE);
|
||||
}
|
||||
else if (buttonModel == patternTest.getModel()) {
|
||||
model.setType(TestType.PATTERN);
|
||||
}
|
||||
}
|
||||
myTestKind.setModel(new CollectionComboBoxModel<>(Arrays.asList(TestType.values())));
|
||||
myTestKind.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
model.setType((TestType)myTestKind.getSelectedItem());
|
||||
}
|
||||
});
|
||||
myTestKind.setRenderer(new ListCellRendererWrapper<TestType>() {
|
||||
@Override
|
||||
public void customize(JList list, TestType value, int index, boolean selected, boolean hasFocus) {
|
||||
if (value != null) {
|
||||
setText(value.getPresentableName());
|
||||
}
|
||||
}
|
||||
});
|
||||
registerListener(new JRadioButton[]{packagesInProject, packagesInModule, packagesAcrossModules}, null);
|
||||
packagesInProject.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
@@ -236,7 +224,8 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
}
|
||||
|
||||
private void redisplay() {
|
||||
if (packageTest.isSelected()) {
|
||||
final TestType testKind = (TestType)myTestKind.getSelectedItem();
|
||||
if (testKind == TestType.PACKAGE) {
|
||||
packagePanel.setVisible(true);
|
||||
packageField.setVisible(true);
|
||||
classField.setVisible(false);
|
||||
@@ -245,7 +234,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
suiteField.setVisible(false);
|
||||
myPattern.setVisible(false);
|
||||
}
|
||||
else if (classTest.isSelected()) {
|
||||
else if (testKind == TestType.CLASS) {
|
||||
packagePanel.setVisible(false);
|
||||
classField.setVisible(true);
|
||||
methodField.setVisible(false);
|
||||
@@ -253,7 +242,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
suiteField.setVisible(false);
|
||||
myPattern.setVisible(false);
|
||||
}
|
||||
else if (methodTest.isSelected()) {
|
||||
else if (testKind == TestType.METHOD || testKind == TestType.SOURCE) {
|
||||
packagePanel.setVisible(false);
|
||||
classField.setVisible(true);
|
||||
methodField.setVisible(true);
|
||||
@@ -261,7 +250,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
suiteField.setVisible(false);
|
||||
myPattern.setVisible(false);
|
||||
}
|
||||
else if (groupTest.isSelected()) {
|
||||
else if (testKind == TestType.GROUP) {
|
||||
packagePanel.setVisible(true);
|
||||
classField.setVisible(false);
|
||||
methodField.setVisible(false);
|
||||
@@ -269,7 +258,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
suiteField.setVisible(false);
|
||||
myPattern.setVisible(false);
|
||||
}
|
||||
else if (suiteTest.isSelected()) {
|
||||
else if (testKind == TestType.SUITE) {
|
||||
packagePanel.setVisible(true);
|
||||
classField.setVisible(false);
|
||||
methodField.setVisible(false);
|
||||
@@ -277,7 +266,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
suiteField.setVisible(true);
|
||||
myPattern.setVisible(false);
|
||||
}
|
||||
else if (patternTest.isSelected()) {
|
||||
else if (testKind == TestType.PATTERN) {
|
||||
packagePanel.setVisible(true);
|
||||
classField.setVisible(false);
|
||||
methodField.setVisible(false);
|
||||
@@ -327,7 +316,8 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
model.apply(getModuleSelector().getModule(), config);
|
||||
getModuleSelector().applyTo(config);
|
||||
TestData data = config.getPersistantData();
|
||||
if (!classTest.isSelected() && !methodTest.isSelected()) {
|
||||
final TestType testKind = (TestType)myTestKind.getSelectedItem();
|
||||
if (testKind != TestType.CLASS && testKind != TestType.METHOD && testKind != TestType.SOURCE) {
|
||||
if (packagesInProject.isSelected()) {
|
||||
data.setScope(TestSearchScope.WHOLE_PROJECT);
|
||||
}
|
||||
@@ -379,6 +369,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
outputDirectory.setAnchor(anchor);
|
||||
classField.setAnchor(anchor);
|
||||
myPattern.setAnchor(anchor);
|
||||
myTestLabel.setAnchor(anchor);
|
||||
}
|
||||
|
||||
private static void registerListener(JRadioButton[] buttons, ChangeListener changelistener) {
|
||||
@@ -393,17 +384,6 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
|
||||
private void createView() {
|
||||
commonParametersPanel.add(commonJavaParameters, BorderLayout.CENTER);
|
||||
|
||||
packageTest.setSelected(false);
|
||||
suiteTest.setSelected(false);
|
||||
suiteTest.setEnabled(true);
|
||||
groupTest.setSelected(false);
|
||||
groupTest.setEnabled(true);
|
||||
classTest.setSelected(false);
|
||||
classTest.setEnabled(true);
|
||||
patternTest.setSelected(false);
|
||||
patternTest.setEnabled(true);
|
||||
|
||||
classField.setComponent(new EditorTextFieldWithBrowseButton(project, true, new JavaCodeFragment.VisibilityChecker() {
|
||||
@Override
|
||||
public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
|
||||
@@ -503,8 +483,8 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
|
||||
public void onTypeChanged(TestType type) {
|
||||
//LOGGER.info("onTypeChanged with " + type);
|
||||
myTestKind.setSelectedItem(type);
|
||||
if (type == TestType.PACKAGE) {
|
||||
packageTest.setSelected(true);
|
||||
packageField.setEnabled(true);
|
||||
classField.setEnabled(false);
|
||||
methodField.setEnabled(false);
|
||||
@@ -513,7 +493,6 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
myPattern.setEnabled(false);
|
||||
}
|
||||
else if (type == TestType.CLASS) {
|
||||
classTest.setSelected(true);
|
||||
packageField.setEnabled(false);
|
||||
classField.setEnabled(true);
|
||||
methodField.setEnabled(false);
|
||||
@@ -521,8 +500,7 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
suiteField.setEnabled(false);
|
||||
myPattern.setEnabled(false);
|
||||
}
|
||||
else if (type == TestType.METHOD) {
|
||||
methodTest.setSelected(true);
|
||||
else if (type == TestType.METHOD || type == TestType.SOURCE) {
|
||||
packageField.setEnabled(false);
|
||||
classField.setEnabled(true);
|
||||
methodField.setEnabled(true);
|
||||
@@ -531,7 +509,6 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
myPattern.setEnabled(false);
|
||||
}
|
||||
else if (type == TestType.GROUP) {
|
||||
groupTest.setSelected(true);
|
||||
groupField.setEnabled(true);
|
||||
packageField.setVisible(false);
|
||||
classField.setEnabled(false);
|
||||
@@ -540,7 +517,6 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
myPattern.setEnabled(false);
|
||||
}
|
||||
else if (type == TestType.SUITE) {
|
||||
suiteTest.setSelected(true);
|
||||
suiteField.setEnabled(true);
|
||||
packageField.setVisible(false);
|
||||
classField.setEnabled(false);
|
||||
@@ -549,7 +525,6 @@ public class TestNGConfigurationEditor<T extends TestNGConfiguration> extends Se
|
||||
myPattern.setEnabled(false);
|
||||
}
|
||||
else if (type == TestType.PATTERN) {
|
||||
patternTest.setSelected(true);
|
||||
myPattern.setEnabled(true);
|
||||
suiteField.setEnabled(false);
|
||||
packageField.setVisible(false);
|
||||
|
||||
+1
-3
@@ -17,15 +17,13 @@ package com.theoryinpractice.testng.configuration;
|
||||
|
||||
import com.intellij.execution.JavaTestFrameworkDebuggerRunner;
|
||||
import com.intellij.execution.configurations.RunProfile;
|
||||
import com.theoryinpractice.testng.configuration.testDiscovery.TestNGTestDiscoveryConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class TestNGDebuggerRunner extends JavaTestFrameworkDebuggerRunner {
|
||||
@Override
|
||||
protected boolean validForProfile(@NotNull RunProfile profile) {
|
||||
return profile instanceof TestNGConfiguration ||
|
||||
profile instanceof TestNGTestDiscoveryConfiguration;
|
||||
return profile instanceof TestNGConfiguration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
-103
@@ -1,103 +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.theoryinpractice.testng.configuration.testDiscovery;
|
||||
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.Executor;
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoveryConfiguration;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoverySearchHelper;
|
||||
import com.intellij.execution.testframework.TestSearchScope;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.theoryinpractice.testng.configuration.SearchingForTestsTask;
|
||||
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
|
||||
import com.theoryinpractice.testng.configuration.TestNGConfigurationType;
|
||||
import com.theoryinpractice.testng.configuration.TestNGRunnableState;
|
||||
import com.theoryinpractice.testng.model.TestNGTestPattern;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class TestNGTestDiscoveryConfiguration extends TestDiscoveryConfiguration {
|
||||
|
||||
public TestNGTestDiscoveryConfiguration(String name, Project project, ConfigurationFactory factory) {
|
||||
super(name, new JavaRunConfigurationModule(project, false), factory,
|
||||
new TestNGConfiguration("", project, TestNGConfigurationType.getInstance().getConfigurationFactories()[0]));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
|
||||
return new TestNGTestDiscoveryRunnableState(environment);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RefactoringElementListener getRefactoringElementListener(PsiElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFrameworkPrefix() {
|
||||
return "g";
|
||||
}
|
||||
|
||||
private class TestNGTestDiscoveryRunnableState extends TestNGRunnableState {
|
||||
public TestNGTestDiscoveryRunnableState(ExecutionEnvironment environment) {
|
||||
super(environment, ((TestNGConfiguration)myDelegate));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestSearchScope getScope() {
|
||||
return TestSearchScope.MODULE_WITH_DEPENDENCIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean forkPerModule() {
|
||||
return getConfigurationModule().getModule() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchingForTestsTask createSearchingForTestsTask() {
|
||||
return new SearchingForTestsTask(myServerSocket, getConfiguration(), myTempFile, client) {
|
||||
@Override
|
||||
protected void search() throws CantRunException {
|
||||
myClasses.clear();
|
||||
final Set<String> patterns = TestDiscoverySearchHelper.search(getProject(), getPosition(), getChangeList(), getFrameworkPrefix());
|
||||
final Module module = getConfigurationModule().getModule();
|
||||
final GlobalSearchScope searchScope =
|
||||
module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(getProject());
|
||||
TestNGTestPattern.fillTestObjects(myClasses, patterns, TestSearchScope.MODULE_WITH_DEPENDENCIES,
|
||||
TestNGTestDiscoveryConfiguration.this, searchScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFound() {
|
||||
super.onFound();
|
||||
writeClassesPerModule(myClasses);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
-1
@@ -15,11 +15,33 @@
|
||||
*/
|
||||
package com.theoryinpractice.testng.configuration.testDiscovery;
|
||||
|
||||
import com.intellij.execution.JavaTestConfigurationBase;
|
||||
import com.intellij.execution.PsiLocation;
|
||||
import com.intellij.execution.configurations.ConfigurationTypeUtil;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoveryConfigurationProducer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
|
||||
import com.theoryinpractice.testng.configuration.TestNGConfigurationType;
|
||||
import com.theoryinpractice.testng.model.TestData;
|
||||
import com.theoryinpractice.testng.model.TestType;
|
||||
|
||||
public class TestNGTestDiscoveryConfigurationProducer extends TestDiscoveryConfigurationProducer {
|
||||
protected TestNGTestDiscoveryConfigurationProducer() {
|
||||
super(ConfigurationTypeUtil.findConfigurationType(TestNGTestDiscoveryConfigurationType.class));
|
||||
super(TestNGConfigurationType.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPosition(JavaTestConfigurationBase configuration, PsiLocation<PsiMethod> position) {
|
||||
((TestNGConfiguration)configuration).beFromSourcePosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, String> getPosition(JavaTestConfigurationBase configuration) {
|
||||
final TestData data = ((TestNGConfiguration)configuration).getPersistantData();
|
||||
if (data.TEST_OBJECT.equals(TestType.SOURCE.getType())) {
|
||||
return Pair.create(data.getMainClassName(), data.getMethodName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
-71
@@ -1,71 +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.theoryinpractice.testng.configuration.testDiscovery;
|
||||
|
||||
import com.intellij.execution.configuration.ConfigurationFactoryEx;
|
||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||
import com.intellij.execution.configurations.ConfigurationType;
|
||||
import com.intellij.execution.configurations.ModuleBasedConfiguration;
|
||||
import com.intellij.execution.configurations.RunConfiguration;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import icons.TestngIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class TestNGTestDiscoveryConfigurationType implements ConfigurationType {
|
||||
private final ConfigurationFactory myFactory;
|
||||
|
||||
public TestNGTestDiscoveryConfigurationType() {
|
||||
myFactory = new ConfigurationFactoryEx(this) {
|
||||
public RunConfiguration createTemplateConfiguration(Project project) {
|
||||
return new TestNGTestDiscoveryConfiguration("", project, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewConfigurationCreated(@NotNull RunConfiguration configuration) {
|
||||
((ModuleBasedConfiguration)configuration).onNewConfigurationCreated();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "TestNG Test Discovery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigurationTypeDescription() {
|
||||
return "Runs TestNG tests which passed changed code";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return TestngIcons.TestNG;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getId() {
|
||||
return "TestNGTestDiscovery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationFactory[] getConfigurationFactories() {
|
||||
return new ConfigurationFactory[] {myFactory};
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.theoryinpractice.testng.configuration.testDiscovery;
|
||||
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.testDiscovery.TestDiscoverySearchHelper;
|
||||
import com.intellij.execution.testframework.TestSearchScope;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.theoryinpractice.testng.configuration.SearchingForTestsTask;
|
||||
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
|
||||
import com.theoryinpractice.testng.configuration.TestNGRunnableState;
|
||||
import com.theoryinpractice.testng.model.TestData;
|
||||
import com.theoryinpractice.testng.model.TestNGTestPattern;
|
||||
import com.theoryinpractice.testng.model.TestType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class TestNGTestDiscoveryRunnableState extends TestNGRunnableState {
|
||||
|
||||
public TestNGTestDiscoveryRunnableState(ExecutionEnvironment environment,
|
||||
TestNGConfiguration configuration) {
|
||||
super(environment, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestSearchScope getScope() {
|
||||
return TestSearchScope.MODULE_WITH_DEPENDENCIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean forkPerModule() {
|
||||
return getConfiguration().getConfigurationModule().getModule() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchingForTestsTask createSearchingForTestsTask() {
|
||||
return new SearchingForTestsTask(myServerSocket, getConfiguration(), myTempFile, client) {
|
||||
@Override
|
||||
protected void search() throws CantRunException {
|
||||
myClasses.clear();
|
||||
final TestData data = getConfiguration().getPersistantData();
|
||||
final Pair<String, String> position = data.TEST_OBJECT.equals(TestType.SOURCE.getType())
|
||||
? Pair.create(data.getMainClassName(), data.getMethodName()) : null;
|
||||
final Set<String> patterns = TestDiscoverySearchHelper
|
||||
.search(getProject(), position, data.getChangeList(), getConfiguration().getFrameworkPrefix());
|
||||
final Module module = getConfiguration().getConfigurationModule().getModule();
|
||||
final GlobalSearchScope searchScope =
|
||||
module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(getProject());
|
||||
TestNGTestPattern.fillTestObjects(myClasses, patterns, TestSearchScope.MODULE_WITH_DEPENDENCIES,
|
||||
getConfiguration(), searchScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFound() {
|
||||
super.onFound();
|
||||
writeClassesPerModule(myClasses);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import com.intellij.execution.testframework.TestSearchScope;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
@@ -57,6 +58,7 @@ public class TestData implements Cloneable
|
||||
public boolean USE_DEFAULT_REPORTERS = false;
|
||||
public String PROPERTIES_FILE;
|
||||
private LinkedHashSet<String> myPatterns = new LinkedHashSet<String>();
|
||||
private String myChangeList;
|
||||
|
||||
public TestData() {
|
||||
TEST_OBJECT = TestType.CLASS.getType();
|
||||
@@ -220,4 +222,12 @@ public class TestData implements Cloneable
|
||||
public void setPatterns(LinkedHashSet<String> set) {
|
||||
myPatterns = set;
|
||||
}
|
||||
|
||||
public String getChangeList() {
|
||||
return myChangeList;
|
||||
}
|
||||
|
||||
public void setChangeList(String changeList) {
|
||||
myChangeList = changeList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class TestNGConfigurationModel
|
||||
private final Project project;
|
||||
|
||||
public TestNGConfigurationModel(Project project) {
|
||||
type = TestType.INVALID;
|
||||
type = TestType.CLASS;
|
||||
for (int i = 3; i < typeDocuments.length; i++)
|
||||
typeDocuments[i] = new PlainDocument();
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.theoryinpractice.testng.model;
|
||||
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.configurations.RuntimeConfigurationException;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TestNGSource extends TestNGTestMethod {
|
||||
public TestNGSource(TestNGConfiguration config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillTestObjects(Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {}
|
||||
|
||||
@Override
|
||||
public String getGeneratedName() {
|
||||
final TestData data = myConfig.getPersistantData();
|
||||
return "Tests for " + StringUtil.getQualifiedName(data.getMainClassName(), data.getMethodName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionName() {
|
||||
return getGeneratedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkConfiguration() throws RuntimeConfigurationException {
|
||||
super.checkConfiguration();
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,10 @@ public abstract class TestNGTestObject {
|
||||
if (testObject.equals(TestType.SUITE.getType())){
|
||||
return new TestNGTestSuite(config);
|
||||
}
|
||||
|
||||
if (testObject.equals(TestType.SOURCE.getType())) {
|
||||
return new TestNGSource(config);
|
||||
}
|
||||
assert false : testObject;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -22,21 +22,24 @@
|
||||
*/
|
||||
package com.theoryinpractice.testng.model;
|
||||
|
||||
public class TestType
|
||||
public enum TestType
|
||||
{
|
||||
public static final TestType INVALID = new TestType("INVALID", -1);
|
||||
public static final TestType PACKAGE = new TestType("PACKAGE", 0);
|
||||
public static final TestType CLASS = new TestType("CLASS", 1);
|
||||
public static final TestType METHOD = new TestType("METHOD", 2);
|
||||
public static final TestType GROUP = new TestType("GROUP", 3);
|
||||
public static final TestType SUITE = new TestType("SUITE", 4);
|
||||
public static final TestType PATTERN = new TestType("PATTERN", 5);
|
||||
|
||||
PACKAGE("PACKAGE", "All in package", 0),
|
||||
CLASS ("CLASS", "Class", 1),
|
||||
METHOD ("METHOD", "Method", 2),
|
||||
GROUP ("GROUP", "Group", 3),
|
||||
SUITE ("SUITE", "Suite", 4),
|
||||
PATTERN("PATTERN", "Pattern", 5),
|
||||
SOURCE ("SOURCE", "Source location", 6);
|
||||
|
||||
public final String type;
|
||||
private final String presentableName;
|
||||
public final int value;
|
||||
|
||||
private TestType(String type, int value) {
|
||||
TestType(String type, String presentableName, int value) {
|
||||
this.type = type;
|
||||
this.presentableName = presentableName;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -47,36 +50,8 @@ public class TestType
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static TestType valueOf(String type)
|
||||
{
|
||||
if(INVALID.type.equals(type))
|
||||
{
|
||||
return INVALID;
|
||||
}
|
||||
if(PACKAGE.type.equals(type))
|
||||
{
|
||||
return PACKAGE;
|
||||
}
|
||||
if(CLASS.type.equals(type))
|
||||
{
|
||||
return CLASS;
|
||||
}
|
||||
if(METHOD.type.equals(type))
|
||||
{
|
||||
return METHOD;
|
||||
}
|
||||
if(GROUP.type.equals(type))
|
||||
{
|
||||
return GROUP;
|
||||
}
|
||||
if(SUITE.type.equals(type))
|
||||
{
|
||||
return SUITE;
|
||||
}
|
||||
if (PATTERN.type.equals(type)) {
|
||||
return PATTERN;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid type requested " + type);
|
||||
|
||||
public String getPresentableName() {
|
||||
return presentableName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user