Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for requires.nb.javac modules with javac.source/target > 8. #7201

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Mar 27, 2024

Currently, when a module sets requires.nb.javac, it cannot have javac.source/javac.target > 8, and the use of --release is disabled for it. This is because the requires.nb.javac is implemented using -Xbootclasspath/p:, which is incompatible with both javac.source > 8 and --release.

As NetBeans now practically only supports JDK 17 as the build/runtime JDK, this is becoming increasingly troublesome. JDK 17 includes things like Text Blocks, which would be immensely useful for writing tests, but we cannot use that because javac.source is stuck on 8 for the javac-based modules.

There are multiple ways out of this, but the one in this patch is that we run the compilation with --limit-modules setup in such a way that java.compiler and jdk.compiler are disabled. The correct javac is then pulled from the classpath as any ordinary library. This is a bit tricky, as it means we need to list modules that should be enabled. This is achieved using a custom Ant task, which may run a probe on the target JDK, determining modules that are neither java.compiler nor jdk.compiler, and do not depend either of these.

Some alternatives:

  • using --patch-module, and replace the content of the module (which may be tricky, as this does not remove the all module content)
  • having more precise dependencies on JDK modules inside project.xml, and specifically setup the system module paths to only include these modules. This would work, but is a lot of more work. So, while we may do that in the long run, the patch here still seems reasonable for now to me.

There is an obvious relation to #7188 - either this or that patch will need tweaks to accommodate changes from the other. I am completely fine with doing that here, assuming there's a reasonable timeline.

@lahodaj lahodaj added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) VSCode Extension [ci] enable VSCode Extension tests build ci:all-tests [ci] enable all tests labels Mar 27, 2024
@lahodaj lahodaj requested review from mbien and dbalek March 27, 2024 13:05
@mbien
Copy link
Member

mbien commented Mar 27, 2024

sounds like this would fix #6817? awesome! Thanks for looking into this.

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this solution. It has a very small footprint and is only active for modules which request nb-javac.

As mentioned in the linked issue I investigated a bit the option of making a java module out of nb-javac and patch the jdk with it, which sounded like the closest thing to a boot classpath, but this approach is more elegant.

Comment on lines +96 to +100
InputStream in = p.getInputStream();
int r;
while ((r = in.read()) != (-1)) {
limitModulesText.append((char) r);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the input stream intentionally left open?

@ebarboni
Copy link
Contributor

ebarboni commented Apr 5, 2024

make sense for NB22 ?

@mbien
Copy link
Member

mbien commented Apr 5, 2024

I suggest the following merge order:
NB 22:

NB 23:

This gives devs a chance to update to NB 22 before starting to use the option (since the build would work but NB would break since it would load everything with 1.4 lang level).

cc @matthiasblaesing @neilcsmith-net

@lahodaj lahodaj force-pushed the java-modules-using-jdk9-plus branch from e84e989 to 3e88fb0 Compare April 9, 2024 18:34
@lahodaj
Copy link
Contributor Author

lahodaj commented Apr 9, 2024

FWIW - I've merged with master (to get javac.release), and tried adjust this patch for that:
a7e81d3

Also tried to fix apisupport.ant to support the --limit-modules. The effective way is that is asks nb-javac about modules for the target source level, which also includes the data for --release, and hence this is to a degree independent on the runtime platform. This is:
3e88fb0

Please let me know what you think!

@mbien mbien self-requested a review April 9, 2024 20:15
@mbien
Copy link
Member

mbien commented Apr 10, 2024

the diff below would make the tests pass. It moves the tests to the build-tools job which is JDK 17 and disables some. Feel free to apply to your changes if you want.

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 8c1fcf4..ac9f4ec 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -922,6 +922,10 @@
         if: ${{ matrix.java == '17' }}
         run: ant $OPTS -f extide/o.apache.tools.ant.module test
 
+      - name: apisupport.ant
+        if: ${{ matrix.java == '17' }}
+        run: ant $OPTS -f apisupport/apisupport.ant test
+
       - name: Create Test Summary
         uses: test-summary/action@v2
         if: failure()
@@ -1544,9 +1548,6 @@
       - name: Extract
         run: tar --zstd -xf build.tar.zst
 
-      - name: apisupport.ant
-        run: ant $OPTS -f apisupport/apisupport.ant test
-
       - name: apisupport.project
         run: ant $OPTS -f apisupport/apisupport.project test
 
diff --git a/apisupport/apisupport.ant/nbproject/project.properties b/apisupport/apisupport.ant/nbproject/project.properties
index 03ab15a..eb26886 100644
--- a/apisupport/apisupport.ant/nbproject/project.properties
+++ b/apisupport/apisupport.ant/nbproject/project.properties
@@ -21,39 +21,16 @@
 
 requires.nb.javac=true
 javac.compilerargs=-Xlint -Xlint:-serial
-javac.source=1.8
-javac.release=17
+javac.source=11
+javac.target=11
 javadoc.arch=${basedir}/arch.xml
 
 test-unit-sys-prop.test.nbroot=${nb_all}
 test-unit-sys-prop.test.netbeans.dest.dir=${netbeans.dest.dir}
 test-unit-sys-prop.java.awt.headless=true
 
-test.config.stableBTD.includes=**/*Test.class
-test.config.stableBTD.excludes=\
-    **/AccessibilityQueryImplTest.class,\
-    **/AntArtifactProviderImplTest.class,\
-    **/ApisupportAntUtilsTest.class,\
-    **/AvoidModuleListInProjectConstructorTest.class,\
-    **/BrandingSupportTest.class,\
-    **/BuildZipDistributionTest.class,\
-    **/ClassPathProviderImplTest.class,\
-    **/CustomizerLibrariesTest.class,\
-    **/EvaluatorTest.class,\
-    **/GlobalJavadocForBinaryImplTest.class,\
-    **/GlobalSourceForBinaryImplTest.class,\
-    **/Issue167725DeadlockTest.class,\
-    **/JavadocForBinaryImplTest.class,\
-    **/ModuleActionsTest.class,\
-    **/ModuleListTest.class,\
-    **/ModuleTypePanelTest.class,\
-    **/NbModuleProjectTest.class,\
-    **/ProjectXMLManagerTest.class,\
-    **/SingleModulePropertiesTest.class,\
-    **/SourceForBinaryImplTest.class,\
-    **/SourceLevelQueryImplTest.class,\
-    **/SubprojectProviderImplTest.class,\
-    **/SuiteOperationsTest.class,\
-    **/TestEntryTest.class,\
-    **/UnitTestForSourceQueryImplTest.class,\
-    **/UpdateTrackingFileOwnerQueryTest.class
+test.config.default.includes=**/*Test.class
+test.config.default.excludes=\
+    **/ExternalBuildDirTest.class,\
+    **/UseHtml4JavaTest.class
+
diff --git a/apisupport/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/CompilationDependencyTest.java b/apisupport/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/CompilationDependencyTest.java
index 597b38d..ef778b0 100644
--- a/apisupport/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/CompilationDependencyTest.java
+++ b/apisupport/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/CompilationDependencyTest.java
@@ -88,8 +88,9 @@
         assertFalse("Successfully compiled when is invalid specification version",
                 testingProject.getModuleJarLocation().exists());
     }
-    
-    public void testCompileAgainstPublicPackage() throws Exception {
+
+    // TODO fixme
+    public void fails_on_11_testCompileAgainstPublicPackage() throws Exception {
         NbModuleProject testingProject = TestBase.generateStandaloneModule(getWorkDir(), "testing");
         testingProject.open();
         FileObject buildScript = findBuildXml(testingProject);

@ebarboni ebarboni added this to the NB22 milestone Apr 10, 2024
@lahodaj lahodaj force-pushed the java-modules-using-jdk9-plus branch from 3e88fb0 to ea4246c Compare April 11, 2024 12:24
@lahodaj
Copy link
Contributor Author

lahodaj commented Apr 11, 2024

the diff below would make the tests pass. It moves the tests to the build-tools job which is JDK 17 and disables some. Feel free to apply to your changes if you want.

Thanks! I've applied your patch, except for the change in source/target for apisupport.ant:
ea4246c
Lets see is tests will pass.

@lahodaj lahodaj force-pushed the java-modules-using-jdk9-plus branch from ea4246c to 060f83e Compare April 12, 2024 06:21
@lahodaj lahodaj force-pushed the java-modules-using-jdk9-plus branch from 060f83e to 909eb7e Compare April 15, 2024 05:44
@mbien
Copy link
Member

mbien commented Apr 16, 2024

@lahodaj although I do like the changes here, I am a bit worried that this could cause unexpected issues. Would it make more sense to merge this early in the NB 23 dev cycle rather than at the end of NB 22?

One nitpick I have is that I am no fan of duplicated code in the repo, we might find a way to copy SetupLimitModulesProbe.java around before merging this.

@ebarboni ebarboni modified the milestones: NB22, NB23 Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build ci:all-tests [ci] enable all tests Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) VSCode Extension [ci] enable VSCode Extension tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modules which use nb-javac can't change their source/target/release level
4 participants