From 70f083c446a8cc031e30017c6b71045446c6a7fd Mon Sep 17 00:00:00 2001 From: dshimo Date: Tue, 27 Feb 2024 12:27:07 -0600 Subject: [PATCH 01/17] init ServerConfigDocument unit tests --- .../plugins/config/ServerConfigDocument.java | 96 ++++---- .../config/ServerConfigDocumentTest.java | 218 ++++++++++++++++++ .../serverConfig/liberty/wlp/etc/server.env | 2 + .../wlp/usr/servers/defaultServer/server.env | 4 +- .../wlp/usr/servers/defaultServer/server.xml | 2 + .../wlp/usr/servers/defaultServer/server2.env | 2 + .../liberty/wlp/usr/shared/server.env | 2 + .../resources/servers/bootstrap2.properties | 2 + .../servers/bootstrapsInclude.properties | 1 + .../resources/servers/definedVariables.xml | 5 + .../servers/testIncludeParseVariables.xml | 4 + 11 files changed, 294 insertions(+), 44 deletions(-) create mode 100644 src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java create mode 100644 src/test/resources/serverConfig/liberty/wlp/etc/server.env create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server2.env create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/shared/server.env create mode 100644 src/test/resources/servers/bootstrap2.properties create mode 100644 src/test/resources/servers/bootstrapsInclude.properties create mode 100644 src/test/resources/servers/definedVariables.xml create mode 100644 src/test/resources/servers/testIncludeParseVariables.xml diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index 1a1a2e4d..3cab8eb7 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -123,12 +123,8 @@ public ServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, F // LCLS constructor public ServerConfigDocument(CommonLoggerI log) { - this.log = log; - props = new Properties(); - defaultProps = new Properties(); - - // TODO: populate with workspace information - libertyDirectoryPropertyToFile = new HashMap(); + // TODO: populate libertyDirectoryPropertyToFile with workspace information + initializeFields(log, null, null, null); } private DocumentBuilder getDocumentBuilder() { @@ -154,22 +150,7 @@ private DocumentBuilder getDocumentBuilder() { private void initializeAppsLocation(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile, Map bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) { try { - this.log = log; - serverXMLFile = serverXML; - configDirectory = configDir; - if (libertyDirPropertyFiles != null) { - libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); - } else { - log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); - libertyDirectoryPropertyToFile = new HashMap(); - } - - locations = new HashSet(); - names = new HashSet(); - namelessLocations = new HashSet(); - locationsAndNames = new HashMap(); - props = new Properties(); - defaultProps = new Properties(); + initializeFields(log, serverXML, configDir, libertyDirPropertyFiles); Document doc = parseDocument(serverXMLFile); @@ -191,28 +172,10 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf parseVariablesForDefaultValues(doc); // 2. get variables from server.env - File cfgFile = findConfigFile("server.env", serverEnvFile, giveConfigDirPrecedence); - - if (cfgFile != null) { - parseProperties(new FileInputStream(cfgFile)); - } + processServerEnv(serverEnvFile, giveConfigDirPrecedence); // 3. get variables from bootstrap.properties - File cfgDirFile = getFileFromConfigDirectory("bootstrap.properties"); - - if (giveConfigDirPrecedence && cfgDirFile != null) { - parseProperties(new FileInputStream(cfgDirFile)); - } else if (bootstrapProp != null && !bootstrapProp.isEmpty()) { - for (Map.Entry entry : bootstrapProp.entrySet()) { - if (entry.getValue() != null) { - props.setProperty(entry.getKey(),entry.getValue()); - } - } - } else if (bootstrapFile != null && bootstrapFile.exists()) { - parseProperties(new FileInputStream(bootstrapFile)); - } else if (cfgDirFile != null) { - parseProperties(new FileInputStream(cfgDirFile)); - } + processBootstrapProperties(bootstrapFile, bootstrapProp, giveConfigDirPrecedence); // 4. parse variables from include files (both default and non-default values - which we store separately) parseIncludeVariables(doc); @@ -238,6 +201,53 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf } } + public void processServerEnv(File serverEnvFile, boolean giveConfigDirPrecedence) + throws Exception, FileNotFoundException { + File cfgFile = findConfigFile("server.env", serverEnvFile, giveConfigDirPrecedence); + if (cfgFile != null) { + parseProperties(new FileInputStream(cfgFile)); + } + } + + public void initializeFields(CommonLoggerI log, File serverXML, File configDir, + Map libertyDirPropertyFiles) { + this.log = log; + serverXMLFile = serverXML; + configDirectory = configDir; + if (libertyDirPropertyFiles != null) { + libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); + } else { + log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); + libertyDirectoryPropertyToFile = new HashMap(); + } + + locations = new HashSet(); + names = new HashSet(); + namelessLocations = new HashSet(); + locationsAndNames = new HashMap(); + props = new Properties(); + defaultProps = new Properties(); + } + + public void processBootstrapProperties(File bootstrapFile, Map bootstrapProp, boolean giveConfigDirPrecedence) + throws Exception, FileNotFoundException { + File cfgDirFile = getFileFromConfigDirectory("bootstrap.properties"); + + if (giveConfigDirPrecedence && cfgDirFile != null) { + parseProperties(new FileInputStream(cfgDirFile)); + } else if (bootstrapProp != null && !bootstrapProp.isEmpty()) { + for (Map.Entry entry : bootstrapProp.entrySet()) { + if (entry.getValue() != null) { + props.setProperty(entry.getKey(),entry.getValue()); + } + } + } else if (bootstrapFile != null && bootstrapFile.exists()) { + parseProperties(new FileInputStream(bootstrapFile)); + } else if (cfgDirFile != null) { + parseProperties(new FileInputStream(cfgDirFile)); + } + } + //Checks for application names in the document. Will add locations without names to a Set private void parseNames(Document doc, String expression) throws XPathExpressionException, IOException, SAXException { // parse input document @@ -539,7 +549,7 @@ private boolean isValidURL(String url) { } - private void parseVariablesForDefaultValues(Document doc) throws XPathExpressionException { + public void parseVariablesForDefaultValues(Document doc) throws XPathExpressionException { parseVariables(doc, true, false, false); } diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java new file mode 100644 index 00000000..b59c0923 --- /dev/null +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java @@ -0,0 +1,218 @@ +package io.openliberty.tools.common.config; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; + +import javax.xml.xpath.XPathExpressionException; + +import org.junit.Test; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import io.openliberty.tools.common.TestLogger; +import io.openliberty.tools.common.plugins.config.ServerConfigDocument; + +/* + Docs: https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html + # Variable substitution in increasing order of precedence (7 overrides 1) + 1. variable default values in the server.xml file + 2. environment variables + 3. bootstrap.properties + 4. Java system properties + 5. Variables loaded from files in the ${server.config.dir}/variables directory or other directories as specified by the VARIABLE_SOURCE_DIRS environment variable + 6. variable values declared in the server.xml file + 7. variables declared on the command line + */ + +public class ServerConfigDocumentTest { + public final static Logger LOGGER = Logger.getLogger(ServerConfigDocumentTest.class.getName()); + private final static String RESOURCES_DIR = "src/test/resources/"; + private final static String WLP_DIR = "serverConfig/liberty/wlp/"; + private final static String WLP_USER_DIR = "serverConfig/liberty/wlp/usr/"; + private final static String DEFAULT_USER_SERVER_DIR = "servers/defaultServer/"; + private final static String DEFAULT_SERVER_DIR = "servers/"; + + // 1. variable default values in server.xml file + // 6. variable values declared in the server.xml file + @Test + public void processServerXml() throws FileNotFoundException, IOException, XPathExpressionException, SAXException { + File serversDir = new File(RESOURCES_DIR + DEFAULT_SERVER_DIR); + Document doc; + + // no variables defined + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); + File empty = new File(serversDir, "emptyList.xml"); + doc = configDocument.parseDocument(empty); + configDocument.parseVariablesForBothValues(doc); + assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty()); + + // variables defined + configDocument = new ServerConfigDocument(new TestLogger()); + File defined = new File(serversDir, "definedVariables.xml"); + doc = configDocument.parseDocument(defined); + configDocument.parseVariablesForBothValues(doc); + assertEquals(1, configDocument.getDefaultProperties().size()); + assertEquals("9080", configDocument.getDefaultProperties().getProperty("default.http.port")); + assertEquals(1, configDocument.getProperties().size()); + assertEquals("9081", configDocument.getProperties().getProperty("http.port")); + + // variables defined in files + configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), new File(serversDir, "server.xml"), null, null); + File include = new File(serversDir, "testIncludeParseVariables.xml"); + doc = configDocument.parseDocument(include); + assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty()); + configDocument.parseIncludeVariables(doc); + assertEquals(1, configDocument.getDefaultProperties().size()); + assertEquals("9080", configDocument.getDefaultProperties().getProperty("default.http.port")); + assertEquals(1, configDocument.getProperties().size()); + assertEquals("9081", configDocument.getProperties().getProperty("http.port")); + + // server.xmls read in increasing precedence + // TODO: refactor + // configDropins/defaults + // server.xml + // configDropins/overrides + } + + // server.env files are read in increasing precedence + // 1. {wlp.install.dir}/etc + // 2. {wlp.user.dir}/shared + // 3. {server.config.dir} + // Table of directories: https://openliberty.io/docs/latest/reference/directory-locations-properties.html + @Test + public void processServerEnv() throws FileNotFoundException, Exception { + File serverDir = new File(RESOURCES_DIR + WLP_USER_DIR + DEFAULT_USER_SERVER_DIR); + File specificFile = new File(serverDir, "server2.env"); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serverDir, null); + configDocument.processServerEnv(specificFile, false); + assertEquals("TEST", configDocument.getProperties().getProperty("keystore_password")); + + configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serverDir, null); + configDocument.processServerEnv(specificFile, true); + assertNotEquals("TEST", configDocument.getProperties().getProperty("keystore_password")); + + // TODO: multiple file locations + // File wlpDir = new File(RESOURCES_DIR + WLP_DIR); + } + + // 2. environment variables + // TODO: test without using processServerEnv + @Test + public void environmentVariables() throws FileNotFoundException, Exception { + // TODO: alt var lookups - https://github.com/OpenLiberty/ci.common/issues/126 + File serverConfigDir = new File(RESOURCES_DIR + WLP_USER_DIR + DEFAULT_USER_SERVER_DIR); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), new File(serverConfigDir, "server.xml"), serverConfigDir, null); + Document doc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); + + // env var not set + configDocument.parseVariablesForBothValues(doc); + assertEquals("${my.env.var}", configDocument.getProperties().getProperty("my.env.var.level")); + + // replace non-alphanumeric characters with '_' and to uppercase + configDocument.processServerEnv(new File(serverConfigDir, "server2.env"), false); + assertEquals("3", configDocument.getProperties().getProperty("MY_ENV_VAR")); + configDocument.parseVariablesForBothValues(doc); + // assertEquals("3", configDocument.getProperties().getProperty("my.env.var.level")); + + // replace non-alphanumeric characters with '_' + configDocument.processServerEnv(null, true); + assertEquals("2", configDocument.getProperties().getProperty("my_env_var")); + configDocument.parseVariablesForBothValues(doc); + // assertEquals("2", configDocument.getProperties().getProperty("my.env.var.level")); + } + + + // 3. bootstrap.properties + @Test + public void processBootstrapProperties() throws FileNotFoundException, Exception { + File serversDir = new File(RESOURCES_DIR + DEFAULT_SERVER_DIR); + File altBootstrapPropertiesFile = new File(serversDir, "bootstrap2.properties"); + Map bootstrapProp = new HashMap(); + bootstrapProp.put("http.port", "1000"); + ServerConfigDocument configDocument; + + // lowest to highest precedence + // default bootstrap.properties in config dir + configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument.processBootstrapProperties(new File("DOES_NOT_EXIST"), new HashMap<>(), false); + assertEquals(1, configDocument.getProperties().size()); + + // use bootstrapFile + configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument.processBootstrapProperties(altBootstrapPropertiesFile, new HashMap<>(), false); + assertEquals(2, configDocument.getProperties().size()); + assertEquals("9080", configDocument.getProperties().getProperty("http.port")); + + // test bootstrapProperty overrides + File serverXml = new File(serversDir, "definedVariables.xml"); + configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serversDir, null); + Document doc = configDocument.parseDocument(serverXml); + configDocument.parseVariablesForBothValues(doc); + assertEquals("9081", configDocument.getProperties().getProperty("http.port")); + configDocument.processBootstrapProperties(altBootstrapPropertiesFile, bootstrapProp, false); + assertEquals("1000", configDocument.getProperties().getProperty("http.port")); + + // use giveConfigDirPrecedence + configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument.processBootstrapProperties(altBootstrapPropertiesFile, new HashMap<>(), true); + assertEquals(1, configDocument.getProperties().size()); + + // TODO: bootstraps.include + // configDocument = new ServerConfigDocument(new TestLogger()); + // configDocument.initializeFields(new TestLogger(), null, serversDir, null); + // configDocument.processBootstrapProperties(new File(serversDir, "bootstrapsInclude.properties"), new HashMap<>(), false); + // assertEquals("9080", configDocument.getProperties().getProperty("http.port")); + } + + // 4. Java system properties + @Test + public void jvmOptions() { + + } + + // 5. Variables loaded from files in the ${server.config.dir}/variables directory or other + // directories as specified by the VARIABLE_SOURCE_DIRS environment variable + @Test + public void variablesDir() { + // TODO: not yet implemented. read copied dir instead of src for now + // see https://github.com/OpenLiberty/ci.common/issues/126 + } + + + // 7. variables declared on the command line + @Test + public void CLI() { + + } + + // TODO: test each overrides layer + // jvm.options override server.env + // bootstrap.properties override jvm.options and server.env + // server.xml override bootstrap.properties, jvm.options, and server.env + @Test + public void overrides() { + File serversDir = new File(RESOURCES_DIR + WLP_USER_DIR + DEFAULT_USER_SERVER_DIR); + + // server.xml overrides server.env + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), + new File(serversDir, "server.xml"), serversDir, new File(serversDir, "bootstrap.properties"), + new HashMap<>(), new File(serversDir, "server.env"), false, null); + assertEquals("new_value", configDocument.getProperties().getProperty("overriden_value")); + } +} diff --git a/src/test/resources/serverConfig/liberty/wlp/etc/server.env b/src/test/resources/serverConfig/liberty/wlp/etc/server.env new file mode 100644 index 00000000..1eff25ce --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/etc/server.env @@ -0,0 +1,2 @@ +http.port=9080 +https.port=9081 \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env index 2b0a48a6..d0a8e5a0 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env @@ -1 +1,3 @@ -keystore_password=C7ANPlAi0MQD154BJ5ZOURn \ No newline at end of file +keystore_password=C7ANPlAi0MQD154BJ5ZOURn +overriden_value=old_value +my_env_var=2 \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml index bc801f17..fcf023fd 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml @@ -21,4 +21,6 @@ + + \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server2.env b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server2.env new file mode 100644 index 00000000..6e646b70 --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server2.env @@ -0,0 +1,2 @@ +keystore_password=TEST +MY_ENV_VAR=3 \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/shared/server.env b/src/test/resources/serverConfig/liberty/wlp/usr/shared/server.env new file mode 100644 index 00000000..6a88f0c8 --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/shared/server.env @@ -0,0 +1,2 @@ +http.port=9082 +https.port=9083 \ No newline at end of file diff --git a/src/test/resources/servers/bootstrap2.properties b/src/test/resources/servers/bootstrap2.properties new file mode 100644 index 00000000..d2ada960 --- /dev/null +++ b/src/test/resources/servers/bootstrap2.properties @@ -0,0 +1,2 @@ +extras.filename=extraFeatures.xml +http.port=9080 \ No newline at end of file diff --git a/src/test/resources/servers/bootstrapsInclude.properties b/src/test/resources/servers/bootstrapsInclude.properties new file mode 100644 index 00000000..a83d44ec --- /dev/null +++ b/src/test/resources/servers/bootstrapsInclude.properties @@ -0,0 +1 @@ +bootstrap.include=bootstrap2.properties \ No newline at end of file diff --git a/src/test/resources/servers/definedVariables.xml b/src/test/resources/servers/definedVariables.xml new file mode 100644 index 00000000..7ee645c6 --- /dev/null +++ b/src/test/resources/servers/definedVariables.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/test/resources/servers/testIncludeParseVariables.xml b/src/test/resources/servers/testIncludeParseVariables.xml new file mode 100644 index 00000000..950c5351 --- /dev/null +++ b/src/test/resources/servers/testIncludeParseVariables.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From ae69dc43d90766926c98227823949ddc2666191f Mon Sep 17 00:00:00 2001 From: dshimo Date: Wed, 28 Feb 2024 14:04:55 -0600 Subject: [PATCH 02/17] utilize libertyDirPropMap, processServerEnv done --- .../plugins/config/ServerConfigDocument.java | 87 ++++++++---- .../config/ServerConfigDocumentTest.java | 131 +++++++++--------- .../serverConfig/liberty/wlp/etc/server.env | 5 +- .../defaultServer/bootstrap.properties | 3 +- .../wlp/usr/servers/defaultServer/server.env | 3 +- .../wlp/usr/servers/defaultServer/server.xml | 4 +- .../wlp/usr/servers/defaultServer/server2.env | 2 - .../liberty/wlp/usr/shared/server.env | 5 +- .../resources/servers/bootstrap2.properties | 2 - .../servers/bootstrapsInclude.properties | 2 +- 10 files changed, 138 insertions(+), 106 deletions(-) delete mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server2.env delete mode 100644 src/test/resources/servers/bootstrap2.properties diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index 3cab8eb7..e2a5a419 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.net.URL; import java.net.URLConnection; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -57,6 +58,11 @@ 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 Set names; private Set namelessLocations; @@ -116,6 +122,17 @@ public File getServerXML() { return serverXMLFile; } + /** + * + * @param log + * @param serverXML + * @param configDir + * @param bootstrapFile + * @param bootstrapProp + * @param serverEnvFile + * @param giveConfigDirPrecedence + * @param libertyDirPropertyFiles - Contains a property to file mapping of direcdty locations + */ public ServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile, Map bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) { initializeAppsLocation(log, serverXML, configDir, bootstrapFile, bootstrapProp, serverEnvFile, giveConfigDirPrecedence, libertyDirPropertyFiles); @@ -154,28 +171,26 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf Document doc = parseDocument(serverXMLFile); - // Server variable precedence in ascending order if defined in - // multiple locations. - // - // 1. defaultValue from variables defined in server.xml or defined in files - // e.g. - // 2. variables from 'server.env' - // 3. variables from 'bootstrap.properties' - // 4. variables defined in files - // 5. variables from configDropins/defaults/ - // 6. variables defined in server.xml - // e.g. - // 7. variables from configDropins/overrides/ + // Server variable precedence in ascending order if defined in multiple locations. + // 1. variable default values in the server.xml file + // 2. environment variables + // 3. bootstrap.properties + // 4. Java system properties + // 5. Variables loaded from files in the ${server.config.dir}/variables directory or other directories as specified by the VARIABLE_SOURCE_DIRS environment variable + // 6. variable values declared in the server.xml file + // 7. variables declared on the command line // 1. Need to parse variables in the server.xml for default values before trying to find the include files in case one of the variables is used // in the location. parseVariablesForDefaultValues(doc); // 2. get variables from server.env - processServerEnv(serverEnvFile, giveConfigDirPrecedence); + processServerEnv(); + + // 3. get variables from jvm.options // 3. get variables from bootstrap.properties - processBootstrapProperties(bootstrapFile, bootstrapProp, giveConfigDirPrecedence); + processBootstrapProperties(bootstrapProp, bootstrapFile); // 4. parse variables from include files (both default and non-default values - which we store separately) parseIncludeVariables(doc); @@ -201,16 +216,29 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf } } - public void processServerEnv(File serverEnvFile, boolean giveConfigDirPrecedence) - throws Exception, FileNotFoundException { - File cfgFile = findConfigFile("server.env", serverEnvFile, giveConfigDirPrecedence); - if (cfgFile != null) { - parseProperties(new FileInputStream(cfgFile)); + /** + * server.env file read order + * 1. {wlp.install.dir}/etc/ + * 2. {wlp.user.dir}/shared/ + * 3. {server.config.dir}/ + * @param serverEnvFile + * @throws Exception + * @throws FileNotFoundException + */ + 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)); + } + + public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileNotFoundException { + if (propertiesFile != null && propertiesFile.exists()) { + parseProperties(new FileInputStream(propertiesFile)); } } - public void initializeFields(CommonLoggerI log, File serverXML, File configDir, - Map libertyDirPropertyFiles) { + public void initializeFields(CommonLoggerI log, File serverXML, File configDir, Map libertyDirPropertyFiles) { this.log = log; serverXMLFile = serverXML; configDirectory = configDir; @@ -220,7 +248,6 @@ public void initializeFields(CommonLoggerI log, File serverXML, File configDir, log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); libertyDirectoryPropertyToFile = new HashMap(); } - locations = new HashSet(); names = new HashSet(); namelessLocations = new HashSet(); @@ -229,13 +256,17 @@ public void initializeFields(CommonLoggerI log, File serverXML, File configDir, defaultProps = new Properties(); } - public void processBootstrapProperties(File bootstrapFile, Map bootstrapProp, boolean giveConfigDirPrecedence) - throws Exception, FileNotFoundException { + /** + * Process bootstrap.properties and boostrap.include + * @param bootstrapProp + * @param bootstrapFile - Optional specific file + * @throws Exception + * @throws FileNotFoundException + */ + public void processBootstrapProperties(Map bootstrapProp, File bootstrapFile) throws Exception, FileNotFoundException { File cfgDirFile = getFileFromConfigDirectory("bootstrap.properties"); - - if (giveConfigDirPrecedence && cfgDirFile != null) { - parseProperties(new FileInputStream(cfgDirFile)); - } else if (bootstrapProp != null && !bootstrapProp.isEmpty()) { + // TODO: bootstrap.include + if (bootstrapProp != null && !bootstrapProp.isEmpty()) { for (Map.Entry entry : bootstrapProp.entrySet()) { if (entry.getValue() != null) { props.setProperty(entry.getKey(),entry.getValue()); diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java index b59c0923..b97abe27 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java @@ -2,14 +2,15 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; -import java.util.logging.Logger; +import java.util.Properties; import javax.xml.xpath.XPathExpressionException; @@ -33,18 +34,17 @@ */ public class ServerConfigDocumentTest { - public final static Logger LOGGER = Logger.getLogger(ServerConfigDocumentTest.class.getName()); - private final static String RESOURCES_DIR = "src/test/resources/"; - private final static String WLP_DIR = "serverConfig/liberty/wlp/"; - private final static String WLP_USER_DIR = "serverConfig/liberty/wlp/usr/"; - private final static String DEFAULT_USER_SERVER_DIR = "servers/defaultServer/"; - private final static String DEFAULT_SERVER_DIR = "servers/"; + private final static Path RESOURCES_DIR = Paths.get("src/test/resources/"); + private final static Path WLP_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/"); + private final static Path WLP_USER_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/usr/"); + private final static Path DEFAULTSERVER_CONFIG_DIR = WLP_USER_DIR.resolve("servers/defaultServer"); + private final static Path MOCK_SERVER_DIR = RESOURCES_DIR.resolve("servers/"); // 1. variable default values in server.xml file // 6. variable values declared in the server.xml file @Test public void processServerXml() throws FileNotFoundException, IOException, XPathExpressionException, SAXException { - File serversDir = new File(RESOURCES_DIR + DEFAULT_SERVER_DIR); + File serversDir = MOCK_SERVER_DIR.toFile(); Document doc; // no variables defined @@ -83,100 +83,100 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE // configDropins/overrides } + // when a server.xml references an environment variable that could not be resolved, additionally search for: + // 1. replace all non-alphanumeric characters with underscore char '_' + // 2. change all characters to uppercase + @Test + public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Exception { + File serverXml = DEFAULTSERVER_CONFIG_DIR.resolve("server.xml").toFile(); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), serverXml, DEFAULTSERVER_CONFIG_DIR.toFile(), new HashMap<>()); + Document serverXmlDoc = configDocument.parseDocument(serverXml); + configDocument.parseVariablesForBothValues(serverXmlDoc); + assertEquals("${this.value}", configDocument.getDefaultProperties().getProperty("server.env.defined")); + assertEquals("${this.value}", configDocument.getProperties().getProperty("server.env.defined")); + configDocument.processBootstrapProperties(new HashMap<>(), null); + configDocument.processServerEnv(); + + configDocument.parseVariablesForBothValues(serverXmlDoc); + // TODO: implement feature and uncomment these lines + // assertEquals("DEFINED", configDocument.getProperties().getProperty("server.env.defined")); + // assertEquals("DEFINED", configDocument.getProperties().getProperty("bootstrap.properties.defined")); + } + // server.env files are read in increasing precedence // 1. {wlp.install.dir}/etc // 2. {wlp.user.dir}/shared // 3. {server.config.dir} - // Table of directories: https://openliberty.io/docs/latest/reference/directory-locations-properties.html + // Liberty Directory Properties: https://openliberty.io/docs/latest/reference/directory-locations-properties.html @Test public void processServerEnv() throws FileNotFoundException, Exception { - File serverDir = new File(RESOURCES_DIR + WLP_USER_DIR + DEFAULT_USER_SERVER_DIR); - File specificFile = new File(serverDir, "server2.env"); + File wlpInstallDir = WLP_DIR.toFile(); + File wlpUserDir = WLP_USER_DIR.toFile(); + File serverDir = DEFAULTSERVER_CONFIG_DIR.toFile(); ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serverDir, null); - configDocument.processServerEnv(specificFile, false); - assertEquals("TEST", configDocument.getProperties().getProperty("keystore_password")); + Map libertyDirectoryPropertyToFileMap = new HashMap(); + libertyDirectoryPropertyToFileMap.put("wlp.install.dir", wlpInstallDir); + libertyDirectoryPropertyToFileMap.put("wlp.user.dir", wlpUserDir); + libertyDirectoryPropertyToFileMap.put("server.config.dir", serverDir); - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serverDir, null); - configDocument.processServerEnv(specificFile, true); - assertNotEquals("TEST", configDocument.getProperties().getProperty("keystore_password")); + configDocument.initializeFields(new TestLogger(), null, serverDir, libertyDirectoryPropertyToFileMap); + configDocument.processServerEnv(); + Properties props = configDocument.getProperties(); - // TODO: multiple file locations - // File wlpDir = new File(RESOURCES_DIR + WLP_DIR); + // {wlp.install.dir}/etc + assertEquals("true", props.get("etc.unique")); + + // {wlp.user.dir}/shared + assertEquals("true", props.get("shared.unique")); + assertEquals("true", props.get("shared.overriden")); + + // {server.config.dir} + assertEquals("old_value", props.get("overriden_value")); + assertEquals("1111", props.get("http.port")); } // 2. environment variables - // TODO: test without using processServerEnv @Test public void environmentVariables() throws FileNotFoundException, Exception { - // TODO: alt var lookups - https://github.com/OpenLiberty/ci.common/issues/126 - File serverConfigDir = new File(RESOURCES_DIR + WLP_USER_DIR + DEFAULT_USER_SERVER_DIR); - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), new File(serverConfigDir, "server.xml"), serverConfigDir, null); - Document doc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); - - // env var not set - configDocument.parseVariablesForBothValues(doc); - assertEquals("${my.env.var}", configDocument.getProperties().getProperty("my.env.var.level")); - - // replace non-alphanumeric characters with '_' and to uppercase - configDocument.processServerEnv(new File(serverConfigDir, "server2.env"), false); - assertEquals("3", configDocument.getProperties().getProperty("MY_ENV_VAR")); - configDocument.parseVariablesForBothValues(doc); - // assertEquals("3", configDocument.getProperties().getProperty("my.env.var.level")); - // replace non-alphanumeric characters with '_' - configDocument.processServerEnv(null, true); - assertEquals("2", configDocument.getProperties().getProperty("my_env_var")); - configDocument.parseVariablesForBothValues(doc); - // assertEquals("2", configDocument.getProperties().getProperty("my.env.var.level")); } // 3. bootstrap.properties @Test public void processBootstrapProperties() throws FileNotFoundException, Exception { - File serversDir = new File(RESOURCES_DIR + DEFAULT_SERVER_DIR); - File altBootstrapPropertiesFile = new File(serversDir, "bootstrap2.properties"); - Map bootstrapProp = new HashMap(); - bootstrapProp.put("http.port", "1000"); + File serversDir = MOCK_SERVER_DIR.toFile(); ServerConfigDocument configDocument; - // lowest to highest precedence - // default bootstrap.properties in config dir + // bootstrap.properties in config dir configDocument = new ServerConfigDocument(new TestLogger()); configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(new File("DOES_NOT_EXIST"), new HashMap<>(), false); + configDocument.processBootstrapProperties(new HashMap<>(), new File("DOES_NOT_EXIST")); assertEquals(1, configDocument.getProperties().size()); - // use bootstrapFile + // use bootstrapFile, kept for flexibility configDocument = new ServerConfigDocument(new TestLogger()); configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(altBootstrapPropertiesFile, new HashMap<>(), false); + configDocument.processBootstrapProperties(new HashMap<>(), DEFAULTSERVER_CONFIG_DIR.resolve("bootstrap.properties").toFile()); assertEquals(2, configDocument.getProperties().size()); - assertEquals("9080", configDocument.getProperties().getProperty("http.port")); + assertEquals("DEFINED", configDocument.getProperties().getProperty("THAT_VALUE")); - // test bootstrapProperty overrides + // test bootstrapProperty map overrides + Map bootstrapPropertyMap = new HashMap(); + bootstrapPropertyMap.put("http.port", "1000"); File serverXml = new File(serversDir, "definedVariables.xml"); configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); - Document doc = configDocument.parseDocument(serverXml); - configDocument.parseVariablesForBothValues(doc); + configDocument.initializeFields(new TestLogger(), serverXml, serversDir, null); + configDocument.parseVariablesForBothValues(configDocument.parseDocument(serverXml)); assertEquals("9081", configDocument.getProperties().getProperty("http.port")); - configDocument.processBootstrapProperties(altBootstrapPropertiesFile, bootstrapProp, false); + configDocument.processBootstrapProperties(bootstrapPropertyMap, null); assertEquals("1000", configDocument.getProperties().getProperty("http.port")); - // use giveConfigDirPrecedence - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(altBootstrapPropertiesFile, new HashMap<>(), true); - assertEquals(1, configDocument.getProperties().size()); - // TODO: bootstraps.include // configDocument = new ServerConfigDocument(new TestLogger()); // configDocument.initializeFields(new TestLogger(), null, serversDir, null); - // configDocument.processBootstrapProperties(new File(serversDir, "bootstrapsInclude.properties"), new HashMap<>(), false); + // configDocument.processBootstrapProperties(new HashMap<>(), MOCK_SERVER_DIR.resolve("bootstrapInclude.properties").toFile()); // assertEquals("9080", configDocument.getProperties().getProperty("http.port")); } @@ -207,8 +207,7 @@ public void CLI() { // server.xml override bootstrap.properties, jvm.options, and server.env @Test public void overrides() { - File serversDir = new File(RESOURCES_DIR + WLP_USER_DIR + DEFAULT_USER_SERVER_DIR); - + File serversDir = DEFAULTSERVER_CONFIG_DIR.toFile(); // server.xml overrides server.env ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), new File(serversDir, "server.xml"), serversDir, new File(serversDir, "bootstrap.properties"), diff --git a/src/test/resources/serverConfig/liberty/wlp/etc/server.env b/src/test/resources/serverConfig/liberty/wlp/etc/server.env index 1eff25ce..437b75ce 100644 --- a/src/test/resources/serverConfig/liberty/wlp/etc/server.env +++ b/src/test/resources/serverConfig/liberty/wlp/etc/server.env @@ -1,2 +1,3 @@ -http.port=9080 -https.port=9081 \ No newline at end of file +etc.unique=true +shared.overriden=false +http.port=9080 \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties index 3efd222e..6a28af62 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties @@ -1 +1,2 @@ -extras.filename=extraFeatures.xml \ No newline at end of file +extras.filename=extraFeatures.xml +THAT_VALUE=DEFINED \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env index d0a8e5a0..027ead57 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env @@ -1,3 +1,4 @@ keystore_password=C7ANPlAi0MQD154BJ5ZOURn +http.port=1111 overriden_value=old_value -my_env_var=2 \ No newline at end of file +this_value=DEFINED \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml index fcf023fd..43a7f85e 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml @@ -22,5 +22,7 @@ - + + + \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server2.env b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server2.env deleted file mode 100644 index 6e646b70..00000000 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server2.env +++ /dev/null @@ -1,2 +0,0 @@ -keystore_password=TEST -MY_ENV_VAR=3 \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/shared/server.env b/src/test/resources/serverConfig/liberty/wlp/usr/shared/server.env index 6a88f0c8..dcbb2923 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/shared/server.env +++ b/src/test/resources/serverConfig/liberty/wlp/usr/shared/server.env @@ -1,2 +1,3 @@ -http.port=9082 -https.port=9083 \ No newline at end of file +shared.unique=true +shared.overriden=true +http.port=9081 \ No newline at end of file diff --git a/src/test/resources/servers/bootstrap2.properties b/src/test/resources/servers/bootstrap2.properties deleted file mode 100644 index d2ada960..00000000 --- a/src/test/resources/servers/bootstrap2.properties +++ /dev/null @@ -1,2 +0,0 @@ -extras.filename=extraFeatures.xml -http.port=9080 \ No newline at end of file diff --git a/src/test/resources/servers/bootstrapsInclude.properties b/src/test/resources/servers/bootstrapsInclude.properties index a83d44ec..1f510731 100644 --- a/src/test/resources/servers/bootstrapsInclude.properties +++ b/src/test/resources/servers/bootstrapsInclude.properties @@ -1 +1 @@ -bootstrap.include=bootstrap2.properties \ No newline at end of file +bootstrap.include=bootstrap.properties \ No newline at end of file From 83ac9043a9c7603fa9d49a1a16f96bd5dbdfdc17 Mon Sep 17 00:00:00 2001 From: dshimo Date: Thu, 29 Feb 2024 10:56:12 -0600 Subject: [PATCH 03/17] bootstrap.include feature, init jvm.options --- .../plugins/config/ServerConfigDocument.java | 44 +++++++++++++++---- .../config/ServerConfigDocumentTest.java | 9 ++-- ...properties => bootstrapInclude.properties} | 0 3 files changed, 39 insertions(+), 14 deletions(-) rename src/test/resources/servers/{bootstrapsInclude.properties => bootstrapInclude.properties} (100%) diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index e2a5a419..bdb42c83 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -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; @@ -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 @@ -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 names; private Set namelessLocations; @@ -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); @@ -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/ @@ -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 { @@ -265,7 +283,6 @@ public void initializeFields(CommonLoggerI log, File serverXML, File configDir, */ public void processBootstrapProperties(Map bootstrapProp, File bootstrapFile) throws Exception, FileNotFoundException { File cfgDirFile = getFileFromConfigDirectory("bootstrap.properties"); - // TODO: bootstrap.include if (bootstrapProp != null && !bootstrapProp.isEmpty()) { for (Map.Entry entry : bootstrapProp.entrySet()) { if (entry.getValue() != null) { @@ -277,6 +294,15 @@ public void processBootstrapProperties(Map 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 diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java index b97abe27..c2b37574 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java @@ -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 diff --git a/src/test/resources/servers/bootstrapsInclude.properties b/src/test/resources/servers/bootstrapInclude.properties similarity index 100% rename from src/test/resources/servers/bootstrapsInclude.properties rename to src/test/resources/servers/bootstrapInclude.properties From dd83f0a4aff3c6ba04ed25797b725932340e024f Mon Sep 17 00:00:00 2001 From: dshimo Date: Mon, 4 Mar 2024 15:47:09 -0600 Subject: [PATCH 04/17] bootstrap.include recursion --- .../plugins/config/ServerConfigDocument.java | 53 +++++++++++++++---- .../config/ServerConfigDocumentTest.java | 7 ++- .../servers/bootstrapOuroboros.properties | 1 + 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 src/test/resources/servers/bootstrapOuroboros.properties diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index bdb42c83..67dab44b 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -223,6 +223,7 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf * 2. {server.config.dir}/configDropins/defaults/ * 3. {server.config.dir}/ * 4. {server.config.dir}/configDropins/overrides/ + * TODO: potential processing for system property tags? (-D prefixes?) * @throws FileNotFoundException * @throws Exception */ @@ -276,13 +277,16 @@ public void initializeFields(CommonLoggerI log, File serverXML, File configDir, /** * Process bootstrap.properties and boostrap.include - * @param bootstrapProp - * @param bootstrapFile - Optional specific file + * @param bootstrapProp - Populated in Maven/Gradle + * @param bootstrapFile - Optional specific file which will take precedence over config dir file * @throws Exception * @throws FileNotFoundException */ public void processBootstrapProperties(Map bootstrapProp, File bootstrapFile) throws Exception, FileNotFoundException { - File cfgDirFile = getFileFromConfigDirectory("bootstrap.properties"); + File configDirBootstrapProperties = getFileFromConfigDirectory("bootstrap.properties"); + File processedFile = null; + + // Initial bootstrap.properties processing if (bootstrapProp != null && !bootstrapProp.isEmpty()) { for (Map.Entry entry : bootstrapProp.entrySet()) { if (entry.getValue() != null) { @@ -291,18 +295,47 @@ public void processBootstrapProperties(Map bootstrapProp, File b } } else if (bootstrapFile != null && bootstrapFile.exists()) { parseProperties(new FileInputStream(bootstrapFile)); - } else if (cfgDirFile != null) { - parseProperties(new FileInputStream(cfgDirFile)); + processedFile = bootstrapFile; + } else if (configDirBootstrapProperties != null) { + parseProperties(new FileInputStream(configDirBootstrapProperties)); + processedFile = configDirBootstrapProperties; } + // Recursive processing for bootstrap.include 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)); + Set visited = new HashSet(); + if (processedFile != null) { + visited.add(processedFile.getAbsolutePath()); } + processBootstrapInclude(getBootstrapIncludeProperty(), visited); + } + } + + /** + * Recursive processing for a series of bootstrap.include that terminates upon revisit + * @param bootstrapIncludeLocation + * @param processedBootstrapIncludes + * @throws Exception + * @throws FileNotFoundException + */ + private void processBootstrapInclude(String bootstrapIncludeLocation, Set processedBootstrapIncludes) throws FileNotFoundException, Exception { + Path bootstrapIncludePath = Paths.get(bootstrapIncludeLocation); + File bootstrapIncludeFile = bootstrapIncludePath.isAbsolute() ? + new File(bootstrapIncludePath.toString()) : new File(configDirectory, bootstrapIncludePath.toString()); + + if (processedBootstrapIncludes.contains(bootstrapIncludeFile.getAbsolutePath())) { + return; } + + if (bootstrapIncludeFile.exists()) { + parseProperties(new FileInputStream(bootstrapIncludeFile)); + processedBootstrapIncludes.add(bootstrapIncludeFile.getAbsolutePath()); + processBootstrapInclude(getBootstrapIncludeProperty(), processedBootstrapIncludes); + } + } + + private String getBootstrapIncludeProperty() { + return props.getProperty("bootstrap.include"); } //Checks for application names in the document. Will add locations without names to a Set diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java index c2b37574..8ff5e26e 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java @@ -142,7 +142,6 @@ public void environmentVariables() throws FileNotFoundException, Exception { } - // 3. bootstrap.properties @Test public void processBootstrapProperties() throws FileNotFoundException, Exception { @@ -173,10 +172,16 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception configDocument.processBootstrapProperties(bootstrapPropertyMap, null); assertEquals("1000", configDocument.getProperties().getProperty("http.port")); + // bootstrap.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("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); + + // bootstrap.include infinite termination check + configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument.processBootstrapProperties(new HashMap<>(), MOCK_SERVER_DIR.resolve("bootstrapOuroboros.properties").toFile()); } // 4. Java system properties diff --git a/src/test/resources/servers/bootstrapOuroboros.properties b/src/test/resources/servers/bootstrapOuroboros.properties new file mode 100644 index 00000000..f628030e --- /dev/null +++ b/src/test/resources/servers/bootstrapOuroboros.properties @@ -0,0 +1 @@ +bootstrap.include=bootstrapOuroboros.properties \ No newline at end of file From d7d7059734c40e372d2448ba7a469120800f1396 Mon Sep 17 00:00:00 2001 From: dshimo Date: Tue, 5 Mar 2024 16:24:02 -0600 Subject: [PATCH 05/17] variables directory processing --- .../plugins/config/ServerConfigDocument.java | 162 +++++++++++++----- .../common/plugins/util/VariableUtility.java | 4 + .../config/ServerConfigDocumentTest.java | 55 ++++-- .../servers/defaultServer/variables/httpPort | 1 + .../defaultServer/variables/nested/httpPort | 1 + .../variables/nested/nested.properties | 2 + .../resources/servers/variables/outer.source | 1 + 7 files changed, 170 insertions(+), 56 deletions(-) create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/httpPort create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/nested/httpPort create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/nested/nested.properties create mode 100644 src/test/resources/servers/variables/outer.source diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index 67dab44b..7eda33e2 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -24,6 +24,7 @@ import java.net.URLConnection; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -143,6 +144,24 @@ public ServerConfigDocument(CommonLoggerI log) { initializeFields(log, null, null, null); } + public void initializeFields(CommonLoggerI log, File serverXML, File configDir, Map libertyDirPropertyFiles) { + this.log = log; + serverXMLFile = serverXML; + configDirectory = configDir; + if (libertyDirPropertyFiles != null) { + libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); + } else { + log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); + libertyDirectoryPropertyToFile = new HashMap(); + } + locations = new HashSet(); + names = new HashSet(); + namelessLocations = new HashSet(); + locationsAndNames = new HashMap(); + props = new Properties(); + defaultProps = new Properties(); + } + private DocumentBuilder getDocumentBuilder() { DocumentBuilder docBuilder; @@ -187,11 +206,25 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf processServerEnv(); // 3. get variables from jvm.options - processJvmOptions(); + // processJvmOptions(); // 3. get variables from bootstrap.properties processBootstrapProperties(bootstrapProp, bootstrapFile); + // 4. Java system properties + // configured in Maven/Gradle + + // 5. Variables loaded from 'variables' directory + processVariablesDirectory(); + + // 6. variable values declared in server.xml + // processVariablesForValues(doc); + + // 7. variables delcared on the command line + // configured in Maven/Gradle + + // TODO: cleanup rest + // 4. parse variables from include files (both default and non-default values - which we store separately) parseIncludeVariables(doc); @@ -216,23 +249,10 @@ 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/ - * TODO: potential processing for system property tags? (-D prefixes?) - * @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)); + public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileNotFoundException { + if (propertiesFile != null && propertiesFile.exists()) { + parseProperties(new FileInputStream(propertiesFile)); + } } /** @@ -251,28 +271,17 @@ public void processServerEnv() throws Exception, FileNotFoundException { parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR), serverEnvString)); } - public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileNotFoundException { - if (propertiesFile != null && propertiesFile.exists()) { - parseProperties(new FileInputStream(propertiesFile)); - } - } - - public void initializeFields(CommonLoggerI log, File serverXML, File configDir, Map libertyDirPropertyFiles) { - this.log = log; - serverXMLFile = serverXML; - configDirectory = configDir; - if (libertyDirPropertyFiles != null) { - libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); - } else { - log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); - libertyDirectoryPropertyToFile = new HashMap(); - } - locations = new HashSet(); - names = new HashSet(); - namelessLocations = new HashSet(); - locationsAndNames = new HashMap(); - props = new Properties(); - defaultProps = new Properties(); + /** + * Likely not needed to be processed by the LMP/LGP tools. These properties benefit the JVM. + * @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)); } /** @@ -326,7 +335,7 @@ private void processBootstrapInclude(String bootstrapIncludeLocation, Set toProcess = new ArrayList(); + if (!props.containsKey(variableDirectoryProperty)) { + toProcess.add(getFileFromConfigDirectory("variables")); + } else { + String delimiter = (File.separator.equals("/")) ? ":" : ";"; // OS heuristic + String[] splitDirectories = props.get(variableDirectoryProperty).toString().split(delimiter); + for (String directory : splitDirectories) { + Path directoryPath = Paths.get(directory); + File directoryFile = directoryPath.toFile(); + if (directoryFile.exists()) { + toProcess.add(directoryFile); + } + } + } + + processVariableSourceDirs(toProcess); + } + + /** + * The file name is the variable and the contents are the values. + * If a directory is within the directory, it is recurisvely processed. + * The parent dir gets prepended to the file name for the property name ("{parent directory}/{file name}") + * If the file name ends with *.properties, then it's processed as a properties file. + * @param directories - The root directories to process + * @throws Exception + * @throws FileNotFoundException + */ + public void processVariableSourceDirs(ArrayList directories) throws FileNotFoundException, Exception { + for (File directory : directories) { + if (!directory.isDirectory()) { + continue; + } + processNestedVariableSourceDirs(directory, ""); + } + } + + /** + * The nested operation + * @param directory - The directory being processed + * @param propertyPrefix - Tracks the nested directories to prepend + * @throws FileNotFoundException + * @throws Exception + */ + public void processNestedVariableSourceDirs(File directory, String propertyPrefix) throws FileNotFoundException, Exception { + for (File child : directory.listFiles()) { + if (child.isDirectory()) { + processNestedVariableSourceDirs(child, child.getName() + File.separator); + continue; + } + + if (child.getName().endsWith(".properties")) { + parsePropertiesFromFile(child); + continue; + } + + String propertyName = propertyPrefix + child.getName(); + String propertyValue = Files.readString(child.toPath()); + props.setProperty(propertyName, propertyValue); + } + } + //Checks for application names in the document. Will add locations without names to a Set private void parseNames(Document doc, String expression) throws XPathExpressionException, IOException, SAXException { // parse input document diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java index 46d5471f..8f5d0091 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java @@ -28,6 +28,10 @@ public class VariableUtility { private static final String VARIABLE_NAME_PATTERN = "\\$\\{(.*?)\\}"; private static final Pattern varNamePattern = Pattern.compile(VARIABLE_NAME_PATTERN); + // If a property is not immediately found, replace non-alphanumeric values with '_'. If still not found, search with toUpper + // Integer value properties can be evaluated if 'simple' arithemetic + // A list of ports can be defined using keyword 'list' + /** * Attempts to resolve all variables in the passed in nodeValue. Variable value/defaultValue can reference other variables. * This method is called recursively to resolve the variables. The variableChain collection keeps track of the variable references diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java index 8ff5e26e..9d46a6b3 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Properties; +import javax.xml.bind.annotation.XmlElement.DEFAULT; import javax.xml.xpath.XPathExpressionException; import org.junit.Test; @@ -37,14 +38,14 @@ public class ServerConfigDocumentTest { private final static Path RESOURCES_DIR = Paths.get("src/test/resources/"); private final static Path WLP_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/"); private final static Path WLP_USER_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/usr/"); - private final static Path DEFAULTSERVER_CONFIG_DIR = WLP_USER_DIR.resolve("servers/defaultServer"); - private final static Path MOCK_SERVER_DIR = RESOURCES_DIR.resolve("servers/"); + private final static Path SERVER_CONFIG_DIR = WLP_USER_DIR.resolve("servers/defaultServer"); + private final static Path SERVERS_RESOURCES_DIR = RESOURCES_DIR.resolve("servers/"); // 1. variable default values in server.xml file // 6. variable values declared in the server.xml file @Test public void processServerXml() throws FileNotFoundException, IOException, XPathExpressionException, SAXException { - File serversDir = MOCK_SERVER_DIR.toFile(); + File serversDir = SERVERS_RESOURCES_DIR.toFile(); Document doc; // no variables defined @@ -88,9 +89,9 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE // 2. change all characters to uppercase @Test public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Exception { - File serverXml = DEFAULTSERVER_CONFIG_DIR.resolve("server.xml").toFile(); + File serverXml = SERVER_CONFIG_DIR.resolve("server.xml").toFile(); ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), serverXml, DEFAULTSERVER_CONFIG_DIR.toFile(), new HashMap<>()); + configDocument.initializeFields(new TestLogger(), serverXml, SERVER_CONFIG_DIR.toFile(), new HashMap<>()); Document serverXmlDoc = configDocument.parseDocument(serverXml); configDocument.parseVariablesForBothValues(serverXmlDoc); assertEquals("${this.value}", configDocument.getDefaultProperties().getProperty("server.env.defined")); @@ -113,7 +114,7 @@ public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Excep public void processServerEnv() throws FileNotFoundException, Exception { File wlpInstallDir = WLP_DIR.toFile(); File wlpUserDir = WLP_USER_DIR.toFile(); - File serverDir = DEFAULTSERVER_CONFIG_DIR.toFile(); + File serverDir = SERVER_CONFIG_DIR.toFile(); ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); Map libertyDirectoryPropertyToFileMap = new HashMap(); libertyDirectoryPropertyToFileMap.put("wlp.install.dir", wlpInstallDir); @@ -145,7 +146,7 @@ public void environmentVariables() throws FileNotFoundException, Exception { // 3. bootstrap.properties @Test public void processBootstrapProperties() throws FileNotFoundException, Exception { - File serversDir = MOCK_SERVER_DIR.toFile(); + File serversDir = SERVERS_RESOURCES_DIR.toFile(); ServerConfigDocument configDocument; // bootstrap.properties in config dir @@ -157,7 +158,7 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception // use bootstrapFile, kept for flexibility configDocument = new ServerConfigDocument(new TestLogger()); configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(new HashMap<>(), DEFAULTSERVER_CONFIG_DIR.resolve("bootstrap.properties").toFile()); + configDocument.processBootstrapProperties(new HashMap<>(), SERVER_CONFIG_DIR.resolve("bootstrap.properties").toFile()); assertEquals(2, configDocument.getProperties().size()); assertEquals("DEFINED", configDocument.getProperties().getProperty("THAT_VALUE")); @@ -175,13 +176,13 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception // bootstrap.include configDocument = new ServerConfigDocument(new TestLogger()); configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(new HashMap<>(), MOCK_SERVER_DIR.resolve("bootstrapInclude.properties").toFile()); + configDocument.processBootstrapProperties(new HashMap<>(), SERVERS_RESOURCES_DIR.resolve("bootstrapInclude.properties").toFile()); assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); // bootstrap.include infinite termination check configDocument = new ServerConfigDocument(new TestLogger()); configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(new HashMap<>(), MOCK_SERVER_DIR.resolve("bootstrapOuroboros.properties").toFile()); + configDocument.processBootstrapProperties(new HashMap<>(), SERVERS_RESOURCES_DIR.resolve("bootstrapOuroboros.properties").toFile()); } // 4. Java system properties @@ -193,12 +194,36 @@ public void jvmOptions() { // 5. Variables loaded from files in the ${server.config.dir}/variables directory or other // directories as specified by the VARIABLE_SOURCE_DIRS environment variable @Test - public void variablesDir() { - // TODO: not yet implemented. read copied dir instead of src for now - // see https://github.com/OpenLiberty/ci.common/issues/126 + public void variablesDir() throws FileNotFoundException, Exception { + File serversDir = SERVER_CONFIG_DIR.toFile(); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument.processVariablesDirectory(); + + Properties props = configDocument.getProperties(); + assertEquals("9080", props.getProperty("httpPort")); + assertEquals("1000", props.getProperty("nested/httpPort")); + assertEquals("1", props.getProperty("VALUE_1")); + assertEquals("2", props.getProperty("VALUE_2")); + + // process VARIABLE_SOURCE_DIRS + configDocument = new ServerConfigDocument(new TestLogger()); + configDocument.initializeFields(new TestLogger(), null, serversDir, null); + Map bootstrapProp = new HashMap(); + String delimiter = (File.separator.equals("/")) ? ":" : ";"; + String variableSourceDirsTestValue = String.join(delimiter, + SERVERS_RESOURCES_DIR.resolve("variables").toString(), + SERVER_CONFIG_DIR.toString(), + "DOES_NOT_EXIST"); + bootstrapProp.put("VARIABLE_SOURCE_DIRS", variableSourceDirsTestValue); + configDocument.processBootstrapProperties(bootstrapProp, null); + configDocument.processVariablesDirectory(); + + props = configDocument.getProperties(); + assertEquals("outer_space", props.getProperty("outer.source")); + assertEquals("1", props.getProperty("VALUE_1")); } - // 7. variables declared on the command line @Test public void CLI() { @@ -211,7 +236,7 @@ public void CLI() { // server.xml override bootstrap.properties, jvm.options, and server.env @Test public void overrides() { - File serversDir = DEFAULTSERVER_CONFIG_DIR.toFile(); + File serversDir = SERVER_CONFIG_DIR.toFile(); // server.xml overrides server.env ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), new File(serversDir, "server.xml"), serversDir, new File(serversDir, "bootstrap.properties"), diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/httpPort b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/httpPort new file mode 100644 index 00000000..04a3078b --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/httpPort @@ -0,0 +1 @@ +9080 \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/nested/httpPort b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/nested/httpPort new file mode 100644 index 00000000..e37d32ab --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/nested/httpPort @@ -0,0 +1 @@ +1000 \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/nested/nested.properties b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/nested/nested.properties new file mode 100644 index 00000000..abccd5b2 --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/nested/nested.properties @@ -0,0 +1,2 @@ +VALUE_1=1 +VALUE_2=2 \ No newline at end of file diff --git a/src/test/resources/servers/variables/outer.source b/src/test/resources/servers/variables/outer.source new file mode 100644 index 00000000..f4ed48a9 --- /dev/null +++ b/src/test/resources/servers/variables/outer.source @@ -0,0 +1 @@ +outer_space \ No newline at end of file From 2dc70f96e6587701286887ffdbad86e64eae92db Mon Sep 17 00:00:00 2001 From: dshimo Date: Tue, 5 Mar 2024 19:58:10 -0600 Subject: [PATCH 06/17] support Java 8, fix test for windows --- .../plugins/config/ServerConfigDocument.java | 20 +++++++++++++------ .../config/ServerConfigDocumentTest.java | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index 7eda33e2..b5ad2905 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -266,19 +266,27 @@ public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileN */ public void processServerEnv() throws Exception, FileNotFoundException { final String serverEnvString = "server.env"; - 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)); + 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)); } /** - * Likely not needed to be processed by the LMP/LGP tools. These properties benefit the JVM. + * Likely not needed to be processed by the LMP/LGP tools. These properties benefit the JVM + * 1. ${wlp.user.dir}/shared/jvm.options + * 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(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.WLP_USER_DIR), + "shared" + File.separator + jvmOptionsString)); parsePropertiesFromFile(getFileFromConfigDirectory(CONFIGDROPINS_DEFAULT + File.separator + jvmOptionsString)); parsePropertiesFromFile(getFileFromConfigDirectory(jvmOptionsString)); parsePropertiesFromFile(getFileFromConfigDirectory(CONFIGDROPINS_OVERRIDES + File.separator + jvmOptionsString)); @@ -413,7 +421,7 @@ public void processNestedVariableSourceDirs(File directory, String propertyPrefi } String propertyName = propertyPrefix + child.getName(); - String propertyValue = Files.readString(child.toPath()); + String propertyValue = new String(Files.readAllBytes(child.toPath())); props.setProperty(propertyName, propertyValue); } } diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java index 9d46a6b3..865028a5 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java @@ -202,7 +202,7 @@ public void variablesDir() throws FileNotFoundException, Exception { Properties props = configDocument.getProperties(); assertEquals("9080", props.getProperty("httpPort")); - assertEquals("1000", props.getProperty("nested/httpPort")); + assertEquals("1000", props.getProperty(String.join(File.separator, "nested", "httpPort"))); assertEquals("1", props.getProperty("VALUE_1")); assertEquals("2", props.getProperty("VALUE_2")); From cce148ca1cf398c2982bf4f9f4288977efcf72ab Mon Sep 17 00:00:00 2001 From: dshimo Date: Tue, 5 Mar 2024 21:24:50 -0600 Subject: [PATCH 07/17] simpifly processBootstrapProperties --- .../plugins/config/ServerConfigDocument.java | 66 +++++++++---------- .../config/ServerConfigDocumentTest.java | 55 +++++----------- .../bootstrapInclude/bootstrap.properties | 1 + .../servers/bootstrapOuroboros.properties | 1 - .../bootstrap.properties} | 0 5 files changed, 48 insertions(+), 75 deletions(-) create mode 100644 src/test/resources/servers/bootstrapInclude/bootstrap.properties delete mode 100644 src/test/resources/servers/bootstrapOuroboros.properties rename src/test/resources/servers/{bootstrapInclude.properties => bootstrapOuroboros/bootstrap.properties} (100%) diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index b5ad2905..a09abb4b 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -138,6 +138,10 @@ public ServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, F initializeAppsLocation(log, serverXML, configDir, bootstrapFile, bootstrapProp, serverEnvFile, giveConfigDirPrecedence, libertyDirPropertyFiles); } + public ServerConfigDocument() { + + } + // LCLS constructor public ServerConfigDocument(CommonLoggerI log) { // TODO: populate libertyDirectoryPropertyToFile with workspace information @@ -192,6 +196,10 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf // Server variable precedence in ascending order if defined in multiple locations. // 1. variable default values in the server.xml file // 2. environment variables + // server.env + // a. ${wlp.install.dir}/etc/ + // b. ${wlp.user.dir}/shared/ + // c. ${server.config.dir}/ // 3. bootstrap.properties // 4. Java system properties // 5. Variables loaded from files in the ${server.config.dir}/variables directory or other directories as specified by the VARIABLE_SOURCE_DIRS environment variable @@ -209,7 +217,7 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf // processJvmOptions(); // 3. get variables from bootstrap.properties - processBootstrapProperties(bootstrapProp, bootstrapFile); + processBootstrapProperties(); // 4. Java system properties // configured in Maven/Gradle @@ -218,14 +226,17 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf processVariablesDirectory(); // 6. variable values declared in server.xml - // processVariablesForValues(doc); + parseVariablesForValues(doc); // 7. variables delcared on the command line // configured in Maven/Gradle // TODO: cleanup rest - + // current code parses the includes section for a list of files to iterate through + // includes section needs to resolve the variables because it's in the server.xml + // after includes is determined, configDropins are analyzed // 4. parse variables from include files (both default and non-default values - which we store separately) + parseIncludeVariables(doc); // 5. variables from configDropins/defaults/ @@ -249,11 +260,6 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf } } - public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileNotFoundException { - if (propertiesFile != null && propertiesFile.exists()) { - parseProperties(new FileInputStream(propertiesFile)); - } - } /** * server.env file read order @@ -299,32 +305,17 @@ public void processJvmOptions() throws FileNotFoundException, Exception { * @throws Exception * @throws FileNotFoundException */ - public void processBootstrapProperties(Map bootstrapProp, File bootstrapFile) throws Exception, FileNotFoundException { + public void processBootstrapProperties() throws Exception, FileNotFoundException { File configDirBootstrapProperties = getFileFromConfigDirectory("bootstrap.properties"); - File processedFile = null; - - // Initial bootstrap.properties processing - if (bootstrapProp != null && !bootstrapProp.isEmpty()) { - for (Map.Entry entry : bootstrapProp.entrySet()) { - if (entry.getValue() != null) { - props.setProperty(entry.getKey(),entry.getValue()); - } - } - } else if (bootstrapFile != null && bootstrapFile.exists()) { - parseProperties(new FileInputStream(bootstrapFile)); - processedFile = bootstrapFile; - } else if (configDirBootstrapProperties != null) { - parseProperties(new FileInputStream(configDirBootstrapProperties)); - processedFile = configDirBootstrapProperties; + if (configDirBootstrapProperties == null) { + return; } - // Recursive processing for bootstrap.include + parseProperties(new FileInputStream(configDirBootstrapProperties)); if (props.containsKey("bootstrap.include")) { Set visited = new HashSet(); - if (processedFile != null) { - visited.add(processedFile.getAbsolutePath()); - } - processBootstrapInclude(getBootstrapIncludeProperty(), visited); + visited.add(configDirBootstrapProperties.getAbsolutePath()); + processBootstrapInclude(visited); } } @@ -335,8 +326,9 @@ public void processBootstrapProperties(Map bootstrapProp, File b * @throws Exception * @throws FileNotFoundException */ - private void processBootstrapInclude(String bootstrapIncludeLocation, Set processedBootstrapIncludes) throws FileNotFoundException, Exception { - Path bootstrapIncludePath = Paths.get(bootstrapIncludeLocation); + private void processBootstrapInclude(Set processedBootstrapIncludes) throws FileNotFoundException, Exception { + String bootstrapIncludeLocationString = props.getProperty("bootstrap.include"); + Path bootstrapIncludePath = Paths.get(bootstrapIncludeLocationString); File bootstrapIncludeFile = bootstrapIncludePath.isAbsolute() ? new File(bootstrapIncludePath.toString()) : new File(configDirectory, bootstrapIncludePath.toString()); @@ -347,14 +339,10 @@ private void processBootstrapInclude(String bootstrapIncludeLocation, Set(), null); + configDocument.processBootstrapProperties(); configDocument.processServerEnv(); configDocument.parseVariablesForBothValues(serverXmlDoc); @@ -105,11 +105,6 @@ public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Excep // assertEquals("DEFINED", configDocument.getProperties().getProperty("bootstrap.properties.defined")); } - // server.env files are read in increasing precedence - // 1. {wlp.install.dir}/etc - // 2. {wlp.user.dir}/shared - // 3. {server.config.dir} - // Liberty Directory Properties: https://openliberty.io/docs/latest/reference/directory-locations-properties.html @Test public void processServerEnv() throws FileNotFoundException, Exception { File wlpInstallDir = WLP_DIR.toFile(); @@ -125,14 +120,15 @@ public void processServerEnv() throws FileNotFoundException, Exception { configDocument.processServerEnv(); Properties props = configDocument.getProperties(); - // {wlp.install.dir}/etc + // in increasing precedence + // 1. {wlp.install.dir}/etc assertEquals("true", props.get("etc.unique")); - // {wlp.user.dir}/shared + // 2. {wlp.user.dir}/shared assertEquals("true", props.get("shared.unique")); assertEquals("true", props.get("shared.overriden")); - - // {server.config.dir} + + // 3. {server.config.dir} assertEquals("old_value", props.get("overriden_value")); assertEquals("1111", props.get("http.port")); } @@ -149,40 +145,25 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception File serversDir = SERVERS_RESOURCES_DIR.toFile(); ServerConfigDocument configDocument; - // bootstrap.properties in config dir + // bootstrap.properties configDocument = new ServerConfigDocument(new TestLogger()); configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(new HashMap<>(), new File("DOES_NOT_EXIST")); + configDocument.processBootstrapProperties(); assertEquals(1, configDocument.getProperties().size()); - - // use bootstrapFile, kept for flexibility - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(new HashMap<>(), SERVER_CONFIG_DIR.resolve("bootstrap.properties").toFile()); - assertEquals(2, configDocument.getProperties().size()); - assertEquals("DEFINED", configDocument.getProperties().getProperty("THAT_VALUE")); - - // test bootstrapProperty map overrides - Map bootstrapPropertyMap = new HashMap(); - bootstrapPropertyMap.put("http.port", "1000"); - File serverXml = new File(serversDir, "definedVariables.xml"); - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), serverXml, serversDir, null); - configDocument.parseVariablesForBothValues(configDocument.parseDocument(serverXml)); - assertEquals("9081", configDocument.getProperties().getProperty("http.port")); - configDocument.processBootstrapProperties(bootstrapPropertyMap, null); - assertEquals("1000", configDocument.getProperties().getProperty("http.port")); + assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); // bootstrap.include configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(new HashMap<>(), SERVERS_RESOURCES_DIR.resolve("bootstrapInclude.properties").toFile()); + configDocument.initializeFields(new TestLogger(), null, new File(serversDir, "bootstrapInclude"), null); + configDocument.processBootstrapProperties(); + assertEquals(2, configDocument.getProperties().size()); + assertTrue(configDocument.getProperties().containsKey("bootstrap.include")); assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); - // bootstrap.include infinite termination check + // bootstrap.include termination check configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); - configDocument.processBootstrapProperties(new HashMap<>(), SERVERS_RESOURCES_DIR.resolve("bootstrapOuroboros.properties").toFile()); + configDocument.initializeFields(new TestLogger(), null, new File(serversDir, "bootstrapOuroboros"), null); + configDocument.processBootstrapProperties(); } // 4. Java system properties @@ -209,14 +190,12 @@ public void variablesDir() throws FileNotFoundException, Exception { // process VARIABLE_SOURCE_DIRS configDocument = new ServerConfigDocument(new TestLogger()); configDocument.initializeFields(new TestLogger(), null, serversDir, null); - Map bootstrapProp = new HashMap(); String delimiter = (File.separator.equals("/")) ? ":" : ";"; String variableSourceDirsTestValue = String.join(delimiter, SERVERS_RESOURCES_DIR.resolve("variables").toString(), SERVER_CONFIG_DIR.toString(), "DOES_NOT_EXIST"); - bootstrapProp.put("VARIABLE_SOURCE_DIRS", variableSourceDirsTestValue); - configDocument.processBootstrapProperties(bootstrapProp, null); + configDocument.getProperties().put("VARIABLE_SOURCE_DIRS", variableSourceDirsTestValue); configDocument.processVariablesDirectory(); props = configDocument.getProperties(); diff --git a/src/test/resources/servers/bootstrapInclude/bootstrap.properties b/src/test/resources/servers/bootstrapInclude/bootstrap.properties new file mode 100644 index 00000000..9ebd0bd6 --- /dev/null +++ b/src/test/resources/servers/bootstrapInclude/bootstrap.properties @@ -0,0 +1 @@ +bootstrap.include=../bootstrap.properties \ No newline at end of file diff --git a/src/test/resources/servers/bootstrapOuroboros.properties b/src/test/resources/servers/bootstrapOuroboros.properties deleted file mode 100644 index f628030e..00000000 --- a/src/test/resources/servers/bootstrapOuroboros.properties +++ /dev/null @@ -1 +0,0 @@ -bootstrap.include=bootstrapOuroboros.properties \ No newline at end of file diff --git a/src/test/resources/servers/bootstrapInclude.properties b/src/test/resources/servers/bootstrapOuroboros/bootstrap.properties similarity index 100% rename from src/test/resources/servers/bootstrapInclude.properties rename to src/test/resources/servers/bootstrapOuroboros/bootstrap.properties From 77072fd8b5cf3029d5bc40bf089a050de68ef2bd Mon Sep 17 00:00:00 2001 From: dshimo Date: Thu, 7 Mar 2024 11:46:11 -0600 Subject: [PATCH 08/17] cleanup + comment changes --- .../plugins/config/ServerConfigDocument.java | 90 ++++++++++--------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index a09abb4b..5c53ebc7 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -196,14 +196,24 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf // Server variable precedence in ascending order if defined in multiple locations. // 1. variable default values in the server.xml file // 2. environment variables - // server.env - // a. ${wlp.install.dir}/etc/ - // b. ${wlp.user.dir}/shared/ - // c. ${server.config.dir}/ + // server.env + // a. ${wlp.install.dir}/etc/ + // b. ${wlp.user.dir}/shared/ + // c. ${server.config.dir}/ + // jvm.options + // a. ${wlp.user.dir}/shared/jvm.options + // b. ${server.config.dir}/configDropins/defaults/ + // c. ${server.config.dir}/ + // d. ${server.config.dir}/configDropins/overrides/ // 3. bootstrap.properties + // a. additional references by bootstrap.include // 4. Java system properties - // 5. Variables loaded from files in the ${server.config.dir}/variables directory or other directories as specified by the VARIABLE_SOURCE_DIRS environment variable + // 5. Variables loaded from files in the ${server.config.dir}/variables directory or + // other directories as specified by the VARIABLE_SOURCE_DIRS environment variable // 6. variable values declared in the server.xml file + // a. ${server.config.dir}/configDropins/defaults/ + // b. ${server.config.dir}/server.xml + // c. ${server.config.dir}/configDropins/overrides/ // 7. variables declared on the command line // 1. Need to parse variables in the server.xml for default values before trying to find the include files in case one of the variables is used @@ -226,7 +236,10 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf processVariablesDirectory(); // 6. variable values declared in server.xml - parseVariablesForValues(doc); + // resolve variable references along the way + // configDropins/defaults + // server.xml + // configDropins/overrides // 7. variables delcared on the command line // configured in Maven/Gradle @@ -346,7 +359,7 @@ private void processBootstrapInclude(Set processedBootstrapIncludes) thr /** * By default, ${server.config.directory}/variables is processed. * If VARIABLE_SOURCE_DIRS is defined, those directories are processed instead. - * The path delimiter for the property is ';' on Windows, and is ':' on Unix + * A list of directories are delimited by ';' on Windows, and ':' on Unix * @throws Exception * @throws FileNotFoundException */ @@ -358,8 +371,8 @@ public void processVariablesDirectory() throws FileNotFoundException, Exception toProcess.add(getFileFromConfigDirectory("variables")); } else { String delimiter = (File.separator.equals("/")) ? ":" : ";"; // OS heuristic - String[] splitDirectories = props.get(variableDirectoryProperty).toString().split(delimiter); - for (String directory : splitDirectories) { + String[] directories = props.get(variableDirectoryProperty).toString().split(delimiter); + for (String directory : directories) { Path directoryPath = Paths.get(directory); File directoryFile = directoryPath.toFile(); if (directoryFile.exists()) { @@ -368,38 +381,29 @@ public void processVariablesDirectory() throws FileNotFoundException, Exception } } - processVariableSourceDirs(toProcess); - } - - /** - * The file name is the variable and the contents are the values. - * If a directory is within the directory, it is recurisvely processed. - * The parent dir gets prepended to the file name for the property name ("{parent directory}/{file name}") - * If the file name ends with *.properties, then it's processed as a properties file. - * @param directories - The root directories to process - * @throws Exception - * @throws FileNotFoundException - */ - public void processVariableSourceDirs(ArrayList directories) throws FileNotFoundException, Exception { - for (File directory : directories) { + for (File directory : toProcess) { if (!directory.isDirectory()) { continue; } - processNestedVariableSourceDirs(directory, ""); + processVariablesDirectory(directory, ""); } } /** - * The nested operation + * The file name defines the variable name and its contents define the value. + * If a directory is nested within a directory, it is recurisvely processed. + * A nested file will have its parent dir prepended for the property name e.g. {parent directory}/{file name} + * If the file name ends with *.properties, then it's processed as a properties file. * @param directory - The directory being processed * @param propertyPrefix - Tracks the nested directories to prepend * @throws FileNotFoundException * @throws Exception */ - public void processNestedVariableSourceDirs(File directory, String propertyPrefix) throws FileNotFoundException, Exception { + private void processVariablesDirectory(File directory, String propertyPrefix) + throws FileNotFoundException, Exception { for (File child : directory.listFiles()) { if (child.isDirectory()) { - processNestedVariableSourceDirs(child, child.getName() + File.separator); + processVariablesDirectory(child, child.getName() + File.separator); continue; } @@ -772,24 +776,26 @@ public void parseIncludeVariables(Document doc) throws XPathExpressionException, NodeList nodeList = (NodeList) XPATH_SERVER_INCLUDE.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { - if (nodeList.item(i) instanceof Element) { - Element child = (Element) nodeList.item(i); - // Need to handle more variable substitution for include location. - String nodeValue = child.getAttribute("location"); - String includeFileName = VariableUtility.resolveVariables(log, nodeValue, null, getProperties(), getDefaultProperties(), getLibertyDirPropertyFiles()); + if (!(nodeList.item(i) instanceof Element)) { + continue; + } - if (includeFileName == null || includeFileName.trim().isEmpty()) { - log.warn("Unable to resolve include file location "+nodeValue+". Skipping the included file during application location processing."); - continue; - } + Element child = (Element) nodeList.item(i); + // Need to handle more variable substitution for include location. + String nodeValue = child.getAttribute("location"); + String includeFileName = VariableUtility.resolveVariables(log, nodeValue, null, getProperties(), getDefaultProperties(), getLibertyDirPropertyFiles()); - ArrayList inclDocs = getIncludeDocs(includeFileName); + if (includeFileName == null || includeFileName.trim().isEmpty()) { + log.warn("Unable to resolve include file location "+nodeValue+". Skipping the included file during application location processing."); + continue; + } - for (Document inclDoc : inclDocs) { - parseVariablesForBothValues(inclDoc); - // handle nested include elements - parseIncludeVariables(inclDoc); - } + ArrayList inclDocs = getIncludeDocs(includeFileName); + + for (Document inclDoc : inclDocs) { + parseVariablesForBothValues(inclDoc); + // handle nested include elements + parseIncludeVariables(inclDoc); } } } From 1054b307bad293139f8b0fceba99cd6a3db3ccc0 Mon Sep 17 00:00:00 2001 From: dshimo Date: Thu, 7 Mar 2024 12:29:31 -0600 Subject: [PATCH 09/17] small shuffle --- .../common/plugins/util/VariableUtility.java | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java index 8f5d0091..e8a34184 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java @@ -54,37 +54,36 @@ public static String resolveVariables(CommonLoggerI log, String nodeValue, Colle // Found recursive reference when resolving variables. Log message and return null. log.debug("Found a recursive variable reference when resolving ${" + varName + "}"); return null; - } else { - variablesToResolve.add(varName); } + variablesToResolve.add(varName); } for (String nextVariable : variablesToResolve) { String value = getPropertyValue(nextVariable, props, defaultProps, libDirPropFiles); - if (value != null && !value.isEmpty()) { - Collection thisVariableChain = new HashSet (); - thisVariableChain.add(nextVariable); + if (value == null || value.isEmpty()) { + // Variable could not be resolved. Log message and return null. + log.debug("Variable " + nextVariable + " cannot be resolved."); + return null; + } - if (variableChain != null && !variableChain.isEmpty()) { - thisVariableChain.addAll(variableChain); - } + Collection thisVariableChain = new HashSet (); + thisVariableChain.add(nextVariable); - String resolvedValue = resolveVariables(log, value, thisVariableChain, props, defaultProps, libDirPropFiles); - - if (resolvedValue != null) { - String escapedVariable = Matcher.quoteReplacement(nextVariable); - // For Windows, avoid escaping the backslashes in the resolvedValue by changing to forward slashes - resolvedValue = resolvedValue.replace("\\","/"); - resolved = resolved.replaceAll("\\$\\{" + escapedVariable + "\\}", resolvedValue); - } else { - // Variable value could not be resolved. Log message and return null. - log.debug("Could not resolve the value " + value + " for variable ${" + nextVariable + "}"); - return null; - } + if (variableChain != null && !variableChain.isEmpty()) { + thisVariableChain.addAll(variableChain); + } + + String resolvedValue = resolveVariables(log, value, thisVariableChain, props, defaultProps, libDirPropFiles); + + if (resolvedValue != null) { + String escapedVariable = Matcher.quoteReplacement(nextVariable); + // For Windows, avoid escaping the backslashes in the resolvedValue by changing to forward slashes + resolvedValue = resolvedValue.replace("\\","/"); + resolved = resolved.replaceAll("\\$\\{" + escapedVariable + "\\}", resolvedValue); } else { - // Variable could not be resolved. Log message and return null. - log.debug("Variable " + nextVariable + " cannot be resolved."); + // Variable value could not be resolved. Log message and return null. + log.debug("Could not resolve the value " + value + " for variable ${" + nextVariable + "}"); return null; } } From d6abc0d28a822e925ee8426b9742fc88997e4734 Mon Sep 17 00:00:00 2001 From: dshimo Date: Thu, 7 Mar 2024 16:17:48 -0600 Subject: [PATCH 10/17] variable name resolution --- .../common/plugins/util/VariableUtility.java | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java index e8a34184..201d96a1 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java @@ -28,10 +28,6 @@ public class VariableUtility { private static final String VARIABLE_NAME_PATTERN = "\\$\\{(.*?)\\}"; private static final Pattern varNamePattern = Pattern.compile(VARIABLE_NAME_PATTERN); - // If a property is not immediately found, replace non-alphanumeric values with '_'. If still not found, search with toUpper - // Integer value properties can be evaluated if 'simple' arithemetic - // A list of ports can be defined using keyword 'list' - /** * Attempts to resolve all variables in the passed in nodeValue. Variable value/defaultValue can reference other variables. * This method is called recursively to resolve the variables. The variableChain collection keeps track of the variable references @@ -59,7 +55,7 @@ public static String resolveVariables(CommonLoggerI log, String nodeValue, Colle } for (String nextVariable : variablesToResolve) { - String value = getPropertyValue(nextVariable, props, defaultProps, libDirPropFiles); + String value = getPropertyValueDraft(nextVariable, props, defaultProps, libDirPropFiles); if (value == null || value.isEmpty()) { // Variable could not be resolved. Log message and return null. @@ -93,6 +89,53 @@ public static String resolveVariables(CommonLoggerI log, String nodeValue, Colle return resolved; } + // TODO: Integer value properties can be evaluated if 'simple' arithemetic + // TODO: A list of ports can be defined using keyword 'list', e.g. list(httpPort) -> 89,9889 versus literal '89,9889' + public static String getPropertyValueDraft(String propertyName, Properties prop, Properties defaultProps, Map libertyDirPropFiles) { + String value = null; + if (libertyDirPropFiles.containsKey(propertyName)) { + return stripQuotes(libertyDirPropFiles.get(propertyName).toString()); + } + + value = lookupProperty(prop, defaultProps, propertyName); + if (value != null) { + return stripQuotes(value); + } + + // try again with non-alphanumeric values replaced with '_', which is exactly \W in regex + String propertyNameVariation = propertyName.replaceAll("\\W", "_"); + value = lookupProperty(prop, defaultProps, propertyNameVariation); + if (value != null) { + return stripQuotes(value); + } + + // try again with propertyNameVariation.toUpperCase() + propertyNameVariation = propertyNameVariation.toUpperCase(); + value = lookupProperty(prop, defaultProps, propertyNameVariation); + if (value != null) { + return stripQuotes(value); + } + + return value; + } + + private static String stripQuotes(String value) { + if (value.startsWith("\"") && value.endsWith("\"") && value.length() > 2) { + return value.substring(1, value.length() - 1); + } + return value; + } + + private static String lookupProperty(Properties prop, Properties defaultProps, String propertyName) { + if (prop.containsKey(propertyName)) { + return stripQuotes(prop.getProperty(propertyName)); + } + if (defaultProps.containsKey(propertyName)) { + return stripQuotes(defaultProps.getProperty(propertyName)); + } + return null; + } + public static String getPropertyValue(String propertyName, Properties props, Properties defaultProps, Map libDirPropFiles) { String value = null; if(!libDirPropFiles.containsKey(propertyName)) { @@ -123,5 +166,4 @@ public static String getPropertyValue(String propertyName, Properties props, Pro } return value; } - } From 9df34d51df404e2dd76e9dfd615c4d6456461b83 Mon Sep 17 00:00:00 2001 From: dshimo Date: Mon, 11 Mar 2024 15:31:01 -0500 Subject: [PATCH 11/17] interface, switch to libertyDirPropMap usage --- .../plugins/config/ServerConfigDocument.java | 192 ++++++++---------- ...=> ServerConfigDocumentOverridesTest.java} | 130 ++++++++---- .../configDropins/defaults/server.xml | 5 + .../configDropins/overrides/server.xml | 3 + .../wlp/usr/servers/defaultServer/server.xml | 3 +- 5 files changed, 183 insertions(+), 150 deletions(-) rename src/test/java/io/openliberty/tools/common/config/{ServerConfigDocumentTest.java => ServerConfigDocumentOverridesTest.java} (62%) create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/server.xml create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index 5c53ebc7..34566d4f 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -123,7 +123,7 @@ public File getServerXML() { } /** - * + * Deprecated. Migrate to the simpler constructor. * @param log * @param serverXML * @param configDir @@ -131,29 +131,40 @@ public File getServerXML() { * @param bootstrapProp * @param serverEnvFile * @param giveConfigDirPrecedence - * @param libertyDirPropertyFiles - Contains a property to file mapping of direcdty locations + * @param libertyDirPropertyFiles - Contains a property to file mapping of directory locations */ public ServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile, Map bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) { - initializeAppsLocation(log, serverXML, configDir, bootstrapFile, bootstrapProp, serverEnvFile, giveConfigDirPrecedence, libertyDirPropertyFiles); - } - - public ServerConfigDocument() { - - } + this.log = log; + serverXMLFile = serverXML; + configDirectory = configDir; + if (libertyDirPropertyFiles != null) { + libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); + } else { + log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); + libertyDirectoryPropertyToFile = new HashMap(); + } + locations = new HashSet(); + names = new HashSet(); + namelessLocations = new HashSet(); + locationsAndNames = new HashMap(); + props = new Properties(); + defaultProps = new Properties(); - // LCLS constructor - public ServerConfigDocument(CommonLoggerI log) { - // TODO: populate libertyDirectoryPropertyToFile with workspace information - initializeFields(log, null, null, null); + initializeAppsLocation(); } - public void initializeFields(CommonLoggerI log, File serverXML, File configDir, Map libertyDirPropertyFiles) { + /** + * Adapt when ready. Expects the libertyDirPropertyFiles to be populated + * @param log + * @param libertyDirPropertyFiles + */ + public ServerConfigDocument(CommonLoggerI log, Map libertyDirPropertyFiles) { this.log = log; - serverXMLFile = serverXML; - configDirectory = configDir; if (libertyDirPropertyFiles != null) { libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); + configDirectory = libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR); + serverXMLFile = getFileFromConfigDirectory("server.xml"); } else { log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); libertyDirectoryPropertyToFile = new HashMap(); @@ -164,6 +175,14 @@ public void initializeFields(CommonLoggerI log, File serverXML, File configDir, locationsAndNames = new HashMap(); props = new Properties(); defaultProps = new Properties(); + + // initializeAppsLocation(); + } + + // LCLS constructor + // TODO: populate libertyDirectoryPropertyToFile with workspace information + public ServerConfigDocument(CommonLoggerI log) { + this(log, null); } private DocumentBuilder getDocumentBuilder() { @@ -186,38 +205,35 @@ private DocumentBuilder getDocumentBuilder() { return docBuilder; } - private void initializeAppsLocation(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile, - Map bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) { + /** + // Server variable precedence in ascending order if defined in multiple locations. + // 1. variable default values in the server.xml file + // 2. environment variables + // server.env + // a. ${wlp.install.dir}/etc/ + // b. ${wlp.user.dir}/shared/ + // c. ${server.config.dir}/ + // jvm.options + // a. ${wlp.user.dir}/shared/jvm.options + // b. ${server.config.dir}/configDropins/defaults/ + // c. ${server.config.dir}/ + // d. ${server.config.dir}/configDropins/overrides/ + // 3. bootstrap.properties + // a. additional references by bootstrap.include + // 4. Java system properties + // 5. Variables loaded from files in the ${server.config.dir}/variables directory or + // other directories as specified by the VARIABLE_SOURCE_DIRS environment variable + // 6. variable values declared in the server.xml file + // a. ${server.config.dir}/configDropins/defaults/ + // b. ${server.config.dir}/server.xml + // c. ${server.config.dir}/configDropins/overrides/ + // 7. variables declared on the command line + */ + public void initializeAppsLocation() { try { - initializeFields(log, serverXML, configDir, libertyDirPropertyFiles); - + // 1. Need to parse variables in the server.xml for default values before trying to + // find the include files in case one of the variables is used in the location. Document doc = parseDocument(serverXMLFile); - - // Server variable precedence in ascending order if defined in multiple locations. - // 1. variable default values in the server.xml file - // 2. environment variables - // server.env - // a. ${wlp.install.dir}/etc/ - // b. ${wlp.user.dir}/shared/ - // c. ${server.config.dir}/ - // jvm.options - // a. ${wlp.user.dir}/shared/jvm.options - // b. ${server.config.dir}/configDropins/defaults/ - // c. ${server.config.dir}/ - // d. ${server.config.dir}/configDropins/overrides/ - // 3. bootstrap.properties - // a. additional references by bootstrap.include - // 4. Java system properties - // 5. Variables loaded from files in the ${server.config.dir}/variables directory or - // other directories as specified by the VARIABLE_SOURCE_DIRS environment variable - // 6. variable values declared in the server.xml file - // a. ${server.config.dir}/configDropins/defaults/ - // b. ${server.config.dir}/server.xml - // c. ${server.config.dir}/configDropins/overrides/ - // 7. variables declared on the command line - - // 1. Need to parse variables in the server.xml for default values before trying to find the include files in case one of the variables is used - // in the location. parseVariablesForDefaultValues(doc); // 2. get variables from server.env @@ -235,45 +251,23 @@ private void initializeAppsLocation(CommonLoggerI log, File serverXML, File conf // 5. Variables loaded from 'variables' directory processVariablesDirectory(); - // 6. variable values declared in server.xml - // resolve variable references along the way - // configDropins/defaults - // server.xml - // configDropins/overrides + // 6. variable values declared in server.xml(s) + processServerXml(doc); // 7. variables delcared on the command line // configured in Maven/Gradle - // TODO: cleanup rest - // current code parses the includes section for a list of files to iterate through - // includes section needs to resolve the variables because it's in the server.xml - // after includes is determined, configDropins are analyzed - // 4. parse variables from include files (both default and non-default values - which we store separately) - - parseIncludeVariables(doc); - - // 5. variables from configDropins/defaults/ - parseConfigDropinsDirVariables("defaults"); - - // 6. variables defined in server.xml - non-default values - parseVariablesForValues(doc); - - // 7. variables from configDropins/overrides/ - parseConfigDropinsDirVariables("overrides"); - parseApplication(doc, XPATH_SERVER_APPLICATION); parseApplication(doc, XPATH_SERVER_WEB_APPLICATION); parseApplication(doc, XPATH_SERVER_ENTERPRISE_APPLICATION); parseNames(doc, "/server/application | /server/webApplication | /server/enterpriseApplication"); parseInclude(doc); parseConfigDropinsDir(); - } catch (Exception e) { e.printStackTrace(); } } - /** * server.env file read order * 1. {wlp.install.dir}/etc/ @@ -289,8 +283,7 @@ public void processServerEnv() throws Exception, FileNotFoundException { "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)); + parsePropertiesFromFile(getFileFromConfigDirectory(serverEnvString)); } /** @@ -319,15 +312,15 @@ public void processJvmOptions() throws FileNotFoundException, Exception { * @throws FileNotFoundException */ public void processBootstrapProperties() throws Exception, FileNotFoundException { - File configDirBootstrapProperties = getFileFromConfigDirectory("bootstrap.properties"); - if (configDirBootstrapProperties == null) { + File bootstrapFile = getFileFromConfigDirectory("bootstrap.properties"); + if (bootstrapFile == null) { return; } - parseProperties(new FileInputStream(configDirBootstrapProperties)); + parsePropertiesFromFile(bootstrapFile); if (props.containsKey("bootstrap.include")) { Set visited = new HashSet(); - visited.add(configDirBootstrapProperties.getAbsolutePath()); + visited.add(bootstrapFile.getAbsolutePath()); processBootstrapInclude(visited); } } @@ -382,7 +375,7 @@ public void processVariablesDirectory() throws FileNotFoundException, Exception } for (File directory : toProcess) { - if (!directory.isDirectory()) { + if (directory == null || !directory.isDirectory()) { continue; } processVariablesDirectory(directory, ""); @@ -418,6 +411,20 @@ private void processVariablesDirectory(File directory, String propertyPrefix) } } + /** + * + * @param doc + * @throws XPathExpressionException + * @throws IOException + * @throws SAXException + */ + public void processServerXml(Document doc) throws XPathExpressionException, IOException, SAXException { + parseIncludeVariables(doc); + parseConfigDropinsDirVariables("defaults"); + parseVariablesForValues(doc); + parseConfigDropinsDirVariables("overrides"); + } + //Checks for application names in the document. Will add locations without names to a Set private void parseNames(Document doc, String expression) throws XPathExpressionException, IOException, SAXException { // parse input document @@ -700,6 +707,7 @@ public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileN if (propertiesFile != null && propertiesFile.exists()) { parseProperties(new FileInputStream(propertiesFile)); } + log.debug("Ignoring non-existing properties file: " + propertiesFile.getAbsolutePath()); } private void parseProperties(InputStream ins) throws Exception { @@ -846,39 +854,11 @@ private void parseDropinsFilesVariables(File file) } } - /* - * If giveConfigDirPrecedence is set to true, return the file from the configDirectory if it exists; - * otherwise return specificFile if it exists, or null if not. - * If giveConfigDirPrecedence is set to false, return specificFile if it exists; - * otherwise return the file from the configDirectory if it exists, or null if not. - */ - private File findConfigFile(String fileName, File specificFile, boolean giveConfigDirPrecedence) { - File f = new File(configDirectory, fileName); - - if (giveConfigDirPrecedence) { - if (configDirectory != null && f.exists()) { - return f; - } - if (specificFile != null && specificFile.exists()) { - return specificFile; - } - } else { - if (specificFile != null && specificFile.exists()) { - return specificFile; - } - if (configDirectory != null && f.exists()) { - return f; - } - } - - return null; - } - /* * Get the file from configDrectory if it exists, or null if not */ - private File getFileFromConfigDirectory(String file) { - File f = new File(configDirectory, file); + private File getFileFromConfigDirectory(String filename) { + File f = new File(configDirectory, filename); if (configDirectory != null && f.exists()) { return f; } diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java similarity index 62% rename from src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java rename to src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java index 0ea79012..6caf3a52 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.io.File; import java.io.FileNotFoundException; @@ -12,7 +13,6 @@ import java.util.Map; import java.util.Properties; -import javax.xml.bind.annotation.XmlElement.DEFAULT; import javax.xml.xpath.XPathExpressionException; import org.junit.Test; @@ -21,6 +21,8 @@ import io.openliberty.tools.common.TestLogger; import io.openliberty.tools.common.plugins.config.ServerConfigDocument; +import io.openliberty.tools.common.plugins.util.ServerFeatureUtil; +import io.openliberty.tools.common.plugins.util.VariableUtility; /* Docs: https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html @@ -34,7 +36,7 @@ 7. variables declared on the command line */ -public class ServerConfigDocumentTest { +public class ServerConfigDocumentOverridesTest { private final static Path RESOURCES_DIR = Paths.get("src/test/resources/"); private final static Path WLP_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/"); private final static Path WLP_USER_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/usr/"); @@ -45,19 +47,21 @@ public class ServerConfigDocumentTest { // 6. variable values declared in the server.xml file @Test public void processServerXml() throws FileNotFoundException, IOException, XPathExpressionException, SAXException { - File serversDir = SERVERS_RESOURCES_DIR.toFile(); + File serversResourceDir = SERVERS_RESOURCES_DIR.toFile(); Document doc; + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversResourceDir); // no variables defined - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - File empty = new File(serversDir, "emptyList.xml"); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + File empty = new File(serversResourceDir, "emptyList.xml"); doc = configDocument.parseDocument(empty); configDocument.parseVariablesForBothValues(doc); assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty()); // variables defined - configDocument = new ServerConfigDocument(new TestLogger()); - File defined = new File(serversDir, "definedVariables.xml"); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + File defined = new File(serversResourceDir, "definedVariables.xml"); doc = configDocument.parseDocument(defined); configDocument.parseVariablesForBothValues(doc); assertEquals(1, configDocument.getDefaultProperties().size()); @@ -66,9 +70,8 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE assertEquals("9081", configDocument.getProperties().getProperty("http.port")); // variables defined in files - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), new File(serversDir, "server.xml"), null, null); - File include = new File(serversDir, "testIncludeParseVariables.xml"); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + File include = new File(serversResourceDir, "testIncludeParseVariables.xml"); doc = configDocument.parseDocument(include); assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty()); configDocument.parseIncludeVariables(doc); @@ -76,12 +79,16 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE assertEquals("9080", configDocument.getDefaultProperties().getProperty("default.http.port")); assertEquals(1, configDocument.getProperties().size()); assertEquals("9081", configDocument.getProperties().getProperty("http.port")); - - // server.xmls read in increasing precedence - // TODO: refactor - // configDropins/defaults - // server.xml - // configDropins/overrides + + // server.xml configDropins precedence + File serverConfigDir = SERVER_CONFIG_DIR.toFile(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + doc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); + configDocument.processServerXml(doc); // Variable resolution warnings can be ignored here + assertEquals("1", configDocument.getProperties().getProperty("config.dropins.defaults")); + assertEquals("2", configDocument.getProperties().getProperty("config.dropins.server")); + assertEquals("3", configDocument.getProperties().getProperty("config.dropins.overrides")); } // when a server.xml references an environment variable that could not be resolved, additionally search for: @@ -89,20 +96,32 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE // 2. change all characters to uppercase @Test public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Exception { - File serverXml = SERVER_CONFIG_DIR.resolve("server.xml").toFile(); - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), serverXml, SERVER_CONFIG_DIR.toFile(), new HashMap<>()); - Document serverXmlDoc = configDocument.parseDocument(serverXml); + File serverConfigDir = SERVER_CONFIG_DIR.toFile(); + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); + + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + Document serverXmlDoc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); configDocument.parseVariablesForBothValues(serverXmlDoc); assertEquals("${this.value}", configDocument.getDefaultProperties().getProperty("server.env.defined")); assertEquals("${this.value}", configDocument.getProperties().getProperty("server.env.defined")); + assertEquals("${that.value}", configDocument.getProperties().getProperty("bootstrap.property.defined")); + configDocument.processBootstrapProperties(); + assertFalse(configDocument.getProperties().containsKey("that.value")); + assertTrue(configDocument.getProperties().containsKey("THAT_VALUE")); configDocument.processServerEnv(); + assertFalse(configDocument.getProperties().containsKey("this.value")); + assertTrue(configDocument.getProperties().containsKey("this_value")); configDocument.parseVariablesForBothValues(serverXmlDoc); - // TODO: implement feature and uncomment these lines - // assertEquals("DEFINED", configDocument.getProperties().getProperty("server.env.defined")); - // assertEquals("DEFINED", configDocument.getProperties().getProperty("bootstrap.properties.defined")); + String resolveUnderscore = VariableUtility.resolveVariables(new TestLogger(), "${this.value}", + null, configDocument.getProperties(), configDocument.getDefaultProperties(), libertyDirPropMap); + assertEquals("DEFINED", resolveUnderscore); + String resolveUnderscoreToUpper = VariableUtility.resolveVariables(new TestLogger(), "${that.value}", + null, configDocument.getProperties(), configDocument.getDefaultProperties(), libertyDirPropMap); + assertEquals("DEFINED", resolveUnderscoreToUpper); + } @Test @@ -110,13 +129,11 @@ public void processServerEnv() throws FileNotFoundException, Exception { File wlpInstallDir = WLP_DIR.toFile(); File wlpUserDir = WLP_USER_DIR.toFile(); File serverDir = SERVER_CONFIG_DIR.toFile(); - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); Map libertyDirectoryPropertyToFileMap = new HashMap(); - libertyDirectoryPropertyToFileMap.put("wlp.install.dir", wlpInstallDir); - libertyDirectoryPropertyToFileMap.put("wlp.user.dir", wlpUserDir); - libertyDirectoryPropertyToFileMap.put("server.config.dir", serverDir); - - configDocument.initializeFields(new TestLogger(), null, serverDir, libertyDirectoryPropertyToFileMap); + libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, wlpInstallDir); + libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.WLP_USER_DIR, wlpUserDir); + libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverDir); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirectoryPropertyToFileMap); configDocument.processServerEnv(); Properties props = configDocument.getProperties(); @@ -144,25 +161,26 @@ public void environmentVariables() throws FileNotFoundException, Exception { public void processBootstrapProperties() throws FileNotFoundException, Exception { File serversDir = SERVERS_RESOURCES_DIR.toFile(); ServerConfigDocument configDocument; + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversDir); // bootstrap.properties - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); configDocument.processBootstrapProperties(); assertEquals(1, configDocument.getProperties().size()); assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); // bootstrap.include - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, new File(serversDir, "bootstrapInclude"), null); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, new File(serversDir, "bootstrapInclude")); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); configDocument.processBootstrapProperties(); assertEquals(2, configDocument.getProperties().size()); assertTrue(configDocument.getProperties().containsKey("bootstrap.include")); assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); // bootstrap.include termination check - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, new File(serversDir, "bootstrapOuroboros"), null); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, new File(serversDir, "bootstrapOuroboros")); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); configDocument.processBootstrapProperties(); } @@ -177,10 +195,11 @@ public void jvmOptions() { @Test public void variablesDir() throws FileNotFoundException, Exception { File serversDir = SERVER_CONFIG_DIR.toFile(); - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversDir); + + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); configDocument.processVariablesDirectory(); - Properties props = configDocument.getProperties(); assertEquals("9080", props.getProperty("httpPort")); assertEquals("1000", props.getProperty(String.join(File.separator, "nested", "httpPort"))); @@ -188,8 +207,7 @@ public void variablesDir() throws FileNotFoundException, Exception { assertEquals("2", props.getProperty("VALUE_2")); // process VARIABLE_SOURCE_DIRS - configDocument = new ServerConfigDocument(new TestLogger()); - configDocument.initializeFields(new TestLogger(), null, serversDir, null); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); String delimiter = (File.separator.equals("/")) ? ":" : ";"; String variableSourceDirsTestValue = String.join(delimiter, SERVERS_RESOURCES_DIR.resolve("variables").toString(), @@ -215,11 +233,37 @@ public void CLI() { // server.xml override bootstrap.properties, jvm.options, and server.env @Test public void overrides() { - File serversDir = SERVER_CONFIG_DIR.toFile(); + File serverConfigDir = SERVER_CONFIG_DIR.toFile(); + // server.xml overrides server.env ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), - new File(serversDir, "server.xml"), serversDir, new File(serversDir, "bootstrap.properties"), - new HashMap<>(), new File(serversDir, "server.env"), false, null); + new File(serverConfigDir, "server.xml"), serverConfigDir, new File(serverConfigDir, "bootstrap.properties"), + new HashMap<>(), new File(serverConfigDir, "server.env"), false, null); assertEquals("new_value", configDocument.getProperties().getProperty("overriden_value")); } + + @Test + public void initializeAppsLocation() { + File serverConfigDir = SERVER_CONFIG_DIR.toFile(); + Map libertyDirPropMap = new HashMap(); + libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); + libertyDirPropMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, WLP_DIR.toFile()); + libertyDirPropMap.put(ServerFeatureUtil.WLP_USER_DIR, WLP_USER_DIR.toFile()); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + configDocument.initializeAppsLocation(); + + Properties properties = configDocument.getProperties(); + Properties defaultProperties = configDocument.getDefaultProperties(); + + // default properties in server.xml + assertEquals(3, defaultProperties.size()); + + // server.env, wlp/etc and wlp/shared + + // bootstrap.properties + + // variables dir + + // configDropins + } } diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/server.xml new file mode 100644 index 00000000..5cf6f7aa --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/server.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml new file mode 100644 index 00000000..8609b5ad --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml index 43a7f85e..77dfb53b 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.xml @@ -24,5 +24,6 @@ - + + \ No newline at end of file From 3d3ece0eb37d3913ea8e5e3aa5d42c9eb60e7ccf Mon Sep 17 00:00:00 2001 From: dshimo Date: Mon, 11 Mar 2024 17:11:34 -0500 Subject: [PATCH 12/17] restore VarUtil log --- .../tools/common/plugins/util/VariableUtility.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java index 201d96a1..c77a316b 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java @@ -78,8 +78,8 @@ public static String resolveVariables(CommonLoggerI log, String nodeValue, Colle resolvedValue = resolvedValue.replace("\\","/"); resolved = resolved.replaceAll("\\$\\{" + escapedVariable + "\\}", resolvedValue); } else { - // Variable value could not be resolved. Log message and return null. - log.debug("Could not resolve the value " + value + " for variable ${" + nextVariable + "}"); + // Variable could not be resolved. Log message and return null. + log.debug("Variable " + nextVariable + " cannot be resolved."); return null; } } From 54545ddfdcba48fc4853ba87c627e1791dfec384 Mon Sep 17 00:00:00 2001 From: dshimo Date: Mon, 11 Mar 2024 19:18:16 -0500 Subject: [PATCH 13/17] final test, debug msg + default --- .../plugins/config/ServerConfigDocument.java | 5 ++- .../ServerConfigDocumentOverridesTest.java | 41 ++++--------------- .../defaultServer/bootstrap.properties | 4 +- .../configDropins/overrides/server.xml | 1 + .../wlp/usr/servers/defaultServer/server.env | 3 +- .../variables/variables.override | 1 + 6 files changed, 20 insertions(+), 35 deletions(-) create mode 100644 src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/variables.override diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index 34566d4f..ed635bc7 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -140,6 +140,9 @@ public ServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, F configDirectory = configDir; if (libertyDirPropertyFiles != null) { libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); + if (libertyDirPropertyFiles.containsKey(ServerFeatureUtil.SERVER_CONFIG_DIR)) { + configDirectory = libertyDirPropertyFiles.get(ServerFeatureUtil.SERVER_CONFIG_DIR); + } } else { log.warn("The properties for directories are null and could lead to application locations not being resolved correctly."); libertyDirectoryPropertyToFile = new HashMap(); @@ -314,6 +317,7 @@ public void processJvmOptions() throws FileNotFoundException, Exception { public void processBootstrapProperties() throws Exception, FileNotFoundException { File bootstrapFile = getFileFromConfigDirectory("bootstrap.properties"); if (bootstrapFile == null) { + log.debug("bootstrap.properties not found in: " + configDirectory.getAbsolutePath()); return; } @@ -707,7 +711,6 @@ public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileN if (propertiesFile != null && propertiesFile.exists()) { parseProperties(new FileInputStream(propertiesFile)); } - log.debug("Ignoring non-existing properties file: " + propertiesFile.getAbsolutePath()); } private void parseProperties(InputStream ins) throws Exception { diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java index 6caf3a52..9d49e9eb 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java @@ -24,18 +24,8 @@ import io.openliberty.tools.common.plugins.util.ServerFeatureUtil; import io.openliberty.tools.common.plugins.util.VariableUtility; -/* - Docs: https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html - # Variable substitution in increasing order of precedence (7 overrides 1) - 1. variable default values in the server.xml file - 2. environment variables - 3. bootstrap.properties - 4. Java system properties - 5. Variables loaded from files in the ${server.config.dir}/variables directory or other directories as specified by the VARIABLE_SOURCE_DIRS environment variable - 6. variable values declared in the server.xml file - 7. variables declared on the command line - */ +// Docs: https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html public class ServerConfigDocumentOverridesTest { private final static Path RESOURCES_DIR = Paths.get("src/test/resources/"); private final static Path WLP_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/"); @@ -121,7 +111,6 @@ public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Excep String resolveUnderscoreToUpper = VariableUtility.resolveVariables(new TestLogger(), "${that.value}", null, configDocument.getProperties(), configDocument.getDefaultProperties(), libertyDirPropMap); assertEquals("DEFINED", resolveUnderscoreToUpper); - } @Test @@ -227,23 +216,9 @@ public void CLI() { } - // TODO: test each overrides layer - // jvm.options override server.env - // bootstrap.properties override jvm.options and server.env - // server.xml override bootstrap.properties, jvm.options, and server.env - @Test - public void overrides() { - File serverConfigDir = SERVER_CONFIG_DIR.toFile(); - - // server.xml overrides server.env - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), - new File(serverConfigDir, "server.xml"), serverConfigDir, new File(serverConfigDir, "bootstrap.properties"), - new HashMap<>(), new File(serverConfigDir, "server.env"), false, null); - assertEquals("new_value", configDocument.getProperties().getProperty("overriden_value")); - } - + // Run the method @Test - public void initializeAppsLocation() { + public void initializeAppsLocationTest() { File serverConfigDir = SERVER_CONFIG_DIR.toFile(); Map libertyDirPropMap = new HashMap(); libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); @@ -257,13 +232,15 @@ public void initializeAppsLocation() { // default properties in server.xml assertEquals(3, defaultProperties.size()); - // server.env, wlp/etc and wlp/shared - + assertEquals("true", properties.get("etc.unique")); // etc + assertEquals("true", properties.get("shared.overriden")); // shared > etc + assertEquals("1111", properties.get("http.port")); // serverConfig > shared // bootstrap.properties - + assertEquals("true", properties.get("bootstrap.properties.override")); // overrides server.env // variables dir - + assertEquals("true", properties.get("variables.override")); // overrides bootstrap.prop // configDropins + assertEquals("7777", properties.get("httpPort")); // overrides variable dir } } diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties index 6a28af62..c22c623f 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties @@ -1,2 +1,4 @@ extras.filename=extraFeatures.xml -THAT_VALUE=DEFINED \ No newline at end of file +THAT_VALUE=DEFINED +bootstrap.properties.override=true +variables.override=false \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml index 8609b5ad..16445372 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/configDropins/overrides/server.xml @@ -1,3 +1,4 @@ + \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env index 027ead57..9caccade 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/server.env @@ -1,4 +1,5 @@ keystore_password=C7ANPlAi0MQD154BJ5ZOURn http.port=1111 overriden_value=old_value -this_value=DEFINED \ No newline at end of file +this_value=DEFINED +bootstrap.properties.override=false \ No newline at end of file diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/variables.override b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/variables.override new file mode 100644 index 00000000..f32a5804 --- /dev/null +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/variables/variables.override @@ -0,0 +1 @@ +true \ No newline at end of file From 91b845e323cb5e0ae911c77d40ca09b54e51027b Mon Sep 17 00:00:00 2001 From: dshimo Date: Thu, 21 Mar 2024 10:20:19 -0500 Subject: [PATCH 14/17] PR comments --- .../plugins/config/ServerConfigDocument.java | 16 +++--- .../common/plugins/util/VariableUtility.java | 49 +++++-------------- .../ServerConfigDocumentOverridesTest.java | 37 ++++++++------ .../defaultServer/bootstrap.properties | 3 +- 4 files changed, 46 insertions(+), 59 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index ed635bc7..6d223103 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -61,8 +61,6 @@ public class ServerConfigDocument { private File configDirectory; private File serverXMLFile; - private static final String CONFIGDROPINS_DEFAULT = Paths.get("configDropins/default/").toString(); - private static final String CONFIGDROPINS_OVERRIDES = Paths.get("configDropins/overrides/").toString(); private Set names; private Set namelessLocations; @@ -242,7 +240,7 @@ public void initializeAppsLocation() { // 2. get variables from server.env processServerEnv(); - // 3. get variables from jvm.options + // 3. get variables from jvm.options. Incomplete uncommon usecase. Uncomment when ready. // processJvmOptions(); // 3. get variables from bootstrap.properties @@ -257,7 +255,7 @@ public void initializeAppsLocation() { // 6. variable values declared in server.xml(s) processServerXml(doc); - // 7. variables delcared on the command line + // 7. variables declared on the command line // configured in Maven/Gradle parseApplication(doc, XPATH_SERVER_APPLICATION); @@ -291,6 +289,7 @@ public void processServerEnv() throws Exception, FileNotFoundException { /** * Likely not needed to be processed by the LMP/LGP tools. These properties benefit the JVM + * System properties would need to process out -D. jvm.options do not support variable substitution * 1. ${wlp.user.dir}/shared/jvm.options * 2. ${server.config.dir}/configDropins/defaults/ * 3. ${server.config.dir}/ @@ -302,9 +301,9 @@ public void processJvmOptions() throws FileNotFoundException, Exception { final String jvmOptionsString = "jvm.options"; parsePropertiesFromFile(new File(libertyDirectoryPropertyToFile.get(ServerFeatureUtil.WLP_USER_DIR), "shared" + File.separator + jvmOptionsString)); - parsePropertiesFromFile(getFileFromConfigDirectory(CONFIGDROPINS_DEFAULT + File.separator + jvmOptionsString)); + parsePropertiesFromFile(getFileFromConfigDirectory("configDropins/default/" + jvmOptionsString)); parsePropertiesFromFile(getFileFromConfigDirectory(jvmOptionsString)); - parsePropertiesFromFile(getFileFromConfigDirectory(CONFIGDROPINS_OVERRIDES + File.separator + jvmOptionsString)); + parsePropertiesFromFile(getFileFromConfigDirectory("configDropins/overrides/" + jvmOptionsString)); } /** @@ -317,7 +316,6 @@ public void processJvmOptions() throws FileNotFoundException, Exception { public void processBootstrapProperties() throws Exception, FileNotFoundException { File bootstrapFile = getFileFromConfigDirectory("bootstrap.properties"); if (bootstrapFile == null) { - log.debug("bootstrap.properties not found in: " + configDirectory.getAbsolutePath()); return; } @@ -347,7 +345,7 @@ private void processBootstrapInclude(Set processedBootstrapIncludes) thr } if (bootstrapIncludeFile.exists()) { - parseProperties(new FileInputStream(bootstrapIncludeFile)); + parsePropertiesFromFile(bootstrapIncludeFile); processedBootstrapIncludes.add(bootstrapIncludeFile.getAbsolutePath()); processBootstrapInclude(processedBootstrapIncludes); } @@ -710,6 +708,7 @@ private Document parseDocument(InputStream in) throws SAXException, IOException public void parsePropertiesFromFile(File propertiesFile) throws Exception, FileNotFoundException { if (propertiesFile != null && propertiesFile.exists()) { parseProperties(new FileInputStream(propertiesFile)); + log.debug("Processed properties from file: " + propertiesFile.getAbsolutePath()); } } @@ -865,6 +864,7 @@ private File getFileFromConfigDirectory(String filename) { if (configDirectory != null && f.exists()) { return f; } + log.debug(filename + " was not found in: " + configDirectory.getAbsolutePath()); return null; } } diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java index c77a316b..fbdb1cf1 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java @@ -55,7 +55,7 @@ public static String resolveVariables(CommonLoggerI log, String nodeValue, Colle } for (String nextVariable : variablesToResolve) { - String value = getPropertyValueDraft(nextVariable, props, defaultProps, libDirPropFiles); + String value = getPropertyValue(nextVariable, props, defaultProps, libDirPropFiles); if (value == null || value.isEmpty()) { // Variable could not be resolved. Log message and return null. @@ -91,7 +91,7 @@ public static String resolveVariables(CommonLoggerI log, String nodeValue, Colle // TODO: Integer value properties can be evaluated if 'simple' arithemetic // TODO: A list of ports can be defined using keyword 'list', e.g. list(httpPort) -> 89,9889 versus literal '89,9889' - public static String getPropertyValueDraft(String propertyName, Properties prop, Properties defaultProps, Map libertyDirPropFiles) { + public static String getPropertyValue(String propertyName, Properties prop, Properties defaultProps, Map libertyDirPropFiles) { String value = null; if (libertyDirPropFiles.containsKey(propertyName)) { return stripQuotes(libertyDirPropFiles.get(propertyName).toString()); @@ -99,21 +99,29 @@ public static String getPropertyValueDraft(String propertyName, Properties prop, value = lookupProperty(prop, defaultProps, propertyName); if (value != null) { - return stripQuotes(value); + return value; } // try again with non-alphanumeric values replaced with '_', which is exactly \W in regex String propertyNameVariation = propertyName.replaceAll("\\W", "_"); value = lookupProperty(prop, defaultProps, propertyNameVariation); if (value != null) { - return stripQuotes(value); + return value; } // try again with propertyNameVariation.toUpperCase() propertyNameVariation = propertyNameVariation.toUpperCase(); value = lookupProperty(prop, defaultProps, propertyNameVariation); if (value != null) { - return stripQuotes(value); + return value; + } + + // support for versions <19.0.0.3. Look for property without the 'env.' prefix + if (propertyName != null && propertyName.startsWith("env.") && propertyName.length() > 4) { + value = lookupProperty(prop, defaultProps, propertyName.substring(4)); + if (value != null) { + return value; + } } return value; @@ -135,35 +143,4 @@ private static String lookupProperty(Properties prop, Properties defaultProps, S } return null; } - - public static String getPropertyValue(String propertyName, Properties props, Properties defaultProps, Map libDirPropFiles) { - String value = null; - if(!libDirPropFiles.containsKey(propertyName)) { - value = props.getProperty(propertyName); - if (value == null) { - // Check for default value since no other value found. - value = defaultProps.getProperty(propertyName); - } - if (value == null && propertyName.startsWith("env.") && propertyName.length() > 4) { - // Look for property without the 'env.' prefix - String newPropName = propertyName.substring(4); - value = props.getProperty(newPropName); - if (value == null) { - // Check for default value since no other value found. - value = defaultProps.getProperty(newPropName); - } - } - } else { - File envDirectory = libDirPropFiles.get(propertyName); - value = envDirectory.toString(); - } - - if (value != null && value.startsWith("\"") && value.endsWith("\"")) { - // need to remove beginning/ending quotes - if (value.length() > 2) { - value = value.substring(1, value.length() -1); - } - } - return value; - } } diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java index 9d49e9eb..72f7049a 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java @@ -77,13 +77,14 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE doc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); configDocument.processServerXml(doc); // Variable resolution warnings can be ignored here assertEquals("1", configDocument.getProperties().getProperty("config.dropins.defaults")); - assertEquals("2", configDocument.getProperties().getProperty("config.dropins.server")); - assertEquals("3", configDocument.getProperties().getProperty("config.dropins.overrides")); + assertEquals("The value is expected to be overriden from 1 to 2", "2", configDocument.getProperties().getProperty("config.dropins.server")); + assertEquals("The value is expected to be overriden from 1 to 3", "3", configDocument.getProperties().getProperty("config.dropins.overrides")); } // when a server.xml references an environment variable that could not be resolved, additionally search for: // 1. replace all non-alphanumeric characters with underscore char '_' // 2. change all characters to uppercase + // 3. remove the env. prefix (<19.0.0.3 behavior) @Test public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Exception { File serverConfigDir = SERVER_CONFIG_DIR.toFile(); @@ -111,6 +112,9 @@ public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Excep String resolveUnderscoreToUpper = VariableUtility.resolveVariables(new TestLogger(), "${that.value}", null, configDocument.getProperties(), configDocument.getDefaultProperties(), libertyDirPropMap); assertEquals("DEFINED", resolveUnderscoreToUpper); + String resolveEnvPrefix = VariableUtility.resolveVariables(new TestLogger(), "${env.HOST}", + null, configDocument.getProperties(), configDocument.getDefaultProperties(), libertyDirPropMap); + assertEquals("localhost", resolveEnvPrefix); } @Test @@ -132,11 +136,11 @@ public void processServerEnv() throws FileNotFoundException, Exception { // 2. {wlp.user.dir}/shared assertEquals("true", props.get("shared.unique")); - assertEquals("true", props.get("shared.overriden")); + assertEquals("This value is expected to be overriden from false to true","true", props.get("shared.overriden")); // 3. {server.config.dir} assertEquals("old_value", props.get("overriden_value")); - assertEquals("1111", props.get("http.port")); + assertEquals("This value is expected to be overriden from 9081 to 1111", "1111", props.get("http.port")); } // 2. environment variables @@ -232,15 +236,20 @@ public void initializeAppsLocationTest() { // default properties in server.xml assertEquals(3, defaultProperties.size()); - // server.env, wlp/etc and wlp/shared - assertEquals("true", properties.get("etc.unique")); // etc - assertEquals("true", properties.get("shared.overriden")); // shared > etc - assertEquals("1111", properties.get("http.port")); // serverConfig > shared - // bootstrap.properties - assertEquals("true", properties.get("bootstrap.properties.override")); // overrides server.env - // variables dir - assertEquals("true", properties.get("variables.override")); // overrides bootstrap.prop - // configDropins - assertEquals("7777", properties.get("httpPort")); // overrides variable dir + + // server.env + // wlp/etc + assertEquals("true", properties.get("etc.unique")); + // wlp/shared > etc + assertEquals("The value is expected to be overriden from false to true","true", properties.get("shared.overriden")); + // serverConfig > shared + assertEquals("The value is expected to be overriden from 9081 to 1111","1111", properties.get("http.port")); + + // bootstrap.properties, overrides server.env + assertEquals("The value is expected to be overriden from false to true","true", properties.get("bootstrap.properties.override")); + // variables dir, overrides bootstrap.prop + assertEquals("The value is expected to be overriden from false to true","true", properties.get("variables.override")); + // configDropins, overrides variable dir + assertEquals("The value is expected to be overriden from 9080 to 7777","7777", properties.get("httpPort")); } } diff --git a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties index c22c623f..883c74ad 100644 --- a/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties +++ b/src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer/bootstrap.properties @@ -1,4 +1,5 @@ extras.filename=extraFeatures.xml THAT_VALUE=DEFINED bootstrap.properties.override=true -variables.override=false \ No newline at end of file +variables.override=false +HOST=localhost \ No newline at end of file From c3c8e567fc8f4a90a94ac0a96402cefb90c9d0c0 Mon Sep 17 00:00:00 2001 From: dshimo Date: Tue, 26 Mar 2024 14:40:27 -0500 Subject: [PATCH 15/17] uncomment initAppLocations --- .../plugins/config/ServerConfigDocument.java | 26 ++++++++++++++++--- .../ServerConfigDocumentOverridesTest.java | 24 ++++++++--------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java index 6d223103..d7eee339 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java +++ b/src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java @@ -177,7 +177,7 @@ public ServerConfigDocument(CommonLoggerI log, Map libertyDirPrope props = new Properties(); defaultProps = new Properties(); - // initializeAppsLocation(); + initializeAppsLocation(); } // LCLS constructor @@ -186,6 +186,21 @@ public ServerConfigDocument(CommonLoggerI log) { this(log, null); } + // test constructor that takes in initial properties to be called modularly + public ServerConfigDocument(CommonLoggerI log, Map libertyDirPropertyFiles, Properties initProperties) { + this.log = log; + libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); + configDirectory = libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR); + serverXMLFile = getFileFromConfigDirectory("server.xml"); + locations = new HashSet(); + names = new HashSet(); + namelessLocations = new HashSet(); + locationsAndNames = new HashMap(); + props = new Properties(); + if (initProperties != null) props.putAll(initProperties); + defaultProps = new Properties(); + } + private DocumentBuilder getDocumentBuilder() { DocumentBuilder docBuilder; @@ -247,7 +262,7 @@ public void initializeAppsLocation() { processBootstrapProperties(); // 4. Java system properties - // configured in Maven/Gradle + processSystemProperties(); // 5. Variables loaded from 'variables' directory processVariablesDirectory(); @@ -256,7 +271,8 @@ public void initializeAppsLocation() { processServerXml(doc); // 7. variables declared on the command line - // configured in Maven/Gradle + // Maven: https://github.com/OpenLiberty/ci.maven/blob/main/docs/common-server-parameters.md#setting-liberty-configuration-with-maven-project-properties + // Gradle: https://github.com/dshimo/ci.gradle/blob/main/docs/libertyExtensions.md parseApplication(doc, XPATH_SERVER_APPLICATION); parseApplication(doc, XPATH_SERVER_WEB_APPLICATION); @@ -351,6 +367,10 @@ private void processBootstrapInclude(Set processedBootstrapIncludes) thr } } + private void processSystemProperties() { + props.putAll(System.getProperties()); + } + /** * By default, ${server.config.directory}/variables is processed. * If VARIABLE_SOURCE_DIRS is defined, those directories are processed instead. diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java index 72f7049a..fcdb0022 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java @@ -32,7 +32,7 @@ public class ServerConfigDocumentOverridesTest { private final static Path WLP_USER_DIR = RESOURCES_DIR.resolve("serverConfig/liberty/wlp/usr/"); private final static Path SERVER_CONFIG_DIR = WLP_USER_DIR.resolve("servers/defaultServer"); private final static Path SERVERS_RESOURCES_DIR = RESOURCES_DIR.resolve("servers/"); - + // 1. variable default values in server.xml file // 6. variable values declared in the server.xml file @Test @@ -43,14 +43,14 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversResourceDir); // no variables defined - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null); File empty = new File(serversResourceDir, "emptyList.xml"); doc = configDocument.parseDocument(empty); configDocument.parseVariablesForBothValues(doc); assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty()); // variables defined - configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null); File defined = new File(serversResourceDir, "definedVariables.xml"); doc = configDocument.parseDocument(defined); configDocument.parseVariablesForBothValues(doc); @@ -60,7 +60,7 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE assertEquals("9081", configDocument.getProperties().getProperty("http.port")); // variables defined in files - configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null); File include = new File(serversResourceDir, "testIncludeParseVariables.xml"); doc = configDocument.parseDocument(include); assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty()); @@ -73,7 +73,7 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE // server.xml configDropins precedence File serverConfigDir = SERVER_CONFIG_DIR.toFile(); libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); - configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null); doc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); configDocument.processServerXml(doc); // Variable resolution warnings can be ignored here assertEquals("1", configDocument.getProperties().getProperty("config.dropins.defaults")); @@ -91,7 +91,7 @@ public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Excep Map libertyDirPropMap = new HashMap(); libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir); - ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null); Document serverXmlDoc = configDocument.parseDocument(new File(serverConfigDir, "server.xml")); configDocument.parseVariablesForBothValues(serverXmlDoc); assertEquals("${this.value}", configDocument.getDefaultProperties().getProperty("server.env.defined")); @@ -158,14 +158,14 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversDir); // bootstrap.properties - configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null); configDocument.processBootstrapProperties(); assertEquals(1, configDocument.getProperties().size()); assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename")); // bootstrap.include libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, new File(serversDir, "bootstrapInclude")); - configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null); configDocument.processBootstrapProperties(); assertEquals(2, configDocument.getProperties().size()); assertTrue(configDocument.getProperties().containsKey("bootstrap.include")); @@ -173,7 +173,7 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception // bootstrap.include termination check libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, new File(serversDir, "bootstrapOuroboros")); - configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null); configDocument.processBootstrapProperties(); } @@ -200,13 +200,14 @@ public void variablesDir() throws FileNotFoundException, Exception { assertEquals("2", props.getProperty("VALUE_2")); // process VARIABLE_SOURCE_DIRS - configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); String delimiter = (File.separator.equals("/")) ? ":" : ";"; String variableSourceDirsTestValue = String.join(delimiter, SERVERS_RESOURCES_DIR.resolve("variables").toString(), SERVER_CONFIG_DIR.toString(), "DOES_NOT_EXIST"); - configDocument.getProperties().put("VARIABLE_SOURCE_DIRS", variableSourceDirsTestValue); + Properties initProperties = new Properties(); + initProperties.put("VARIABLE_SOURCE_DIRS", variableSourceDirsTestValue); + configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, initProperties); configDocument.processVariablesDirectory(); props = configDocument.getProperties(); @@ -229,7 +230,6 @@ public void initializeAppsLocationTest() { libertyDirPropMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, WLP_DIR.toFile()); libertyDirPropMap.put(ServerFeatureUtil.WLP_USER_DIR, WLP_USER_DIR.toFile()); ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap); - configDocument.initializeAppsLocation(); Properties properties = configDocument.getProperties(); Properties defaultProperties = configDocument.getDefaultProperties(); From dd485111c7201e992eb3858544c2230212a47774 Mon Sep 17 00:00:00 2001 From: dshimo Date: Wed, 17 Apr 2024 14:38:48 -0500 Subject: [PATCH 16/17] stripQuotes NPE guard --- .../openliberty/tools/common/plugins/util/VariableUtility.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java index fbdb1cf1..bf58fa70 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/VariableUtility.java @@ -128,6 +128,9 @@ public static String getPropertyValue(String propertyName, Properties prop, Prop } private static String stripQuotes(String value) { + if (value == null) { + return null; + } if (value.startsWith("\"") && value.endsWith("\"") && value.length() > 2) { return value.substring(1, value.length() - 1); } From 17f60f5222bbdd6f8d62ae0daac8f4ff4380e54a Mon Sep 17 00:00:00 2001 From: dshimo Date: Wed, 17 Apr 2024 16:15:08 -0500 Subject: [PATCH 17/17] rm empty tests --- .../ServerConfigDocumentOverridesTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java index fcdb0022..cf283287 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java @@ -143,12 +143,6 @@ public void processServerEnv() throws FileNotFoundException, Exception { assertEquals("This value is expected to be overriden from 9081 to 1111", "1111", props.get("http.port")); } - // 2. environment variables - @Test - public void environmentVariables() throws FileNotFoundException, Exception { - - } - // 3. bootstrap.properties @Test public void processBootstrapProperties() throws FileNotFoundException, Exception { @@ -177,12 +171,6 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception configDocument.processBootstrapProperties(); } - // 4. Java system properties - @Test - public void jvmOptions() { - - } - // 5. Variables loaded from files in the ${server.config.dir}/variables directory or other // directories as specified by the VARIABLE_SOURCE_DIRS environment variable @Test @@ -214,12 +202,6 @@ public void variablesDir() throws FileNotFoundException, Exception { assertEquals("outer_space", props.getProperty("outer.source")); assertEquals("1", props.getProperty("VALUE_1")); } - - // 7. variables declared on the command line - @Test - public void CLI() { - - } // Run the method @Test