Adding right-click run for Kotlin TestNG test classes and methods.
Parallel support to the JUnit implementation, not as fully functional as TestNG plugin for Java.
This commit is contained in:
committed by
Nikolay Krasko
parent
12d19dd9d8
commit
1f236105a6
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="testng-plugin">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/ideaSDK/plugins/testng/lib/testng-plugin.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/ideaSDK/plugins/testng/lib/testng.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/ideaSDK/sources/sources.zip!/plugins/testng/src" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
<orderEntry type="module" module-name="jet.as.java.psi" />
|
<orderEntry type="module" module-name="jet.as.java.psi" />
|
||||||
<orderEntry type="library" name="idea-full" level="project" />
|
<orderEntry type="library" name="idea-full" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="junit-plugin" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="junit-plugin" level="project" />
|
||||||
|
<orderEntry type="library" name="testng-plugin" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="copyright-plugin" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="copyright-plugin" level="project" />
|
||||||
<orderEntry type="module" module-name="j2k" />
|
<orderEntry type="module" module-name="j2k" />
|
||||||
<orderEntry type="module" module-name="js.translator" />
|
<orderEntry type="module" module-name="js.translator" />
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<idea-version since-build="129.1" until-build="129.9999"/>
|
<idea-version since-build="129.1" until-build="129.9999"/>
|
||||||
|
|
||||||
<depends optional="true">JUnit</depends>
|
<depends optional="true">JUnit</depends>
|
||||||
|
<depends optional="true">TestNG-J</depends>
|
||||||
<depends optional="true" config-file="kotlin-copyright.xml">com.intellij.copyright</depends>
|
<depends optional="true" config-file="kotlin-copyright.xml">com.intellij.copyright</depends>
|
||||||
|
|
||||||
<project-components>
|
<project-components>
|
||||||
@@ -210,6 +211,7 @@
|
|||||||
<programRunner implementation="org.jetbrains.jet.plugin.k2jsrun.K2JSBrowserProgramRunner"/>
|
<programRunner implementation="org.jetbrains.jet.plugin.k2jsrun.K2JSBrowserProgramRunner"/>
|
||||||
<configurationProducer implementation="org.jetbrains.jet.plugin.run.JetRunConfigurationProducer"/>
|
<configurationProducer implementation="org.jetbrains.jet.plugin.run.JetRunConfigurationProducer"/>
|
||||||
<configurationProducer implementation="org.jetbrains.jet.plugin.run.JetJUnitConfigurationProducer"/>
|
<configurationProducer implementation="org.jetbrains.jet.plugin.run.JetJUnitConfigurationProducer"/>
|
||||||
|
<configurationProducer implementation="org.jetbrains.jet.plugin.run.JetTestNgConfigurationProducer"/>
|
||||||
<codeInsight.lineMarkerProvider language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.JetLineMarkerProvider"/>
|
<codeInsight.lineMarkerProvider language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.JetLineMarkerProvider"/>
|
||||||
<codeInsight.lineMarkerProvider language="JAVA"
|
<codeInsight.lineMarkerProvider language="JAVA"
|
||||||
implementationClass="org.jetbrains.jet.plugin.ktSignature.KotlinSignatureInJavaMarkerProvider"/>
|
implementationClass="org.jetbrains.jet.plugin.ktSignature.KotlinSignatureInJavaMarkerProvider"/>
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public class JetJUnitConfigurationProducer extends RuntimeConfigurationProducer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JetClass getClassDeclarationInFile(JetFile jetFile) {
|
static JetClass getClassDeclarationInFile(JetFile jetFile) {
|
||||||
JetClass tempSingleDeclaration = null;
|
JetClass tempSingleDeclaration = null;
|
||||||
|
|
||||||
for (JetDeclaration jetDeclaration : jetFile.getDeclarations()) {
|
for (JetDeclaration jetDeclaration : jetFile.getDeclarations()) {
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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 org.jetbrains.jet.plugin.run;
|
||||||
|
|
||||||
|
import com.intellij.execution.JavaRunConfigurationExtensionManager;
|
||||||
|
import com.intellij.execution.Location;
|
||||||
|
import com.intellij.execution.PsiLocation;
|
||||||
|
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||||
|
import com.intellij.execution.actions.ConfigurationContext;
|
||||||
|
import com.intellij.openapi.module.Module;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.psi.PsiClass;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.PsiMethod;
|
||||||
|
import com.intellij.psi.util.PsiClassUtil;
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
|
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
|
||||||
|
import com.theoryinpractice.testng.configuration.TestNGConfigurationProducer;
|
||||||
|
import com.theoryinpractice.testng.util.TestNGUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.asJava.LightClassUtil;
|
||||||
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
|
||||||
|
public class JetTestNgConfigurationProducer extends TestNGConfigurationProducer {
|
||||||
|
|
||||||
|
public JetTestNgConfigurationProducer() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
private JetElement myElement = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiElement getSourceElement() {
|
||||||
|
return myElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
protected RunnerAndConfigurationSettings createConfigurationByElement(Location location, ConfigurationContext context) {
|
||||||
|
// TODO: check TestNG Pattern running first, before method/class (see TestNGInClassConfigurationProducer for logic)
|
||||||
|
// TODO: and PsiClassOwner not handled, which is in TestNGInClassConfigurationProducer
|
||||||
|
|
||||||
|
Project project = location.getProject();
|
||||||
|
PsiElement leaf = location.getPsiElement();
|
||||||
|
|
||||||
|
if (!(leaf.getContainingFile() instanceof JetFile)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
JetFile jetFile = (JetFile) leaf.getContainingFile();
|
||||||
|
|
||||||
|
JetNamedFunction function = PsiTreeUtil.getParentOfType(leaf, JetNamedFunction.class, false);
|
||||||
|
if (function != null) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
JetElement owner = PsiTreeUtil.getParentOfType(function, JetFunction.class, JetClass.class);
|
||||||
|
|
||||||
|
if (owner instanceof JetClass) {
|
||||||
|
PsiClass delegate = LightClassUtil.getPsiClass((JetClass) owner);
|
||||||
|
if (delegate != null) {
|
||||||
|
for (PsiMethod method : delegate.getMethods()) {
|
||||||
|
if (method.getNavigationElement() == function) {
|
||||||
|
if (TestNGUtil.hasTest(method)) {
|
||||||
|
myElement = function;
|
||||||
|
return createRuntimeConfigSettings(location, context, project, delegate, method);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JetClass jetClass = PsiTreeUtil.getParentOfType(leaf, JetClass.class, false);
|
||||||
|
|
||||||
|
if (jetClass == null) {
|
||||||
|
jetClass = JetJUnitConfigurationProducer.getClassDeclarationInFile(jetFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jetClass == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
PsiClass delegate = LightClassUtil.getPsiClass(jetClass);
|
||||||
|
if (!isTestNGClass(delegate)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
myElement = jetClass;
|
||||||
|
return createRuntimeConfigSettings(location, context, project, delegate, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RunnerAndConfigurationSettings createRuntimeConfigSettings(
|
||||||
|
Location location, ConfigurationContext context, Project project,
|
||||||
|
@Nullable PsiClass delegate, @Nullable PsiMethod method) {
|
||||||
|
if (delegate == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context);
|
||||||
|
TestNGConfiguration configuration = (TestNGConfiguration) settings.getConfiguration();
|
||||||
|
setupConfigurationModule(context, configuration);
|
||||||
|
Module originalModule = configuration.getConfigurationModule().getModule();
|
||||||
|
configuration.setClassConfiguration(delegate);
|
||||||
|
if (method != null) {
|
||||||
|
configuration.setMethodConfiguration(PsiLocation.fromPsiElement(project, method));
|
||||||
|
}
|
||||||
|
configuration.restoreOriginalModule(originalModule);
|
||||||
|
settings.setName(configuration.getName());
|
||||||
|
JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, location);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isTestNGClass(PsiClass psiClass) {
|
||||||
|
return psiClass != null && PsiClassUtil.isRunnableClass(psiClass, true, false) && TestNGUtil.hasTest(psiClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(@NotNull Object o) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user