Skip to content
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 (17) #1894: Add SapMachine tools plugin to jlink #1900

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -287,6 +287,13 @@ 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.

add-sapmachine-tools.usage=\
\ --add-sapmachine-tools Add SapMachine specific tools to the image.

main.status.ok=Functional.

main.status.not.ok= Not functional.
Expand Down
2 changes: 2 additions & 0 deletions src/jdk.jlink/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
jdk.tools.jlink.internal.plugins.VendorBugURLPlugin,
jdk.tools.jlink.internal.plugins.VendorVMBugURLPlugin,
jdk.tools.jlink.internal.plugins.VendorVersionPlugin,
// SapMachine 2025-01-09: SapMachine tools plugin
jdk.tools.jlink.internal.plugins.AddSapMachineTools,
jdk.tools.jlink.internal.plugins.CDSPlugin;

}
6 changes: 3 additions & 3 deletions test/hotspot/jtreg/TEST.groups
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,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 \
Expand Down Expand Up @@ -524,10 +527,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 \
Expand Down
5 changes: 3 additions & 2 deletions test/jdk/TEST.groups
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -64,6 +64,7 @@ tier1_sapmachine = \
java/util/jar/Manifest/IncludeInExceptionsTest.java \
jdk/security/JavaDotSecurity/TestJDKIncludeInExceptions.java \
sun/security/lib/cacerts/VerifyCACerts.java \
tools/jlink/plugins/AddSapMachineToolsTest.java \
tools/launcher/HelpFlagsTest.java \
tools/launcher/VersionCheck.java

Expand Down
104 changes: 104 additions & 0 deletions test/jdk/tools/jlink/plugins/AddSapMachineToolsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.jdeps/com.sun.tools.classfile
* 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() ||
(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);
}
}
}
Loading