-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SapMachine #1894: Add SapMachine tools plugin to jlink #1893
Changes from all commits
c515d5a
e8b3b0f
45ec8e7
b32ffe7
73d1695
ed9b99e
3fc80b3
72b75f3
d602bcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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) { | ||
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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 | ||
* @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() || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to intentionally run the test on all platforms. And when there are no async binaries (as expected), no errors should happen. |
||
(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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to get the right indent in the help output.