This is an automated email from the ASF dual-hosted git repository.
dbalek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 409fa4a LSP: Show test results for MX projects. (#3128)
409fa4a is described below
commit 409fa4a81dd0bdd16cf2dd6a8b04c8a4adee2cea
Author: Dusan Balek <[email protected]>
AuthorDate: Mon Aug 30 13:36:30 2021 +0200
LSP: Show test results for MX projects. (#3128)
---
.../support/actions/GroovyComputeTestMethods.java | 18 +++++++++++++++++-
.../java/lsp/server/protocol/WorkspaceServiceImpl.java | 5 ++++-
java/java.lsp.server/vscode/src/testAdapter.ts | 8 ++++++++
.../modules/junit/ui/actions/TestClassInfoTask.java | 17 ++++++++++++++++-
4 files changed, 45 insertions(+), 3 deletions(-)
diff --git
a/groovy/groovy.support/src/org/netbeans/modules/groovy/support/actions/GroovyComputeTestMethods.java
b/groovy/groovy.support/src/org/netbeans/modules/groovy/support/actions/GroovyComputeTestMethods.java
index e8e91d0..c16cfd7 100644
---
a/groovy/groovy.support/src/org/netbeans/modules/groovy/support/actions/GroovyComputeTestMethods.java
+++
b/groovy/groovy.support/src/org/netbeans/modules/groovy/support/actions/GroovyComputeTestMethods.java
@@ -27,6 +27,8 @@ import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.ModuleNode;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.UnitTestForSourceQuery;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.modules.gsf.testrunner.ui.api.TestMethodController;
@@ -49,6 +51,10 @@ public class GroovyComputeTestMethods implements
ComputeTestMethods {
if (cancel.get()) {
return result;
}
+ FileObject fileObject =
parserResult.getSnapshot().getSource().getFileObject();
+ if (!isTestSource(fileObject)) {
+ return result;
+ }
String text = parserResult.getSnapshot().getText().toString();
ModuleNode moduleNode = TestMethodUtil.extractModuleNode(parserResult);
for (ClassNode classNode : moduleNode.getClasses()) {
@@ -68,7 +74,6 @@ public class GroovyComputeTestMethods implements
ComputeTestMethods {
int startOffset = getOffset(text, startLine,
startColumn);
int endOffset = getOffset(text, endLine,
endColumn);
String name =
annotation.getMember("name").getText();
- FileObject fileObject =
parserResult.getSnapshot().getSource().getFileObject();
Project project =
FileOwnerQuery.getOwner(fileObject);
boolean isMaven = project != null &&
project.getLookup().lookup(NbMavenProject.class) != null;
result.add(new
TestMethodController.TestMethod(isMaven ? classNode.getNameWithoutPackage() :
classNode.getName(),
@@ -86,6 +91,17 @@ public class GroovyComputeTestMethods implements
ComputeTestMethods {
return result;
}
+ private static boolean isTestSource(FileObject fo) {
+ ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
+ if (cp != null) {
+ FileObject root = cp.findOwnerRoot(fo);
+ if (root != null) {
+ return UnitTestForSourceQuery.findSources(root).length > 0;
+ }
+ }
+ return false;
+ }
+
private static int getOffset(String text, int lineNumber, int
columnNumber) {
int offset = 0;
String[] lines = text.split("\n");
diff --git
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java
index 43613d6..0d65a1f 100644
---
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java
+++
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java
@@ -388,7 +388,10 @@ public final class WorkspaceServiceImpl implements
WorkspaceService, LanguageCli
}
}
}
- contained = ProjectUtils.getContainedProjects(prj,
true).stream().map(p -> p.getProjectDirectory()).collect(Collectors.toList());
+ Set<Project> containedProjects =
ProjectUtils.getContainedProjects(prj, true);
+ if (containedProjects != null) {
+ contained = containedProjects.stream().map(p ->
p.getProjectDirectory()).collect(Collectors.toList());
+ }
}
return server.asyncOpenSelectedProjects(contained).thenApply(projects
-> {
for (Project project : projects) {
diff --git a/java/java.lsp.server/vscode/src/testAdapter.ts
b/java/java.lsp.server/vscode/src/testAdapter.ts
index ec5388f..95085e5 100644
--- a/java/java.lsp.server/vscode/src/testAdapter.ts
+++ b/java/java.lsp.server/vscode/src/testAdapter.ts
@@ -60,6 +60,7 @@ export class NbTestAdapter implements TestAdapter {
loadedTests.forEach((suite: TestSuite) => {
this.updateTests(suite);
});
+ this.children.sort((a, b) => a.label.localeCompare(b.label));
}
if (this.children.length > 0) {
this.testsEmitter.fire(<TestLoadFinishedEvent>{ type: 'finished',
suite: this.testSuite });
@@ -152,9 +153,13 @@ export class NbTestAdapter implements TestAdapter {
}
testProgress(suite: TestSuite): void {
+ let cnt = this.children.length;
switch (suite.state) {
case 'loaded':
if (this.updateTests(suite)) {
+ if (this.children.length !== cnt) {
+ this.children.sort((a, b) =>
a.label.localeCompare(b.label));
+ }
this.testsEmitter.fire(<TestLoadFinishedEvent>{ type:
'finished', suite: this.testSuite });
}
break;
@@ -166,6 +171,9 @@ export class NbTestAdapter implements TestAdapter {
let errMessage: string | undefined;
if (suite.tests) {
if (this.updateTests(suite, true)) {
+ if (this.children.length !== cnt) {
+ this.children.sort((a, b) =>
a.label.localeCompare(b.label));
+ }
this.testsEmitter.fire(<TestLoadFinishedEvent>{ type:
'finished', suite: this.testSuite });
}
const currentSuite = this.children.find(s => s.id ===
suite.suiteName);
diff --git
a/java/junit.ui/src/org/netbeans/modules/junit/ui/actions/TestClassInfoTask.java
b/java/junit.ui/src/org/netbeans/modules/junit/ui/actions/TestClassInfoTask.java
index 072195a..85578a5 100644
---
a/java/junit.ui/src/org/netbeans/modules/junit/ui/actions/TestClassInfoTask.java
+++
b/java/junit.ui/src/org/netbeans/modules/junit/ui/actions/TestClassInfoTask.java
@@ -44,6 +44,8 @@ import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Position;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.UnitTestForSourceQuery;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.CompilationInfo;
import org.netbeans.api.java.source.JavaSource.Phase;
@@ -77,8 +79,10 @@ public final class TestClassInfoTask implements
Task<CompilationController> {
}
public static List<TestMethod> computeTestMethods(CompilationInfo info,
AtomicBoolean cancel, int caretPosIfAny) {
- //TODO: first verify if this is a test class/class in a test source
group?
FileObject fileObject = info.getFileObject();
+ if (!isTestSource(fileObject)) {
+ return Collections.emptyList();
+ }
ClassTree clazz;
List<TreePath> methods;
if (caretPosIfAny == (-1)) {
@@ -149,6 +153,17 @@ public final class TestClassInfoTask implements
Task<CompilationController> {
return singleMethod;
}
+ private static boolean isTestSource(FileObject fo) {
+ ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
+ if (cp != null) {
+ FileObject root = cp.findOwnerRoot(fo);
+ if (root != null) {
+ return UnitTestForSourceQuery.findSources(root).length > 0;
+ }
+ }
+ return false;
+ }
+
private static boolean isJunit4Test(List<? extends AnnotationMirror>
allAnnotationMirrors) {
for (Iterator<? extends AnnotationMirror> it =
allAnnotationMirrors.iterator(); it.hasNext();) {
AnnotationMirror annotationMirror = it.next();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists