Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge in keystore_password in target server.env if present #1097

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/common-server-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ Starting with the 3.1 release of the liberty-maven-plugin, support is added to s
| liberty.var.{var} | `<variable name="var" value="value">` | liberty-plugin-variable-config.xml | The server configuration file is generated in the configDropins/overrides folder of the target server. |
| liberty.defaultVar.{var} | `<variable name="var" defaultValue="value">` | liberty-plugin-variable-config.xml | The server configuration file is generated in the configDropins/overrides folder of the target server. |

If Liberty configuration is specified with Maven properties, the above indicated files are created in the target Liberty server. By default there is no merging behavior for the Maven properties with files located in the `configDirectory` or the specific configuration file parameters such as `bootstrapPropertiesFile`, `jvmOptionsFile` and `serverEnvFile`. However, the `liberty.env.{var}` Maven properties can be merged with other configured `server.env` files by setting the `mergeServerEnv` parameter to `true`.
If Liberty configuration is specified with Maven properties, the above indicated files are created in the target Liberty server. By default there is no merging behavior for the Maven properties with files located in the `configDirectory` or the specific configuration file parameters such as `bootstrapPropertiesFile`, `jvmOptionsFile` and `serverEnvFile`. However, the `liberty.env.{var}` Maven properties can be merged with other configured `server.env` files by setting the `mergeServerEnv` parameter to `true`. As a special case when `mergeServerEnv` is `false`, an existing "keystore_password" property in the default generated `server.env` file in the target server will be merged in if there is no
serverEnvFile` configured nor `server.env` file located in the `configDirectory`, and the "keystore_password" env var is not defined as a Maven property.
scottkurz marked this conversation as resolved.
Show resolved Hide resolved

Note that properties specified with `-D` on the command line are also analyzed for the property name formats listed above and take precedence over Maven properties specified in the pom.xml.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.name;
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
import static org.twdata.maven.mojoexecutor.MojoExecutor.name;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -36,6 +36,7 @@
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -493,10 +494,14 @@ protected void copyConfigFiles() throws Exception {
}
else {
if (!envMavenProps.isEmpty()) {
if (serverEnvPath != null) {
Map<String,String> envPropsToWrite = envMavenProps;
if (serverEnvFile == null && serverEnvPath == null) {
// Do a special case merge but ONLY if there are no other config options present
envPropsToWrite = mergeSpecialPropsFromInstallServerEnvIfAbsent(envMavenProps);
} else if (serverEnvPath != null) {
log.warn("The " + serverEnvPath + " file is overwritten by inlined configuration.");
}
writeServerEnvProperties(envFile, envMavenProps);
writeServerEnvProperties(envFile, envPropsToWrite);
serverEnvPath = "inlined configuration";
} else if (serverEnvFile != null && serverEnvFile.exists()) {
Copy copy = (Copy) ant.createTask("copy");
Expand Down Expand Up @@ -540,6 +545,33 @@ protected void copyConfigFiles() throws Exception {
copyDependencies();
}

/**
* Merges envProps with special properties found in the install (target) server.env. We return a clone/copy of
* envProps, to which any of a list of special properties found in server.env have been added. We give precedence
* to properties already in envProps.
*/
private Map<String, String> mergeSpecialPropsFromInstallServerEnvIfAbsent(Map<String, String> envProps) throws IOException {

String[] specialProps = { "keystore_password" };

Map<String, String> mergedProps = new HashMap<String,String>();

// Clone to avoid side effects
for (String key : envProps.keySet()) {
scottkurz marked this conversation as resolved.
Show resolved Hide resolved
mergedProps.put(key, envProps.get(key));
}

// From install (target) dir
File serverEnv = new File(serverDirectory, "server.env");
Map<String, String> serverEnvProps = convertServerEnvToProperties(serverEnv);

for (String propertyName : specialProps) {
mergedProps.putIfAbsent(propertyName, serverEnvProps.get(propertyName));
scottkurz marked this conversation as resolved.
Show resolved Hide resolved
}

return mergedProps;
}

// Merges configured serverEnvFile with envMavenProps if specified, and returns the updated serverEnvPath
private String mergeServerEnvFileAndEnvMavenProps(String serverEnvPath) throws IOException {
String modifiedServerEnvPath = serverEnvPath;
Expand Down