Skip to content

Commit

Permalink
Always optimize generate features on dependency change and update fai…
Browse files Browse the repository at this point in the history
…ling dev mode IT

Signed-off-by: Kathryn Kodama <kathryn.s.kodama@gmail.com>
  • Loading branch information
kathrynkodama committed Feb 3, 2022
1 parent 26976de commit 4839d81
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand All @@ -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));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,16 +905,16 @@ public boolean recompileBuildFile(File buildFile, Set<String> 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<String> 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)) {
Expand Down

0 comments on commit 4839d81

Please sign in to comment.