diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddSapMachineTools.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddSapMachineTools.java new file mode 100644 index 00000000000..b7deaae5aea --- /dev/null +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddSapMachineTools.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2025 SAP SE. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package jdk.tools.jlink.internal.plugins; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import jdk.tools.jlink.internal.ExecutableImage; +import jdk.tools.jlink.internal.Platform; +import jdk.tools.jlink.internal.PostProcessor; +import jdk.tools.jlink.plugin.PluginException; +import jdk.tools.jlink.plugin.ResourcePool; +import jdk.tools.jlink.plugin.ResourcePoolBuilder; + +/** + * Adds tools that are SapMachine specific + */ +public class AddSapMachineTools extends AbstractPlugin implements PostProcessor { + + public AddSapMachineTools() { + super("add-sapmachine-tools"); + } + + @Override + public Category getType() { + return Category.ADDER; + } + + @Override + public boolean hasArguments() { + return false; + } + + @Override + public boolean hasRawArgument() { + return false; + } + + private final String[] tools = { + "bin/asprof", + "lib/" + System.mapLibraryName("asyncProfiler"), + "lib/async-profiler.jar", + "lib/converter.jar", + "legal/async/CHANGELOG.md", + "legal/async/LICENSE", + "legal/async/README.md" + }; + + @Override + public List process(ExecutableImage image) { + var targetPlatform = image.getTargetPlatform(); + var runtimePlatform = Platform.runtime(); + + if (!targetPlatform.equals(runtimePlatform)) { + throw new PluginException("Cannot add SapMachine tools: target image platform " + + targetPlatform.toString() + " is different from runtime platform " + + runtimePlatform.toString()); + } + + var sourceJavaHome = Path.of(System.getProperty("java.home")); + var targetJavaHome = image.getHome(); + + for (String tool : tools) { + var path = sourceJavaHome.resolve(tool); + var target = targetJavaHome.resolve(tool); + if (Files.exists(path)) { + try { + Files.createDirectories(target.getParent()); + Files.copy(path, target); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + + return null; + } + + @Override + public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { + return in; + } +} 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..c5250990452 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 @@ -287,6 +287,13 @@ Invalid language tag: %s include-locales.localedatanotfound=\ jdk.localedata module was not specified with --add-modules option +# SapMachine 2025-09-01: SapMachine tools plugin +add-sapmachine-tools.description=\ +Add SapMachine specific tools to the image. + +add-sapmachine-tools.usage=\ +\ --add-sapmachine-tools Add SapMachine specific tools to the image. + main.status.ok=Functional. main.status.not.ok= Not functional. diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins_de.properties b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins_de.properties index 4713eabed85..87cf659394b 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins_de.properties +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins_de.properties @@ -158,6 +158,11 @@ include-locales.invalidtag=Ungültiges Sprachtag: %s include-locales.localedatanotfound=Modul jdk.localedata wurde mit der Option --add-modules nicht angegeben +# SapMachine 2025-09-01: SapMachine tools plugin +add-sapmachine-tools.description=Fügt SapMachine-spezifische Tools zum Image hinzu. + +add-sapmachine-tools.usage=\ --add-sapmachine-tools Fügt SapMachine-spezifische Tools zum Image hinzu. + main.status.ok=Funktional. main.status.not.ok= Nicht funktional. diff --git a/src/jdk.jlink/share/classes/module-info.java b/src/jdk.jlink/share/classes/module-info.java index a4fa40dc790..e078e892737 100644 --- a/src/jdk.jlink/share/classes/module-info.java +++ b/src/jdk.jlink/share/classes/module-info.java @@ -84,5 +84,7 @@ jdk.tools.jlink.internal.plugins.VendorVMBugURLPlugin, jdk.tools.jlink.internal.plugins.VendorVersionPlugin, jdk.tools.jlink.internal.plugins.CDSPlugin, + // SapMachine 2025-01-09: SapMachine tools plugin + jdk.tools.jlink.internal.plugins.AddSapMachineTools, jdk.tools.jlink.internal.plugins.SaveJlinkArgfilesPlugin; } diff --git a/test/hotspot/jtreg/TEST.groups b/test/hotspot/jtreg/TEST.groups index 4724845a52a..28778b7a1bc 100644 --- a/test/hotspot/jtreg/TEST.groups +++ b/test/hotspot/jtreg/TEST.groups @@ -382,7 +382,10 @@ hotspot_gc_shenandoah = \ :tier2_gc_shenandoah \ :tier3_gc_shenandoah +# SapMachine 2019-02-24 : Add tests where SAPMachine has different behavior to tier1, +# or which tests downstream-only features. tier1_runtime = \ + :tier1_sapmachine \ runtime/ \ -runtime/6626217/bug_21227.java \ -runtime/7100935 \ @@ -571,10 +574,7 @@ tier1_sapmachine = \ runtime/Vitals \ runtime/malloctrace -# SapMachine 2019-02-24 : Add tests where SAPMachine has different behavior to tier1, -# or which tests downstream-only features. tier1 = \ - :tier1_sapmachine \ :tier1_common \ :tier1_compiler \ :tier1_gc \ diff --git a/test/jdk/TEST.groups b/test/jdk/TEST.groups index fb975a21209..26af65ea4b2 100644 --- a/test/jdk/TEST.groups +++ b/test/jdk/TEST.groups @@ -37,9 +37,7 @@ jdk_all = \ # # When adding tests to tier1, make sure they end up in one of the tier1_partX groups -# SapMachine 2019-01-24: Add tests where SAPMachine has different behavior to tier1 tier1 = \ - :tier1_sapmachine \ :tier1_part1 \ :tier1_part2 \ :tier1_part3 @@ -50,7 +48,9 @@ tier1_part1 = \ tier1_part2 = \ :jdk_util +# SapMachine 2019-01-24: Add tests where SAPMachine has different behavior to tier1 tier1_part3 = \ + :tier1_sapmachine \ :jdk_math \ :jdk_svc_sanity \ :jdk_foreign \ @@ -67,6 +67,7 @@ tier1_sapmachine = \ jdk/security/JavaDotSecurity/TestJDKIncludeInExceptions.java \ sun/net/www/http/KeepAliveCache/TestConnectionIDFeature.java \ sun/security/lib/cacerts/VerifyCACerts.java \ + tools/jlink/plugins/AddSapMachineToolsTest.java \ tools/launcher/HelpFlagsTest.java \ tools/launcher/VersionCheck.java diff --git a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java new file mode 100644 index 00000000000..a49adac9404 --- /dev/null +++ b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2025 SAP SE. 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 java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.testng.SkipException; +import org.testng.annotations.Test; + +import jdk.test.lib.Platform; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import tests.Helper; + +/* @test + * @summary Test the --add-sapmachine-tools plugin + * @library ../../lib + * @library /test/lib + * @enablePreview + * @modules java.base/jdk.internal.jimage + * jdk.jlink/jdk.tools.jimage + * @run testng AddSapMachineToolsTest + */ +@Test +public class AddSapMachineToolsTest { + + private final String[] sapMachineTools = { + "bin/asprof", + "lib/" + System.mapLibraryName("asyncProfiler"), + "lib/async-profiler.jar", + "lib/converter.jar", + "legal/async/CHANGELOG.md", + "legal/async/LICENSE", + "legal/async/README.md" + }; + + @Test + public void testSapMachineTools() throws IOException { + // async profiler is not pulled in GHA builds, so skip the test there. + // checking whether we are in a GHA environment is hacky because jtreg removes environment variables, + // so we guess by checking for a user name containing the String "runner" + if (System.getProperty("user.name", "n/a").contains("runner")) { + throw new SkipException("Detected a Github Actions environment. No tools get added to SapMachine here, so skip test."); + } + + Helper helper = Helper.newHelper(); + if (helper == null) { + throw new SkipException("JDK image is not suitable for this test."); + } + + // async profiler is only available on a subset of platforms + boolean shouldHaveAsync = Platform.isOSX() || + (Platform.isLinux() && (Platform.isAArch64() || Platform.isPPC() || Platform.isX64()) && !Platform.isMusl()); + + Path sourceJavaHome = Path.of(System.getProperty("java.home")); + + if (shouldHaveAsync) { + for (String tool : sapMachineTools) { + assertTrue(Files.exists(sourceJavaHome.resolve(tool)), tool + " must exist."); + } + System.out.println("All SapMachine tools files found, as expected."); + } else { + for (String tool : sapMachineTools) { + assertFalse(Files.exists(sourceJavaHome.resolve(tool)), tool + " should not exist."); + } + System.out.println("No SapMachine tools files found, as expected."); + } + + var module = "sapmachine.tools"; + helper.generateDefaultJModule(module); + var image = helper + .generateDefaultImage(new String[] { "--add-sapmachine-tools" }, module) + .assertSuccess(); + + if (shouldHaveAsync) { + helper.checkImage(image, module, null, null, sapMachineTools); + } else { + helper.checkImage(image, module, null, sapMachineTools, null); + } + } +}