Skip to content

Commit

Permalink
Removing deprecated constructor, added originalServerXMLFile property
Browse files Browse the repository at this point in the history
Signed-off-by: Arun Venmany <[email protected]>
  • Loading branch information
arunvenmany-ibm committed Nov 12, 2024
1 parent 1724ef4 commit 3a516a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ServerConfigDocument {

private File configDirectory;
private File serverXMLFile;
private File originalServerXMLFile;

private Set<String> names;
private Set<String> namelessLocations;
Expand Down Expand Up @@ -126,47 +127,15 @@ public File getServerXML() {
return serverXMLFile;
}

/**
* Deprecated. Migrate to the simpler constructor.
* @param log
* @param serverXML
* @param configDir
* @param bootstrapFile
* @param bootstrapProp
* @param serverEnvFile
* @param giveConfigDirPrecedence
* @param libertyDirPropertyFiles - Contains a property to file mapping of directory locations
*/
public ServerConfigDocument(CommonLoggerI log, File serverXML, File configDir, File bootstrapFile,
Map<String, String> bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map<String, File> libertyDirPropertyFiles) {
this.log = log;
serverXMLFile = serverXML;
configDirectory = configDir;
if (libertyDirPropertyFiles != null) {
libertyDirectoryPropertyToFile = new HashMap<String, File>(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<String,File>();
}
locations = new HashSet<String>();
names = new HashSet<String>();
namelessLocations = new HashSet<String>();
locationsAndNames = new HashMap<String, String>();
props = new Properties();
defaultProps = new Properties();

initializeAppsLocation();
}

/**
* Adapt when ready. Expects the libertyDirPropertyFiles to be populated
*
* @param log
* @param originalServerXMLFile
* @param libertyDirPropertyFiles
*/
public ServerConfigDocument(CommonLoggerI log, Map<String, File> libertyDirPropertyFiles) {
public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, Map<String, File> libertyDirPropertyFiles) {
this.log = log;
if (libertyDirPropertyFiles != null) {
libertyDirectoryPropertyToFile = new HashMap<String, File>(libertyDirPropertyFiles);
Expand All @@ -182,18 +151,20 @@ public ServerConfigDocument(CommonLoggerI log, Map<String, File> libertyDirPrope
locationsAndNames = new HashMap<String, String>();
props = new Properties();
defaultProps = new Properties();

if (originalServerXMLFile != null) {
this.originalServerXMLFile = originalServerXMLFile;
}
initializeAppsLocation();
}

// LCLS constructor
// TODO: populate libertyDirectoryPropertyToFile with workspace information
public ServerConfigDocument(CommonLoggerI log) {
this(log, null);
this(log, null, null);
}

// test constructor that takes in initial properties to be called modularly
public ServerConfigDocument(CommonLoggerI log, Map<String, File> libertyDirPropertyFiles, Properties initProperties) {
public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, Map<String, File> libertyDirPropertyFiles, Properties initProperties) {
this.log = log;
libertyDirectoryPropertyToFile = new HashMap<String, File>(libertyDirPropertyFiles);
configDirectory = libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR);
Expand All @@ -205,6 +176,9 @@ public ServerConfigDocument(CommonLoggerI log, Map<String, File> libertyDirPrope
props = new Properties();
if (initProperties != null) props.putAll(initProperties);
defaultProps = new Properties();
if (originalServerXMLFile != null) {
this.originalServerXMLFile = originalServerXMLFile;
}
}

private DocumentBuilder getDocumentBuilder() {
Expand Down Expand Up @@ -928,4 +902,12 @@ private File getFileFromConfigDirectory(String filename) {
log.debug(filename + " was not found in: " + configDirectory.getAbsolutePath());
return null;
}

public File getOriginalServerXMLFile() {
return originalServerXMLFile;
}

public void setOriginalServerXMLFile(File originalServerXMLFile) {
this.originalServerXMLFile = originalServerXMLFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public void processServerXml() throws IOException, XPathExpressionException, SAX
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversResourceDir);

// no variables defined
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null);
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), null, 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, null);
configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirPropMap, null);
File defined = new File(serversResourceDir, "definedVariables.xml");
doc = configDocument.parseDocument(defined);
configDocument.parseVariablesForBothValues(doc);
Expand All @@ -61,7 +61,7 @@ public void processServerXml() throws IOException, XPathExpressionException, SAX
assertEquals("9081", configDocument.getProperties().getProperty("http.port"));

// variables defined in <include/> files
configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null);
configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirPropMap, null);
File include = new File(serversResourceDir, "testIncludeParseVariables.xml");
doc = configDocument.parseDocument(include);
assertTrue(configDocument.getDefaultProperties().isEmpty() && configDocument.getProperties().isEmpty());
Expand All @@ -74,7 +74,7 @@ public void processServerXml() throws IOException, XPathExpressionException, SAX
// server.xml configDropins precedence
File serverConfigDir = SERVER_CONFIG_DIR.toFile();
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir);
configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null);
configDocument = new ServerConfigDocument(new TestLogger(), null, 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 @@ -92,7 +92,7 @@ public void serverXmlEnvVarVariationLookup() throws Exception {
Map<String, File> libertyDirPropMap = new HashMap<String, File>();
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir);

ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null);
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), null, 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 @@ -127,7 +127,7 @@ public void processServerEnv() throws Exception {
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);
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirectoryPropertyToFileMap);
configDocument.processServerEnv();
Properties props = configDocument.getProperties();

Expand All @@ -153,22 +153,22 @@ public void processBootstrapProperties() throws FileNotFoundException, Exception
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversDir);

// bootstrap.properties
configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, null);
configDocument = new ServerConfigDocument(new TestLogger(), null, 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, null);
configDocument = new ServerConfigDocument(new TestLogger(), null, 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, null);
configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirPropMap, null);
configDocument.processBootstrapProperties();
}

Expand All @@ -180,7 +180,7 @@ public void variablesDir() throws FileNotFoundException, Exception {
Map<String, File> libertyDirPropMap = new HashMap<String, File>();
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serversDir);

ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap);
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirPropMap);
configDocument.processVariablesDirectory();
Properties props = configDocument.getProperties();
assertEquals("9080", props.getProperty("httpPort"));
Expand All @@ -196,7 +196,7 @@ public void variablesDir() throws FileNotFoundException, Exception {
"DOES_NOT_EXIST");
Properties initProperties = new Properties();
initProperties.put("VARIABLE_SOURCE_DIRS", variableSourceDirsTestValue);
configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap, initProperties);
configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirPropMap, initProperties);
configDocument.processVariablesDirectory();

props = configDocument.getProperties();
Expand All @@ -213,7 +213,7 @@ public void initializeAppsLocationTest() {
libertyDirPropMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, WLP_DIR.toFile());
libertyDirPropMap.put(ServerFeatureUtil.WLP_USER_DIR, WLP_USER_DIR.toFile());
libertyDirPropMap.put(ServerFeatureUtil.SHARED_CONFIG_DIR, SHARED_CONFIG_DIR.toFile());
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), libertyDirPropMap);
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirPropMap);

Properties properties = configDocument.getProperties();
Properties defaultProperties = configDocument.getDefaultProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testAppLocationUsesLibertyProperty() throws Exception {

File serverXML = new File(serverDirectory, "server.xml");

ServerConfigDocument scd = new ServerConfigDocument(log, serverXML, serverDirectory, null, null, null, true, libertyDirectoryPropertyToFile);
ServerConfigDocument scd = new ServerConfigDocument(log, serverXML, libertyDirectoryPropertyToFile);
Set<String> locations = scd.getLocations();
assertTrue("Expected six app locations", locations.size() == 6);

Expand Down

0 comments on commit 3a516a4

Please sign in to comment.