From c515d5afad68425ea9a533d96c656bac1bae9a52 Mon Sep 17 00:00:00 2001
From: Johannes Bechberger <johannes.bechberger@sap.com>
Date: Thu, 9 Jan 2025 10:53:09 +0100
Subject: [PATCH 1/9] Add SapMachine tools jlink plugin

---
 .../internal/plugins/AddSapMachineTools.java  | 111 ++++++++++++++++++
 .../tools/jlink/resources/plugins.properties  |   6 +
 src/jdk.jlink/share/classes/module-info.java  |   1 +
 .../jlink/plugins/AddSapMachineToolsTest.java |  82 +++++++++++++
 4 files changed, 200 insertions(+)
 create mode 100644 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddSapMachineTools.java
 create mode 100644 test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java

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..cbf464eca89
--- /dev/null
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddSapMachineTools.java
@@ -0,0 +1,111 @@
+/*
+ * 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.UncheckedIOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.List;
+import java.util.Locale.Category;
+import java.util.Map;
+import java.util.function.Function;
+import java.io.IOException;
+
+import jdk.tools.jlink.internal.ExecutableImage;
+import jdk.tools.jlink.internal.PostProcessor;
+import jdk.tools.jlink.internal.Platform;
+import jdk.tools.jlink.plugin.PluginException;
+import jdk.tools.jlink.plugin.ResourcePool;
+import jdk.tools.jlink.plugin.ResourcePoolBuilder;
+import jdk.tools.jlink.plugin.ResourcePoolEntry;
+
+/**
+ * Adds tools that are SAPMachine specific tools
+ */
+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 = "lib/" + System.mapLibraryName("asyncProfiler") + " bin/asprof lib/async-profiler.jar lib/converter.jar legal/async/CHANGELOG.md legal/async/LICENSE legal/async/README.md";
+
+    private Path javaHomeFolder;
+
+    @Override
+    public List<String> 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.split(" ")) {
+            var path = sourceJavaHome.resolve(tool);
+            var target = targetJavaHome.resolve(tool);
+            if (Files.exists(path)) {
+                try {
+                    Files.createDirectories(target.getParent());
+                    Files.createFile(target);
+                    Files.copy(path, target, StandardCopyOption.REPLACE_EXISTING);
+                } catch (IOException e) {
+                    throw new UncheckedIOException(e);
+                }
+            }
+        }
+
+        return List.of();
+    }
+
+    @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..4270e66b4cd 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,12 @@ Invalid language tag: %s
 include-locales.localedatanotfound=\
 jdk.localedata module was not specified with --add-modules option
 
+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/module-info.java b/src/jdk.jlink/share/classes/module-info.java
index a4fa40dc790..fc3f88776b8 100644
--- a/src/jdk.jlink/share/classes/module-info.java
+++ b/src/jdk.jlink/share/classes/module-info.java
@@ -84,5 +84,6 @@
         jdk.tools.jlink.internal.plugins.VendorVMBugURLPlugin,
         jdk.tools.jlink.internal.plugins.VendorVersionPlugin,
         jdk.tools.jlink.internal.plugins.CDSPlugin,
+        jdk.tools.jlink.internal.plugins.AddSapMachineTools,
         jdk.tools.jlink.internal.plugins.SaveJlinkArgfilesPlugin;
 }
diff --git a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
new file mode 100644
index 00000000000..a32d93996d2
--- /dev/null
+++ b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import jdk.test.lib.JDKToolFinder;
+import jdk.test.lib.Platform;
+import jdk.test.lib.process.*;
+import jdk.test.whitebox.WhiteBox;
+
+import tests.Helper;
+
+import jtreg.SkippedException;
+
+/* @test
+ * @bug 8264322
+ * @summary Test the --add-sapmachine-tools plugin
+ * @requires os.family == "linux" | os.family == "mac"
+ * @library ../../lib
+ * @library /test/lib
+ * @modules java.base/jdk.internal.jimage
+ *          jdk.jlink/jdk.tools.jlink.internal
+ *          jdk.jlink/jdk.tools.jmod
+ *          jdk.jlink/jdk.tools.jimage
+ *          jdk.compiler
+ * @build tests.*
+ * @build jdk.test.whitebox.WhiteBox
+ * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CDSPluginTest
+ */
+
+public class AddSapMachineToolsTest {
+    public static void main(String[] args) throws Throwable {
+
+        Helper helper = Helper.newHelper();
+        if (helper == null) {
+            System.err.println("Test not run");
+            return;
+        }
+
+        var sourceJavaHome = Path.of(System.getProperty("java.home"));
+
+        if (!Files.exists(sourceJavaHome.resolve("lib/async-profiler.jar"))) {
+            System.err.println("Test not run, async-profiler not configured");
+            return;
+        }
+
+        var module = "sapmachine.tools";
+        helper.generateDefaultJModule(module);
+        var image = helper.generateDefaultImage(new String[] { "--add-sapmachine-tools" },
+                                                module)
+            .assertSuccess();
+
+        String subDir = "lib/server/";
+
+        helper.checkImage(image, module, null, null,
+                      new String[] { "lib/async-profiler.jar", "lib/converter.jar",
+                                     "lib/" + System.mapLibraryName("asyncProfiler")});
+    }
+}

From e8b3b0fa263ddf5897295fd4d9799cb13d9ddde3 Mon Sep 17 00:00:00 2001
From: Johannes Bechberger <johannes.bechberger@sap.com>
Date: Thu, 9 Jan 2025 13:57:48 +0100
Subject: [PATCH 2/9] Fix typo

---
 .../jdk/tools/jlink/internal/plugins/AddSapMachineTools.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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
index cbf464eca89..6429831e111 100644
--- 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
@@ -45,7 +45,7 @@
 import jdk.tools.jlink.plugin.ResourcePoolEntry;
 
 /**
- * Adds tools that are SAPMachine specific tools
+ * Adds tools that are SapMachine specific tools
  */
 public class AddSapMachineTools extends AbstractPlugin implements PostProcessor {
 

From 45ec8e746f462e10941a53d5b3fa0a5c98f3c563 Mon Sep 17 00:00:00 2001
From: Christoph Langer <christoph.langer@sap.com>
Date: Fri, 10 Jan 2025 12:11:47 +0100
Subject: [PATCH 3/9] Updates to sapmachine jlink plugin

---
 .../internal/plugins/AddSapMachineTools.java  | 34 ++++-----
 .../tools/jlink/resources/plugins.properties  |  1 +
 .../jlink/resources/plugins_de.properties     |  5 ++
 src/jdk.jlink/share/classes/module-info.java  |  1 +
 test/jdk/TEST.groups                          |  1 +
 .../jlink/plugins/AddSapMachineToolsTest.java | 75 +++++++++++--------
 6 files changed, 67 insertions(+), 50 deletions(-)

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
index 6429831e111..b7deaae5aea 100644
--- 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
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2025, SAP SE. All rights reserved.
+ * 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
@@ -25,27 +25,21 @@
 
 package jdk.tools.jlink.internal.plugins;
 
+import java.io.IOException;
 import java.io.UncheckedIOException;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
 import java.util.List;
-import java.util.Locale.Category;
-import java.util.Map;
-import java.util.function.Function;
-import java.io.IOException;
 
 import jdk.tools.jlink.internal.ExecutableImage;
-import jdk.tools.jlink.internal.PostProcessor;
 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;
-import jdk.tools.jlink.plugin.ResourcePoolEntry;
 
 /**
- * Adds tools that are SapMachine specific tools
+ * Adds tools that are SapMachine specific
  */
 public class AddSapMachineTools extends AbstractPlugin implements PostProcessor {
 
@@ -68,9 +62,15 @@ public boolean hasRawArgument() {
         return false;
     }
 
-    private final String tools = "lib/" + System.mapLibraryName("asyncProfiler") + " bin/asprof lib/async-profiler.jar lib/converter.jar legal/async/CHANGELOG.md legal/async/LICENSE legal/async/README.md";
-
-    private Path javaHomeFolder;
+    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<String> process(ExecutableImage image) {
@@ -86,26 +86,24 @@ public List<String> process(ExecutableImage image) {
         var sourceJavaHome = Path.of(System.getProperty("java.home"));
         var targetJavaHome = image.getHome();
 
-        for (String tool : tools.split(" ")) {
+        for (String tool : tools) {
             var path = sourceJavaHome.resolve(tool);
             var target = targetJavaHome.resolve(tool);
             if (Files.exists(path)) {
                 try {
                     Files.createDirectories(target.getParent());
-                    Files.createFile(target);
-                    Files.copy(path, target, StandardCopyOption.REPLACE_EXISTING);
+                    Files.copy(path, target);
                 } catch (IOException e) {
                     throw new UncheckedIOException(e);
                 }
             }
         }
 
-        return List.of();
+        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 4270e66b4cd..c9c25e0fade 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,7 @@ 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.
 
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..e83d686cb44 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 fc3f88776b8..e078e892737 100644
--- a/src/jdk.jlink/share/classes/module-info.java
+++ b/src/jdk.jlink/share/classes/module-info.java
@@ -84,6 +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/jdk/TEST.groups b/test/jdk/TEST.groups
index fd76d655172..5392570ef1a 100644
--- a/test/jdk/TEST.groups
+++ b/test/jdk/TEST.groups
@@ -65,6 +65,7 @@ tier1_sapmachine = \
     java/net/Socket/ExceptionText.java \
     java/util/jar/Manifest/IncludeInExceptionsTest.java \
     jdk/security/JavaDotSecurity/TestJDKIncludeInExceptions.java \
+    jdk/tools/jlink/plugins/AddSapMachineToolsTest.java \
     sun/net/www/http/KeepAliveCache/TestConnectionIDFeature.java \
     sun/security/lib/cacerts/VerifyCACerts.java \
     tools/launcher/HelpFlagsTest.java \
diff --git a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
index a32d93996d2..524dae31de6 100644
--- a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
+++ b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2025, SAP SE. All rights reserved.
+ * 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
@@ -21,62 +21,73 @@
  * questions.
  */
 
-import java.io.File;
+import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 
-import jdk.test.lib.JDKToolFinder;
-import jdk.test.lib.Platform;
-import jdk.test.lib.process.*;
-import jdk.test.whitebox.WhiteBox;
+import org.testng.annotations.Test;
 
-import tests.Helper;
+import jdk.test.lib.Platform;
 
 import jtreg.SkippedException;
 
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import tests.Helper;
+
 /* @test
- * @bug 8264322
  * @summary Test the --add-sapmachine-tools plugin
- * @requires os.family == "linux" | os.family == "mac"
  * @library ../../lib
  * @library /test/lib
  * @modules java.base/jdk.internal.jimage
- *          jdk.jlink/jdk.tools.jlink.internal
- *          jdk.jlink/jdk.tools.jmod
  *          jdk.jlink/jdk.tools.jimage
- *          jdk.compiler
- * @build tests.*
- * @build jdk.test.whitebox.WhiteBox
- * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
- * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CDSPluginTest
+ * @run testng AddSapMachineToolsTest
  */
 
 public class AddSapMachineToolsTest {
-    public static void main(String[] args) throws Throwable {
 
-        Helper helper = Helper.newHelper();
-        if (helper == null) {
-            System.err.println("Test not run");
+    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 {
+        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) {
+                assertFalse(Files.exists(sourceJavaHome.resolve(tool)), tool + " should not exist.");
+            }
+            System.out.println("No SapMachine tools files found, as expected.");
             return;
         }
 
-        var sourceJavaHome = Path.of(System.getProperty("java.home"));
+        Helper helper = Helper.newHelper();
+        if (helper == null) {
+            throw new SkippedException("JDK image is not suitable for this test.");
+        }
 
-        if (!Files.exists(sourceJavaHome.resolve("lib/async-profiler.jar"))) {
-            System.err.println("Test not run, async-profiler not configured");
-            return;
+        for (String tool : sapMachineTools) {
+            assertTrue(Files.exists(sourceJavaHome.resolve(tool)), tool + " must exist.");
         }
+        System.out.println("All SapMachine tools files found, as expected.");
 
         var module = "sapmachine.tools";
         helper.generateDefaultJModule(module);
-        var image = helper.generateDefaultImage(new String[] { "--add-sapmachine-tools" },
-                                                module)
-            .assertSuccess();
-
-        String subDir = "lib/server/";
+        var image = helper
+                .generateDefaultImage(new String[] { "--add-sapmachine-tools" }, module)
+                .assertSuccess();
 
-        helper.checkImage(image, module, null, null,
-                      new String[] { "lib/async-profiler.jar", "lib/converter.jar",
-                                     "lib/" + System.mapLibraryName("asyncProfiler")});
+        helper.checkImage(image, module, null, null, sapMachineTools);
     }
 }

From b32ffe7d7b48f755e090bd5942171dc91bbb2205 Mon Sep 17 00:00:00 2001
From: Christoph Langer <christoph.langer@sap.com>
Date: Fri, 10 Jan 2025 19:12:04 +0100
Subject: [PATCH 4/9] Fix TEST.groups entry

---
 test/jdk/TEST.groups | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/jdk/TEST.groups b/test/jdk/TEST.groups
index 5392570ef1a..4ed8e3794c5 100644
--- a/test/jdk/TEST.groups
+++ b/test/jdk/TEST.groups
@@ -65,9 +65,9 @@ tier1_sapmachine = \
     java/net/Socket/ExceptionText.java \
     java/util/jar/Manifest/IncludeInExceptionsTest.java \
     jdk/security/JavaDotSecurity/TestJDKIncludeInExceptions.java \
-    jdk/tools/jlink/plugins/AddSapMachineToolsTest.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
 

From 73d1695e3f9ced531c4fb284e70de43a92007b1f Mon Sep 17 00:00:00 2001
From: Christoph Langer <christoph.langer@sap.com>
Date: Fri, 10 Jan 2025 22:23:48 +0100
Subject: [PATCH 5/9] Make sure SapMachine tier1 tests also run in GHA

---
 test/hotspot/jtreg/TEST.groups | 6 +++---
 test/jdk/TEST.groups           | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/test/hotspot/jtreg/TEST.groups b/test/hotspot/jtreg/TEST.groups
index a664ac03c6e..a018f9fb4fc 100644
--- a/test/hotspot/jtreg/TEST.groups
+++ b/test/hotspot/jtreg/TEST.groups
@@ -361,7 +361,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 \
@@ -621,10 +624,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 4ed8e3794c5..85a5fb2c7f8 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 \

From ed9b99e58c34557590faa6d1ab2f8252517ecfdf Mon Sep 17 00:00:00 2001
From: Christoph Langer <christoph.langer@sap.com>
Date: Sat, 11 Jan 2025 01:06:01 +0100
Subject: [PATCH 6/9] async profiler is not available in Github Actions builds

---
 test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
index 524dae31de6..122dbcbfb9b 100644
--- a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
+++ b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
@@ -59,8 +59,11 @@ public class AddSapMachineToolsTest {
 
     @Test
     public void testSapMachineTools() throws IOException {
-        boolean shouldHaveAsync = Platform.isOSX() ||
-                (Platform.isLinux() && (Platform.isAArch64() || Platform.isPPC() || Platform.isX64()) && !Platform.isMusl());
+        // async profiler is only available on restricted set of platforms and not in Github Actions builds
+        String gha = System.getenv("GITHUB_ACTIONS");
+        boolean shouldHaveAsync = (gha == null || !gha.contains("true")) &&
+                (Platform.isOSX() ||
+                 (Platform.isLinux() && (Platform.isAArch64() || Platform.isPPC() || Platform.isX64()) && !Platform.isMusl()));
 
         Path sourceJavaHome = Path.of(System.getProperty("java.home"));
 

From 3fc80b367346f376e26a8ce3053a455fb078cad1 Mon Sep 17 00:00:00 2001
From: Christoph Langer <christoph.langer@sap.com>
Date: Sat, 11 Jan 2025 09:01:03 +0100
Subject: [PATCH 7/9] Fix detection of GHA

---
 .../jlink/plugins/AddSapMachineToolsTest.java | 22 +++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
index 122dbcbfb9b..b7ec93e8726 100644
--- a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
+++ b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
@@ -25,12 +25,11 @@
 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 jtreg.SkippedException;
-
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
@@ -44,7 +43,7 @@
  *          jdk.jlink/jdk.tools.jimage
  * @run testng AddSapMachineToolsTest
  */
-
+@Test
 public class AddSapMachineToolsTest {
 
     private final String[] sapMachineTools = {
@@ -59,11 +58,16 @@ public class AddSapMachineToolsTest {
 
     @Test
     public void testSapMachineTools() throws IOException {
-        // async profiler is only available on restricted set of platforms and not in Github Actions builds
-        String gha = System.getenv("GITHUB_ACTIONS");
-        boolean shouldHaveAsync = (gha == null || !gha.contains("true")) &&
-                (Platform.isOSX() ||
-                 (Platform.isLinux() && (Platform.isAArch64() || Platform.isPPC() || Platform.isX64()) && !Platform.isMusl()));
+        // 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.");
+        }
+
+        // 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"));
 
@@ -77,7 +81,7 @@ public void testSapMachineTools() throws IOException {
 
         Helper helper = Helper.newHelper();
         if (helper == null) {
-            throw new SkippedException("JDK image is not suitable for this test.");
+            throw new SkipException("JDK image is not suitable for this test.");
         }
 
         for (String tool : sapMachineTools) {

From 72b75f30bb951953fbc8030afdcec5842f71ec6b Mon Sep 17 00:00:00 2001
From: Christoph Langer <christoph.langer@sap.com>
Date: Sat, 11 Jan 2025 17:27:28 +0100
Subject: [PATCH 8/9] Test for absence of async files as well, to make sure
 plugin does not bail out

---
 .../jlink/plugins/AddSapMachineToolsTest.java | 29 ++++++++++---------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
index b7ec93e8726..0dd08bfb4c3 100644
--- a/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
+++ b/test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
@@ -65,36 +65,39 @@ public void testSapMachineTools() throws IOException {
             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) {
+        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.");
-            return;
         }
 
-        Helper helper = Helper.newHelper();
-        if (helper == null) {
-            throw new SkipException("JDK image is not suitable for this test.");
-        }
-
-        for (String tool : sapMachineTools) {
-            assertTrue(Files.exists(sourceJavaHome.resolve(tool)), tool + " must exist.");
-        }
-        System.out.println("All SapMachine tools files found, as expected.");
-
         var module = "sapmachine.tools";
         helper.generateDefaultJModule(module);
         var image = helper
                 .generateDefaultImage(new String[] { "--add-sapmachine-tools" }, module)
                 .assertSuccess();
 
-        helper.checkImage(image, module, null, null, sapMachineTools);
+        if (shouldHaveAsync) {
+            helper.checkImage(image, module, null, null, sapMachineTools);
+        } else {
+            helper.checkImage(image, module, null, sapMachineTools, null);
+        }
     }
 }

From d602bcc11108ae6adb180079a8216b166660457f Mon Sep 17 00:00:00 2001
From: Christoph Langer <christoph.langer@sap.com>
Date: Mon, 13 Jan 2025 13:48:01 +0100
Subject: [PATCH 9/9] Fix help indentation

---
 .../share/classes/jdk/tools/jlink/resources/plugins.properties  | 2 +-
 .../classes/jdk/tools/jlink/resources/plugins_de.properties     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

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 c9c25e0fade..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
@@ -292,7 +292,7 @@ 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.
+\  --add-sapmachine-tools    Add SapMachine specific tools to the image.
 
 main.status.ok=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 e83d686cb44..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
@@ -161,7 +161,7 @@ include-locales.localedatanotfound=Modul jdk.localedata wurde mit der Option --a
 # 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.
+add-sapmachine-tools.usage=\  --add-sapmachine-tools    Fügt SapMachine-spezifische Tools zum Image hinzu.
 
 main.status.ok=Funktional.