Skip to content

Commit 70f0d15

Browse files
SajeerSajeer
authored andcommitted
Added toolchin support for devmode, compiler plugin. Also enabled jdkToolchain for testing
1 parent fce88d9 commit 70f0d15

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import io.openliberty.tools.common.plugins.util.LibertyPropFilesUtility;
4545
import io.openliberty.tools.maven.utils.CommonLogger;
46+
import org.apache.commons.lang3.StringUtils;
4647
import org.apache.maven.artifact.Artifact;
4748
import org.apache.maven.artifact.DependencyResolutionRequiredException;
4849
import org.apache.maven.execution.MavenSession;
@@ -520,7 +521,16 @@ public ServerTask getServerTask() throws Exception {
520521

521522
// set environment variables for server start task
522523
serverTask.setOperation("debug");
523-
serverTask.setEnvironmentVariables(getDebugEnvironmentVariables());
524+
525+
// Merge toolchain environment with debug environment
526+
Map<String, String> debugEnv = getDebugEnvironmentVariables();
527+
if (toolchain != null) {
528+
String toolchainJavaHome = getJdkHomeFromToolchain(toolchain);
529+
if (toolchainJavaHome != null) {
530+
debugEnv.put("JAVA_HOME", toolchainJavaHome);
531+
}
532+
}
533+
serverTask.setEnvironmentVariables(debugEnv);
524534
} else {
525535
serverTask.setOperation("run");
526536
}
@@ -1740,24 +1750,67 @@ private JavaCompilerOptions getMavenCompilerOptions(MavenProject currentProject)
17401750
String release = getCompilerOption(configuration, "release", "maven.compiler.release", currentProject);
17411751
String source = getCompilerOption(configuration, "source", "maven.compiler.source", currentProject);
17421752
String target = getCompilerOption(configuration, "target", "maven.compiler.target", currentProject);
1753+
1754+
// Fetch the toolchain version configured for the project
1755+
String jdkToolchainVersion = jdkToolchain != null ? jdkToolchain.get("version") : null;
1756+
if (StringUtils.isNotEmpty(jdkToolchainVersion)) {
1757+
String compilerJdkToolchainVersion = null;
1758+
if (configuration != null) {
1759+
Xpp3Dom compilerJdkToolchain = configuration.getChild("jdkToolchain");
1760+
if (compilerJdkToolchain != null) {
1761+
Xpp3Dom versionChild = compilerJdkToolchain.getChild("version");
1762+
if (versionChild != null) {
1763+
compilerJdkToolchainVersion = StringUtils.trimToNull(versionChild.getValue());
1764+
}
1765+
}
1766+
}
1767+
1768+
if (compilerJdkToolchainVersion == null) {
1769+
getLog().debug("Maven compiler plugin is not configured with a jdkToolchain. "
1770+
+ "Using liberty-maven-plugin jdkToolchain configuration for Java compiler options.");
1771+
} else {
1772+
if (jdkToolchainVersion.equals(compilerJdkToolchainVersion)) {
1773+
getLog().info("Liberty Maven Plugin jdkToolchain configuration matches the Maven Compiler Plugin jdkToolchain "
1774+
+ "configuration: version " + jdkToolchainVersion + ".");
1775+
} else {
1776+
getLog().debug("Liberty Maven Plugin jdkToolchain configuration (version " + jdkToolchainVersion
1777+
+ ") does not match the Maven Compiler Plugin jdkToolchain configuration "
1778+
+ "(version " + compilerJdkToolchainVersion
1779+
+ "). The project-level Maven Compiler Plugin toolchain configuration will be used for compilation.");
1780+
}
1781+
}
1782+
}
1783+
17431784
if (release != null) {
1744-
getLog().debug("Setting compiler release to " + release);
1785+
if (StringUtils.isNotEmpty(jdkToolchainVersion)) {
1786+
getLog().debug("Setting compiler release to toolchain JDK version " + jdkToolchainVersion);
1787+
} else {
1788+
getLog().debug("Setting compiler release to " + release);
1789+
}
17451790
if (source != null) {
17461791
getLog().debug("Compiler option source will be ignored since release is specified");
17471792
}
17481793
if (target != null) {
17491794
getLog().debug("Compiler option target will be ignored since release is specified");
17501795
}
1751-
compilerOptions.setRelease(release);
1796+
compilerOptions.setRelease(StringUtils.isNotEmpty(jdkToolchainVersion) ? jdkToolchainVersion : release);
17521797
} else {
17531798
// add source and target only if release is not set
17541799
if (source != null) {
1755-
getLog().debug("Setting compiler source to " + source);
1756-
compilerOptions.setSource(source);
1800+
if (StringUtils.isNotEmpty(jdkToolchainVersion)) {
1801+
getLog().debug("Setting compiler source to toolchain JDK version " + jdkToolchainVersion);
1802+
} else {
1803+
getLog().debug("Setting compiler source to " + source);
1804+
}
1805+
compilerOptions.setSource(StringUtils.isNotEmpty(jdkToolchainVersion) ? jdkToolchainVersion : source);
17571806
}
17581807
if (target != null) {
1759-
getLog().debug("Setting compiler target to " + target);
1760-
compilerOptions.setTarget(target);
1808+
if (StringUtils.isNotEmpty(jdkToolchainVersion)) {
1809+
getLog().debug("Setting compiler target to toolchain JDK version " + jdkToolchainVersion);
1810+
} else {
1811+
getLog().debug("Setting compiler target to " + target);
1812+
}
1813+
compilerOptions.setTarget(StringUtils.isNotEmpty(jdkToolchainVersion) ? jdkToolchainVersion : target);
17611814
}
17621815
}
17631816

liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class ExecuteMojoUtil {
9898
"testFailureIgnore", "testNGArtifactName", "threadCount", "threadCountClasses",
9999
"threadCountMethods", "threadCountSuites", "trimStackTrace", "useFile",
100100
"useManifestOnlyJar", "useModulePath", "useSystemClassLoader",
101-
"useUnlimitedThreads", "workingDirectory"
101+
"useUnlimitedThreads", "workingDirectory", "jdkToolchain"
102102
));
103103

104104
// https://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html
@@ -120,7 +120,7 @@ public class ExecuteMojoUtil {
120120
"systemPropertyVariables", "tempDir", "test", "testClassesDirectory",
121121
"testNGArtifactName", "threadCount", "threadCountClasses", "threadCountMethods",
122122
"threadCountSuites", "trimStackTrace", "useFile", "useManifestOnlyJar",
123-
"useModulePath", "useSystemClassLoader", "useUnlimitedThreads", "workingDirectory"
123+
"useModulePath", "useSystemClassLoader", "useUnlimitedThreads", "workingDirectory", "jdkToolchain"
124124
));
125125

126126
// https://maven.apache.org/surefire/maven-failsafe-plugin/verify-mojo.html

0 commit comments

Comments
 (0)