Skip to content

Commit

Permalink
bootstrap.include feature, init jvm.options
Browse files Browse the repository at this point in the history
  • Loading branch information
dshimo committed Feb 29, 2024
1 parent 222a550 commit 48d57a4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -49,6 +50,7 @@
import org.xml.sax.SAXException;

import io.openliberty.tools.common.CommonLoggerI;
import io.openliberty.tools.common.plugins.util.ServerFeatureUtil;
import io.openliberty.tools.common.plugins.util.VariableUtility;

// Moved from ci.maven/liberty-maven-plugin/src/main/java/net/wasdev/wlp/maven/plugins/ServerConfigDocument.java
Expand All @@ -58,11 +60,8 @@ public class ServerConfigDocument {

private File configDirectory;
private File serverXMLFile;
private static final String WLP_INSTALL_DIR_PROPERTY = "wlp.install.dir";
private static final String WLP_USER_DIR_PROPERTY = "wlp.user.dir";
private static final String SERVER_CONFIG_DIR_PROPERTY = "server.config.dir";
// private static final String CONFIGDROPINS_DEFAULT;
// private static final String CONFIGDROPINS_OVERRIDES;
private static final String CONFIGDROPINS_DEFAULT = Paths.get("configDropins/default/").toString();
private static final String CONFIGDROPINS_OVERRIDES = Paths.get("configDropins/overrides/").toString();

private Set<String> names;
private Set<String> namelessLocations;
Expand Down Expand Up @@ -188,6 +187,7 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf
processServerEnv();

// 3. get variables from jvm.options
processJvmOptions();

// 3. get variables from bootstrap.properties
processBootstrapProperties(bootstrapProp, bootstrapFile);
Expand Down Expand Up @@ -216,6 +216,24 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf
}
}


/**
* jvm.options file read order
* 1. {wlp.user.dir}/
* 2. {server.config.dir}/configDropins/defaults/
* 3. {server.config.dir}/
* 4. {server.config.dir}/configDropins/overrides/
* @throws FileNotFoundException
* @throws Exception
*/
public void processJvmOptions() throws FileNotFoundException, Exception {
final String jvmOptionsString = "jvm.options";
parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.WLP_USER_DIR), jvmOptionsString));
parsePropertiesFromFile(getFileFromConfigDirectory(CONFIGDROPINS_DEFAULT + File.separator + jvmOptionsString));
parsePropertiesFromFile(getFileFromConfigDirectory(jvmOptionsString));
parsePropertiesFromFile(getFileFromConfigDirectory(CONFIGDROPINS_OVERRIDES + File.separator + jvmOptionsString));
}

/**
* server.env file read order
* 1. {wlp.install.dir}/etc/
Expand All @@ -227,9 +245,9 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf
*/
public void processServerEnv() throws Exception, FileNotFoundException {
final String serverEnvString = "server.env";
parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(WLP_INSTALL_DIR_PROPERTY), "etc" + File.separator + serverEnvString));
parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(WLP_USER_DIR_PROPERTY), "shared" + File.separator + serverEnvString));
parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(SERVER_CONFIG_DIR_PROPERTY), serverEnvString));
parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.WLP_INSTALL_DIR), "etc" + File.separator + serverEnvString));
parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.WLP_USER_DIR), "shared" + File.separator + serverEnvString));
parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR), serverEnvString));
}

public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileNotFoundException {
Expand Down Expand Up @@ -265,7 +283,6 @@ public void initializeFields(CommonLoggerI log, File serverXML, File configDir,
*/
public void processBootstrapProperties(Map<String, String> bootstrapProp, File bootstrapFile) throws Exception, FileNotFoundException {
File cfgDirFile = getFileFromConfigDirectory("bootstrap.properties");
// TODO: bootstrap.include
if (bootstrapProp != null && !bootstrapProp.isEmpty()) {
for (Map.Entry<String,String> entry : bootstrapProp.entrySet()) {
if (entry.getValue() != null) {
Expand All @@ -277,6 +294,15 @@ public void processBootstrapProperties(Map<String, String> bootstrapProp, File b
} else if (cfgDirFile != null) {
parseProperties(new FileInputStream(cfgDirFile));
}

if (props.containsKey("bootstrap.include")) {
Path bootstrapIncludePath = Paths.get(props.getProperty("bootstrap.include")).normalize();
File bootstrapIncludeFile = bootstrapIncludePath.isAbsolute() ?
new File(bootstrapIncludePath.toString()) : new File(configDirectory, bootstrapIncludePath.toString());
if (bootstrapIncludeFile.exists()) {
parseProperties(new FileInputStream(bootstrapIncludeFile));
}
}
}

//Checks for application names in the document. Will add locations without names to a Set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception
configDocument.processBootstrapProperties(bootstrapPropertyMap, null);
assertEquals("1000", configDocument.getProperties().getProperty("http.port"));

// TODO: bootstraps.include
// configDocument = new ServerConfigDocument(new TestLogger());
// configDocument.initializeFields(new TestLogger(), null, serversDir, null);
// configDocument.processBootstrapProperties(new HashMap<>(), MOCK_SERVER_DIR.resolve("bootstrapInclude.properties").toFile());
// assertEquals("9080", configDocument.getProperties().getProperty("http.port"));
configDocument = new ServerConfigDocument(new TestLogger());
configDocument.initializeFields(new TestLogger(), null, serversDir, null);
configDocument.processBootstrapProperties(new HashMap<>(), MOCK_SERVER_DIR.resolve("bootstrapInclude.properties").toFile());
assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename"));
}

// 4. Java system properties
Expand Down

0 comments on commit 48d57a4

Please sign in to comment.