Skip to content

Commit ae7f8e5

Browse files
parttimenerdRealCLanger
authored andcommitted
SapMachine SAP#1894: Add SapMachine tools plugin to jlink
(cherry picked from commit bbf2165)
1 parent 904e594 commit ae7f8e5

File tree

7 files changed

+232
-5
lines changed

7 files changed

+232
-5
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2025 SAP SE. 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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package jdk.tools.jlink.internal.plugins;
27+
28+
import java.io.IOException;
29+
import java.io.UncheckedIOException;
30+
import java.nio.file.Files;
31+
import java.nio.file.Path;
32+
import java.util.List;
33+
34+
import jdk.tools.jlink.internal.ExecutableImage;
35+
import jdk.tools.jlink.internal.Platform;
36+
import jdk.tools.jlink.internal.PostProcessor;
37+
import jdk.tools.jlink.plugin.PluginException;
38+
import jdk.tools.jlink.plugin.ResourcePool;
39+
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
40+
41+
/**
42+
* Adds tools that are SapMachine specific
43+
*/
44+
public class AddSapMachineTools extends AbstractPlugin implements PostProcessor {
45+
46+
public AddSapMachineTools() {
47+
super("add-sapmachine-tools");
48+
}
49+
50+
@Override
51+
public Category getType() {
52+
return Category.ADDER;
53+
}
54+
55+
@Override
56+
public boolean hasArguments() {
57+
return false;
58+
}
59+
60+
@Override
61+
public boolean hasRawArgument() {
62+
return false;
63+
}
64+
65+
private final String[] tools = {
66+
"bin/asprof",
67+
"lib/" + System.mapLibraryName("asyncProfiler"),
68+
"lib/async-profiler.jar",
69+
"lib/converter.jar",
70+
"legal/async/CHANGELOG.md",
71+
"legal/async/LICENSE",
72+
"legal/async/README.md"
73+
};
74+
75+
@Override
76+
public List<String> process(ExecutableImage image) {
77+
var targetPlatform = image.getTargetPlatform();
78+
var runtimePlatform = Platform.runtime();
79+
80+
if (!targetPlatform.equals(runtimePlatform)) {
81+
throw new PluginException("Cannot add SapMachine tools: target image platform " +
82+
targetPlatform.toString() + " is different from runtime platform " +
83+
runtimePlatform.toString());
84+
}
85+
86+
var sourceJavaHome = Path.of(System.getProperty("java.home"));
87+
var targetJavaHome = image.getHome();
88+
89+
for (String tool : tools) {
90+
var path = sourceJavaHome.resolve(tool);
91+
var target = targetJavaHome.resolve(tool);
92+
if (Files.exists(path)) {
93+
try {
94+
Files.createDirectories(target.getParent());
95+
Files.copy(path, target);
96+
} catch (IOException e) {
97+
throw new UncheckedIOException(e);
98+
}
99+
}
100+
}
101+
102+
return null;
103+
}
104+
105+
@Override
106+
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
107+
return in;
108+
}
109+
}

src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ Invalid language tag: %s
287287
include-locales.localedatanotfound=\
288288
jdk.localedata module was not specified with --add-modules option
289289

290+
# SapMachine 2025-09-01: SapMachine tools plugin
291+
add-sapmachine-tools.description=\
292+
Add SapMachine specific tools to the image.
293+
294+
add-sapmachine-tools.usage=\
295+
\ --add-sapmachine-tools Add SapMachine specific tools to the image.
296+
290297
main.status.ok=Functional.
291298

292299
main.status.not.ok= Not functional.

src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins_de.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ include-locales.invalidtag=Ungültiges Sprachtag: %s
158158

159159
include-locales.localedatanotfound=Modul jdk.localedata wurde mit der Option --add-modules nicht angegeben
160160

161+
# SapMachine 2025-09-01: SapMachine tools plugin
162+
add-sapmachine-tools.description=Fügt SapMachine-spezifische Tools zum Image hinzu.
163+
164+
add-sapmachine-tools.usage=\ --add-sapmachine-tools Fügt SapMachine-spezifische Tools zum Image hinzu.
165+
161166
main.status.ok=Funktional.
162167

163168
main.status.not.ok= Nicht funktional.

src/jdk.jlink/share/classes/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,7 @@
8484
jdk.tools.jlink.internal.plugins.VendorVMBugURLPlugin,
8585
jdk.tools.jlink.internal.plugins.VendorVersionPlugin,
8686
jdk.tools.jlink.internal.plugins.CDSPlugin,
87+
// SapMachine 2025-01-09: SapMachine tools plugin
88+
jdk.tools.jlink.internal.plugins.AddSapMachineTools,
8789
jdk.tools.jlink.internal.plugins.SaveJlinkArgfilesPlugin;
8890
}

test/hotspot/jtreg/TEST.groups

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ hotspot_gc_shenandoah = \
374374
:tier2_gc_shenandoah \
375375
:tier3_gc_shenandoah
376376

377+
# SapMachine 2019-02-24 : Add tests where SAPMachine has different behavior to tier1,
378+
# or which tests downstream-only features.
377379
tier1_runtime = \
380+
:tier1_sapmachine \
378381
runtime/ \
379382
-runtime/6626217/bug_21227.java \
380383
-runtime/7100935 \
@@ -635,10 +638,7 @@ tier1_sapmachine = \
635638
runtime/Vitals \
636639
runtime/malloctrace
637640

638-
# SapMachine 2019-02-24 : Add tests where SAPMachine has different behavior to tier1,
639-
# or which tests downstream-only features.
640641
tier1 = \
641-
:tier1_sapmachine \
642642
:tier1_common \
643643
:tier1_compiler \
644644
:tier1_gc \

test/jdk/TEST.groups

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ jdk_all = \
3737
#
3838

3939
# When adding tests to tier1, make sure they end up in one of the tier1_partX groups
40-
# SapMachine 2019-01-24: Add tests where SAPMachine has different behavior to tier1
4140
tier1 = \
42-
:tier1_sapmachine \
4341
:tier1_part1 \
4442
:tier1_part2 \
4543
:tier1_part3
@@ -50,7 +48,9 @@ tier1_part1 = \
5048
tier1_part2 = \
5149
:jdk_util
5250

51+
# SapMachine 2019-01-24: Add tests where SAPMachine has different behavior to tier1
5352
tier1_part3 = \
53+
:tier1_sapmachine \
5454
:jdk_math \
5555
:jdk_svc_sanity \
5656
:jdk_foreign \
@@ -67,6 +67,7 @@ tier1_sapmachine = \
6767
jdk/security/JavaDotSecurity/TestJDKIncludeInExceptions.java \
6868
sun/net/www/http/KeepAliveCache/TestConnectionIDFeature.java \
6969
sun/security/lib/cacerts/VerifyCACerts.java \
70+
tools/jlink/plugins/AddSapMachineToolsTest.java \
7071
tools/launcher/HelpFlagsTest.java \
7172
tools/launcher/VersionCheck.java
7273

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 2025 SAP SE. 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 java.io.IOException;
25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
27+
28+
import org.testng.SkipException;
29+
import org.testng.annotations.Test;
30+
31+
import jdk.test.lib.Platform;
32+
33+
import static org.testng.Assert.assertFalse;
34+
import static org.testng.Assert.assertTrue;
35+
36+
import tests.Helper;
37+
38+
/* @test
39+
* @summary Test the --add-sapmachine-tools plugin
40+
* @library ../../lib
41+
* @library /test/lib
42+
* @modules java.base/jdk.internal.jimage
43+
* jdk.jlink/jdk.tools.jimage
44+
* @run testng AddSapMachineToolsTest
45+
*/
46+
@Test
47+
public class AddSapMachineToolsTest {
48+
49+
private final String[] sapMachineTools = {
50+
"bin/asprof",
51+
"lib/" + System.mapLibraryName("asyncProfiler"),
52+
"lib/async-profiler.jar",
53+
"lib/converter.jar",
54+
"legal/async/CHANGELOG.md",
55+
"legal/async/LICENSE",
56+
"legal/async/README.md"
57+
};
58+
59+
@Test
60+
public void testSapMachineTools() throws IOException {
61+
// async profiler is not pulled in GHA builds, so skip the test there.
62+
// checking whether we are in a GHA environment is hacky because jtreg removes environment variables,
63+
// so we guess by checking for a user name containing the String "runner"
64+
if (System.getProperty("user.name", "n/a").contains("runner")) {
65+
throw new SkipException("Detected a Github Actions environment. No tools get added to SapMachine here, so skip test.");
66+
}
67+
68+
Helper helper = Helper.newHelper();
69+
if (helper == null) {
70+
throw new SkipException("JDK image is not suitable for this test.");
71+
}
72+
73+
// async profiler is only available on a subset of platforms
74+
boolean shouldHaveAsync = Platform.isOSX() ||
75+
(Platform.isLinux() && (Platform.isAArch64() || Platform.isPPC() || Platform.isX64()) && !Platform.isMusl());
76+
77+
Path sourceJavaHome = Path.of(System.getProperty("java.home"));
78+
79+
if (shouldHaveAsync) {
80+
for (String tool : sapMachineTools) {
81+
assertTrue(Files.exists(sourceJavaHome.resolve(tool)), tool + " must exist.");
82+
}
83+
System.out.println("All SapMachine tools files found, as expected.");
84+
} else {
85+
for (String tool : sapMachineTools) {
86+
assertFalse(Files.exists(sourceJavaHome.resolve(tool)), tool + " should not exist.");
87+
}
88+
System.out.println("No SapMachine tools files found, as expected.");
89+
}
90+
91+
var module = "sapmachine.tools";
92+
helper.generateDefaultJModule(module);
93+
var image = helper
94+
.generateDefaultImage(new String[] { "--add-sapmachine-tools" }, module)
95+
.assertSuccess();
96+
97+
if (shouldHaveAsync) {
98+
helper.checkImage(image, module, null, null, sapMachineTools);
99+
} else {
100+
helper.checkImage(image, module, null, sapMachineTools, null);
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)