Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions liberty-maven-app-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven</artifactId>
<version>3.11.6-SNAPSHOT</version>
<version>3.12.0-SNAPSHOT</version>
</parent>

<artifactId>liberty-maven-app-parent</artifactId>
Expand All @@ -36,7 +36,7 @@
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.11.6-SNAPSHOT</version>
<version>3.12.0-SNAPSHOT</version>
<executions>
<execution>
<id>stop-before-clean</id>
Expand Down
2 changes: 1 addition & 1 deletion liberty-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven</artifactId>
<version>3.11.6-SNAPSHOT</version>
<version>3.12.0-SNAPSHOT</version>
</parent>

<artifactId>liberty-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public void libertyToolchainWithoutCompilerToolchainLogsInfoAndUsesToolchainVers
try {
String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->";
String additionalConfigReplacement = "<jdkToolchain>\n" +
" <version>11</version>\n" +
" </jdkToolchain>\n" +
" <!-- ADDITIONAL_CONFIGURATION -->";
" <version>11</version>\n" +
"</jdkToolchain>\n" +
"<!-- ADDITIONAL_CONFIGURATION -->";
replaceString(additionalConfigMarker, additionalConfigReplacement, pom);

startProcess(null, true, "mvn liberty:");
Expand Down Expand Up @@ -68,26 +68,26 @@ public void matchingToolchainConfigurationsLogInfoMessage() throws Exception {
try {
String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->";
String additionalConfigReplacement = "<jdkToolchain>\n" +
" <version>11</version>\n" +
" </jdkToolchain>\n" +
" <!-- ADDITIONAL_CONFIGURATION -->";
" <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>";
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:");
Expand All @@ -104,26 +104,26 @@ public void mismatchedToolchainConfigurationsLogWarningMessage() throws Exceptio
try {
String additionalConfigMarker = "<!-- ADDITIONAL_CONFIGURATION -->";
String additionalConfigReplacement = "<jdkToolchain>\n" +
" <version>11</version>\n" +
" </jdkToolchain>\n" +
" <!-- ADDITIONAL_CONFIGURATION -->";
" <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>";
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:");
Expand All @@ -133,4 +133,89 @@ public void mismatchedToolchainConfigurationsLogWarningMessage() throws Exceptio
cleanUpAfterClass();
}
}

@Test
public void libertyToolchainWithoutSurefireToolchainLogsInfoAndUsesToolchainVersion() 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 -X liberty:");

assertTrue(verifyLogMessageExists("maven-surefire-plugin is not configured with a jdkToolchain. Using Liberty Maven Plugin jdkToolchain configuration for test execution.", 120000));
} finally {
cleanUpAfterClass();
}
}

@Test
public void matchingSurefireToolchainConfigurationsLogInfoMessage() 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 surefirePluginReplacement = " <plugin>\n" +
" <groupId>org.apache.maven.plugins</groupId>\n" +
" <artifactId>maven-surefire-plugin</artifactId>\n" +
" <version>3.0.0</version>\n" +
" <configuration>\n" +
" <jdkToolchain>\n" +
" <version>11</version>\n" +
" </jdkToolchain>\n" +
" </configuration>\n" +
" </plugin>\n" +
"</plugins>";
replaceString(pluginsEndMarker, surefirePluginReplacement, pom);

startProcess(null, true, "mvn -X liberty:");

assertTrue(verifyLogMessageExists("Liberty Maven Plugin jdkToolchain configuration matches the maven-surefire-plugin jdkToolchain configuration: version 11.", 120000));
} finally {
cleanUpAfterClass();
}
}

@Test
public void mismatchedSurefireToolchainConfigurationsLogWarningMessage() 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 surefirePluginReplacement = " <plugin>\n" +
" <groupId>org.apache.maven.plugins</groupId>\n" +
" <artifactId>maven-surefire-plugin</artifactId>\n" +
" <version>3.0.0</version>\n" +
" <configuration>\n" +
" <jdkToolchain>\n" +
" <version>8</version>\n" +
" </jdkToolchain>\n" +
" </configuration>\n" +
" </plugin>\n" +
"</plugins>";
replaceString(pluginsEndMarker, surefirePluginReplacement, pom);

startProcess(null, true, "mvn -X liberty:");

assertTrue(verifyLogMessageExists("Liberty Maven Plugin jdkToolchain configuration (version 11) does not match the maven-surefire-plugin jdkToolchain configuration (version 8). The Liberty Maven Plugin jdkToolchain configuration will be used for test execution.", 120000));
} finally {
cleanUpAfterClass();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,9 @@ private void doDevMode() throws MojoExecutionException {

JavaCompilerOptions compilerOptions = getMavenCompilerOptions(project);

// Log test toolchain configuration for surefire/failsafe at dev mode startup
logTestToolchainConfiguration(project);

// collect upstream projects
List<ProjectModule> upstreamProjects = new ArrayList<ProjectModule>();
if (!upstreamMavenProjects.isEmpty()) {
Expand Down Expand Up @@ -1833,6 +1836,93 @@ private JavaCompilerOptions getMavenCompilerOptions(MavenProject currentProject)
return compilerOptions;
}

/**
* Logs the toolchain configuration for test plugins (surefire/failsafe) at dev mode startup.
*/
private void logTestToolchainConfiguration(MavenProject currentProject) {
// If no Liberty-level toolchain is configured, there is nothing to log for tests
String jdkToolchainVersion = jdkToolchain != null ? jdkToolchain.get("version") : null;
if (StringUtils.isEmpty(jdkToolchainVersion)) {
return;
}

// Resolve and log configuration for maven-surefire-plugin:test
try {
Plugin surefirePlugin = getPluginForProject("org.apache.maven.plugins", "maven-surefire-plugin",
currentProject);
if (surefirePlugin != null) {
Xpp3Dom surefireConfig = ExecuteMojoUtil.getPluginGoalConfig(surefirePlugin, "test", getLog());
validateTestToolchainOptions("maven-surefire-plugin", surefireConfig);
}
} catch (Exception e) {
getLog().debug("Unable to resolve maven-surefire-plugin configuration for logging test toolchain: "
+ e.getMessage());
getLog().debug(e);
}

// Resolve and log configuration for maven-failsafe-plugin:integration-test
try {
Plugin failsafePlugin = getPluginForProject("org.apache.maven.plugins", "maven-failsafe-plugin",
currentProject);
if (failsafePlugin != null) {
Xpp3Dom failsafeConfig = ExecuteMojoUtil.getPluginGoalConfig(failsafePlugin, "integration-test",
getLog());
validateTestToolchainOptions("maven-failsafe-plugin", failsafeConfig);
}
} catch (Exception e) {
getLog().debug("Unable to resolve maven-failsafe-plugin configuration for logging test toolchain: "
+ e.getMessage());
getLog().debug(e);
}
}

/**
* Validates and logs toolchain configuration for test plugins (surefire/failsafe).
*
* @param testArtifactId The test plugin artifact ID ("maven-surefire-plugin" or "maven-failsafe-plugin")
* @param testConfig The test plugin configuration to update
*/
private void validateTestToolchainOptions(String testArtifactId, Xpp3Dom testConfig) {
String jdkToolchainVersion = jdkToolchain != null ? jdkToolchain.get("version") : null;
Comment thread
venmanyarun marked this conversation as resolved.
Outdated
if (StringUtils.isEmpty(jdkToolchainVersion) || testConfig == null) {
return;
}

String testJdkToolchainVersion = null;
Xpp3Dom testJdkToolchain = testConfig.getChild("jdkToolchain");
if (testJdkToolchain != null) {
Xpp3Dom versionChild = testJdkToolchain.getChild("version");
if (versionChild != null) {
testJdkToolchainVersion = StringUtils.trimToNull(versionChild.getValue());
}
}

if (testJdkToolchainVersion == null) {
getLog().info(testArtifactId + " is not configured with a jdkToolchain. "
+ "Using Liberty Maven Plugin jdkToolchain configuration for test execution.");
} else if (jdkToolchainVersion.equals(testJdkToolchainVersion)) {
getLog().info("Liberty Maven Plugin jdkToolchain configuration matches the " + testArtifactId + " "
+ "jdkToolchain configuration: version " + jdkToolchainVersion + ".");
return;
} else {
getLog().warn("Liberty Maven Plugin jdkToolchain configuration (version " + jdkToolchainVersion
+ ") does not match the " + testArtifactId + " jdkToolchain configuration "
+ "(version " + testJdkToolchainVersion
+ "). The Liberty Maven Plugin jdkToolchain configuration will be used for test execution.");
}
Comment thread
venmanyarun marked this conversation as resolved.

if (testJdkToolchain == null) {
testJdkToolchain = new Xpp3Dom("jdkToolchain");
testConfig.addChild(testJdkToolchain);
}
Xpp3Dom versionChild = testJdkToolchain.getChild("version");
if (versionChild == null) {
versionChild = new Xpp3Dom("version");
testJdkToolchain.addChild(versionChild);
}
versionChild.setValue(jdkToolchainVersion);
}

/**
* Gets a compiler option's value from CLI parameters, maven-compiler-plugin's
* configuration or project properties.
Expand Down Expand Up @@ -1899,6 +1989,10 @@ private void runTestMojo(String groupId, String artifactId, String goal, MavenPr
Plugin plugin = getPluginForProject(groupId, artifactId, project);
Xpp3Dom config = ExecuteMojoUtil.getPluginGoalConfig(plugin, goal, getLog());

if (goal.equals("test") || goal.equals("integration-test")) {
validateTestToolchainOptions(artifactId, config);
}

// check if this is a project module or main module
if (util.isMultiModuleProject()) {
try {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven</artifactId>
<version>3.11.6-SNAPSHOT</version>
<version>3.12.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Liberty Tools for Maven</name>
<description>
Expand Down