From 4839d817c86d054c43018f2066dcae53b730ef4c Mon Sep 17 00:00:00 2001 From: Kathryn Kodama Date: Thu, 3 Feb 2022 10:14:22 -0500 Subject: [PATCH] Always optimize generate features on dependency change and update failing dev mode IT Signed-off-by: Kathryn Kodama --- .../guides/multimodules/web/SystemHealth.java | 21 +++++++++++++ .../wasdev/wlp/test/dev/it/BaseDevTest.java | 17 +++++++++++ .../net/wasdev/wlp/test/dev/it/DevTest.java | 6 ++-- .../dev/it/MultiModuleUpdatePomsTest.java | 30 ++++++++++--------- .../tools/maven/server/DevMojo.java | 16 +++++----- 5 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/typeA/war/src/main/java/io/openliberty/guides/multimodules/web/SystemHealth.java diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/typeA/war/src/main/java/io/openliberty/guides/multimodules/web/SystemHealth.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/typeA/war/src/main/java/io/openliberty/guides/multimodules/web/SystemHealth.java new file mode 100644 index 000000000..f20e9fa69 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/typeA/war/src/main/java/io/openliberty/guides/multimodules/web/SystemHealth.java @@ -0,0 +1,21 @@ +package io.openliberty.guides.multimodules.web; + +import javax.enterprise.context.ApplicationScoped; +import org.eclipse.microprofile.health.Health; +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; + +@Health +@ApplicationScoped +public class SystemHealth implements HealthCheck { + @Override + public HealthCheckResponse call() { + if (!System.getProperty("wlp.server.name").startsWith("defaultServer")) { + return HealthCheckResponse.named(HeightsBean.class.getSimpleName()) + .withData("default server", "not available").down() + .build(); + } + return HealthCheckResponse.named(HeightsBean.class.getSimpleName()) + .withData("default server", "available").up().build(); + } +} diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/BaseDevTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/BaseDevTest.java index d9e40d63b..b2b785de4 100644 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/BaseDevTest.java +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/BaseDevTest.java @@ -61,6 +61,7 @@ public class BaseDevTest { static File pom; static BufferedWriter writer; static Process process; + final static String GENERATED_FEATURES_FILE_NAME = "generated-features.xml"; protected static void setUpBeforeClass(String devModeParams) throws IOException, InterruptedException, FileNotFoundException { setUpBeforeClass(devModeParams, "../resources/basic-dev-project"); @@ -442,4 +443,20 @@ protected static boolean waitForCompilation(File file, long lastModified, long t return false; } + // get generated features file in source directory + protected static File getGeneratedFeaturesFile(String libertyConfigModule) throws Exception { + String newFeatureFilePath = libertyConfigModule == null ? "" : "/" + libertyConfigModule; + newFeatureFilePath += "/src/main/liberty/config/configDropins/overrides/" + GENERATED_FEATURES_FILE_NAME; + File newFeatureFile = new File(tempProj, newFeatureFilePath); + return newFeatureFile; + } + + // get generated features file in target directory + protected static File getTargetGeneratedFeaturesFile(String libertyConfigModule) throws Exception { + String newFeatureFilePath = libertyConfigModule == null ? "" : "/" + libertyConfigModule; + newFeatureFilePath += "/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/" + GENERATED_FEATURES_FILE_NAME; + File newTargetFeatureFile = new File(targetDir,newFeatureFilePath); + return newTargetFeatureFile; + } + } diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevTest.java index 0e2907425..54ca5484c 100644 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevTest.java +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/DevTest.java @@ -195,16 +195,14 @@ public void resolveDependencyTest() throws Exception { @Test public void generateFeatureTest() throws Exception { - - final String GENERATED_FEATURES_FILE_NAME = "generated-features.xml"; final String SERVER_XML_COMMENT = "Plugin has generated Liberty features"; // the explanation added to server.xml final String NEW_FILE_INFO_MESSAGE = "This file was generated by the Liberty Maven Plugin and will be overwritten"; // the explanation added to the generated features file assertTrue(verifyLogMessageExists("Liberty is running in dev mode.", 10000)); assertFalse(verifyLogMessageExists("batch-1.0", 10000)); - File newFeatureFile = new File(tempProj, "/src/main/liberty/config/configDropins/overrides/"+GENERATED_FEATURES_FILE_NAME); - File newTargetFeatureFile = new File(targetDir, "/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/"+GENERATED_FEATURES_FILE_NAME); + File newFeatureFile = getGeneratedFeaturesFile(null); + File newTargetFeatureFile = getTargetGeneratedFeaturesFile(null); File serverXmlFile = new File(tempProj, "/src/main/liberty/config/server.xml"); assertTrue(serverXmlFile.exists()); 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 0e87c6e71..cd8cdc7ba 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * (c) Copyright IBM Corporation 2021. + * (c) Copyright IBM Corporation 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,6 @@ public static void setUpBeforeClass() throws Exception { */ @Test 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); @@ -54,7 +53,11 @@ public void updatePomsTest() throws Exception { int warSourceCount = countOccurrences("guide-maven-multimodules-war source compilation was successful.", logFile); int warTestsCount = countOccurrences("guide-maven-multimodules-war tests compilation was successful.", logFile); int earTestsCount = countOccurrences("guide-maven-multimodules-ear tests compilation was successful.", logFile); - int generateFeaturesCount = countOccurrences("Running liberty:generate-features", logFile); + + // verify that generated-features.xml file exists + File newFeatureFile = getGeneratedFeaturesFile("ear"); + assertTrue(getLogTail(), verifyFileExists(newFeatureFile, 1000)); + long newFeatureFileLastModified = newFeatureFile.lastModified(); touchFileTwice("jar/pom.xml"); @@ -73,9 +76,9 @@ public void updatePomsTest() throws Exception { assertEquals(getLogTail(), ++earTestsCount, countOccurrences("guide-maven-multimodules-ear tests compilation was successful.", logFile)); - // verify that feature generation was trigggered - assertEquals(getLogTail(), ++generateFeaturesCount, - countOccurrences("Running liberty:generate-features", logFile)); + // verify that feature generation ran + assertTrue(getLogTail(), waitForCompilation(newFeatureFile, newFeatureFileLastModified, 1000)); + newFeatureFileLastModified = newFeatureFile.lastModified(); touchFileTwice("war/pom.xml"); @@ -95,9 +98,9 @@ public void updatePomsTest() throws Exception { assertEquals(getLogTail(), ++earTestsCount, countOccurrences("guide-maven-multimodules-ear tests compilation was successful.", logFile)); - // verify that feature generation was triggered - assertEquals(getLogTail(), ++generateFeaturesCount, - countOccurrences("Running liberty:generate-features", logFile)); + // verify that feature generation ran + assertTrue(getLogTail(), waitForCompilation(newFeatureFile, newFeatureFileLastModified, 1000)); + newFeatureFileLastModified = newFeatureFile.lastModified(); touchFileTwice("ear/pom.xml"); @@ -117,18 +120,17 @@ public void updatePomsTest() throws Exception { assertEquals(getLogTail(), ++earTestsCount, countOccurrences("guide-maven-multimodules-ear tests compilation was successful.", logFile)); - // verify that feature generation was not triggered since there are no source class + // verify that feature generation did not run since there are no source class // files for the ear module - assertEquals(getLogTail(), generateFeaturesCount, - countOccurrences("Running liberty:generate-features", logFile)); + assertEquals("generated-features.xml was modified", newFeatureFileLastModified, newFeatureFile.lastModified()); } private void touchFileTwice(String path) throws InterruptedException { File file = new File(tempProj, path); long time = System.currentTimeMillis(); assertTrue(file.setLastModified(time)); - Thread.sleep(20); - assertTrue(file.setLastModified(time+20)); + Thread.sleep(40); + assertTrue(file.setLastModified(time+40)); } 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 aa4ae6c5c..c767f8061 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 @@ -905,16 +905,16 @@ public boolean recompileBuildFile(File buildFile, Set compileArtifactPat util.restartServer(); return true; } else { - // TODO: confirm that a call to generate features is required when a build file's compilation dependencies are modified - // if we generate features here we will also need to skip installing features on - // a failure + // TODO: if we generate features here we will also need to skip installing + // features on a failure if (compileDependenciesChanged && generateFeatures) { - // build file change - provide updated classes and all existing features to binary scanner + // build file change - provide updated classes and all existing features to + // binary scanner Collection javaSourceClassPaths = util.getJavaSourceClassPaths(); - if (!javaSourceClassPaths.isEmpty()) { // only call generateFeatures if there are updated classes to generate for - if (libertyGenerateFeatures(javaSourceClassPaths, false)) { - util.getJavaSourceClassPaths().clear(); - } + // always optimize generate features on dependency change + boolean generateFeaturesSuccess = libertyGenerateFeatures(javaSourceClassPaths, true); + if (generateFeaturesSuccess) { + util.getJavaSourceClassPaths().clear(); } } if (isUsingBoost() && (createServer || runBoostPackage)) {