diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java index b4301ea8e45..25789b4d172 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,11 +25,13 @@ package jdk.tools.jlink.internal.plugins; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; +import java.io.Reader; import java.io.UncheckedIOException; import java.lang.module.ModuleDescriptor; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; @@ -107,8 +109,8 @@ public final class ReleaseInfoPlugin extends AbstractPlugin { default: { // --release-info Properties props = new Properties(); - try (FileInputStream fis = new FileInputStream(operation)) { - props.load(fis); + try (Reader reader = Files.newBufferedReader(Path.of(operation))) { + props.load(reader); // Use reader API so as to read in as UTF-8 } catch (IOException exp) { throw new UncheckedIOException(exp); } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties index a4b780a15c3..e9be0b4e587 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -39,6 +39,7 @@ release-info.argument=|add:=:=:...|del: option is to load release properties from the supplied file.\n\ +\ The specified file is expected to be encoded in UTF-8.\n\ add: is to add properties to the 'release' file.\n\ Any number of = pairs can be passed.\n\ del: is to delete the list of keys in release file. @@ -46,7 +47,8 @@ del: is to delete the list of keys in release file. release-info.usage=\ \ --release-info |add:=:=:...|del:\n\ \ option is to load release properties from\n\ -\ the supplied file.\n\ +\ the supplied file. The specified file is expected\n\ +\ to be encoded in UTF-8.\n\ \ add: is to add properties to the 'release' file.\n\ \ Any number of = pairs can be passed.\n\ \ del: is to delete the list of keys in release file. diff --git a/test/jdk/tools/jlink/plugins/ReleaseInfoPluginTest.java b/test/jdk/tools/jlink/plugins/ReleaseInfoPluginTest.java new file mode 100644 index 00000000000..7db3639e24a --- /dev/null +++ b/test/jdk/tools/jlink/plugins/ReleaseInfoPluginTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025, IBM Corporation. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import jdk.test.lib.process.*; +import jdk.test.lib.Asserts; + +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Files; +import java.util.Properties; + +import jdk.tools.jlink.internal.LinkableRuntimeImage; + +import tests.Helper; + +/* @test + * @bug 8372155 + * @summary Test the --release-info plugin option + * @library ../../lib + * @library /test/lib + * @modules jdk.jlink/jdk.tools.jlink.internal + * jdk.jlink/jdk.tools.jimage + * java.base/jdk.internal.jimage + * @build tests.* + * @run main/othervm ReleaseInfoPluginTest + */ + +public class ReleaseInfoPluginTest { + + private static final String NON_ASCII = "ößäakl vendor oy"; + private static final String IMPL = "IMPLEMENTOR"; + private static final boolean LINKABLE_RUNTIME = LinkableRuntimeImage.isLinkableRuntime(); + + public static void main(String[] args) throws Throwable { + + Helper helper = Helper.newHelper(LINKABLE_RUNTIME); + if (helper == null) { + System.err.println("Test not run"); + return; + } + var utf8File = Path.of("release-info-utf-8.txt"); + Files.writeString(utf8File, IMPL + "=\"" + NON_ASCII + "\"", StandardCharsets.UTF_8); + Path image = helper.generateDefaultImage( + new String[] { + "--release-info", utf8File.toString() + }, "java.base").assertSuccess(); + + // release file produced should have IMPLEMENTOR in + // UTF-8 encoding + Path release = image.resolve("release"); + Properties props = new Properties(); + try (Reader reader= Files.newBufferedReader(release)) { + props.load(reader); // Load as UTF-8 + } + String noQuotesMods = ((String)props.get("MODULES")).replace("\"", ""); + Asserts.assertEquals("java.base", noQuotesMods); + String noQuotesActual = ((String)props.get(IMPL)).replace("\"", ""); + Asserts.assertEquals(NON_ASCII, noQuotesActual); + } + +}