Skip to content

Commit

Permalink
Merge pull request OpenLiberty#1853 from arunvenmany-ibm/server_multi…
Browse files Browse the repository at this point in the history
…_restart_issue_fix

Server multi restart issue fix
  • Loading branch information
arunvenmany-ibm authored Jan 22, 2025
2 parents 743ad42 + 3a55d51 commit dc36c69
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void updateDependencyTest() throws Exception {
assertTrue(verifyLogMessageExists("mpHealth-2.2", 10000)); // should appear in the message "CWWKF0012I: The server installed the following features:"

int generateFeaturesCount = countOccurrences("Running liberty:generate-features", logFile);
assertTrue(verifyLogMessageExists("Source compilation was successful.", 10000));
assertTrue(verifyLogMessageExists("Recompile skipped for dev-sample-proj since earlier compilation is successful", 10000));

// modify MicroProfile umbrella dependency in pom.xml
replaceString("<dependency>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static void cleanUpAfterClass() throws Exception {

@Test
public void autoTestsInvocationTest() throws Exception {
assertTrue(verifyLogMessageExists("Recompile skipped for dev-sample-proj since earlier compilation is successful", 20000));
assertTrue(verifyLogMessageExists("Tests will run automatically", 20000));

testModifyJavaFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public void runTest() throws Exception {
File targetEarClass = new File(tempProj,
"ear/target/test-classes/it/io/openliberty/guides/multimodules/ConverterAppIT.class");
assertFalse(targetEarClass.exists());
assertTrue(verifyLogMessageExists(
"Recompile guide-maven-multimodules-ear due to an earlier compilation error",
20000));

// add a dependency to parent pom and check that it resolves compile errors in
// child modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public void setKeepTempDockerfile(Boolean keepTempDockerfile) {

private boolean isExplodedLooseWarApp = false;
private boolean isNewInstallation = true;
private static Map<String,Boolean> compileMojoError = new HashMap<>();

/**
* Set the container option.
Expand Down Expand Up @@ -359,7 +360,7 @@ public DevMojoUtil(File installDir, File userDir, File serverDirectory, File sou
((long) (compileWait * 1000L)), libertyDebug, false, false, pollingTest, container, containerfile,
containerBuildContext, containerRunOpts, containerBuildTimeout, skipDefaultPorts, compilerOptions,
keepTempContainerfile, mavenCacheLocation, upstreamProjects, recompileDeps, project.getPackaging(),
pom, parentPoms, generateFeatures, compileArtifactPaths, testArtifactPaths, webResourceDirs);
pom, parentPoms, generateFeatures, compileArtifactPaths, testArtifactPaths, webResourceDirs, compileMojoError);

this.libertyDirPropertyFiles = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new CommonLogger(getLog()), installDir, userDir,
serverDirectory);
Expand Down Expand Up @@ -492,7 +493,7 @@ public void libertyDeploy() throws PluginExecutionException {
@Override
public void stopServer() {
super.serverFullyStarted.set(false);

compileMojoError.clear();
if (container) {
// TODO stop the container instead
return;
Expand Down Expand Up @@ -1355,7 +1356,6 @@ private void doDevMode() throws MojoExecutionException {
if (project.getPackaging().equals("ear")) {
isEar = true;
}

// If there are downstream projects (e.g. other modules depend on this module in the Maven Reactor build order),
// then skip dev mode on this module but only run compile.
List<MavenProject> upstreamMavenProjects = new ArrayList<MavenProject>();
Expand Down Expand Up @@ -1386,7 +1386,19 @@ private void doDevMode() throws MojoExecutionException {
getLog().debug("Skipping compile/resources on module with pom packaging type");
} else {
runMojo("org.apache.maven.plugins", "maven-resources-plugin", "resources");
runCompileMojoLogWarning();
try {
runCompileMojoLogWarningWithException("compile");
} catch (MojoExecutionException e) {
// set init recompile necessary in case any module fail
compileMojoError.put(project.getName(),Boolean.TRUE);
}
if(hotTests) {
try {
runCompileMojoLogWarningWithException("testCompile");
} catch (MojoExecutionException e) {
compileMojoError.put(project.getName(),Boolean.TRUE);
}
}
}
return;
} else {
Expand Down Expand Up @@ -1456,13 +1468,27 @@ private void doDevMode() throws MojoExecutionException {
if (isEar) {
runMojo("org.apache.maven.plugins", "maven-ear-plugin", "generate-application-xml");
runMojo("org.apache.maven.plugins", "maven-resources-plugin", "resources");
// for test classes in ear
try {
runCompileMojoLogWarningWithException("testCompile");
} catch (MojoExecutionException e) {
compileMojoError.put(project.getName(),Boolean.TRUE);
}
} else if (project.getPackaging().equals("pom")) {
getLog().debug("Skipping compile/resources on module with pom packaging type");
} else {
runMojo("org.apache.maven.plugins", "maven-resources-plugin", "resources");
runCompileMojoLogWarning();
runMojo("org.apache.maven.plugins", "maven-resources-plugin", "testResources");
runTestCompileMojoLogWarning();
try {
runCompileMojoLogWarningWithException("compile");
} catch (MojoExecutionException e) {
compileMojoError.put(project.getName(),Boolean.TRUE);
}
runMojo("org.apache.maven.plugins", "maven-resources-plugin", "testResources");
try {
runCompileMojoLogWarningWithException("testCompile");
} catch (MojoExecutionException e) {
compileMojoError.put(project.getName(),Boolean.TRUE);
}
}

sourceDirectory = new File(sourceDirectoryString.trim());
Expand Down Expand Up @@ -2025,6 +2051,21 @@ private void runCompileMojo(String goal, MavenProject mavenProject) throws MojoE
executeMojo(plugin, goal(goal), config, executionEnvironment(tempProject, tempSession, pluginManager));
}

private void runCompileMojoLogWarningWithException(String goal) throws MojoExecutionException {
Plugin plugin = getPluginForProject("org.apache.maven.plugins", "maven-compiler-plugin", project);
MavenSession tempSession = session.clone();
tempSession.setCurrentProject(project);
MavenProject tempProject = project;
Xpp3Dom config = ExecuteMojoUtil.getPluginGoalConfig(plugin, goal, getLog());
config = Xpp3Dom.mergeXpp3Dom(configuration(element(name("failOnError"), "true")), config);
goal = goal + "#" + getExecutionId(goal, plugin);
getLog().info("Running maven-compiler-plugin:" + goal + " on " + tempProject.getFile());
getLog().debug("configuration:\n" + config);
executeMojo(plugin, goal(goal), config, executionEnvironment(tempProject, tempSession, pluginManager));

updateArtifactPathToOutputDirectory(project);
}

/**
* Executes maven:compile but logs errors as warning messages
*
Expand Down

0 comments on commit dc36c69

Please sign in to comment.