From 043711f3e128e8d500847d35520671d9402ac7dc Mon Sep 17 00:00:00 2001 From: Sajeer Date: Fri, 27 Feb 2026 15:04:35 +0530 Subject: [PATCH 1/2] Passing the toolchain environment variabled to InstallFeatureUtil of ci.common, so it will get the toolchain JAVA_HOME --- .../gradle/tasks/AbstractFeatureTask.groovy | 10 +++- .../gradle/InstallFeatureToolchainTest.groovy | 55 +++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/test/groovy/io/openliberty/tools/gradle/InstallFeatureToolchainTest.groovy diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy index 14485c7a..031621bf 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy @@ -110,8 +110,8 @@ public class AbstractFeatureTask extends AbstractServerTask { } private class InstallFeatureTaskUtil extends InstallFeatureUtil { - public InstallFeatureTaskUtil(File installDir, File buildDir, String from, String to, Set pluginListedEsas, List propertiesList, String openLibertyVerion, String containerName, List additionalJsons, String verify, Collection> keyMap) throws PluginScenarioException, PluginExecutionException { - super(installDir, buildDir, from, to, pluginListedEsas, propertiesList, openLibertyVerion, containerName, additionalJsons, verify, keyMap) + public InstallFeatureTaskUtil(File installDir, File buildDir, String from, String to, Set pluginListedEsas, List propertiesList, String openLibertyVerion, String containerName, List additionalJsons, String verify, Collection> keyMap, Map environmentVariables) throws PluginScenarioException, PluginExecutionException { + super(installDir, buildDir, from, to, pluginListedEsas, propertiesList, openLibertyVerion, containerName, additionalJsons, verify, keyMap, environmentVariables) setContainerEngine(this); } @@ -295,7 +295,11 @@ public class AbstractFeatureTask extends AbstractServerTask { private void createNewInstallFeatureUtil(Set pluginListedEsas, List propertiesList, String openLibertyVerion, String containerName, List additionalJsons, Collection> keyMap) throws PluginExecutionException { try { logger.info("Feature signature verify option: " + server.features.verify) - util = new InstallFeatureTaskUtil(getInstallDir(project), project.getLayout().getBuildDirectory().getAsFile().get(), server.features.from, server.features.to, pluginListedEsas, propertiesList, openLibertyVerion, containerName, additionalJsons, server.features.verify, keyMap) + Map envVars = getToolchainEnvVar() + if (envVars != null && !envVars.isEmpty() && envVars.containsKey("JAVA_HOME")) { + logger.debug("Passing toolchain JAVA_HOME to InstallFeatureUtil: " + envVars.get("JAVA_HOME")) + } + util = new InstallFeatureTaskUtil(getInstallDir(project), project.getLayout().getBuildDirectory().getAsFile().get(), server.features.from, server.features.to, pluginListedEsas, propertiesList, openLibertyVerion, containerName, additionalJsons, server.features.verify, keyMap, envVars) } catch (PluginScenarioException e) { logger.debug("Exception received: " + e.getMessage(), (Throwable) e) logger.debug("Installing features from installUtility.") diff --git a/src/test/groovy/io/openliberty/tools/gradle/InstallFeatureToolchainTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/InstallFeatureToolchainTest.groovy new file mode 100644 index 00000000..e28d8ec1 --- /dev/null +++ b/src/test/groovy/io/openliberty/tools/gradle/InstallFeatureToolchainTest.groovy @@ -0,0 +1,55 @@ +package io.openliberty.tools.gradle + +import org.gradle.testkit.runner.BuildResult +import org.junit.Before +import org.junit.BeforeClass +import org.junit.Test + +import static org.junit.Assert.assertTrue + +class InstallFeatureToolchainTest extends AbstractIntegrationTest { + + static File resourceDir = new File("build/resources/test/kernel-install-feature-test") + static File buildDir = new File(integTestDir, "/install-feature-toolchain-test") + static String buildFilename = "install_features_dependencies.gradle" + + @BeforeClass + public static void setup() { + createDir(buildDir) + createTestProject(buildDir, resourceDir, buildFilename) + + // Modify build.gradle to add java plugin and toolchain configuration + File buildFile = new File(buildDir, "build.gradle") + String originalContent = buildFile.text + + // Insert java plugin and toolchain configuration after the liberty plugin line + String modifiedContent = originalContent.replace( + "apply plugin: 'liberty'", + "apply plugin: 'liberty'\napply plugin: 'java'\n\njava {\n toolchain {\n languageVersion = JavaLanguageVersion.of(17)\n }\n}" + ) + buildFile.text = modifiedContent + } + + @Before + public void before() { + runTasks(buildDir, "libertyCreate") + copyServer("server_empty.xml") + deleteDir(new File(buildDir, "build/wlp/lib/features")) + } + + @Test + public void testInstallFeatureWithToolchain() { + BuildResult result = runTasksResult(buildDir, "installFeature") + + String output = result.getOutput() + + assertTrue("Should show toolchain configured message for installFeature task", + output.contains(String.format(TOOLCHAIN_CONFIGURED, "installFeature"))) + } + + private void copyServer(String serverXmlFile) { + File serverXml = new File(buildDir, "build/wlp/usr/servers/defaultServer/server.xml") + File sourceServerXml = new File(resourceDir, serverXmlFile) + copyFile(sourceServerXml, serverXml) + } +} From 256f9e2e91e66c837dde462079a4936626db24fa Mon Sep 17 00:00:00 2001 From: Sajeer Date: Fri, 27 Feb 2026 18:14:33 +0530 Subject: [PATCH 2/2] Added the assertion back to copyServer method --- .../gradle/InstallFeatureToolchainTest.groovy | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/test/groovy/io/openliberty/tools/gradle/InstallFeatureToolchainTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/InstallFeatureToolchainTest.groovy index e28d8ec1..066575be 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/InstallFeatureToolchainTest.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/InstallFeatureToolchainTest.groovy @@ -17,17 +17,14 @@ class InstallFeatureToolchainTest extends AbstractIntegrationTest { public static void setup() { createDir(buildDir) createTestProject(buildDir, resourceDir, buildFilename) - - // Modify build.gradle to add java plugin and toolchain configuration + File buildFile = new File(buildDir, "build.gradle") - String originalContent = buildFile.text - - // Insert java plugin and toolchain configuration after the liberty plugin line - String modifiedContent = originalContent.replace( + def fileContent = buildFile.text + fileContent = fileContent.replace( "apply plugin: 'liberty'", "apply plugin: 'liberty'\napply plugin: 'java'\n\njava {\n toolchain {\n languageVersion = JavaLanguageVersion.of(17)\n }\n}" ) - buildFile.text = modifiedContent + buildFile.text = fileContent } @Before @@ -46,10 +43,9 @@ class InstallFeatureToolchainTest extends AbstractIntegrationTest { assertTrue("Should show toolchain configured message for installFeature task", output.contains(String.format(TOOLCHAIN_CONFIGURED, "installFeature"))) } - - private void copyServer(String serverXmlFile) { - File serverXml = new File(buildDir, "build/wlp/usr/servers/defaultServer/server.xml") - File sourceServerXml = new File(resourceDir, serverXmlFile) - copyFile(sourceServerXml, serverXml) + + private copyServer(String serverFile) { + assertTrue(new File(resourceDir, serverFile).exists()) + copyFile(new File(resourceDir, serverFile), new File(buildDir, "build/wlp/usr/servers/defaultServer/server.xml")) } }