|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, IBM Corporation. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +import jdk.test.lib.process.*; |
| 25 | +import jdk.test.lib.Asserts; |
| 26 | + |
| 27 | +import java.io.InputStreamReader; |
| 28 | +import java.io.FileInputStream; |
| 29 | +import java.nio.charset.StandardCharsets; |
| 30 | +import java.nio.file.Path; |
| 31 | +import java.nio.file.Files; |
| 32 | +import java.util.Properties; |
| 33 | + |
| 34 | +import jdk.tools.jlink.internal.LinkableRuntimeImage; |
| 35 | + |
| 36 | +import tests.Helper; |
| 37 | + |
| 38 | +/* @test |
| 39 | + * @bug 8372155 |
| 40 | + * @summary Test the --release-info <file> plugin option |
| 41 | + * @library ../../lib |
| 42 | + * @library /test/lib |
| 43 | + * @modules jdk.jlink/jdk.tools.jlink.internal |
| 44 | + * jdk.jlink/jdk.tools.jimage |
| 45 | + * java.base/jdk.internal.jimage |
| 46 | + * @build tests.* |
| 47 | + * @run main/othervm ReleaseInfoPluginTest |
| 48 | + */ |
| 49 | + |
| 50 | +public class ReleaseInfoPluginTest { |
| 51 | + |
| 52 | + private static final String NON_ASCII = "ößäakl vendor oy"; |
| 53 | + private static final String IMPL = "IMPLEMENTOR"; |
| 54 | + private static final boolean LINKABLE_RUNTIME = LinkableRuntimeImage.isLinkableRuntime(); |
| 55 | + |
| 56 | + public static void main(String[] args) throws Throwable { |
| 57 | + |
| 58 | + Helper helper = Helper.newHelper(LINKABLE_RUNTIME); |
| 59 | + if (helper == null) { |
| 60 | + System.err.println("Test not run"); |
| 61 | + return; |
| 62 | + } |
| 63 | + var utf8File = Path.of("release-info-utf-8.txt"); |
| 64 | + Files.writeString(utf8File, IMPL + "=\"" + NON_ASCII + "\"", StandardCharsets.UTF_8); |
| 65 | + var image = helper.generateDefaultImage( |
| 66 | + new String[] { |
| 67 | + "--release-info", utf8File.toString() |
| 68 | + }, "java.base").assertSuccess(); |
| 69 | + |
| 70 | + // release file produced should have IMPLEMENTOR in an |
| 71 | + // appropriate encoding |
| 72 | + var release = image.resolve("release"); |
| 73 | + Properties props = new Properties(); |
| 74 | + try (InputStreamReader isr = new InputStreamReader(new FileInputStream(release.toFile()), "UTF-8")) { |
| 75 | + props.load(isr); |
| 76 | + } |
| 77 | + String noQuotesMods = ((String)props.get("MODULES")).replace("\"", ""); |
| 78 | + Asserts.assertEquals("java.base", noQuotesMods); |
| 79 | + String noQuotesActual = ((String)props.get(IMPL)).replace("\"", ""); |
| 80 | + Asserts.assertEquals(NON_ASCII, noQuotesActual); |
| 81 | + } |
| 82 | + |
| 83 | +} |
0 commit comments