-
Notifications
You must be signed in to change notification settings - Fork 97
Toolchain support for DevMode #1949
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70f0d15
Added toolchin support for devmode, compiler plugin. Also enabled jdk…
b9b6669
Toolchain IT added for devmode
a31a418
Fixed the confusion on logged messaged for maven compiler plugin tool…
4357886
Improved the unit tests
59fbc4c
New test added for maven surefire and failsafe
6bf5136
Updated the toolchain devmode test to reduce failures in some cases
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
...maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevToolchainTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package net.wasdev.wlp.test.dev.it; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| import org.apache.commons.io.FileUtils; | ||
| import org.junit.Test; | ||
|
|
||
| public class DevToolchainTest extends BaseDevTest { | ||
|
|
||
| @Test | ||
| public void libertyToolchainWithoutCompilerToolchainLogsInfoAndUsesToolchainVersion() throws Exception { | ||
| setUpBeforeClass(null, "../resources/basic-dev-project", true, false, null, null); | ||
| try { | ||
| String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->"; | ||
| String additionalConfigReplacement = "<jdkToolchain>\n" + | ||
| " <version>11</version>\n" + | ||
| " </jdkToolchain>\n" + | ||
| " <!-- ADDITIONAL_CONFIGURATION -->"; | ||
| replaceString(additionalConfigMarker, additionalConfigReplacement, pom); | ||
|
|
||
| startProcess(null, true, "mvn liberty:"); | ||
|
|
||
| assertTrue(verifyLogMessageExists("Maven compiler plugin is not configured with a jdkToolchain. Using Liberty Maven Plugin jdkToolchain configuration for Java compiler options.", 120000)); | ||
| assertTrue(verifyLogMessageExists("Setting compiler source to toolchain JDK version 11", 120000)); | ||
|
|
||
| // Trigger a recompile by modifying a Java source file | ||
| File javaFile = new File(tempProj, "src/main/java/com/demo/HelloWorld.java"); | ||
| String originalContent = "public String helloWorld() {\n\t\treturn \"helloWorld\";\n\t}"; | ||
| String modifiedContent = "public String helloWorld() {\n\t\treturn \"helloWorldModified\";\n\t}"; | ||
| String fileContent = FileUtils.readFileToString(javaFile, "UTF-8"); | ||
| String newContent = fileContent.replace(originalContent, modifiedContent); | ||
| FileUtils.writeStringToFile(javaFile, newContent, "UTF-8"); | ||
|
|
||
| // Verify that recompilation used compiler options | ||
| assertTrue(verifyLogMessageExists("Recompiling with compiler options:", 120000)); | ||
| assertTrue(verifyLogMessageExists("-source, 11", 120000)); | ||
| assertTrue(verifyLogMessageExists("-target, 11", 120000)); | ||
| } finally { | ||
| cleanUpAfterClass(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void noToolchainConfigurationDoesNotEmitToolchainMessages() throws Exception { | ||
| setUpBeforeClass(null, "../resources/basic-dev-project", true, false, null, null); | ||
| try { | ||
| startProcess(null, true, "mvn liberty:"); | ||
|
|
||
| assertTrue(verifyLogMessageDoesNotExist( | ||
| "Maven compiler plugin is not configured with a jdkToolchain. Using Liberty Maven Plugin jdkToolchain configuration for Java compiler options.", | ||
| 120000)); | ||
| assertTrue(verifyLogMessageDoesNotExist( | ||
| "Liberty Maven Plugin jdkToolchain configuration matches the Maven Compiler Plugin jdkToolchain configuration", | ||
| 120000)); | ||
| assertTrue(verifyLogMessageDoesNotExist( | ||
| "Liberty Maven Plugin jdkToolchain configuration (version", | ||
| 120000)); | ||
| } finally { | ||
| cleanUpAfterClass(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void matchingToolchainConfigurationsLogInfoMessage() throws Exception { | ||
| setUpBeforeClass(null, "../resources/basic-dev-project", true, false, null, null); | ||
| try { | ||
| String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->"; | ||
| String additionalConfigReplacement = "<jdkToolchain>\n" + | ||
| " <version>11</version>\n" + | ||
| " </jdkToolchain>\n" + | ||
| " <!-- ADDITIONAL_CONFIGURATION -->"; | ||
| replaceString(additionalConfigMarker, additionalConfigReplacement, pom); | ||
|
|
||
| String pluginsEndMarker = "</plugins>"; | ||
| String compilerPluginReplacement = "<plugin>\n" + | ||
| " <groupId>org.apache.maven.plugins</groupId>\n" + | ||
| " <artifactId>maven-compiler-plugin</artifactId>\n" + | ||
| " <version>3.11.0</version>\n" + | ||
| " <configuration>\n" + | ||
| " <jdkToolchain>\n" + | ||
| " <version>11</version>\n" + | ||
| " </jdkToolchain>\n" + | ||
| " <release>11</release>\n" + | ||
| " <source>11</source>\n" + | ||
| " <target>11</target>\n" + | ||
| " </configuration>\n" + | ||
| " </plugin>\n" + | ||
| " </plugins>"; | ||
| replaceString(pluginsEndMarker, compilerPluginReplacement, pom); | ||
|
|
||
| startProcess(null, true, "mvn liberty:"); | ||
|
|
||
| assertTrue(verifyLogMessageExists("Liberty Maven Plugin jdkToolchain configuration matches the Maven Compiler Plugin jdkToolchain configuration: version 11.", 120000)); | ||
| } finally { | ||
| cleanUpAfterClass(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void mismatchedToolchainConfigurationsLogWarningMessage() throws Exception { | ||
| setUpBeforeClass(null, "../resources/basic-dev-project", true, false, null, null); | ||
| try { | ||
| String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->"; | ||
| String additionalConfigReplacement = "<jdkToolchain>\n" + | ||
| " <version>11</version>\n" + | ||
| " </jdkToolchain>\n" + | ||
| " <!-- ADDITIONAL_CONFIGURATION -->"; | ||
| replaceString(additionalConfigMarker, additionalConfigReplacement, pom); | ||
|
|
||
| String pluginsEndMarker = "</plugins>"; | ||
| String compilerPluginReplacement = "<plugin>\n" + | ||
| " <groupId>org.apache.maven.plugins</groupId>\n" + | ||
| " <artifactId>maven-compiler-plugin</artifactId>\n" + | ||
| " <version>3.11.0</version>\n" + | ||
| " <configuration>\n" + | ||
| " <jdkToolchain>\n" + | ||
| " <version>8</version>\n" + | ||
| " </jdkToolchain>\n" + | ||
| " <release>8</release>\n" + | ||
| " <source>8</source>\n" + | ||
| " <target>8</target>\n" + | ||
| " </configuration>\n" + | ||
| " </plugin>\n" + | ||
| " </plugins>"; | ||
| replaceString(pluginsEndMarker, compilerPluginReplacement, pom); | ||
|
|
||
| startProcess(null, true, "mvn liberty:"); | ||
|
|
||
| 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)); | ||
| } finally { | ||
| cleanUpAfterClass(); | ||
| } | ||
| } | ||
| } |
65 changes: 65 additions & 0 deletions
65
...-run-it/src/test/java/net/wasdev/wlp/test/dev/it/ToolchainSurefireFailsafeConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package net.wasdev.wlp.test.dev.it; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
|
|
||
| import org.apache.maven.model.Plugin; | ||
| import org.apache.maven.plugin.logging.SystemStreamLog; | ||
| import org.codehaus.plexus.util.xml.Xpp3Dom; | ||
| import org.junit.Test; | ||
|
|
||
| import io.openliberty.tools.maven.utils.ExecuteMojoUtil; | ||
|
|
||
| public class ToolchainSurefireFailsafeConfigTest { | ||
|
|
||
| @Test | ||
| public void jdkToolchainIsPreservedForMavenSurefirePluginTestGoal() { | ||
| Plugin plugin = new Plugin(); | ||
| plugin.setGroupId("org.apache.maven.plugins"); | ||
| plugin.setArtifactId("maven-surefire-plugin"); | ||
| plugin.setVersion("3.1.2"); | ||
|
|
||
| Xpp3Dom config = new Xpp3Dom("configuration"); | ||
| Xpp3Dom jdkToolchain = new Xpp3Dom("jdkToolchain"); | ||
| Xpp3Dom version = new Xpp3Dom("version"); | ||
| version.setValue("11"); | ||
| jdkToolchain.addChild(version); | ||
| config.addChild(jdkToolchain); | ||
|
|
||
| plugin.setConfiguration(config); | ||
|
|
||
| Xpp3Dom goalConfig = ExecuteMojoUtil.getPluginGoalConfig(plugin, "test", new SystemStreamLog()); | ||
| Xpp3Dom jdkToolchainChild = goalConfig.getChild("jdkToolchain"); | ||
| Xpp3Dom versionChild = jdkToolchainChild.getChild("version"); | ||
|
|
||
| assertNotNull("jdkToolchain element should be preserved for maven-surefire-plugin:test", jdkToolchainChild); | ||
| assertNotNull("version child should be present under jdkToolchain", versionChild); | ||
| assertEquals("11", versionChild.getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void jdkToolchainIsPreservedForMavenFailsafePluginIntegrationTestGoal() { | ||
| Plugin plugin = new Plugin(); | ||
| plugin.setGroupId("org.apache.maven.plugins"); | ||
| plugin.setArtifactId("maven-failsafe-plugin"); | ||
| plugin.setVersion("3.1.2"); | ||
|
|
||
| Xpp3Dom config = new Xpp3Dom("configuration"); | ||
| Xpp3Dom jdkToolchain = new Xpp3Dom("jdkToolchain"); | ||
| Xpp3Dom version = new Xpp3Dom("version"); | ||
| version.setValue("11"); | ||
| jdkToolchain.addChild(version); | ||
| config.addChild(jdkToolchain); | ||
|
|
||
| plugin.setConfiguration(config); | ||
|
|
||
| Xpp3Dom goalConfig = ExecuteMojoUtil.getPluginGoalConfig(plugin, "integration-test", new SystemStreamLog()); | ||
| Xpp3Dom jdkToolchainChild = goalConfig.getChild("jdkToolchain"); | ||
| Xpp3Dom versionChild = jdkToolchainChild.getChild("version"); | ||
|
|
||
| assertNotNull("jdkToolchain element should be preserved for maven-failsafe-plugin:integration-test", jdkToolchainChild); | ||
| assertNotNull("version child should be present under jdkToolchain", versionChild); | ||
| assertEquals("11", versionChild.getValue()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.