Skip to content

Commit 068dd81

Browse files
sajeerzejivenmanyarunSajeerSajeerSajeer
authored
Toolchain support for devmode (#1041)
* toolchain initial commit Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * adding toolchain jdk setup Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * adding logs and correcting tests Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * adding branch to workflow yaml (#1036) * adding branch to workflow yaml Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * adding branch to workflow yaml Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * removing env Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * sending java installation path as parameter Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * sending java installation path as parameter Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * refactoring test method, enabling back workflow steps Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * changes to fix tests Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * changes to fix tests Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> --------- Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * Toolchain v1 (#1037) * adding branch to workflow yaml Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * adding branch to workflow yaml Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * removing env Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * sending java installation path as parameter Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * sending java installation path as parameter Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * trying with gradle init step Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * fixing run script Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * refactoring test method, enabling back workflow steps Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * changes to fix tests Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * changes to fix tests Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * Adding more tests for libertyCreate and libertyStart Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * adding tests similar to LibertyTests.groovy with toolchains Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * updating tests Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * updating tests Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> --------- Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * adding jvmArgs metspace for test Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * steps in workflow to upload reports Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * increase metaspace to 1g Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * set metaspace to gradle.properties Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * adding back other java versions to matrix Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * removing toolchain branch from workflow (#1039) Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> * Environment variables merging processes added * Added logs for devmode recompilation for toolchain * Added test for devmode recompilation * Corrected a leftover code * Copyright years updated * DevmodeToolchainTest excluded for windows in pipeline * Toolchain doc updated for toolchain config precedence section * Updated the toolchain.md documentation by adding some examples * Added more logs as sample * Removed adding foojay plugin through test code to settings.gradle, and added it to ther test projects settings.gradle directly * Liberty version and ant version are updated * Auto provisioning link added to the toolchain.md toubleshooting section --------- Signed-off-by: Arun Venmany <arun.kumar.v.n@ibm.com> Co-authored-by: Arun Venmany <arun.kumar.v.n@ibm.com> Co-authored-by: Sajeer <sajeer@Sajeers-MacBook-Pro.local> Co-authored-by: Sajeer <sajeer@Mac.lan> Co-authored-by: Sajeer <sajeer@mac.in.ibm.com>
1 parent ba89a69 commit 068dd81

File tree

7 files changed

+277
-9
lines changed

7 files changed

+277
-9
lines changed

.github/workflows/gradle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ jobs:
110110
- java: 11
111111
RUNTIME: wlp
112112
name: ${{ matrix.RUNTIME }} ${{ matrix.RUNTIME_VERSION }}, Java ${{ matrix.java }}, Windows
113-
env:
114-
TEST_EXCLUDE: ${{ ((matrix.java == '8') && '**/TestCreateWithConfigDir*,**/Polling*,**/LibertyTest*,**/LibertyToolchainTest*,**/GenerateFeaturesTest*,**/TestSpringBootApplication30*,**/TestCompileJSPSource17*,**/DevContainerTest*') || '**/Polling*,**/LibertyTest*,**/LibertyToolchainTest*,**/GenerateFeaturesTest*,**/TestSpringBootApplication30*,**/TestCompileJSPSource17*,**/DevContainerTest*'}}
113+
env:
114+
TEST_EXCLUDE: ${{ ((matrix.java == '8') && '**/TestCreateWithConfigDir*,**/Polling*,**/LibertyTest*,**/LibertyToolchainTest*,**/GenerateFeaturesTest*,**/TestSpringBootApplication30*,**/TestCompileJSPSource17*,**/DevContainerTest*,**/DevModeToolchainTest*') || '**/Polling*,**/LibertyTest*,**/LibertyToolchainTest*,**/GenerateFeaturesTest*,**/TestSpringBootApplication30*,**/TestCompileJSPSource17*,**/DevContainerTest*,**/DevModeToolchainTest*' }}
115115
steps:
116116
# Checkout repos
117117
- name: Checkout ci.gradle

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: "com.gradle.plugin-publish"
55
apply plugin: 'base'
66

77
group = 'io.openliberty.tools'
8-
version = '3.9.7-SNAPSHOT'
8+
version = '3.10.0-SNAPSHOT'
99
base {
1010
archivesName='liberty-gradle-plugin'
1111
}
@@ -62,7 +62,7 @@ compileTestGroovy {
6262
targetCompatibility = JavaVersion.VERSION_1_8
6363
}
6464

65-
def libertyAntVersion = "1.9.18-SNAPSHOT"
65+
def libertyAntVersion = "1.9.18"
6666
def libertyCommonVersion = "1.8.40"
6767

6868

docs/toolchain.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
## toolchain
2+
3+
Gradle Java toolchains let you select a specific JDK for your project. When a toolchain is configured, the Liberty Gradle plugin will try to run Liberty server tasks with that JDK (by setting `JAVA_HOME`), even if Gradle itself is running on a different JVM.
4+
5+
For more details on toolchains, see the [Gradle Java Toolchains documentation](https://docs.gradle.org/current/userguide/toolchains.html).
6+
7+
8+
### Overview
9+
10+
Gradle Java toolchains are configured through the `java` plugin using the `java { toolchain { ... } }` block.
11+
12+
The Liberty Gradle plugin does not add a Liberty-specific toolchain block. Instead, it uses the toolchain configuration from the `java` plugin.
13+
14+
* When a Java toolchain is configured, Liberty server tasks attempt to run with the selected toolchain JDK.
15+
* In dev mode (`libertyDev`), the plugin:
16+
* Uses the configured toolchain JDK for the Liberty server JVM (via `JAVA_HOME`).
17+
* Triggers Gradle compile tasks (`compileJava`, `compileTestJava`).
18+
19+
20+
### Configuration
21+
22+
Apply the Gradle `java` plugin and configure a Java toolchain in your build.
23+
24+
Example (`build.gradle`):
25+
26+
```groovy
27+
plugins {
28+
id 'java'
29+
id 'io.openliberty.tools.gradle.Liberty'
30+
}
31+
32+
java {
33+
toolchain {
34+
// Required Java version for your project
35+
languageVersion = JavaLanguageVersion.of(11)
36+
}
37+
}
38+
```
39+
40+
Make sure the Gradle version you use supports Java toolchains (Gradle 6.7+), and that the requested toolchain can be resolved (either from a locally installed JDK or via a toolchain provisioning plugin).
41+
42+
43+
### Liberty server tasks
44+
45+
When you configure a Gradle Java toolchain, the Liberty Gradle plugin uses the resolved toolchain JDK home as `JAVA_HOME` when it runs Liberty server commands.
46+
47+
**NOTE:** If `JAVA_HOME` is already set in `server.env` or `jvm.options`, that configuration takes precedence. In that case, the plugin does not override `JAVA_HOME` with the toolchain JDK.
48+
49+
This includes cases where `JAVA_HOME` is set by the Liberty server configuration in your build, for example:
50+
51+
* `liberty { server { env = ['JAVA_HOME': '...'] } }`
52+
* Gradle project properties such as `liberty.server.env.JAVA_HOME` (for example, `-Pliberty.server.env.JAVA_HOME=/path/to/jdk`)
53+
54+
When a toolchain is detected, you will see a message like:
55+
56+
`CWWKM4100I: Using toolchain from build context. JDK Version specified is 11`
57+
58+
When the toolchain JDK is applied for a task, you will see a message like:
59+
60+
`CWWKM4101I: The :libertyDev task is using the configured toolchain JDK located at /path/to/jdk-11`
61+
62+
If `JAVA_HOME` is set in `server.env` or `jvm.options`, you will see a warning like:
63+
64+
`CWWKM4101W: The toolchain JDK configuration for task :libertyDev is not honored because the JAVA_HOME property is specified in the server.env or jvm.options file`
65+
66+
67+
### libertyDev
68+
69+
Dev mode uses the configured Gradle Java toolchain in two places.
70+
71+
#### Liberty server JVM
72+
73+
When a Java toolchain is configured, dev mode sets `JAVA_HOME` for the Liberty server process using the resolved toolchain JDK home (unless `JAVA_HOME` is already set in `server.env` or `jvm.options`).
74+
75+
To confirm which JDK the server started with, check `messages.log` for a `java.version` entry.
76+
77+
Example (`messages.log`):
78+
79+
```text
80+
********************************************************************************
81+
product = Open Liberty 25.0.0.12 (wlp-1.0.108.cl251220251117-0302)
82+
wlp.install.dir = /path/to/project/build/wlp/
83+
java.home = /path/to/java/semeru-11.0.28/Contents/Home
84+
java.version = 11.0.28
85+
java.runtime = IBM Semeru Runtime Open Edition (11.0.28+6)
86+
os = Mac OS X (26.1; aarch64) (en_IN)
87+
process = 62955@Device-Name.local
88+
Classpath = /path/to/project/build/wlp/bin/tools/ws-server.jar
89+
Java Library path = /path/to/java/semeru-11.0.28/Contents/Home/lib/default:/path/to/java/semeru-11.0.28/Contents/Home/lib:/usr/lib
90+
********************************************************************************
91+
```
92+
93+
#### Build recompilation and tests
94+
95+
When files change, dev mode triggers standard Gradle tasks:
96+
97+
* `compileJava`, `processResources`
98+
* `compileTestJava`, `processTestResources`
99+
* `cleanTest`, `test` (when dev mode runs tests)
100+
101+
The JDK used for compilation is controlled by the Gradle toolchain configuration.
102+
103+
To show which toolchain is being used when dev mode triggers compilation, dev mode logs messages like:
104+
105+
* `Using Java toolchain for dev mode compilation: version=11, javaHome=/path/to/jdk-11`
106+
* `Using Java toolchain for dev mode test compilation: version=11, javaHome=/path/to/jdk-11`
107+
108+
109+
### Rules and precedence
110+
111+
* **No Gradle toolchain configured (`java.toolchain` absent)**
112+
113+
Server tasks and dev mode run using the JVM that runs Gradle and whatever configuration is present in `server.env` / `jvm.options`.
114+
If `JAVA_HOME` is not set in those files, Liberty uses the default `JAVA_HOME` from the system environment (or the JVM that is running Gradle).
115+
116+
* **Gradle toolchain configured, toolchain JDK resolved successfully**
117+
118+
For Liberty server tasks, if `JAVA_HOME` is *not* specified in `server.env` or `jvm.options`, the plugin sets `JAVA_HOME` to the resolved toolchain JDK home. The build output includes `CWWKM4101I` indicating which toolchain JDK is used.
119+
120+
For dev mode recompilation, the toolchain used for compilation is controlled by Gradle. Dev mode logs the toolchain version and the resolved `javaHome` when it triggers compilation.
121+
122+
* **Gradle toolchain configured, but toolchain JDK cannot be resolved**
123+
124+
The plugin logs a warning indicating that the toolchain cannot be honored. Server tasks fall back to using the JVM that runs Gradle (or any existing `JAVA_HOME` settings).
125+
126+
* **`JAVA_HOME` set in `server.env` or `jvm.options`**
127+
128+
`JAVA_HOME` takes precedence over the toolchain JDK for the Liberty server JVM. This includes `JAVA_HOME` provided through the `liberty { server { env ... } }` configuration or `liberty.server.env.*` Gradle project properties. The plugin logs a warning (`CWWKM4101W`) indicating the toolchain is not honored.
129+
130+
131+
### Troubleshooting
132+
133+
**If you do not see toolchain log messages (`CWWKM4100I`, `CWWKM4101I`, or the dev mode toolchain compilation logs):**
134+
135+
* Verify that your project applies the `java` plugin.
136+
* Verify that `java { toolchain { languageVersion = JavaLanguageVersion.of(11) } }` (or another version) is configured.
137+
* Ensure that Gradle can resolve the requested toolchain JDK by using a locally installed JDK or by automatically downloading one via a [provisioning plugin](https://docs.gradle.org/current/userguide/toolchains.html#sec:provisioning).
138+
139+
**If Liberty does not appear to run with the toolchain JDK (for example, `java.version` in `messages.log` does not match the configured toolchain):**
140+
141+
* Check `server.env` and `jvm.options` for `JAVA_HOME`.
142+
* If `JAVA_HOME` is present there, it overrides the toolchain. Remove it if you want the toolchain JDK to be used.
143+
* Also check whether your build is setting `JAVA_HOME` through the `liberty` server configuration (for example, `server { env = ... }`) or through `liberty.server.env.*` Gradle project properties.
144+
* Check the build logs for warnings indicating that the toolchain is not honored.
145+
146+
**If dev mode recompilation does not show the toolchain compilation logs:**
147+
148+
* Make sure your changes are in `src/main/java` or `src/test/java` so that dev mode triggers `compileJava` / `compileTestJava`.
149+
* Check `output.log` from dev mode for lines starting with:
150+
* `Using Java toolchain for dev mode compilation: ...`
151+
* `Using Java toolchain for dev mode test compilation: ...`

src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class CompileJSPTask extends AbstractFeatureTask {
6161
Map<String, String> envVars = getToolchainEnvVar();
6262
if (!envVars.isEmpty()) {
6363
if (compileJsp.getEnvironmentVariables() != null && !compileJsp.getEnvironmentVariables().isEmpty()) {
64-
compileJsp.setEnvironmentVariables(compileJsp.getEnvironmentVariables().putAll(envVars));
64+
Map<String, String> mergedEnv = new HashMap<>(compileJsp.getEnvironmentVariables());
65+
mergedEnv.putAll(envVars);
66+
compileJsp.setEnvironmentVariables(mergedEnv);
6567
} else {
6668
compileJsp.setEnvironmentVariables(envVars);
6769
}

src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ class DevTask extends AbstractFeatureTask {
510510
private void updateServerTaskEnvironmentVariables(Map<String, String> envVars) {
511511
if (!envVars.isEmpty()) {
512512
if (serverTask.getEnvironmentVariables() != null && !serverTask.getEnvironmentVariables().isEmpty()) {
513-
serverTask.setEnvironmentVariables(serverTask.getEnvironmentVariables().putAll(envVars));
513+
Map<String, String> mergedEnv = new HashMap<>(serverTask.getEnvironmentVariables());
514+
mergedEnv.putAll(envVars);
515+
serverTask.setEnvironmentVariables(mergedEnv);
514516
} else {
515517
serverTask.setEnvironmentVariables(envVars);
516518
}
@@ -937,13 +939,34 @@ class DevTask extends AbstractFeatureTask {
937939
BuildLauncher gradleBuildLauncher = gradleConnection.newBuild();
938940

939941
try {
940-
if (dir.equals(sourceDirectory)) {
942+
boolean isMain = dir.equals(sourceDirectory);
943+
boolean isTest = dir.equals(testSourceDirectory);
944+
945+
if (isMain || isTest) {
946+
def launcher = getJavaLauncher();
947+
def scopeString = isTest ? "test " : "";
948+
949+
if (launcher != null && launcher.metadata != null) {
950+
def metadata = launcher.metadata;
951+
logger.lifecycle(
952+
"Using Java toolchain for dev mode ${scopeString}compilation: " +
953+
"version=${metadata.languageVersion}, javaHome=${metadata.installationPath.asFile}"
954+
);
955+
} else {
956+
logger.debug(
957+
"No Java toolchain launcher is configured for dev mode ${scopeString}compilation."
958+
);
959+
}
960+
}
961+
962+
if (isMain) {
941963
runGradleTask(gradleBuildLauncher, 'compileJava', 'processResources');
942964
}
943965

944-
if (dir.equals(testSourceDirectory)) {
966+
if (isTest) {
945967
runGradleTask(gradleBuildLauncher, 'compileTestJava', 'processTestResources');
946968
}
969+
947970
return true;
948971
} catch (BuildException e) {
949972
// stdout/stderr from the compile task is sent to the terminal
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package io.openliberty.tools.gradle
2+
3+
import org.junit.AfterClass
4+
import org.junit.BeforeClass
5+
import org.junit.Test
6+
7+
import static org.junit.Assert.assertTrue
8+
9+
class DevModeToolchainTest extends BaseDevTest {
10+
11+
static final String projectName = "basic-dev-project"
12+
13+
static File resourceDir = new File("build/resources/test/dev-test/" + projectName)
14+
static File buildDir = new File(integTestDir, "dev-test/" + projectName + "-toolchain-" + System.currentTimeMillis())
15+
16+
@BeforeClass
17+
static void setup() throws Exception {
18+
createDir(buildDir)
19+
createTestProject(buildDir, resourceDir, buildFilename)
20+
File buildFile = new File(buildDir, "build.gradle")
21+
buildFile.append("\n\njava {\n toolchain {\n languageVersion.set(JavaLanguageVersion.of(11))\n }\n}\n")
22+
23+
runDevMode("--info --skipTests --generateFeatures=false", buildDir)
24+
}
25+
26+
@Test
27+
void verifyToolchainHonoredInDevMode() throws Exception {
28+
assertTrue(verifyLogMessage(60000, String.format(TOOLCHAIN_USED, "11"), logFile))
29+
assertTrue(verifyLogMessage(60000, String.format(TOOLCHAIN_CONFIGURED, "libertyDev"), logFile))
30+
31+
File messagesLogFile = new File(targetDir, "wlp/usr/servers/defaultServer/logs/messages.log")
32+
assertTrue("messages.log not found: " + messagesLogFile.getCanonicalPath(), messagesLogFile.exists())
33+
assertTrue(verifyLogMessage(60000, "java.version = 11", messagesLogFile))
34+
}
35+
36+
@Test
37+
void verifyToolchainUsedForDevRecompile() throws Exception {
38+
File javaFile = new File(buildDir, "src/main/java/com/demo/HelloWorld.java")
39+
assertTrue("Source file not found: " + javaFile.getCanonicalPath(), javaFile.exists())
40+
41+
waitLongEnough()
42+
BufferedWriter writer = new BufferedWriter(new FileWriter(javaFile, true))
43+
writer.append(" // adding for testing toolchain devmode recompile")
44+
writer.close()
45+
46+
assertTrue(verifyLogMessage(60000, "Using Java toolchain for dev mode compilation: version=11, javaHome=", logFile))
47+
48+
// Test that the toolchain is used for test compilation
49+
File testDir = new File(buildDir, "src/test/java")
50+
File unitTestSrcFile = new File(testDir, "ToolchainUnitTest.java")
51+
52+
if (!testDir.exists()) {
53+
assertTrue("Failed creating test directory: " + testDir.getCanonicalPath(), testDir.mkdirs())
54+
} else if (unitTestSrcFile.exists()) {
55+
assertTrue("Failed deleting existing test file: " + unitTestSrcFile.getCanonicalPath(), unitTestSrcFile.delete())
56+
}
57+
58+
String unitTest = """import org.junit.Test;\n
59+
import static org.junit.Assert.*;\n
60+
public class ToolchainUnitTest {\n
61+
@Test\n
62+
public void testTrue() {\n
63+
assertTrue(true);\n
64+
}\n
65+
}\n
66+
"""
67+
BufferedWriter testWriter = new BufferedWriter(new FileWriter(unitTestSrcFile))
68+
testWriter.write(unitTest)
69+
testWriter.close()
70+
assertTrue(unitTestSrcFile.exists())
71+
72+
File unitTestTargetFile = new File(targetDir, "classes/java/test/ToolchainUnitTest.class")
73+
assertTrue(verifyFileExists(unitTestTargetFile, 10000))
74+
75+
assertTrue(verifyLogMessage(60000, "Using Java toolchain for dev mode test compilation: version=11, javaHome=", logFile))
76+
77+
File messagesLogFile = new File(targetDir, "wlp/usr/servers/defaultServer/logs/messages.log")
78+
assertTrue("messages.log not found: " + messagesLogFile.getCanonicalPath(), messagesLogFile.exists())
79+
assertTrue(verifyLogMessage(60000, "java.version = 11", messagesLogFile))
80+
}
81+
82+
@AfterClass
83+
static void cleanUpAfterClass() throws Exception {
84+
String stdout = getContents(logFile, "Dev mode std output")
85+
System.out.println(stdout)
86+
String stderr = getContents(errFile, "Dev mode std error")
87+
System.out.println(stderr)
88+
cleanUpAfterClass(true)
89+
}
90+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
//Empty
1+
plugins {
2+
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
3+
}

0 commit comments

Comments
 (0)