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

Commit 6a10a7a

Browse files
authored
Merge pull request #397 from uberskigeek/360-runtimeversion
Issue 360 add support for specifying liberty runtime version
2 parents 1b616d3 + fb4cbf3 commit 6a10a7a

File tree

5 files changed

+178
-14
lines changed

5 files changed

+178
-14
lines changed

boost-common/src/main/java/org/microshed/boost/common/config/BoostProperties.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public final class BoostProperties {
4040
public static final String AES_ENCRYPTION_KEY = "boost_aes_key";
4141

4242
public static final String INTERNAL_COMPILER_TARGET = "boost.internal.compiler.target";
43+
public static final String LIBERTY_VERSION = "libertyRuntimeVersion";
4344

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

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

71+
logger.debug("Found boost property: " + entry.getKey() + ":" + entry.getValue());
7272
boostProperties.put(entry.getKey(), entry.getValue());
7373
}
7474
}
7575

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

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

81+
logger.debug("Found boost property: " + entry.getKey() + ":" + entry.getValue());
8382
boostProperties.put(entry.getKey(), entry.getValue());
8483
}
8584
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals.1 = clean install -DlibertyRuntimeVersion=19.0.0.7
2+
invoker.goals.2 = clean install

boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@
5959
<version>3.1</version>
6060
<scope>test</scope>
6161
</dependency>
62+
<dependency>
63+
<groupId>org.eclipse.aether</groupId>
64+
<artifactId>aether-impl</artifactId>
65+
<version>1.1.0</version>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.eclipse.aether</groupId>
70+
<artifactId>aether-connector-basic</artifactId>
71+
<version>1.1.0</version>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.eclipse.aether</groupId>
76+
<artifactId>aether-transport-file</artifactId>
77+
<version>1.1.0</version>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.eclipse.aether</groupId>
82+
<artifactId>aether-transport-http</artifactId>
83+
<version>1.1.0</version>
84+
<scope>test</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.apache.maven</groupId>
88+
<artifactId>maven-aether-provider</artifactId>
89+
<version>3.3.9</version>
90+
<scope>test</scope>
91+
</dependency>
6292
</dependencies>
6393

6494
<build>

boost-maven/boost-maven-plugin/src/it/test-jaxrs-2.0/src/test/java/it/LibertyFeatureVersionIT.java

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,91 @@
1515
import java.io.BufferedReader;
1616
import java.io.File;
1717
import java.io.FileReader;
18+
import java.io.IOException;
19+
import java.util.Arrays;
20+
import java.io.FileInputStream;
21+
import java.io.FileNotFoundException;
22+
import java.util.Properties;
1823

1924
import org.junit.BeforeClass;
2025
import org.junit.Test;
26+
import org.eclipse.aether.repository.RemoteRepository;
27+
import org.eclipse.aether.RepositorySystem;
28+
import org.eclipse.aether.RepositorySystemSession;
29+
import org.eclipse.aether.artifact.Artifact;
30+
import org.eclipse.aether.resolution.VersionRangeRequest;
31+
import org.eclipse.aether.resolution.VersionRangeResult;
32+
import org.eclipse.aether.resolution.VersionRangeResolutionException;
33+
import org.eclipse.aether.DefaultRepositorySystemSession;
34+
import org.eclipse.aether.artifact.DefaultArtifact;
35+
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
36+
import org.eclipse.aether.impl.DefaultServiceLocator;
37+
import org.eclipse.aether.repository.LocalRepository;
38+
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
39+
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
40+
import org.eclipse.aether.transport.file.FileTransporterFactory;
41+
import org.eclipse.aether.transport.http.HttpTransporterFactory;
42+
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
43+
44+
import org.apache.commons.logging.Log;
45+
import org.apache.commons.logging.LogFactory;
2146

2247
public class LibertyFeatureVersionIT {
2348

2449
private static final String JAXRS_20_FEATURE = "<feature>jaxrs-2.0</feature>";
2550
private static String SERVER_XML = "target/liberty/wlp/usr/servers/defaultServer/server.xml";
51+
private static String LIBERTY_PROPERTIES = "target/liberty/wlp/lib/versions/openliberty.properties";
52+
private static String LIBERTY_VERSION = "com.ibm.websphere.productVersion";
53+
private static String runtimeVersion;
54+
private final static Log log = LogFactory.getLog(LibertyFeatureVersionIT.class);
2655

2756
@BeforeClass
2857
public static void init() {
2958
String runtime = System.getProperty("boostRuntime");
3059
org.junit.Assume.assumeTrue("ol".equals(runtime) || "wlp".equals(runtime));
60+
runtimeVersion = System.getProperty("libertyRuntimeVersion");
61+
}
62+
63+
/*
64+
* Go to Maven and figure out what the latest version of liberty runtime is out
65+
* there. Use that version for comparing what level should be found in the
66+
* messages.log file when the server is run. Only used when no libertyRunTime
67+
* version is provided.
68+
*/
69+
private String getLatestLibertyRuntimeVersion() {
70+
String libertyVersion = null;
71+
72+
RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/")
73+
.build();
74+
RepositorySystem repoSystem = newRepositorySystem();
75+
RepositorySystemSession session = newSession(repoSystem);
76+
String version = "[19.0.0.6,)";
77+
Artifact artifact = new DefaultArtifact("io.openliberty:openliberty-runtime:" + version);
78+
VersionRangeRequest request = new VersionRangeRequest(artifact, Arrays.asList(central), null);
79+
try {
80+
VersionRangeResult versionResult = repoSystem.resolveVersionRange(session, request);
81+
libertyVersion = versionResult.getHighestVersion().toString();
82+
} catch (VersionRangeResolutionException e) {
83+
e.printStackTrace();
84+
}
85+
86+
return libertyVersion;
87+
88+
}
89+
90+
private RepositorySystem newRepositorySystem() {
91+
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
92+
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
93+
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
94+
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
95+
return locator.getService(RepositorySystem.class);
96+
}
97+
98+
private RepositorySystemSession newSession(RepositorySystem system) {
99+
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
100+
LocalRepository localRepo = new LocalRepository("target/local-repo");
101+
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
102+
return session;
31103
}
32104

33105
@Test
@@ -56,4 +128,59 @@ public void testLibertyFeatureVersion() throws Exception {
56128

57129
assertTrue("The " + JAXRS_20_FEATURE + " feature was not found in the server configuration", found);
58130
}
131+
132+
@Test
133+
public void testLibertyRuntimeVersion() throws Exception {
134+
135+
String installedVersion = getLibertyVersionPropertyFromInstall();
136+
137+
if (runtimeVersion == null) {
138+
139+
// The getLatestLibertyRuntimeVersion() relies on a scan of the maven repository
140+
// to find the latest version of liberty available, possibly remotely.
141+
//
142+
// Not sure what subtle issues this might cause. If there are issues matching
143+
// the runtime versions then this may be the culprit and not actually a Boost
144+
// issue.
145+
String expectedVersion = getLatestLibertyRuntimeVersion();
146+
147+
log.info("Found installed version = " + installedVersion
148+
+ ". From Boost we defaulted the runtime version (to the latest). According to the test logic the latest version available is: "
149+
+ expectedVersion);
150+
151+
String assertMsg = "Expected default runtime version not found in installed Liberty properties file. This may be because the "
152+
+ "default to latest version algorithm produced subtly different results when it was called from the runtime code "
153+
+ "vs. the test code trying to validate that the latest was used. As such, this may not be a boost issue, but an "
154+
+ "implementation detail of the underlying Maven APIs.";
155+
assertEquals(assertMsg, expectedVersion, installedVersion);
156+
} else {
157+
158+
log.info("Found installed version = " + installedVersion + ", looking for runtime version = "
159+
+ runtimeVersion);
160+
161+
assertEquals("Didn't find expected runtime version in product install properties file", runtimeVersion,
162+
installedVersion);
163+
}
164+
}
165+
166+
private String getLibertyVersionPropertyFromInstall() throws FileNotFoundException, IOException {
167+
168+
Properties libertyProps = new Properties();
169+
String propsRuntime = null;
170+
FileInputStream fis = null;
171+
try {
172+
fis = new FileInputStream(LIBERTY_PROPERTIES);
173+
libertyProps.load(fis);
174+
propsRuntime = libertyProps.getProperty(LIBERTY_VERSION);
175+
} finally {
176+
if (fis != null) {
177+
fis.close();
178+
}
179+
}
180+
assertNotNull("Didn't find property: " + LIBERTY_VERSION + " in file: " + LIBERTY_PROPERTIES, propsRuntime);
181+
assertNotEquals("Found empty-valued property: " + LIBERTY_VERSION + " in file: " + LIBERTY_PROPERTIES, "",
182+
propsRuntime);
183+
184+
return propsRuntime;
185+
}
59186
}

boost-maven/boost-runtimes/runtime-openliberty/src/main/java/org/microshed/boost/runtimes/openliberty/LibertyRuntime.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public class LibertyRuntime implements RuntimeI {
5555

5656
private final String runtimeGroupId = "io.openliberty";
5757
private final String runtimeArtifactId = "openliberty-runtime";
58-
private final String runtimeVersion = "19.0.0.9";
58+
private final String defaultRuntimeVersion = "[19.0.0.6,)";
59+
private String runtimeVersion;
5960

6061
private String libertyMavenPluginGroupId = "io.openliberty.tools";
6162
private String libertyMavenPluginArtifactId = "liberty-maven-plugin";
@@ -69,6 +70,7 @@ public LibertyRuntime() {
6970
this.projectBuildDir = null;
7071
this.libertyServerPath = null;
7172
this.mavenDepPlugin = null;
73+
this.runtimeVersion = defaultRuntimeVersion;
7274
}
7375

7476
public LibertyRuntime(RuntimeParams runtimeParams) {
@@ -79,6 +81,9 @@ public LibertyRuntime(RuntimeParams runtimeParams) {
7981
this.projectBuildDir = project.getBuild().getDirectory();
8082
this.libertyServerPath = projectBuildDir + "/liberty/wlp/usr/servers/" + serverName;
8183
this.mavenDepPlugin = runtimeParams.getMavenDepPlugin();
84+
this.runtimeVersion = boostProperties.getProperty("libertyRuntimeVersion", defaultRuntimeVersion);
85+
BoostLogger log = BoostLogger.getSystemStreamLogger();
86+
log.info("Liberty Runtime version selected = " + runtimeVersion);
8287
}
8388

8489
private Plugin getPlugin() throws MojoExecutionException {
@@ -167,8 +172,9 @@ private void generateServerConfig(List<AbstractBoosterConfig> boosterConfigs) th
167172
}
168173

169174
/**
170-
* Assumes a non-WAR packaging type (like JAR) has a WAR dependency.
171-
* We assume there's only 1 but don't check, just return the first one.
175+
* Assumes a non-WAR packaging type (like JAR) has a WAR dependency. We assume
176+
* there's only 1 but don't check, just return the first one.
177+
*
172178
* @return
173179
* @throws BoostException
174180
*/
@@ -177,7 +183,7 @@ private String getWarName() throws BoostException {
177183
String retVal = null;
178184
if (project.getPackaging().equals(ConfigConstants.WAR_PKG_TYPE)) {
179185
retVal = project.getBuild().getFinalName();
180-
} else {
186+
} else {
181187
// JAR package "release", get WAR from dependency
182188
for (Artifact artifact : project.getArtifacts()) {
183189
// first WAR
@@ -193,7 +199,7 @@ private String getWarName() throws BoostException {
193199
throw new BoostException(msg);
194200
}
195201
}
196-
202+
197203
return retVal;
198204
}
199205

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

219225
String httpsPort = (String) boostProperties.getOrDefault(BoostProperties.ENDPOINT_HTTPS_PORT, "9443");
220226
libertyConfig.addHttpsPort(httpsPort);
221-
227+
222228
String warName = getWarName();
223229
libertyConfig.addApplication(warName);
224230

0 commit comments

Comments
 (0)