|
| 1 | +package net.wasdev.wlp.test.dev.it; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | + |
| 5 | +import java.io.File; |
| 6 | + |
| 7 | +import org.apache.commons.io.FileUtils; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +public class DevToolchainTest extends BaseDevTest { |
| 11 | + |
| 12 | + @Test |
| 13 | + public void libertyToolchainWithoutCompilerToolchainLogsInfoAndUsesToolchainVersion() throws Exception { |
| 14 | + setUpBeforeClass(null, "../resources/basic-dev-project", true, false, null, null); |
| 15 | + try { |
| 16 | + String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->"; |
| 17 | + String additionalConfigReplacement = "<jdkToolchain>\n" + |
| 18 | + " <version>11</version>\n" + |
| 19 | + " </jdkToolchain>\n" + |
| 20 | + " <!-- ADDITIONAL_CONFIGURATION -->"; |
| 21 | + replaceString(additionalConfigMarker, additionalConfigReplacement, pom); |
| 22 | + |
| 23 | + startProcess(null, true, "mvn liberty:"); |
| 24 | + |
| 25 | + assertTrue(verifyLogMessageExists("Maven compiler plugin is not configured with a jdkToolchain. Using Liberty Maven Plugin jdkToolchain configuration for Java compiler options.", 120000)); |
| 26 | + assertTrue(verifyLogMessageExists("Setting compiler source to toolchain JDK version 11", 120000)); |
| 27 | + |
| 28 | + // Trigger a recompile by modifying a Java source file |
| 29 | + File javaFile = new File(tempProj, "src/main/java/com/demo/HelloWorld.java"); |
| 30 | + String originalContent = "public String helloWorld() {\n\t\treturn \"helloWorld\";\n\t}"; |
| 31 | + String modifiedContent = "public String helloWorld() {\n\t\treturn \"helloWorldModified\";\n\t}"; |
| 32 | + String fileContent = FileUtils.readFileToString(javaFile, "UTF-8"); |
| 33 | + String newContent = fileContent.replace(originalContent, modifiedContent); |
| 34 | + FileUtils.writeStringToFile(javaFile, newContent, "UTF-8"); |
| 35 | + |
| 36 | + // Verify that recompilation used compiler options |
| 37 | + assertTrue(verifyLogMessageExists("Recompiling with compiler options:", 120000)); |
| 38 | + assertTrue(verifyLogMessageExists("-source, 11", 120000)); |
| 39 | + assertTrue(verifyLogMessageExists("-target, 11", 120000)); |
| 40 | + } finally { |
| 41 | + cleanUpAfterClass(); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void noToolchainConfigurationDoesNotEmitToolchainMessages() throws Exception { |
| 47 | + setUpBeforeClass(null, "../resources/basic-dev-project", true, false, null, null); |
| 48 | + try { |
| 49 | + startProcess(null, true, "mvn liberty:"); |
| 50 | + |
| 51 | + assertTrue(verifyLogMessageDoesNotExist( |
| 52 | + "Maven compiler plugin is not configured with a jdkToolchain. Using Liberty Maven Plugin jdkToolchain configuration for Java compiler options.", |
| 53 | + 120000)); |
| 54 | + assertTrue(verifyLogMessageDoesNotExist( |
| 55 | + "Liberty Maven Plugin jdkToolchain configuration matches the Maven Compiler Plugin jdkToolchain configuration", |
| 56 | + 120000)); |
| 57 | + assertTrue(verifyLogMessageDoesNotExist( |
| 58 | + "Liberty Maven Plugin jdkToolchain configuration (version", |
| 59 | + 120000)); |
| 60 | + } finally { |
| 61 | + cleanUpAfterClass(); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void matchingToolchainConfigurationsLogInfoMessage() throws Exception { |
| 67 | + setUpBeforeClass(null, "../resources/basic-dev-project", true, false, null, null); |
| 68 | + try { |
| 69 | + String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->"; |
| 70 | + String additionalConfigReplacement = "<jdkToolchain>\n" + |
| 71 | + " <version>11</version>\n" + |
| 72 | + " </jdkToolchain>\n" + |
| 73 | + " <!-- ADDITIONAL_CONFIGURATION -->"; |
| 74 | + replaceString(additionalConfigMarker, additionalConfigReplacement, pom); |
| 75 | + |
| 76 | + String pluginsEndMarker = "</plugins>"; |
| 77 | + String compilerPluginReplacement = "<plugin>\n" + |
| 78 | + " <groupId>org.apache.maven.plugins</groupId>\n" + |
| 79 | + " <artifactId>maven-compiler-plugin</artifactId>\n" + |
| 80 | + " <version>3.11.0</version>\n" + |
| 81 | + " <configuration>\n" + |
| 82 | + " <jdkToolchain>\n" + |
| 83 | + " <version>11</version>\n" + |
| 84 | + " </jdkToolchain>\n" + |
| 85 | + " <release>11</release>\n" + |
| 86 | + " <source>11</source>\n" + |
| 87 | + " <target>11</target>\n" + |
| 88 | + " </configuration>\n" + |
| 89 | + " </plugin>\n" + |
| 90 | + " </plugins>"; |
| 91 | + replaceString(pluginsEndMarker, compilerPluginReplacement, pom); |
| 92 | + |
| 93 | + startProcess(null, true, "mvn liberty:"); |
| 94 | + |
| 95 | + assertTrue(verifyLogMessageExists("Liberty Maven Plugin jdkToolchain configuration matches the Maven Compiler Plugin jdkToolchain configuration: version 11.", 120000)); |
| 96 | + } finally { |
| 97 | + cleanUpAfterClass(); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void mismatchedToolchainConfigurationsLogWarningMessage() throws Exception { |
| 103 | + setUpBeforeClass(null, "../resources/basic-dev-project", true, false, null, null); |
| 104 | + try { |
| 105 | + String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->"; |
| 106 | + String additionalConfigReplacement = "<jdkToolchain>\n" + |
| 107 | + " <version>11</version>\n" + |
| 108 | + " </jdkToolchain>\n" + |
| 109 | + " <!-- ADDITIONAL_CONFIGURATION -->"; |
| 110 | + replaceString(additionalConfigMarker, additionalConfigReplacement, pom); |
| 111 | + |
| 112 | + String pluginsEndMarker = "</plugins>"; |
| 113 | + String compilerPluginReplacement = "<plugin>\n" + |
| 114 | + " <groupId>org.apache.maven.plugins</groupId>\n" + |
| 115 | + " <artifactId>maven-compiler-plugin</artifactId>\n" + |
| 116 | + " <version>3.11.0</version>\n" + |
| 117 | + " <configuration>\n" + |
| 118 | + " <jdkToolchain>\n" + |
| 119 | + " <version>8</version>\n" + |
| 120 | + " </jdkToolchain>\n" + |
| 121 | + " <release>8</release>\n" + |
| 122 | + " <source>8</source>\n" + |
| 123 | + " <target>8</target>\n" + |
| 124 | + " </configuration>\n" + |
| 125 | + " </plugin>\n" + |
| 126 | + " </plugins>"; |
| 127 | + replaceString(pluginsEndMarker, compilerPluginReplacement, pom); |
| 128 | + |
| 129 | + startProcess(null, true, "mvn liberty:"); |
| 130 | + |
| 131 | + assertTrue(verifyLogMessageExists("Liberty Maven Plugin jdkToolchain configuration (version 11) does not match the Maven Compiler Plugin jdkToolchain configuration (version 8). The Liberty Maven Plugin jdkToolchain configuration will be used for compilation.", 120000)); |
| 132 | + } finally { |
| 133 | + cleanUpAfterClass(); |
| 134 | + } |
| 135 | + } |
| 136 | +} |
0 commit comments