From 16112cc9e1557dbb64a4cf169b0bb16a07724bd0 Mon Sep 17 00:00:00 2001 From: Mike Andrasak Date: Thu, 19 Sep 2019 15:00:20 -0400 Subject: [PATCH 1/2] Issue 360 add support for specifying libberty runtime version --- .../src/it/test-jaxrs-2.0/invoker.properties | 3 ++ .../test/java/it/LibertyFeatureVersionIT.java | 33 +++++++++++++++++++ .../runtimes/openliberty/LibertyRuntime.java | 16 +++++---- 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/invoker.properties diff --git a/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/invoker.properties b/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/invoker.properties new file mode 100644 index 00000000..fa8abd43 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/invoker.properties @@ -0,0 +1,3 @@ +invoker.goals.1 = clean install -Dboost_runtime_version=19.0.0.7 +invoker.goals.2 = clean install -Dboost_runtime_version=19.0.0.8 +invoker.goals.3 = clean install \ No newline at end of file diff --git a/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java b/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java index 460ba481..150dd77a 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java +++ b/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java @@ -23,17 +23,23 @@ public class LibertyFeatureVersionIT { private static final String JAXRS_20_FEATURE = "jaxrs-2.0"; private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml"; + private static String MESSAGES_LOG = "target/liberty/wlp/usr/servers/defaultServer/logs/messages.log"; + private static String runtimeVersion; + private static String defaultRunTimeVersion = "19.0.0.9"; @BeforeClass public static void init() { String runtime = System.getProperty("boostRuntime"); org.junit.Assume.assumeTrue("ol".equals(runtime) || "wlp".equals(runtime)); + runtimeVersion = System.getProperty("boost_runtime_version"); } @Test public void testLibertyFeatureVersion() throws Exception { File targetFile = new File(SERVER_XML); assertTrue(targetFile.getCanonicalFile() + "does not exist.", targetFile.exists()); + if (runtimeVersion == null) + runtimeVersion = defaultRunTimeVersion; // Check contents of file for jaxrs feature boolean found = false; @@ -56,4 +62,31 @@ public void testLibertyFeatureVersion() throws Exception { assertTrue("The " + JAXRS_20_FEATURE + " feature was not found in the server configuration", found); } + + @Test + public void testLibertyRuntimeVersion() throws Exception { + File targetFile = new File(MESSAGES_LOG); + assertTrue(targetFile.getCanonicalFile() + "does not exist.", targetFile.exists()); + + // Check contents of file for jaxrs feature + boolean found = false; + BufferedReader br = null; + + try { + br = new BufferedReader(new FileReader(MESSAGES_LOG)); + String line; + while ((line = br.readLine()) != null) { + if (line.contains(runtimeVersion)) { + found = true; + break; + } + } + } finally { + if (br != null) { + br.close(); + } + } + + assertTrue("The run time version " + runtimeVersion + " was not found in the messages log", found); + } } diff --git a/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/org/microshed/boost/runtimes/openliberty/LibertyRuntime.java b/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/org/microshed/boost/runtimes/openliberty/LibertyRuntime.java index c85076a3..ef9d77e0 100644 --- a/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/org/microshed/boost/runtimes/openliberty/LibertyRuntime.java +++ b/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/org/microshed/boost/runtimes/openliberty/LibertyRuntime.java @@ -55,7 +55,8 @@ public class LibertyRuntime implements RuntimeI { private final String runtimeGroupId = "io.openliberty"; private final String runtimeArtifactId = "openliberty-runtime"; - private final String runtimeVersion = "19.0.0.9"; + private final String defaultRuntimeVersion = "19.0.0.9"; + private String runtimeVersion; private String libertyMavenPluginGroupId = "io.openliberty.tools"; private String libertyMavenPluginArtifactId = "liberty-maven-plugin"; @@ -69,6 +70,7 @@ public LibertyRuntime() { this.projectBuildDir = null; this.libertyServerPath = null; this.mavenDepPlugin = null; + this.runtimeVersion = defaultRuntimeVersion; } public LibertyRuntime(RuntimeParams runtimeParams) { @@ -79,6 +81,7 @@ public LibertyRuntime(RuntimeParams runtimeParams) { this.projectBuildDir = project.getBuild().getDirectory(); this.libertyServerPath = projectBuildDir + "/liberty/wlp/usr/servers/" + serverName; this.mavenDepPlugin = runtimeParams.getMavenDepPlugin(); + this.runtimeVersion = boostProperties.getProperty("boost_runtime_version", defaultRuntimeVersion); } private Plugin getPlugin() throws MojoExecutionException { @@ -167,8 +170,9 @@ private void generateServerConfig(List boosterConfigs) th } /** - * Assumes a non-WAR packaging type (like JAR) has a WAR dependency. - * We assume there's only 1 but don't check, just return the first one. + * Assumes a non-WAR packaging type (like JAR) has a WAR dependency. We assume + * there's only 1 but don't check, just return the first one. + * * @return * @throws BoostException */ @@ -177,7 +181,7 @@ private String getWarName() throws BoostException { String retVal = null; if (project.getPackaging().equals(ConfigConstants.WAR_PKG_TYPE)) { retVal = project.getBuild().getFinalName(); - } else { + } else { // JAR package "release", get WAR from dependency for (Artifact artifact : project.getArtifacts()) { // first WAR @@ -193,7 +197,7 @@ private String getWarName() throws BoostException { throw new BoostException(msg); } } - + return retVal; } @@ -218,7 +222,7 @@ private void generateLibertyServerConfig(List boosterConf String httpsPort = (String) boostProperties.getOrDefault(BoostProperties.ENDPOINT_HTTPS_PORT, "9443"); libertyConfig.addHttpsPort(httpsPort); - + String warName = getWarName(); libertyConfig.addApplication(warName); From fb4cbf393b94eb8016a4a026b4f971e3ea12a6e0 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Wed, 25 Sep 2019 11:21:09 -0400 Subject: [PATCH 2/2] Refactor runtime version IT checks; add logging to boost properties loading Signed-off-by: Scott Kurz --- .../boost/common/config/BoostProperties.java | 8 +-- .../test/java/it/LibertyFeatureVersionIT.java | 57 +++++++++++++------ 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/boost-common/src/main/java/org/microshed/boost/common/config/BoostProperties.java b/boost-common/src/main/java/org/microshed/boost/common/config/BoostProperties.java index 7ccb736e..bdd39825 100644 --- a/boost-common/src/main/java/org/microshed/boost/common/config/BoostProperties.java +++ b/boost-common/src/main/java/org/microshed/boost/common/config/BoostProperties.java @@ -68,9 +68,7 @@ public static Properties getConfiguredBoostProperties(Properties projectProperti if (entry.getKey().toString().startsWith(BOOST_PROP_PREFIX) || entry.getKey().toString().equals(LIBERTY_VERSION)) { - // logger.debug("Found boost property: " + - // entry.getKey() + ":" + entry.getValue()); - + logger.debug("Found boost property: " + entry.getKey() + ":" + entry.getValue()); boostProperties.put(entry.getKey(), entry.getValue()); } } @@ -80,9 +78,7 @@ public static Properties getConfiguredBoostProperties(Properties projectProperti if (entry.getKey().toString().startsWith(BOOST_PROP_PREFIX) || entry.getKey().toString().equals(LIBERTY_VERSION)) { - // logger.debug("Found boost property: " + - // entry.getKey() + ":" + entry.getValue()); - + logger.debug("Found boost property: " + entry.getKey() + ":" + entry.getValue()); boostProperties.put(entry.getKey(), entry.getValue()); } } diff --git a/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java b/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java index 159de3b1..a5e0adb1 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java +++ b/boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java @@ -15,8 +15,10 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; +import java.io.IOException; import java.util.Arrays; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.util.Properties; import org.junit.BeforeClass; @@ -39,6 +41,9 @@ import org.eclipse.aether.transport.http.HttpTransporterFactory; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + public class LibertyFeatureVersionIT { private static final String JAXRS_20_FEATURE = "jaxrs-2.0"; @@ -46,6 +51,7 @@ public class LibertyFeatureVersionIT { private static String LIBERTY_PROPERTIES = "target/liberty/wlp/lib/versions/openliberty.properties"; private static String LIBERTY_VERSION = "com.ibm.websphere.productVersion"; private static String runtimeVersion; + private final static Log log = LogFactory.getLog(LibertyFeatureVersionIT.class); @BeforeClass public static void init() { @@ -60,7 +66,7 @@ public static void init() { * messages.log file when the server is run. Only used when no libertyRunTime * version is provided. */ - private String getLatesLibertyRuntimeVersion() { + private String getLatestLibertyRuntimeVersion() { String libertyVersion = null; RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/") @@ -126,17 +132,38 @@ public void testLibertyFeatureVersion() throws Exception { @Test public void testLibertyRuntimeVersion() throws Exception { - boolean found = false; + String installedVersion = getLibertyVersionPropertyFromInstall(); if (runtimeVersion == null) { - // This relies on a scan of the maven repository to find the lastest version of - // liberty installed. Not sure what subtle issues this might cause. - // if there are issues matching the runtime versions then - // this may be the culprit and not actually a Boost issue. - runtimeVersion = getLatesLibertyRuntimeVersion(); + + // The getLatestLibertyRuntimeVersion() relies on a scan of the maven repository + // to find the latest version of liberty available, possibly remotely. + // + // Not sure what subtle issues this might cause. If there are issues matching + // the runtime versions then this may be the culprit and not actually a Boost + // issue. + String expectedVersion = getLatestLibertyRuntimeVersion(); + + log.info("Found installed version = " + installedVersion + + ". From Boost we defaulted the runtime version (to the latest). According to the test logic the latest version available is: " + + expectedVersion); + + String assertMsg = "Expected default runtime version not found in installed Liberty properties file. This may be because the " + + "default to latest version algorithm produced subtly different results when it was called from the runtime code " + + "vs. the test code trying to validate that the latest was used. As such, this may not be a boost issue, but an " + + "implementation detail of the underlying Maven APIs."; + assertEquals(assertMsg, expectedVersion, installedVersion); + } else { + + log.info("Found installed version = " + installedVersion + ", looking for runtime version = " + + runtimeVersion); + + assertEquals("Didn't find expected runtime version in product install properties file", runtimeVersion, + installedVersion); } - String assertMsg = "Runtime version is null. This may be an issue with checking for the latest runtime version from maven and may not be a boost issue"; - assertNotNull(assertMsg, runtimeVersion); + } + + private String getLibertyVersionPropertyFromInstall() throws FileNotFoundException, IOException { Properties libertyProps = new Properties(); String propsRuntime = null; @@ -145,19 +172,15 @@ public void testLibertyRuntimeVersion() throws Exception { fis = new FileInputStream(LIBERTY_PROPERTIES); libertyProps.load(fis); propsRuntime = libertyProps.getProperty(LIBERTY_VERSION); - assertNotNull("Property runtime empty", propsRuntime); - if (propsRuntime.equals(runtimeVersion)) { - found = true; - } } finally { if (fis != null) { fis.close(); } } - assertMsg = "The run time version " + runtimeVersion - + " was not found in the openliberty.properties. openliberty.properties version = " + propsRuntime - + ". This may be an issue with checking for the latest runtime version from maven and may not be a boost issue"; + assertNotNull("Didn't find property: " + LIBERTY_VERSION + " in file: " + LIBERTY_PROPERTIES, propsRuntime); + assertNotEquals("Found empty-valued property: " + LIBERTY_VERSION + " in file: " + LIBERTY_PROPERTIES, "", + propsRuntime); - assertTrue(assertMsg, found); + return propsRuntime; } }