mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use MultiMap as return type of com.intellij.execution.testDiscovery.TestDiscoveryProducer.getDiscoveredTests
This commit is contained in:
+11
-8
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.io.HttpRequests;
|
||||
import com.intellij.util.io.RequestBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -23,22 +24,24 @@ public class IntellijTestDiscoveryProducer implements TestDiscoveryProducer {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<DiscoveredTest> getDiscoveredTests(@NotNull Project project,
|
||||
@NotNull String classFQName,
|
||||
@NotNull String methodName,
|
||||
@NotNull String frameworkId) {
|
||||
public MultiMap<String, String> getDiscoveredTests(@NotNull Project project,
|
||||
@NotNull String classFQName,
|
||||
@NotNull String methodName,
|
||||
@NotNull String frameworkId) {
|
||||
String methodFqn = classFQName + "." + methodName;
|
||||
RequestBuilder r = HttpRequests.request(INTELLIJ_TEST_DISCOVERY_HOST + "/search/tests/by-method/" + methodFqn);
|
||||
|
||||
try {
|
||||
return r.connect(request -> {
|
||||
MultiMap<String, String> map = new MultiMap<>();
|
||||
TestsSearchResult result = new ObjectMapper().readValue(request.getInputStream(), TestsSearchResult.class);
|
||||
return result.getTests().stream().map(s -> {
|
||||
result.getTests().forEach(s -> {
|
||||
String str = s.length() > 1 && s.charAt(0) == 'j' ? s.substring(1) : s;
|
||||
String classFqn = StringUtil.substringBefore(str, "-");
|
||||
String testMethodName = StringUtil.substringAfter(str, "-");
|
||||
return new DiscoveredTest(classFqn, testMethodName);
|
||||
}).collect(Collectors.toList());
|
||||
map.putValue(classFqn, testMethodName);
|
||||
});
|
||||
return map;
|
||||
});
|
||||
}
|
||||
catch (HttpRequests.HttpStatusException http) {
|
||||
@@ -47,7 +50,7 @@ public class IntellijTestDiscoveryProducer implements TestDiscoveryProducer {
|
||||
catch (IOException e) {
|
||||
LOG.debug(e);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
return MultiMap.empty();
|
||||
}
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
|
||||
+11
-9
@@ -3,6 +3,7 @@ package com.intellij.execution.testDiscovery;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -14,24 +15,25 @@ import java.util.stream.Collectors;
|
||||
public class LocalTestDiscoveryProducer implements TestDiscoveryProducer {
|
||||
@Override
|
||||
@NotNull
|
||||
public List<DiscoveredTest> getDiscoveredTests(@NotNull Project project,
|
||||
@NotNull String classFQName,
|
||||
@NotNull String methodName,
|
||||
@NotNull String frameworkId) {
|
||||
public MultiMap<String, String> getDiscoveredTests(@NotNull Project project,
|
||||
@NotNull String classFQName,
|
||||
@NotNull String methodName,
|
||||
@NotNull String frameworkId) {
|
||||
try {
|
||||
TestDiscoveryIndex discoveryIndex = TestDiscoveryIndex.getInstance(project);
|
||||
Collection<String> testsByMethodName = discoveryIndex.getTestsByMethodName(classFQName, methodName, frameworkId);
|
||||
if (testsByMethodName != null) {
|
||||
// todo[batkovich]: filter by framework id
|
||||
return testsByMethodName.stream()
|
||||
.map(pattern -> StringUtil.split(pattern, "-")).filter(split -> split.size() == 2)
|
||||
.map(split -> new DiscoveredTest(split.get(0), split.get(1)))
|
||||
.collect(Collectors.toList());
|
||||
MultiMap<String, String> result = new MultiMap<>();
|
||||
testsByMethodName.stream()
|
||||
.map(pattern -> StringUtil.split(pattern, "-")).filter(split -> split.size() == 2)
|
||||
.forEach(split -> result.putValue(split.get(0), split.get(1)));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (IOException io) {
|
||||
TestDiscoveryProducer.LOG.warn(io);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
return MultiMap.empty();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -168,10 +168,10 @@ public class ShowDiscoveredTestsAction extends AnAction {
|
||||
for (TestDiscoveryConfigurationProducer producer : getProducers(project)) {
|
||||
String frameworkPrefix =
|
||||
((JavaTestConfigurationBase)producer.getConfigurationFactory().createTemplateConfiguration(project)).getFrameworkPrefix();
|
||||
TestDiscoveryProducer.consumeDiscoveredTests(project, fqn, methodName, frameworkPrefix, test -> {
|
||||
TestDiscoveryProducer.consumeDiscoveredTests(project, fqn, methodName, frameworkPrefix, (testClass, testMethod) -> {
|
||||
PsiMethod psiMethod = ReadAction.compute(() -> {
|
||||
PsiClass cc = test.getTestClassQName() == null ? null : javaFacade.findClass(test.getTestClassQName(), scope);
|
||||
return cc == null ? null : ArrayUtil.getFirstElement(cc.findMethodsByName(test.getTestMethodName(), false));
|
||||
PsiClass cc = testClass == null ? null : javaFacade.findClass(testClass, scope);
|
||||
return cc == null ? null : ArrayUtil.getFirstElement(cc.findMethodsByName(testMethod, false));
|
||||
});
|
||||
if (psiMethod != null) {
|
||||
loadTestsTask.updateComponent(psiMethod);
|
||||
|
||||
+16
-23
@@ -4,39 +4,26 @@ package com.intellij.execution.testDiscovery;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public interface TestDiscoveryProducer {
|
||||
Logger LOG = Logger.getInstance(LocalTestDiscoveryProducer.class);
|
||||
|
||||
class DiscoveredTest {
|
||||
private final String myTestClassQName;
|
||||
private final String myTestMethodName;
|
||||
|
||||
public DiscoveredTest(String testClassQName, String testMethodName) {
|
||||
myTestClassQName = testClassQName;
|
||||
myTestMethodName = testMethodName;
|
||||
}
|
||||
|
||||
public String getTestClassQName() {
|
||||
return myTestClassQName;
|
||||
}
|
||||
|
||||
public String getTestMethodName() {
|
||||
return myTestMethodName;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
List<DiscoveredTest> getDiscoveredTests(@NotNull Project project,
|
||||
@NotNull String classFQName,
|
||||
@NotNull String methodName,
|
||||
@NotNull String frameworkId);
|
||||
MultiMap<String, String> getDiscoveredTests(@NotNull Project project,
|
||||
@NotNull String classFQName,
|
||||
@NotNull String methodName,
|
||||
@NotNull String frameworkId);
|
||||
|
||||
ExtensionPointName<TestDiscoveryProducer> EP = ExtensionPointName.create("com.intellij.testDiscoveryProducer");
|
||||
|
||||
@@ -44,9 +31,15 @@ public interface TestDiscoveryProducer {
|
||||
@NotNull String classFQName,
|
||||
@NotNull String methodName,
|
||||
@NotNull String frameworkId,
|
||||
@NotNull Consumer<DiscoveredTest> consumer) {
|
||||
@NotNull BiConsumer<String, String> consumer) {
|
||||
for (TestDiscoveryProducer producer : EP.getExtensions()) {
|
||||
producer.getDiscoveredTests(project, classFQName, methodName, frameworkId).forEach(consumer);
|
||||
for (Map.Entry<String, Collection<String>> entry : producer.getDiscoveredTests(project, classFQName, methodName, frameworkId)
|
||||
.entrySet()) {
|
||||
String cName = entry.getKey();
|
||||
for (String mName : entry.getValue()) {
|
||||
consumer.accept(cName, mName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ public class TestDiscoverySearchHelper {
|
||||
@NotNull String classFQName,
|
||||
@NotNull String methodName,
|
||||
@NotNull String frameworkId) {
|
||||
TestDiscoveryProducer.consumeDiscoveredTests(project, classFQName, methodName, frameworkId, t -> patterns.add(t.getTestClassQName() + "," + t.getTestMethodName()));
|
||||
TestDiscoveryProducer.consumeDiscoveredTests(project, classFQName, methodName, frameworkId, (c, m) -> patterns.add(c + "," + m));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user