From e0ce87e039a001c4aafcbb2dba6ca33455933097 Mon Sep 17 00:00:00 2001 From: Ed Merks Date: Fri, 15 Mar 2024 10:07:59 +0100 Subject: [PATCH] Ensure the product *.ini is loaded and saved using the native encoding The native launcher executable reads the product *.ini, e.g., eclipse.ini, using the native system encoding. Currently the *.ini is loaded and saved in the launched Java application using the system default encoding, but in Java 21 the default encoding is always UTF-8 so we need to be more careful to always use the native encoding regardless of the default encoding. --- .../META-INF/MANIFEST.MF | 2 +- .../equinox/EclipseLauncherParser.java | 3 ++- .../frameworkadmin/equinox/utils/FileUtils.java | 15 ++++++++++++++- .../feature.xml | 2 +- .../feature.xml | 2 +- .../feature.xml | 2 +- features/org.eclipse.equinox.p2.sdk/feature.xml | 2 +- .../org.eclipse.equinox.p2.user.ui/feature.xml | 2 +- .../org.eclipse.equinox.server.p2/feature.xml | 2 +- 9 files changed, 23 insertions(+), 9 deletions(-) diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF index d4e64d91c5..7067043df5 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.frameworkadmin.equinox;singleton:=true -Bundle-Version: 1.3.100.qualifier +Bundle-Version: 1.3.200.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Import-Package: org.eclipse.equinox.frameworkadmin;version="[2.0.0,3.0.0)", diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java index 385d348620..7d1c27aa48 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java @@ -338,7 +338,8 @@ void save(EquinoxLauncherData launcherData, boolean backup) throws IOException { // only write the file if we actually have content if (newlines.size() > 0) { - try (BufferedWriter bw = new BufferedWriter(new FileWriter(launcherConfigFile));) { + try (BufferedWriter bw = new BufferedWriter( + new FileWriter(launcherConfigFile, FileUtils.getNativeCharset()));) { for (String arg : newlines) { if (arg == null) continue; diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java index e139ec970d..54cc0e5c38 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java @@ -16,6 +16,7 @@ import java.io.*; import java.net.*; +import java.nio.charset.Charset; import java.util.*; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.URIUtil; @@ -214,9 +215,12 @@ public static URI fromFileURL(String url) throws URISyntaxException { * Loads an ini file, returning a list of all non-blank lines in the file. Like * eclipseConfig.c/readConfigFile() comment lines ('#' its first character) are * skipped too. + * + * This must load the content using the native system encoding because that's + * what the native launcher executable does. */ public static List loadFile(File file) throws IOException { - try (BufferedReader br = new BufferedReader(new FileReader(file));) { + try (BufferedReader br = new BufferedReader(new FileReader(file, getNativeCharset()));) { String line; List list = new ArrayList<>(); while ((line = br.readLine()) != null) { @@ -230,4 +234,13 @@ public static List loadFile(File file) throws IOException { } } + /** + * The encoding used for reading and writing the ini file. This must be the + * native encoding; as of Java 21, the default encoding is UTF-8. + */ + public static Charset getNativeCharset() { + String encoding = System.getProperty("native.encoding"); //$NON-NLS-1$ + return encoding != null ? Charset.forName(encoding) : Charset.defaultCharset(); + } + } diff --git a/features/org.eclipse.equinox.p2.core.feature/feature.xml b/features/org.eclipse.equinox.p2.core.feature/feature.xml index 30ce00ec72..24ce033068 100644 --- a/features/org.eclipse.equinox.p2.core.feature/feature.xml +++ b/features/org.eclipse.equinox.p2.core.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/features/org.eclipse.equinox.p2.extras.feature/feature.xml b/features/org.eclipse.equinox.p2.extras.feature/feature.xml index b64c373b84..a8937c9fc4 100644 --- a/features/org.eclipse.equinox.p2.extras.feature/feature.xml +++ b/features/org.eclipse.equinox.p2.extras.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/features/org.eclipse.equinox.p2.rcp.feature/feature.xml b/features/org.eclipse.equinox.p2.rcp.feature/feature.xml index 92ccf940ad..af02c57fcb 100644 --- a/features/org.eclipse.equinox.p2.rcp.feature/feature.xml +++ b/features/org.eclipse.equinox.p2.rcp.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/features/org.eclipse.equinox.p2.sdk/feature.xml b/features/org.eclipse.equinox.p2.sdk/feature.xml index e6e76c89b5..57b6f9fa83 100644 --- a/features/org.eclipse.equinox.p2.sdk/feature.xml +++ b/features/org.eclipse.equinox.p2.sdk/feature.xml @@ -2,7 +2,7 @@ diff --git a/features/org.eclipse.equinox.p2.user.ui/feature.xml b/features/org.eclipse.equinox.p2.user.ui/feature.xml index a58bf95841..2d999df15c 100644 --- a/features/org.eclipse.equinox.p2.user.ui/feature.xml +++ b/features/org.eclipse.equinox.p2.user.ui/feature.xml @@ -2,7 +2,7 @@ diff --git a/features/org.eclipse.equinox.server.p2/feature.xml b/features/org.eclipse.equinox.server.p2/feature.xml index eff5d57db1..0761830750 100644 --- a/features/org.eclipse.equinox.server.p2/feature.xml +++ b/features/org.eclipse.equinox.server.p2/feature.xml @@ -2,7 +2,7 @@