From 398c98855c2eab6d26ecb93400e171f9ae96ab23 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Thu, 29 Aug 2024 17:38:21 +0800 Subject: [PATCH] Add default --add-opens args to tooling api --- .../GradleBuildServerProjectImporter.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java index e55483e9..9f6ca170 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java @@ -2,12 +2,15 @@ package com.microsoft.gradle.bs.importer; import java.io.File; import java.net.URI; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.CompletionException; import java.util.stream.Collectors; @@ -401,7 +404,24 @@ public class GradleBuildServerProjectImporter extends AbstractProjectImporter { pref.setGradleArguments(jdtlsPreferences.getGradleArguments()); pref.setGradleHome(jdtlsPreferences.getGradleHome()); pref.setGradleJavaHome(jdtlsPreferences.getGradleJavaHome()); - pref.setGradleJvmArguments(jdtlsPreferences.getGradleJvmArguments()); + Set jvmArgs = jdtlsPreferences.getGradleJvmArguments().stream() + .map(String::trim) + .collect(Collectors.toCollection(LinkedHashSet::new)); + String[] defaultJvmArgs = { + "--add-opens=java.base/java.lang=ALL-UNNAMED", + "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED", + "--add-opens=java.base/java.net=ALL-UNNAMED", + "--add-opens=java.base/java.nio.charset=ALL-UNNAMED", + "--add-opens=java.base/java.util=ALL-UNNAMED", + "--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED", + "--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED", + }; + for (String arg : defaultJvmArgs) { + if (!jvmArgs.contains(arg)) { + jvmArgs.add(arg); + } + } + pref.setGradleJvmArguments(new ArrayList<>(jvmArgs)); pref.setGradleUserHome(jdtlsPreferences.getGradleUserHome()); pref.setGradleVersion(jdtlsPreferences.getGradleVersion()); pref.setJdks(EclipseVmUtil.getAllVmInstalls());