This is an automated email from the ASF dual-hosted git repository. jlahoda 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 8deace60d9 The list of tests should include TestNG tests. new 96f6fefb96 Merge pull request #6615 from lahodaj/include-testng-tests 8deace60d9 is described below commit 8deace60d995131825d9b31c536a4e9099abe8eb Author: Jan Lahoda <jan.lah...@oracle.com> AuthorDate: Tue Oct 24 13:08:44 2023 +0200 The list of tests should include TestNG tests. --- .../gsf/testrunner/ui/TestMethodFinderImpl.java | 2 +- java/java.lsp.server/vscode/README.md | 2 +- .../junit/ui/actions/TestClassInfoTask.java | 2 +- java/testng.ui/nbproject/project.xml | 9 ++++++ .../testng/ui/actions/TestClassInfoTask.java | 34 ++++++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/ide/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/TestMethodFinderImpl.java b/ide/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/TestMethodFinderImpl.java index cd505c486c..1aa46f7245 100644 --- a/ide/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/TestMethodFinderImpl.java +++ b/ide/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/TestMethodFinderImpl.java @@ -56,7 +56,7 @@ import org.openide.util.WeakSet; public final class TestMethodFinderImpl extends EmbeddingIndexer { public static final String NAME = "tests"; // NOI18N - public static final int VERSION = 1; + public static final int VERSION = 2; public static final TestMethodFinderImpl INSTANCE = new TestMethodFinderImpl(); private final WeakSet<BiConsumer<FileObject, Collection<TestMethodController.TestMethod>>> listeners = new WeakSet<>(); diff --git a/java/java.lsp.server/vscode/README.md b/java/java.lsp.server/vscode/README.md index 2d401e928f..ddf404874d 100644 --- a/java/java.lsp.server/vscode/README.md +++ b/java/java.lsp.server/vscode/README.md @@ -42,7 +42,7 @@ When running this extension on GraalVM, as its runtime JDK, behind proxy it requ * __Java: New Project...__ allows creation of new Maven or Gradle project * __Java: New from Template...__ add various files to currently selected open project. Files are: * Java - broad selection of various predefined Java classes - * Unit tests - JUnit and TestNB templates for test suites and test cases + * Unit tests - JUnit and TestNG templates for test suites and test cases * HTML5/JavaScript - Templates for JS, HTML, CSS,... files * Other - various templates for JSON, YAML, properties, ... files * __Java: Compile Workspace__ - invoke Maven or Gradle build 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 051645ab73..00103e9b96 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 @@ -281,7 +281,7 @@ public final class TestClassInfoTask implements Task<CompilationController> { } @MimeRegistration(mimeType="text/x-java", service=org.netbeans.modules.gsf.testrunner.ui.spi.ComputeTestMethods.class) - public static final class GenericComputeTestMethodsImpl implements org.netbeans.modules.gsf.testrunner.ui.spi.ComputeTestMethods { + public static final class JUnitComputeTestMethodsImpl implements org.netbeans.modules.gsf.testrunner.ui.spi.ComputeTestMethods { @Override public List<TestMethod> computeTestMethods(Parser.Result parserResult, AtomicBoolean cancel) { diff --git a/java/testng.ui/nbproject/project.xml b/java/testng.ui/nbproject/project.xml index 971beaa66b..65c7364426 100644 --- a/java/testng.ui/nbproject/project.xml +++ b/java/testng.ui/nbproject/project.xml @@ -34,6 +34,15 @@ <specification-version>1.52</specification-version> </run-dependency> </dependency> + <dependency> + <code-name-base>org.netbeans.api.java.classpath</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <release-version>1</release-version> + <specification-version>1.77</specification-version> + </run-dependency> + </dependency> <dependency> <code-name-base>org.netbeans.api.progress</code-name-base> <build-prerequisite/> diff --git a/java/testng.ui/src/org/netbeans/modules/testng/ui/actions/TestClassInfoTask.java b/java/testng.ui/src/org/netbeans/modules/testng/ui/actions/TestClassInfoTask.java index 5a9bb9b781..e8419fa08e 100644 --- a/java/testng.ui/src/org/netbeans/modules/testng/ui/actions/TestClassInfoTask.java +++ b/java/testng.ui/src/org/netbeans/modules/testng/ui/actions/TestClassInfoTask.java @@ -41,6 +41,9 @@ import javax.lang.model.util.Elements; 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.CancellableTask; import org.netbeans.api.java.source.CompilationController; import org.netbeans.api.java.source.CompilationInfo; @@ -48,8 +51,10 @@ import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.modules.gsf.testrunner.ui.api.TestMethodController.TestMethod; import org.netbeans.modules.java.testrunner.ui.spi.ComputeTestMethods; import org.netbeans.modules.java.testrunner.ui.spi.ComputeTestMethods.Factory; +import org.netbeans.modules.parsing.spi.Parser; import org.netbeans.spi.project.SingleMethod; import org.openide.filesystems.FileObject; +import org.openide.util.Exceptions; import org.openide.util.lookup.ServiceProvider; /** @@ -213,6 +218,35 @@ public final class TestClassInfoTask implements CancellableTask<CompilationContr } + @MimeRegistration(mimeType="text/x-java", service=org.netbeans.modules.gsf.testrunner.ui.spi.ComputeTestMethods.class) + public static final class TestNGComputeTestMethodsImpl implements org.netbeans.modules.gsf.testrunner.ui.spi.ComputeTestMethods { + + @Override + public List<TestMethod> computeTestMethods(Parser.Result parserResult, AtomicBoolean cancel) { + try { + CompilationController cc = CompilationController.get(parserResult); + if (isTestSource(cc.getFileObject()) && cc.toPhase(Phase.ELEMENTS_RESOLVED).compareTo(Phase.ELEMENTS_RESOLVED) >= 0) { + return TestClassInfoTask.computeTestMethods(cc, cancel, -1); + } + } catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + return Collections.emptyList(); + } + + 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 class SimplePosition implements Position { private final int offset; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists