From e314f54e4faa92f89e49b224a42080657f394dcd Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Thu, 19 Dec 2024 11:21:18 +0530 Subject: [PATCH 1/6] fix for multiple server restart and re deployment in maven Signed-off-by: Arun Venmany --- liberty-maven-plugin/pom.xml | 2 +- .../tools/maven/server/DevMojo.java | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/liberty-maven-plugin/pom.xml b/liberty-maven-plugin/pom.xml index b7912546f..0f642c1cc 100644 --- a/liberty-maven-plugin/pom.xml +++ b/liberty-maven-plugin/pom.xml @@ -88,7 +88,7 @@ io.openliberty.tools ci.common - 1.8.36 + 1.8.37-SNAPSHOT org.twdata.maven diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 709ddaf88..855af6a3a 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -352,14 +352,14 @@ public DevMojoUtil(File installDir, File userDir, File serverDirectory, File sou List resourceDirs, JavaCompilerOptions compilerOptions, String mavenCacheLocation, List upstreamProjects, List upstreamMavenProjects, boolean recompileDeps, File pom, Map> parentPoms, boolean generateFeatures, boolean skipInstallFeature, - Set compileArtifactPaths, Set testArtifactPaths, List webResourceDirs) throws IOException, PluginExecutionException { + Set compileArtifactPaths, Set testArtifactPaths, List webResourceDirs, boolean compileMojoError) throws IOException, PluginExecutionException { super(new File(project.getBuild().getDirectory()), serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, multiModuleProjectDirectory, resourceDirs, changeOnDemandTestsAction, hotTests, skipTests, skipUTs, skipITs, skipInstallFeature, project.getArtifactId(), serverStartTimeout, verifyTimeout, verifyTimeout, ((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); @@ -1342,6 +1342,7 @@ private boolean isUsingBoost() { } private void doDevMode() throws MojoExecutionException { + boolean compileMojoError = false; String mvnVersion = runtime.getMavenVersion(); getLog().debug("Maven version: " + mvnVersion); // Maven 3.8.2 and 3.8.3 contain a bug where compile artifacts are not resolved @@ -1460,8 +1461,12 @@ 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(); - runMojo("org.apache.maven.plugins", "maven-resources-plugin", "testResources"); + try { + runCompileMojoLogWarningWithException(); + } catch (MojoExecutionException e) { + compileMojoError = true; + } + runMojo("org.apache.maven.plugins", "maven-resources-plugin", "testResources"); runTestCompileMojoLogWarning(); } @@ -1614,7 +1619,7 @@ private void doDevMode() throws MojoExecutionException { util = new DevMojoUtil(installDirectory, userDirectory, serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, project.getBasedir(), multiModuleProjectDirectory, resourceDirs, compilerOptions, settings.getLocalRepository(), upstreamProjects, upstreamMavenProjects, recompileDeps, pom, parentPoms, - generateFeatures, skipInstallFeature, compileArtifactPaths, testArtifactPaths, webResourceDirs); + generateFeatures, skipInstallFeature, compileArtifactPaths, testArtifactPaths, webResourceDirs, compileMojoError); } catch (IOException | PluginExecutionException |DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error initializing dev mode.", e); } @@ -2024,6 +2029,23 @@ private void runCompileMojo(String goal, MavenProject mavenProject) throws MojoE executeMojo(plugin, goal(goal), config, executionEnvironment(tempProject, tempSession, pluginManager)); } + private void runCompileMojoLogWarningWithException() throws MojoExecutionException { + + String goal = "compile"; + + 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); + 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 * From ba46698afb120eb93cfbcd4985684e8263a61fb7 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 23 Dec 2024 10:14:55 +0530 Subject: [PATCH 2/6] changing workflow yaml Signed-off-by: Arun Venmany --- .github/workflows/maven.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 24d837339..2a7ef64eb 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -48,8 +48,9 @@ jobs: - name: Checkout ci.common uses: actions/checkout@v3 with: - repository: OpenLiberty/ci.common + repository: arunvenmany-ibm/ci.common path: ci.common + ref: server_multi_restart_issue_fix - name: Checkout ci.ant uses: actions/checkout@v3 with: @@ -102,7 +103,7 @@ jobs: - name: Clone ci.ant, ci.common, ci.maven repos to C drive run: | cp -r D:/a/ci.maven/ci.maven C:/ci.maven - git clone https://github.com/OpenLiberty/ci.common.git C:/ci.common + git clone https://github.com/arunvenmany-ibm/ci.common.git --branch server_multi_restart_issue_fix --single-branch C:/ci.common git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant - name: Set up Maven uses: stCarolas/setup-maven@v4.5 From a693fe3a36d05fe304afa62d02c251d36354d02a Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 23 Dec 2024 16:54:26 +0530 Subject: [PATCH 3/6] making code changes to fix test failures Signed-off-by: Arun Venmany --- .../DevGenerateFeaturesDependenciesTest.java | 2 +- .../dev/it/MultiModuleUpdatePomsTest.java | 11 +++--- .../tools/maven/server/DevMojo.java | 39 ++++++++++++++----- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java index e817f2e04..4dfc06f2b 100644 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java @@ -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("\n" diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultiModuleUpdatePomsTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultiModuleUpdatePomsTest.java index be9d05d09..285a9980c 100644 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultiModuleUpdatePomsTest.java +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultiModuleUpdatePomsTest.java @@ -47,6 +47,11 @@ public void updatePomsTest() throws Exception { // Wait until the last module (ear) finishes compiling during dev mode startup // TODO: this can be removed if dev mode does not recompile after first starting up verifyLogMessageExists("guide-maven-multimodules-ear tests compilation was successful", 10000); + // verify that generated-features.xml file exists + File newFeatureFile = getGeneratedFeaturesFile("ear"); + assertTrue(getLogTail(), verifyFileExists(newFeatureFile, 1000)); + long newFeatureFileLastModified = newFeatureFile.lastModified(); + waitLongEnough(); int jarSourceCount = countOccurrences("guide-maven-multimodules-jar source compilation was successful.", logFile); int jarTestsCount = countOccurrences("guide-maven-multimodules-jar tests compilation was successful.", logFile); @@ -54,12 +59,6 @@ public void updatePomsTest() throws Exception { int warTestsCount = countOccurrences("guide-maven-multimodules-war tests compilation was successful.", logFile); int earTestsCount = countOccurrences("guide-maven-multimodules-ear tests compilation was successful.", logFile); - // verify that generated-features.xml file exists - File newFeatureFile = getGeneratedFeaturesFile("ear"); - assertTrue(getLogTail(), verifyFileExists(newFeatureFile, 1000)); - long newFeatureFileLastModified = newFeatureFile.lastModified(); - waitLongEnough(); - touchFileTwice("jar/pom.xml"); // Give time for recompile to occur diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 855af6a3a..bcc219081 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -311,6 +311,7 @@ public void setKeepTempDockerfile(Boolean keepTempDockerfile) { private boolean isExplodedLooseWarApp = false; private boolean isNewInstallation = true; + private boolean compileMojoError = false; /** * Set the container option. @@ -352,7 +353,7 @@ public DevMojoUtil(File installDir, File userDir, File serverDirectory, File sou List resourceDirs, JavaCompilerOptions compilerOptions, String mavenCacheLocation, List upstreamProjects, List upstreamMavenProjects, boolean recompileDeps, File pom, Map> parentPoms, boolean generateFeatures, boolean skipInstallFeature, - Set compileArtifactPaths, Set testArtifactPaths, List webResourceDirs, boolean compileMojoError) throws IOException, PluginExecutionException { + Set compileArtifactPaths, Set testArtifactPaths, List webResourceDirs) throws IOException, PluginExecutionException { super(new File(project.getBuild().getDirectory()), serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, multiModuleProjectDirectory, resourceDirs, changeOnDemandTestsAction, hotTests, skipTests, skipUTs, skipITs, skipInstallFeature, project.getArtifactId(), serverStartTimeout, verifyTimeout, verifyTimeout, @@ -1342,7 +1343,6 @@ private boolean isUsingBoost() { } private void doDevMode() throws MojoExecutionException { - boolean compileMojoError = false; String mvnVersion = runtime.getMavenVersion(); getLog().debug("Maven version: " + mvnVersion); // Maven 3.8.2 and 3.8.3 contain a bug where compile artifacts are not resolved @@ -1387,7 +1387,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 = true; + } + if(hotTests) { + try { + runCompileMojoLogWarningWithException("testCompile"); + } catch (MojoExecutionException e) { + compileMojoError = true; + } + } } return; } else { @@ -1457,17 +1469,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 = 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"); try { - runCompileMojoLogWarningWithException(); + runCompileMojoLogWarningWithException("compile"); } catch (MojoExecutionException e) { compileMojoError = true; } runMojo("org.apache.maven.plugins", "maven-resources-plugin", "testResources"); - runTestCompileMojoLogWarning(); + try { + runCompileMojoLogWarningWithException("testCompile"); + } catch (MojoExecutionException e) { + compileMojoError = true; + } } sourceDirectory = new File(sourceDirectoryString.trim()); @@ -1619,7 +1641,7 @@ private void doDevMode() throws MojoExecutionException { util = new DevMojoUtil(installDirectory, userDirectory, serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, project.getBasedir(), multiModuleProjectDirectory, resourceDirs, compilerOptions, settings.getLocalRepository(), upstreamProjects, upstreamMavenProjects, recompileDeps, pom, parentPoms, - generateFeatures, skipInstallFeature, compileArtifactPaths, testArtifactPaths, webResourceDirs, compileMojoError); + generateFeatures, skipInstallFeature, compileArtifactPaths, testArtifactPaths, webResourceDirs); } catch (IOException | PluginExecutionException |DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error initializing dev mode.", e); } @@ -2029,10 +2051,7 @@ private void runCompileMojo(String goal, MavenProject mavenProject) throws MojoE executeMojo(plugin, goal(goal), config, executionEnvironment(tempProject, tempSession, pluginManager)); } - private void runCompileMojoLogWarningWithException() throws MojoExecutionException { - - String goal = "compile"; - + 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); From c4c22762ec710f3dafa69505bf04a293ac12d2aa Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 30 Dec 2024 12:58:33 +0530 Subject: [PATCH 4/6] changes to use map with each project separately for recompile Signed-off-by: Arun Venmany --- .../tools/maven/server/DevMojo.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index bcc219081..1c7e81202 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -311,7 +311,7 @@ public void setKeepTempDockerfile(Boolean keepTempDockerfile) { private boolean isExplodedLooseWarApp = false; private boolean isNewInstallation = true; - private boolean compileMojoError = false; + private static Map compileMojoError; /** * Set the container option. @@ -493,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; @@ -1356,7 +1356,9 @@ private void doDevMode() throws MojoExecutionException { if (project.getPackaging().equals("ear")) { isEar = true; } - + if (compileMojoError == null) { + compileMojoError = new HashMap<>(); + } // 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 upstreamMavenProjects = new ArrayList(); @@ -1391,13 +1393,13 @@ private void doDevMode() throws MojoExecutionException { runCompileMojoLogWarningWithException("compile"); } catch (MojoExecutionException e) { // set init recompile necessary in case any module fail - compileMojoError = true; + compileMojoError.put(project.getName(),Boolean.TRUE); } if(hotTests) { try { runCompileMojoLogWarningWithException("testCompile"); } catch (MojoExecutionException e) { - compileMojoError = true; + compileMojoError.put(project.getName(),Boolean.TRUE); } } } @@ -1473,7 +1475,7 @@ private void doDevMode() throws MojoExecutionException { try { runCompileMojoLogWarningWithException("testCompile"); } catch (MojoExecutionException e) { - compileMojoError = true; + compileMojoError.put(project.getName(),Boolean.TRUE); } } else if (project.getPackaging().equals("pom")) { getLog().debug("Skipping compile/resources on module with pom packaging type"); @@ -1482,13 +1484,13 @@ private void doDevMode() throws MojoExecutionException { try { runCompileMojoLogWarningWithException("compile"); } catch (MojoExecutionException e) { - compileMojoError = true; + compileMojoError.put(project.getName(),Boolean.TRUE); } runMojo("org.apache.maven.plugins", "maven-resources-plugin", "testResources"); try { runCompileMojoLogWarningWithException("testCompile"); } catch (MojoExecutionException e) { - compileMojoError = true; + compileMojoError.put(project.getName(),Boolean.TRUE); } } From ed7c0a732202628ceb7f580305b52823f241caab Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 30 Dec 2024 14:35:30 +0530 Subject: [PATCH 5/6] changes to use map with each project separately for recompile Signed-off-by: Arun Venmany --- .../wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java index 4dfc06f2b..0a6fcf325 100644 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevGenerateFeaturesDependenciesTest.java @@ -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("Recompile skipped for dev-sample-proj since earlier compilation is successful", 10000)); + assertTrue(verifyLogMessageExists("Recompile dev-sample-proj due to an earlier compilation error", 10000)); // modify MicroProfile umbrella dependency in pom.xml replaceString("\n" From beee25cbc9a03bff900e4e52d5fdf03d1089f720 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Thu, 9 Jan 2025 13:46:52 +0530 Subject: [PATCH 6/6] changes based on review comments Signed-off-by: Arun Venmany --- .../main/java/io/openliberty/tools/maven/server/DevMojo.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 1c7e81202..d8e4015f9 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -311,7 +311,7 @@ public void setKeepTempDockerfile(Boolean keepTempDockerfile) { private boolean isExplodedLooseWarApp = false; private boolean isNewInstallation = true; - private static Map compileMojoError; + private static Map compileMojoError = new HashMap<>(); /** * Set the container option. @@ -1356,9 +1356,6 @@ private void doDevMode() throws MojoExecutionException { if (project.getPackaging().equals("ear")) { isEar = true; } - if (compileMojoError == null) { - compileMojoError = new HashMap<>(); - } // 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 upstreamMavenProjects = new ArrayList();