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 4e644069..5ba9d7c3 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 @@ -62,6 +62,7 @@ public class ServerConfigDocument { private File configDirectory; private File serverXMLFile; + private File originalServerXMLFile; private Set names; private Set namelessLocations; @@ -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 bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) { - this.log = log; - serverXMLFile = serverXML; - 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(); - } - locations = new HashSet(); - names = new HashSet(); - namelessLocations = new HashSet(); - locationsAndNames = new HashMap(); - 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 libertyDirPropertyFiles) { + public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, Map libertyDirPropertyFiles) { this.log = log; if (libertyDirPropertyFiles != null) { libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); @@ -182,18 +151,20 @@ public ServerConfigDocument(CommonLoggerI log, Map libertyDirPrope locationsAndNames = new HashMap(); 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 libertyDirPropertyFiles, Properties initProperties) { + public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, Map libertyDirPropertyFiles, Properties initProperties) { this.log = log; libertyDirectoryPropertyToFile = new HashMap(libertyDirPropertyFiles); configDirectory = libertyDirectoryPropertyToFile.get(ServerFeatureUtil.SERVER_CONFIG_DIR); @@ -205,6 +176,9 @@ public ServerConfigDocument(CommonLoggerI log, Map libertyDirPrope props = new Properties(); if (initProperties != null) props.putAll(initProperties); defaultProps = new Properties(); + if (originalServerXMLFile != null) { + this.originalServerXMLFile = originalServerXMLFile; + } } private DocumentBuilder getDocumentBuilder() { @@ -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; + } } \ No newline at end of file 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 ca74130a..d3995f62 100644 --- a/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java +++ b/src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java @@ -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); @@ -61,7 +61,7 @@ public void processServerXml() throws IOException, XPathExpressionException, SAX assertEquals("9081", configDocument.getProperties().getProperty("http.port")); // variables defined in 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()); @@ -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")); @@ -92,7 +92,7 @@ public void serverXmlEnvVarVariationLookup() throws Exception { Map libertyDirPropMap = new HashMap(); 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")); @@ -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(); @@ -153,14 +153,14 @@ 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")); @@ -168,7 +168,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, null); + configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirPropMap, null); configDocument.processBootstrapProperties(); } @@ -180,7 +180,7 @@ public void variablesDir() throws FileNotFoundException, Exception { Map libertyDirPropMap = new HashMap(); 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")); @@ -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(); @@ -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(); diff --git a/src/test/java/io/openliberty/tools/common/plugins/util/ServerConfigDocumentTest.java b/src/test/java/io/openliberty/tools/common/plugins/util/ServerConfigDocumentTest.java index ac3e19f6..686044f1 100644 --- a/src/test/java/io/openliberty/tools/common/plugins/util/ServerConfigDocumentTest.java +++ b/src/test/java/io/openliberty/tools/common/plugins/util/ServerConfigDocumentTest.java @@ -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 locations = scd.getLocations(); assertTrue("Expected six app locations", locations.size() == 6);