Skip to content

Commit 228320a

Browse files
committed
Updates to sapmachine jlink plugin
1 parent e8b3b0f commit 228320a

File tree

5 files changed

+66
-50
lines changed

5 files changed

+66
-50
lines changed

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddSapMachineTools.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, SAP SE. All rights reserved.
2+
* Copyright (c) 2025 SAP SE. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,27 +25,21 @@
2525

2626
package jdk.tools.jlink.internal.plugins;
2727

28+
import java.io.IOException;
2829
import java.io.UncheckedIOException;
29-
import java.nio.charset.StandardCharsets;
3030
import java.nio.file.Files;
3131
import java.nio.file.Path;
32-
import java.nio.file.StandardCopyOption;
3332
import java.util.List;
34-
import java.util.Locale.Category;
35-
import java.util.Map;
36-
import java.util.function.Function;
37-
import java.io.IOException;
3833

3934
import jdk.tools.jlink.internal.ExecutableImage;
40-
import jdk.tools.jlink.internal.PostProcessor;
4135
import jdk.tools.jlink.internal.Platform;
36+
import jdk.tools.jlink.internal.PostProcessor;
4237
import jdk.tools.jlink.plugin.PluginException;
4338
import jdk.tools.jlink.plugin.ResourcePool;
4439
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
45-
import jdk.tools.jlink.plugin.ResourcePoolEntry;
4640

4741
/**
48-
* Adds tools that are SapMachine specific tools
42+
* Adds tools that are SapMachine specific
4943
*/
5044
public class AddSapMachineTools extends AbstractPlugin implements PostProcessor {
5145

@@ -68,9 +62,15 @@ public boolean hasRawArgument() {
6862
return false;
6963
}
7064

71-
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";
72-
73-
private Path javaHomeFolder;
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+
};
7474

7575
@Override
7676
public List<String> process(ExecutableImage image) {
@@ -86,26 +86,24 @@ public List<String> process(ExecutableImage image) {
8686
var sourceJavaHome = Path.of(System.getProperty("java.home"));
8787
var targetJavaHome = image.getHome();
8888

89-
for (String tool : tools.split(" ")) {
89+
for (String tool : tools) {
9090
var path = sourceJavaHome.resolve(tool);
9191
var target = targetJavaHome.resolve(tool);
9292
if (Files.exists(path)) {
9393
try {
9494
Files.createDirectories(target.getParent());
95-
Files.createFile(target);
96-
Files.copy(path, target, StandardCopyOption.REPLACE_EXISTING);
95+
Files.copy(path, target);
9796
} catch (IOException e) {
9897
throw new UncheckedIOException(e);
9998
}
10099
}
101100
}
102101

103-
return List.of();
102+
return null;
104103
}
105104

106105
@Override
107106
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
108107
return in;
109108
}
110-
111109
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ 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
290291
add-sapmachine-tools.description=\
291292
Add SapMachine specific tools to the image.
292293

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +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
8788
jdk.tools.jlink.internal.plugins.AddSapMachineTools,
8889
jdk.tools.jlink.internal.plugins.SaveJlinkArgfilesPlugin;
8990
}
Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, SAP SE. All rights reserved.
2+
* Copyright (c) 2025 SAP SE. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,62 +21,73 @@
2121
* questions.
2222
*/
2323

24-
import java.io.File;
24+
import java.io.IOException;
2525
import java.nio.file.Files;
2626
import java.nio.file.Path;
2727

28-
import jdk.test.lib.JDKToolFinder;
29-
import jdk.test.lib.Platform;
30-
import jdk.test.lib.process.*;
31-
import jdk.test.whitebox.WhiteBox;
28+
import org.testng.annotations.Test;
3229

33-
import tests.Helper;
30+
import jdk.test.lib.Platform;
3431

3532
import jtreg.SkippedException;
3633

34+
import static org.testng.Assert.assertFalse;
35+
import static org.testng.Assert.assertTrue;
36+
37+
import tests.Helper;
38+
3739
/* @test
38-
* @bug 8264322
3940
* @summary Test the --add-sapmachine-tools plugin
40-
* @requires os.family == "linux" | os.family == "mac"
4141
* @library ../../lib
4242
* @library /test/lib
4343
* @modules java.base/jdk.internal.jimage
44-
* jdk.jlink/jdk.tools.jlink.internal
45-
* jdk.jlink/jdk.tools.jmod
4644
* jdk.jlink/jdk.tools.jimage
47-
* jdk.compiler
48-
* @build tests.*
49-
* @build jdk.test.whitebox.WhiteBox
50-
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
51-
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CDSPluginTest
45+
* @run testng AddSapMachineToolsTest
5246
*/
5347

5448
public class AddSapMachineToolsTest {
55-
public static void main(String[] args) throws Throwable {
5649

57-
Helper helper = Helper.newHelper();
58-
if (helper == null) {
59-
System.err.println("Test not run");
50+
private final String[] sapMachineTools = {
51+
"bin/asprof",
52+
"lib/" + System.mapLibraryName("asyncProfiler"),
53+
"lib/async-profiler.jar",
54+
"lib/converter.jar",
55+
"legal/async/CHANGELOG.md",
56+
"legal/async/LICENSE",
57+
"legal/async/README.md"
58+
};
59+
60+
@Test
61+
public void testSapMachineTools() throws IOException {
62+
boolean shouldHaveAsync = Platform.isOSX() ||
63+
(Platform.isLinux() && (Platform.isAArch64() || Platform.isPPC() || Platform.isX64()) && !Platform.isMusl());
64+
65+
Path sourceJavaHome = Path.of(System.getProperty("java.home"));
66+
67+
if (!shouldHaveAsync) {
68+
for (String tool : sapMachineTools) {
69+
assertFalse(Files.exists(sourceJavaHome.resolve(tool)), tool + " should not exist.");
70+
}
71+
System.out.println("No SapMachine tools files found, as expected.");
6072
return;
6173
}
6274

63-
var sourceJavaHome = Path.of(System.getProperty("java.home"));
75+
Helper helper = Helper.newHelper();
76+
if (helper == null) {
77+
throw new SkippedException("JDK image is not suitable for this test.");
78+
}
6479

65-
if (!Files.exists(sourceJavaHome.resolve("lib/async-profiler.jar"))) {
66-
System.err.println("Test not run, async-profiler not configured");
67-
return;
80+
for (String tool : sapMachineTools) {
81+
assertTrue(Files.exists(sourceJavaHome.resolve(tool)), tool + " must exist.");
6882
}
83+
System.out.println("All SapMachine tools files found, as expected.");
6984

7085
var module = "sapmachine.tools";
7186
helper.generateDefaultJModule(module);
72-
var image = helper.generateDefaultImage(new String[] { "--add-sapmachine-tools" },
73-
module)
74-
.assertSuccess();
75-
76-
String subDir = "lib/server/";
87+
var image = helper
88+
.generateDefaultImage(new String[] { "--add-sapmachine-tools" }, module)
89+
.assertSuccess();
7790

78-
helper.checkImage(image, module, null, null,
79-
new String[] { "lib/async-profiler.jar", "lib/converter.jar",
80-
"lib/" + System.mapLibraryName("asyncProfiler")});
91+
helper.checkImage(image, module, null, null, sapMachineTools);
8192
}
8293
}

0 commit comments

Comments
 (0)