This is an automated email from the ASF dual-hosted git repository.

matthiasblaesing 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 9121943540 Fix unstable unittest 
org.netbeans.modules.maven.ModuleInfoSupportTest
     new a872ceb725 Merge pull request #6168 from 
matthiasblaesing/maven_module_support_2
9121943540 is described below

commit 91219435407853d1a854c41be491cd731063c3fa
Author: Matthias Bläsing <mblaes...@doppel-helix.eu>
AuthorDate: Sat Jul 8 22:10:17 2023 +0200

    Fix unstable unittest org.netbeans.modules.maven.ModuleInfoSupportTest
    
    25347dfe7f75e540d751f06b541320dc6c5511ce introduces a new unittest,
    that proved to be unstable in CI/CD pipeline. The failure can be
    reproduced after several tries. Adding
    
    workDir.getFileSystem().refresh(true);
    
    seems to fix the issue. Hypothesis:
    
    The new module files are written outside the filesystem infrastructure
    of NetBeans and the cache of the javac integration does not pick up the
    module files created by the javac-Tool.
    
    Apart from the fix, style of the code was improved.
---
 .../modules/maven/ModuleInfoSupportTest.java       | 62 ++++++++++++++--------
 1 file changed, 41 insertions(+), 21 deletions(-)

diff --git 
a/java/maven/test/unit/src/org/netbeans/modules/maven/ModuleInfoSupportTest.java
 
b/java/maven/test/unit/src/org/netbeans/modules/maven/ModuleInfoSupportTest.java
index badb91c19e..aa3d26a93c 100644
--- 
a/java/maven/test/unit/src/org/netbeans/modules/maven/ModuleInfoSupportTest.java
+++ 
b/java/maven/test/unit/src/org/netbeans/modules/maven/ModuleInfoSupportTest.java
@@ -21,11 +21,13 @@ package org.netbeans.modules.maven;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import javax.tools.ToolProvider;
 import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.java.platform.JavaPlatformManager;
 import org.netbeans.api.java.source.ClasspathInfo;
 import org.netbeans.api.java.source.JavaSource;
 import org.netbeans.junit.NbTestCase;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.filesystems.test.TestFileUtils;
@@ -43,50 +45,68 @@ public class ModuleInfoSupportTest extends NbTestCase {
 
     public void testAddRequires() throws Exception {
         System.setProperty("test.load.sync", "true");
-        FileObject d = FileUtil.toFileObject(getWorkDir());
-        TestFileUtils.writeFile(d, "module-info.java",
-                "module Mavenproject {\n}");
-        FileObject moduleInfo = d.getFileObject("module-info.java");
+        FileObject workDir = FileUtil.toFileObject(getWorkDir());
+        FileObject moduleInfo = TestFileUtils.writeFile(
+                workDir,
+                "module-info.java",
+                "module Mavenproject {\n}"
+        );
         ModuleInfoSupport.addRequires(moduleInfo, List.of("test.dummy"));
         assertEquals("module Mavenproject {\n    requires test.dummy;\n}", 
moduleInfo.asText());
     }
 
     public void testGetDeclaredModules() throws Exception {
         System.setProperty("test.load.sync", "true");
-        FileObject d = FileUtil.toFileObject(getWorkDir());
-        FileObject dummy = d.createFolder("dummy");
-        FileObject dummy2 = d.createFolder("dummy2");
-        TestFileUtils.writeFile(dummy, "module-info.java", "module test.dummy 
{}");
-        TestFileUtils.writeFile(dummy2, "module-info.java", "module 
test.dummy2x {}");
-        TestFileUtils.writeFile(d, "module-info.java",
+        FileObject workDir = FileUtil.toFileObject(getWorkDir());
+        FileObject dummyDir = workDir.createFolder("dummy");
+        FileObject dummy2xDir = workDir.createFolder("dummy2x");
+        FileObject dummyModuleInfo = TestFileUtils.writeFile(
+                dummyDir,
+                "module-info.java",
+                "module test.dummy {}"
+        );
+        FileObject dummy2xModuleInfo = TestFileUtils.writeFile(
+                dummy2xDir,
+                "module-info.java",
+                "module test.dummy2x {}"
+        );
+        FileObject moduleInfo = TestFileUtils.writeFile(workDir, 
"module-info.java",
                 "module Mavenproject {"
                 + "    requires test.dummy;\n"
                 + "    requires test.dummy2x;\n"
                 + "\n}");
-        FileObject moduleInfo = d.getFileObject("module-info.java");
 
-        javax.tools.ToolProvider.getSystemJavaCompiler().run(
+        ToolProvider.getSystemJavaCompiler().run(
                 System.in,
                 System.out,
                 System.err,
-                "-d", dummy.getPath(),
-                dummy.getFileObject("module-info.java").getPath()
+                "-d", dummyDir.getPath(),
+                dummyModuleInfo.getPath()
         );
 
-        javax.tools.ToolProvider.getSystemJavaCompiler().run(
+        ToolProvider.getSystemJavaCompiler().run(
                 System.in,
                 System.out,
                 System.err,
-                "-d", dummy2.getPath(),
-                dummy2.getFileObject("module-info.java").getPath()
+                "-d", dummy2xDir.getPath(),
+                dummy2xModuleInfo.getPath()
         );
 
-        ClassPath cp = 
org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(
-                dummy, dummy2
+        // Enforce refresh NB view of filesystem - assumes, that file system 
for
+        // both dummy modules is identical
+        workDir.getFileSystem().refresh(true);
+
+        ClassPath bootClasspath = JavaPlatformManager
+                .getDefault()
+                .getDefaultPlatform()
+                .getBootstrapLibraries();
+
+        ClassPath modulePath = ClassPathSupport.createClassPath(
+                dummyDir, dummy2xDir
         );
 
-        ClasspathInfo cpi = new 
ClasspathInfo.Builder(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries())
-                .setModuleCompilePath(cp)
+        ClasspathInfo cpi = new ClasspathInfo.Builder(bootClasspath)
+                .setModuleCompilePath(modulePath)
                 .build();
 
         JavaSource js = JavaSource.create(cpi, moduleInfo);


---------------------------------------------------------------------
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

Reply via email to