Skip to content

Commit

Permalink
Add runtime groupId and artifactId properties (#1287)
Browse files Browse the repository at this point in the history
* Adding groupId and artifactId properties

* Add runtime property override tests

* Use default value for empty runtime property

* Update default OL version and bump runtime property test versions

* Updating docs with new runtime property info

* Add runtime property information to installation-configuration documentation
  • Loading branch information
mattbsox authored Nov 15, 2021
1 parent f2a5bcc commit 168a77e
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 79 deletions.
2 changes: 2 additions & 0 deletions docs/common-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Parameters shared by all goals.
| installDirectory | Local installation directory of the Liberty server. | Yes, only when `runtimeArchive`, `runtimeArtifact`, and `install` parameters are not set. |
| runtimeArchive | Location of the Liberty server compressed archive. The archive will be unpacked into a directory as specified by the `runtimeInstallDirectory` parameter. | Yes, only when `installDirectory`, `runtimeArtifact`, and `install` parameters are not set. |
| runtimeArtifact | Maven artifact name of the Liberty runtime. The runtime will be installed into a directory as specified by the `runtimeInstallDirectory` parameter. The default runtime is the latest version of `io.openliberty:openliberty-kernel`. | No |
| libertyRuntimeGroupId | Liberty runtime groupId to use instead of the `runtimeArtifact` groupId. This can also be specified with `-Dliberty.runtime.groupId` from the command line. | No |
| libertyRuntimeArtifactId | Liberty runtime artifactId to use instead of the `runtimeArtifact` artifactId. This can also be specified with `-Dliberty.runtime.artifactId` from the command line. | No |
| libertyRuntimeVersion | Liberty runtime version to use instead of the `runtimeArtifact` version. This can also be specified with `-Dliberty.runtime.version` from the command line. | No |
| install | Install Liberty runtime from the [Liberty repository](installation-configuration.md#using-the-install-liberty-ant-task). | Yes, only when `installDirectory`, `runtimeArchive`, and `runtimeArtifact` parameters are not set. |
| licenseArtifact | Maven artifact name of the Liberty license jar. It will be used to upgrade the installation at the location specified by the `runtimeInstallDirectory` parameter. | No |
Expand Down
51 changes: 51 additions & 0 deletions docs/installation-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,57 @@ Example for using the `runtimeArtifact` parameter:
</plugin>
```

The coordinates for `runtimeArtifact` can be overridden using `libertyRuntimeGroupId`, `libertyRuntimeArtifactId`, and `libertyRuntimeVersion`. These can be set using command line properties, pom.xml properties, or additional plugin configuration. Empty or `null` values will result in a default value overriding the respective `runtimeArtifact` coordinate value. More information on these properties can be found in [common parameters](docs/common-parameters.md#common-parameters).

Example of overriding the `runtimeArtifact` parameter through the command line:

```
mvn clean install -Dliberty.runtime.groupId=io.openliberty -Dliberty.runtime.artifactId=openliberty-runtime -Dliberty.runtime.version=21.0.0.9
```

Example of overriding the `runtimeArtifact` parameter with pom properties:

```xml
<properties>
<liberty.runtime.groupId>io.openliberty</liberty.runtime.groupId>
<liberty.runtime.artifactId>openliberty-runtime</liberty.runtime.artifactId>
<liberty.runtime.version>21.0.0.9</liberty.runtime.version>
</properties>

<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<configuration>
<runtimeArtifact>
<groupId>com.ibm.websphere.appserver.runtime</groupId>
<artifactId>wlp-webProfile7</artifactId>
<version>8.5.5.7</version>
<type>zip</type>
</runtimeArtifact>
</configuration>
</plugin>
```

Example of overriding the `runtimeArtifact` parameter with plugin configuration:

```xml
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<configuration>
<libertyRuntimeGroupId>io.openliberty</libertyRuntimeGroupId>
<libertyRuntimeArtifactId>openliberty-runtime</libertyRuntimeArtifactId>
<libertyRuntimeVersion>21.0.0.9</libertyRuntimeVersion>
<runtimeArtifact>
<groupId>com.ibm.websphere.appserver.runtime</groupId>
<artifactId>wlp-webProfile7</artifactId>
<version>8.5.5.7</version>
<type>zip</type>
</runtimeArtifact>
</configuration>
</plugin>
```

### Using an existing installation

Use the `installDirectory` parameter to specify the directory of an existing Liberty server installation. For example:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# prove the runtime version can be overridden
invoker.goals.1 = clean install -Dliberty.runtime.groupId=io.openliberty -Dliberty.runtime.artifactId=openliberty-runtime -Dliberty.runtime.version=21.0.0.3
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>basic-runtime-version-property-override-it</artifactId>
<artifactId>basic-runtime-properties-override-it</artifactId>
<packaging>jar</packaging>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package net.wasdev.wlp.maven.test.app;

import java.io.File;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.Scanner;

import static junit.framework.Assert.*;

// Check that the liberty runtime groupId, artifactId, and version were successfully overridden by the
// -Dliberty.runtime.groupId, -Dliberty.runtime.artifactId, and -Dliberty.runtime.version properties
public class LibertyRuntimePropertiesIT {

@Test
public void testLibertyVersionInstalled() throws Exception {
File f = new File("./liberty/wlp/lib/versions/openliberty.properties");
assertTrue(f.getCanonicalFile() + " doesn't exist.", f.exists());

FileInputStream input = new FileInputStream(f);
Properties libertyProductProperties = new Properties();

libertyProductProperties.load(input);
String version = libertyProductProperties.getProperty("com.ibm.websphere.productVersion");
assertNotNull("The com.ibm.websphere.productVersion property does not exist.",version);
assertEquals("The com.ibm.websphere.productVersion property has an unexpected value.","21.0.0.3",version);
}

@Test
public void buildLogCheck() throws Exception {
File buildLog = new File("../build.log");
assertTrue(buildLog.exists());

InputStream buildOutput = null;
InputStreamReader in = null;
Scanner s = null;

final String GROUPID_MESSAGE = "[INFO] The runtimeArtifact groupId io.openliberty is overwritten by the liberty.runtime.groupId value io.openliberty.";
boolean GROUPID_MESSAGE_FOUND = false;

final String ARTIFACTID_MESSAGE = "[INFO] The runtimeArtifact artifactId openliberty-webProfile8 is overwritten by the liberty.runtime.artifactId value openliberty-runtime.";
boolean ARTIFACTID_MESSAGE_FOUND = false;

final String VERSION_MESSAGE = "[INFO] The runtimeArtifact version 19.0.0.6 is overwritten by the liberty.runtime.version value 21.0.0.3.";
boolean VERSION_MESSAGE_FOUND = false;

try {
buildOutput = new FileInputStream(buildLog);
in = new InputStreamReader(buildOutput);
s = new Scanner(in);

while (s.hasNextLine()) {
String line = s.nextLine();
if (line.equals(GROUPID_MESSAGE)) {
GROUPID_MESSAGE_FOUND = true;
} else if (line.equals(ARTIFACTID_MESSAGE)) {
ARTIFACTID_MESSAGE_FOUND = true;
} else if (line.equals(VERSION_MESSAGE)) {
VERSION_MESSAGE_FOUND = true;
}
}
} catch (Exception e) {

}

assertTrue(GROUPID_MESSAGE_FOUND && ARTIFACTID_MESSAGE_FOUND && VERSION_MESSAGE_FOUND);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>basic-runtime-version-pom-override-it</artifactId>
<artifactId>basic-runtime-properties-pom-override-it</artifactId>
<packaging>jar</packaging>

<properties>
<liberty.runtime.version>19.0.0.7</liberty.runtime.version>
<liberty.runtime.groupId>io.openliberty</liberty.runtime.groupId>
<liberty.runtime.artifactId>openliberty-runtime</liberty.runtime.artifactId>
<liberty.runtime.version>21.0.0.3</liberty.runtime.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package net.wasdev.wlp.maven.test.app;

import java.io.File;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.Scanner;

import static junit.framework.Assert.*;

// Check that the liberty runtime groupId, artifactId, and version were successfully overridden by the
// liberty.runtime.groupId, liberty.runtime.artifactId, and liberty.runtime.version properties in the pom.xml
public class LibertyRuntimePropertiesIT {

@Test
public void testLibertyVersionInstalled() throws Exception {
File f = new File("./liberty/wlp/lib/versions/openliberty.properties");
assertTrue(f.getCanonicalFile() + " doesn't exist.", f.exists());

FileInputStream input = new FileInputStream(f);
Properties libertyProductProperties = new Properties();

libertyProductProperties.load(input);
String version = libertyProductProperties.getProperty("com.ibm.websphere.productVersion");
assertNotNull("The com.ibm.websphere.productVersion property does not exist.",version);
assertEquals("The com.ibm.websphere.productVersion property has an unexpected value.","21.0.0.3",version);
}

@Test
public void buildLogCheck() throws Exception {
File buildLog = new File("../build.log");
assertTrue(buildLog.exists());

InputStream buildOutput = null;
InputStreamReader in = null;
Scanner s = null;

final String GROUPID_MESSAGE = "[INFO] The runtimeArtifact groupId io.openliberty is overwritten by the liberty.runtime.groupId value io.openliberty.";
boolean GROUPID_MESSAGE_FOUND = false;

final String ARTIFACTID_MESSAGE = "[INFO] The runtimeArtifact artifactId openliberty-webProfile8 is overwritten by the liberty.runtime.artifactId value openliberty-runtime.";
boolean ARTIFACTID_MESSAGE_FOUND = false;

final String VERSION_MESSAGE = "[INFO] The runtimeArtifact version 19.0.0.6 is overwritten by the liberty.runtime.version value 21.0.0.3.";
boolean VERSION_MESSAGE_FOUND = false;

try {
buildOutput = new FileInputStream(buildLog);
in = new InputStreamReader(buildOutput);
s = new Scanner(in);

while (s.hasNextLine()) {
String line = s.nextLine();
if (line.equals(GROUPID_MESSAGE)) {
GROUPID_MESSAGE_FOUND = true;
} else if (line.equals(ARTIFACTID_MESSAGE)) {
ARTIFACTID_MESSAGE_FOUND = true;
} else if (line.equals(VERSION_MESSAGE)) {
VERSION_MESSAGE_FOUND = true;
}
}
} catch (Exception e) {

}

assertTrue(GROUPID_MESSAGE_FOUND && ARTIFACTID_MESSAGE_FOUND && VERSION_MESSAGE_FOUND);
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2014, 2020.
* (C) Copyright IBM Corporation 2014, 2021.
*
* 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 @@ -170,6 +170,18 @@ protected static enum InstallType {
@Parameter(property = "mergeServerEnv", defaultValue = "false")
protected boolean mergeServerEnv;

/**
* GroupId to override any specified in the assemblyArtifact
*/
@Parameter(alias = "libertyRuntimeGroupId", property = "liberty.runtime.groupId")
protected String libertyRuntimeGroupId = null;

/**
* ArtifactId to override any specified in the assemblyArtifact
*/
@Parameter(alias = "libertyRuntimeArtifactId", property = "liberty.runtime.artifactId")
protected String libertyRuntimeArtifactId = null;

/**
* Version to override any specified in the assemblyArtifact
*/
Expand Down Expand Up @@ -209,17 +221,39 @@ protected void init() throws MojoExecutionException, MojoFailureException {
}
else { // default to install from runtime artifact
assemblyArtifact.setType("zip");
if(assemblyArtifact.getGroupId() == null) {
log.debug("Defaulting runtimeArtifact group id to 'io.openliberty'");
assemblyArtifact.setGroupId("io.openliberty");

// check for liberty.runtime.groupId property which overrides any groupId set in the assemblyArtifact
if (libertyRuntimeGroupId != null && !libertyRuntimeGroupId.isEmpty()) {
if (assemblyArtifact.getGroupId() != null) {
log.info("The runtimeArtifact groupId " + assemblyArtifact.getGroupId() + " is overwritten by the liberty.runtime.groupId value "+ libertyRuntimeGroupId +".");
} else {
log.info("The liberty.runtime.groupId property value "+ libertyRuntimeGroupId +" is used for the runtimeArtifact groupId.");
}
assemblyArtifact.setGroupId(libertyRuntimeGroupId);
} else {
if(assemblyArtifact.getGroupId() == null) {
log.debug("Defaulting runtimeArtifact group id to 'io.openliberty'");
assemblyArtifact.setGroupId("io.openliberty");
}
}
if(assemblyArtifact.getArtifactId() == null) {
log.debug("Defaulting runtimeArtifact artifact id to 'openliberty-kernel'");
assemblyArtifact.setArtifactId("openliberty-kernel");

// check for liberty.runtime.artifactId property which overrides any artifactId set in the assemblyArtifact
if (libertyRuntimeArtifactId != null && !libertyRuntimeArtifactId.isEmpty()) {
if (assemblyArtifact.getArtifactId() != null) {
log.info("The runtimeArtifact artifactId " + assemblyArtifact.getArtifactId() + " is overwritten by the liberty.runtime.artifactId value "+ libertyRuntimeArtifactId +".");
} else {
log.info("The liberty.runtime.artifactId property value "+ libertyRuntimeArtifactId +" is used for the runtimeArtifact artifactId.");
}
assemblyArtifact.setArtifactId(libertyRuntimeArtifactId);
} else {
if(assemblyArtifact.getArtifactId() == null) {
log.debug("Defaulting runtimeArtifact artifact id to 'openliberty-kernel'");
assemblyArtifact.setArtifactId("openliberty-kernel");
}
}

// check for liberty.runtime.version property which overrides any version set in the assemblyArtifact
if (libertyRuntimeVersion != null) {
if (libertyRuntimeVersion != null && !libertyRuntimeVersion.isEmpty()) {
if (assemblyArtifact.getVersion() != null) {
log.info("The runtimeArtifact version " + assemblyArtifact.getVersion() + " is overwritten by the liberty.runtime.version value "+ libertyRuntimeVersion +".");
} else {
Expand All @@ -229,8 +263,8 @@ protected void init() throws MojoExecutionException, MojoFailureException {
}
else {
if(assemblyArtifact.getVersion() == null) {
log.debug("Defaulting runtimeArtifact version to '[19.0.0.6,)'");
assemblyArtifact.setVersion("[19.0.0.6,)");
log.debug("Defaulting runtimeArtifact version to '[21.0.0.9,)'");
assemblyArtifact.setVersion("[21.0.0.9,)");
}
}

Expand Down

0 comments on commit 168a77e

Please sign in to comment.