Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #397 from uberskigeek/360-runtimeversion
Browse files Browse the repository at this point in the history
Issue 360 add support for specifying liberty runtime version
  • Loading branch information
scottkurz authored Sep 26, 2019
2 parents 1b616d3 + fb4cbf3 commit 6a10a7a
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class BoostProperties {
public static final String AES_ENCRYPTION_KEY = "boost_aes_key";

public static final String INTERNAL_COMPILER_TARGET = "boost.internal.compiler.target";
public static final String LIBERTY_VERSION = "libertyRuntimeVersion";

/**
* Return a list of all properties that need to be encrypted
Expand All @@ -64,22 +65,20 @@ public static Properties getConfiguredBoostProperties(Properties projectProperti
// system properties (set at command line)
for (Map.Entry<Object, Object> entry : projectProperties.entrySet()) {

if (entry.getKey().toString().startsWith(BOOST_PROP_PREFIX)) {

// logger.debug("Found boost property: " +
// entry.getKey() + ":" + entry.getValue());
if (entry.getKey().toString().startsWith(BOOST_PROP_PREFIX)
|| entry.getKey().toString().equals(LIBERTY_VERSION)) {

logger.debug("Found boost property: " + entry.getKey() + ":" + entry.getValue());
boostProperties.put(entry.getKey(), entry.getValue());
}
}

for (Map.Entry<Object, Object> entry : systemProperties.entrySet()) {

if (entry.getKey().toString().startsWith(BOOST_PROP_PREFIX)) {

// logger.debug("Found boost property: " +
// entry.getKey() + ":" + entry.getValue());
if (entry.getKey().toString().startsWith(BOOST_PROP_PREFIX)
|| entry.getKey().toString().equals(LIBERTY_VERSION)) {

logger.debug("Found boost property: " + entry.getKey() + ":" + entry.getValue());
boostProperties.put(entry.getKey(), entry.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals.1 = clean install -DlibertyRuntimeVersion=19.0.0.7
invoker.goals.2 = clean install
30 changes: 30 additions & 0 deletions boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-file</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.3.9</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,91 @@
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;
import org.junit.Test;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.resolution.VersionRangeRequest;
import org.eclipse.aether.resolution.VersionRangeResult;
import org.eclipse.aether.resolution.VersionRangeResolutionException;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
import org.eclipse.aether.transport.file.FileTransporterFactory;
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 = "<feature>jaxrs-2.0</feature>";
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";
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() {
String runtime = System.getProperty("boostRuntime");
org.junit.Assume.assumeTrue("ol".equals(runtime) || "wlp".equals(runtime));
runtimeVersion = System.getProperty("libertyRuntimeVersion");
}

/*
* Go to Maven and figure out what the latest version of liberty runtime is out
* there. Use that version for comparing what level should be found in the
* messages.log file when the server is run. Only used when no libertyRunTime
* version is provided.
*/
private String getLatestLibertyRuntimeVersion() {
String libertyVersion = null;

RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/")
.build();
RepositorySystem repoSystem = newRepositorySystem();
RepositorySystemSession session = newSession(repoSystem);
String version = "[19.0.0.6,)";
Artifact artifact = new DefaultArtifact("io.openliberty:openliberty-runtime:" + version);
VersionRangeRequest request = new VersionRangeRequest(artifact, Arrays.asList(central), null);
try {
VersionRangeResult versionResult = repoSystem.resolveVersionRange(session, request);
libertyVersion = versionResult.getHighestVersion().toString();
} catch (VersionRangeResolutionException e) {
e.printStackTrace();
}

return libertyVersion;

}

private RepositorySystem newRepositorySystem() {
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
return locator.getService(RepositorySystem.class);
}

private RepositorySystemSession newSession(RepositorySystem system) {
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository("target/local-repo");
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
return session;
}

@Test
Expand Down Expand Up @@ -56,4 +128,59 @@ 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 {

String installedVersion = getLibertyVersionPropertyFromInstall();

if (runtimeVersion == null) {

// 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);
}
}

private String getLibertyVersionPropertyFromInstall() throws FileNotFoundException, IOException {

Properties libertyProps = new Properties();
String propsRuntime = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(LIBERTY_PROPERTIES);
libertyProps.load(fis);
propsRuntime = libertyProps.getProperty(LIBERTY_VERSION);
} finally {
if (fis != null) {
fis.close();
}
}
assertNotNull("Didn't find property: " + LIBERTY_VERSION + " in file: " + LIBERTY_PROPERTIES, propsRuntime);
assertNotEquals("Found empty-valued property: " + LIBERTY_VERSION + " in file: " + LIBERTY_PROPERTIES, "",
propsRuntime);

return propsRuntime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.6,)";
private String runtimeVersion;

private String libertyMavenPluginGroupId = "io.openliberty.tools";
private String libertyMavenPluginArtifactId = "liberty-maven-plugin";
Expand All @@ -69,6 +70,7 @@ public LibertyRuntime() {
this.projectBuildDir = null;
this.libertyServerPath = null;
this.mavenDepPlugin = null;
this.runtimeVersion = defaultRuntimeVersion;
}

public LibertyRuntime(RuntimeParams runtimeParams) {
Expand All @@ -79,6 +81,9 @@ 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("libertyRuntimeVersion", defaultRuntimeVersion);
BoostLogger log = BoostLogger.getSystemStreamLogger();
log.info("Liberty Runtime version selected = " + runtimeVersion);
}

private Plugin getPlugin() throws MojoExecutionException {
Expand Down Expand Up @@ -167,8 +172,9 @@ private void generateServerConfig(List<AbstractBoosterConfig> 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
*/
Expand All @@ -177,7 +183,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
Expand All @@ -193,7 +199,7 @@ private String getWarName() throws BoostException {
throw new BoostException(msg);
}
}

return retVal;
}

Expand All @@ -218,7 +224,7 @@ private void generateLibertyServerConfig(List<AbstractBoosterConfig> boosterConf

String httpsPort = (String) boostProperties.getOrDefault(BoostProperties.ENDPOINT_HTTPS_PORT, "9443");
libertyConfig.addHttpsPort(httpsPort);

String warName = getWarName();
libertyConfig.addApplication(warName);

Expand Down

0 comments on commit 6a10a7a

Please sign in to comment.