Skip to content

Commit a75478b

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

File tree

5 files changed

+60
-49
lines changed

5 files changed

+60
-49
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: 37 additions & 31 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,68 @@
2121
* questions.
2222
*/
2323

24-
import java.io.File;
2524
import java.nio.file.Files;
2625
import java.nio.file.Path;
2726

28-
import jdk.test.lib.JDKToolFinder;
2927
import jdk.test.lib.Platform;
30-
import jdk.test.lib.process.*;
31-
import jdk.test.whitebox.WhiteBox;
32-
33-
import tests.Helper;
3428

3529
import jtreg.SkippedException;
3630

31+
import static org.testng.Assert.assertFalse;
32+
import static org.testng.Assert.assertTrue;
33+
34+
import tests.Helper;
35+
3736
/* @test
38-
* @bug 8264322
3937
* @summary Test the --add-sapmachine-tools plugin
40-
* @requires os.family == "linux" | os.family == "mac"
4138
* @library ../../lib
4239
* @library /test/lib
4340
* @modules java.base/jdk.internal.jimage
44-
* jdk.jlink/jdk.tools.jlink.internal
45-
* jdk.jlink/jdk.tools.jmod
4641
* 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
42+
* @run testng AddSapMachineToolsTest
5243
*/
5344

5445
public class AddSapMachineToolsTest {
46+
47+
private static final String[] tools = {
48+
"bin/asprof",
49+
"lib/" + System.mapLibraryName("asyncProfiler"),
50+
"lib/async-profiler.jar",
51+
"lib/converter.jar",
52+
"legal/async/CHANGELOG.md",
53+
"legal/async/LICENSE",
54+
"legal/async/README.md"
55+
};
56+
5557
public static void main(String[] args) throws Throwable {
58+
boolean shouldHaveAsync = Platform.isOSX() ||
59+
(Platform.isLinux() && (Platform.isAArch64() || Platform.isPPC() || Platform.isX64()) && !Platform.isMusl());
5660

57-
Helper helper = Helper.newHelper();
58-
if (helper == null) {
59-
System.err.println("Test not run");
61+
Path sourceJavaHome = Path.of(System.getProperty("java.home"));
62+
63+
if (!shouldHaveAsync) {
64+
for (String tool : tools) {
65+
assertFalse(Files.exists(sourceJavaHome.resolve(tool)), tool + " should not exist.");
66+
}
67+
System.err.println("No SapMachine tools files found, as expected");
6068
return;
6169
}
6270

63-
var sourceJavaHome = Path.of(System.getProperty("java.home"));
71+
Helper helper = Helper.newHelper();
72+
if (helper == null) {
73+
throw new SkippedException("JDK image is not suitable for this test.");
74+
}
6475

65-
if (!Files.exists(sourceJavaHome.resolve("lib/async-profiler.jar"))) {
66-
System.err.println("Test not run, async-profiler not configured");
67-
return;
76+
for (String tool : tools) {
77+
assertTrue(Files.exists(sourceJavaHome.resolve(tool)), tool + " must exist.");
6878
}
6979

7080
var module = "sapmachine.tools";
7181
helper.generateDefaultJModule(module);
72-
var image = helper.generateDefaultImage(new String[] { "--add-sapmachine-tools" },
73-
module)
74-
.assertSuccess();
75-
76-
String subDir = "lib/server/";
82+
var image = helper
83+
.generateDefaultImage(new String[] { "--add-sapmachine-tools" }, module)
84+
.assertSuccess();
7785

78-
helper.checkImage(image, module, null, null,
79-
new String[] { "lib/async-profiler.jar", "lib/converter.jar",
80-
"lib/" + System.mapLibraryName("asyncProfiler")});
86+
helper.checkImage(image, module, null, null, tools);
8187
}
8288
}

0 commit comments

Comments
 (0)