Skip to content

Commit

Permalink
uncomment initAppLocations
Browse files Browse the repository at this point in the history
  • Loading branch information
dshimo committed Mar 26, 2024
1 parent 91b845e commit c3c8e56
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public ServerConfigDocument(CommonLoggerI log, Map<String, File> libertyDirPrope
props = new Properties();
defaultProps = new Properties();

// initializeAppsLocation();
initializeAppsLocation();
}

// LCLS constructor
Expand All @@ -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<String, File> libertyDirPropertyFiles, Properties initProperties) {
this.log = log;
libertyDirectoryPropertyToFile = new HashMap<String, File>(libertyDirPropertyFiles);
configDirectory = libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR);
serverXMLFile = getFileFromConfigDirectory("server.xml");
locations = new HashSet<String>();
names = new HashSet<String>();
namelessLocations = new HashSet<String>();
locationsAndNames = new HashMap<String, String>();
props = new Properties();
if (initProperties != null) props.putAll(initProperties);
defaultProps = new Properties();
}

private DocumentBuilder getDocumentBuilder() {
DocumentBuilder docBuilder;

Expand Down Expand Up @@ -247,7 +262,7 @@ public void initializeAppsLocation() {
processBootstrapProperties();

// 4. Java system properties
// configured in Maven/Gradle
processSystemProperties();

// 5. Variables loaded from 'variables' directory
processVariablesDirectory();
Expand All @@ -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);
Expand Down Expand Up @@ -351,6 +367,10 @@ private void processBootstrapInclude(Set<String> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -60,7 +60,7 @@ public void processServerXml() throws FileNotFoundException, IOException, XPathE
assertEquals("9081", configDocument.getProperties().getProperty("http.port"));

// variables defined in <include/> 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());
Expand All @@ -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"));
Expand All @@ -91,7 +91,7 @@ public void serverXmlEnvVarVariationLookup() throws FileNotFoundException, Excep
Map<String, File> libertyDirPropMap = new HashMap<String, File>();
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"));
Expand Down Expand Up @@ -158,22 +158,22 @@ 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"));
assertEquals("extraFeatures.xml", configDocument.getProperties().getProperty("extras.filename"));

// 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();
}

Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit c3c8e56

Please sign in to comment.