Skip to content

Commit cef2347

Browse files
committed
changes to support pre defined variables
Signed-off-by: Arun Venmany <Arun.Kumar.V.N@ibm.com>
1 parent 29c07e9 commit cef2347

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

src/main/java/io/openliberty/tools/common/plugins/config/ServerConfigDocument.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, Map<S
175175
* @throws PluginExecutionException
176176
* @throws IOException
177177
*/
178-
public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, File installDirectory, File userDirectory, File serverDirectory) throws PluginExecutionException, IOException {
179-
this(log, originalServerXMLFile, LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(log,installDirectory, userDirectory, serverDirectory));
178+
public ServerConfigDocument(CommonLoggerI log, File originalServerXMLFile, File installDirectory, File userDirectory, File serverDirectory, File serverOutputDirectory) throws PluginExecutionException, IOException {
179+
this(log, originalServerXMLFile, LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(log, installDirectory, userDirectory, serverDirectory, serverOutputDirectory));
180180
}
181181

182182
// test constructor that takes in initial properties to be called modularly
@@ -244,6 +244,7 @@ private DocumentBuilder getDocumentBuilder() {
244244
// b. ${server.config.dir}/server.xml
245245
// c. ${server.config.dir}/configDropins/overrides/
246246
// 7. variables declared on the command line
247+
// 8. add liberty predefined variables to variable map
247248
*/
248249
public void initializeAppsLocation() throws PluginExecutionException {
249250
try {
@@ -274,6 +275,9 @@ public void initializeAppsLocation() throws PluginExecutionException {
274275
// Maven: https://github.com/OpenLiberty/ci.maven/blob/main/docs/common-server-parameters.md#setting-liberty-configuration-with-maven-project-properties
275276
// Gradle: https://github.com/dshimo/ci.gradle/blob/main/docs/libertyExtensions.md
276277

278+
// 8. liberty pre defined variables
279+
processPredefinedVariables();
280+
277281
parseApplication(doc, XPATH_SERVER_APPLICATION);
278282
parseApplication(doc, XPATH_SERVER_WEB_APPLICATION);
279283
parseApplication(doc, XPATH_SERVER_ENTERPRISE_APPLICATION);
@@ -283,13 +287,25 @@ public void initializeAppsLocation() throws PluginExecutionException {
283287
parseConfigDropinsDir();
284288

285289
} catch (Exception e) {
286-
if(e instanceof PluginExecutionException){
290+
if(e instanceof PluginExecutionException){
287291
throw (PluginExecutionException)e;
288292
}
289293
e.printStackTrace();
290294
}
291295
}
292296

297+
/**
298+
* Add predefined variables into variable map
299+
* uses liberty property files map and take all predefined properties
300+
* LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles() takes care of adding all predefined properties into libertyDirPropertyFiles
301+
* @throws IOException
302+
*/
303+
private void processPredefinedVariables() throws IOException{
304+
for (Map.Entry<String, File> stringFileEntry : getLibertyDirPropertyFiles().entrySet()) {
305+
props.put(stringFileEntry.getKey(), stringFileEntry.getValue().getCanonicalPath());
306+
}
307+
}
308+
293309
/**
294310
* server.env file read order
295311
* 1. {wlp.install.dir}/etc/

src/main/java/io/openliberty/tools/common/plugins/util/LibertyPropFilesUtility.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corporation 2024
2+
* (C) Copyright IBM Corporation 2024, 2025
33
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,15 +18,14 @@
1818
import io.openliberty.tools.common.CommonLoggerI;
1919

2020
import java.io.File;
21-
import java.io.IOException;
2221
import java.util.Collections;
2322
import java.util.HashMap;
2423
import java.util.Map;
2524

2625
public class LibertyPropFilesUtility {
2726

2827

29-
public static Map<String, File> getLibertyDirectoryPropertyFiles(CommonLoggerI log, File installDir, File userDir, File serverDir) {
28+
public static Map<String, File> getLibertyDirectoryPropertyFiles(CommonLoggerI log, File installDir, File userDir, File serverDir, File serverOutputDirectory) {
3029
Map<String, File> libertyDirectoryPropertyToFile = new HashMap<>();
3130

3231
if (serverDir.exists()) {
@@ -50,6 +49,7 @@ public static Map<String, File> getLibertyDirectoryPropertyFiles(CommonLoggerI l
5049
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_CONFIG_DIR, userSharedConfigDir.getCanonicalFile());
5150
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_RESOURCES_DIR, userSharedResourcesDir.getCanonicalFile());
5251
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_STACKGROUP_DIR, userSharedStackGroupsDir.getCanonicalFile());
52+
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SERVER_OUTPUT_DIR, serverOutputDirectory.getCanonicalFile());
5353

5454
return libertyDirectoryPropertyToFile;
5555
} catch (Exception e) {

src/main/java/io/openliberty/tools/common/plugins/util/ServerFeatureUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public abstract class ServerFeatureUtil extends AbstractContainerSupportUtil imp
7676
public static final String SHARED_RESOURCES_DIR = "shared.resource.dir";
7777
public static final String SHARED_STACKGROUP_DIR = "shared.stackgroup.dir";
7878
public static final String SERVER_CONFIG_DIR = "server.config.dir";
79+
public static final String SERVER_OUTPUT_DIR = "server.output.dir";
7980

8081
private Map<String, File> libertyDirectoryPropertyToFile = null;
8182
private boolean lowerCaseFeatures = true;

src/test/java/io/openliberty/tools/common/config/ServerConfigDocumentOverridesTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void processServerEnv() throws Exception {
133133
libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, wlpInstallDir);
134134
libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.WLP_USER_DIR, wlpUserDir);
135135
libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverDir);
136+
libertyDirectoryPropertyToFileMap.put(ServerFeatureUtil.SERVER_OUTPUT_DIR, serverDir);
136137
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), null, libertyDirectoryPropertyToFileMap);
137138
configDocument.processServerEnv();
138139
Properties props = configDocument.getProperties();
@@ -148,6 +149,12 @@ public void processServerEnv() throws Exception {
148149
// 3. {server.config.dir}
149150
assertEquals("old_value", props.get("overriden_value"));
150151
assertEquals("This value is expected to be overriden from 9081 to 1111", "1111", props.get("http.port"));
152+
153+
//4. validate predefined variables
154+
assertEquals(serverDir.getCanonicalPath(), props.get(ServerFeatureUtil.SERVER_CONFIG_DIR));
155+
assertEquals(wlpUserDir.getCanonicalPath(), props.get(ServerFeatureUtil.WLP_USER_DIR));
156+
assertEquals(wlpInstallDir.getCanonicalPath(), props.get(ServerFeatureUtil.WLP_INSTALL_DIR));
157+
assertEquals(serverDir.getCanonicalPath(), props.get(ServerFeatureUtil.SERVER_OUTPUT_DIR));
151158
}
152159

153160
// 3. bootstrap.properties
@@ -216,6 +223,7 @@ public void initializeAppsLocationTest() throws PluginExecutionException {
216223
File serverConfigDir = SERVER_CONFIG_DIR.toFile();
217224
Map<String, File> libertyDirPropMap = new HashMap<String, File>();
218225
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir);
226+
libertyDirPropMap.put(ServerFeatureUtil.SERVER_OUTPUT_DIR, serverConfigDir);
219227
libertyDirPropMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, WLP_DIR.toFile());
220228
libertyDirPropMap.put(ServerFeatureUtil.WLP_USER_DIR, WLP_USER_DIR.toFile());
221229
libertyDirPropMap.put(ServerFeatureUtil.SHARED_CONFIG_DIR, SHARED_CONFIG_DIR.toFile());
@@ -273,10 +281,11 @@ public void testProcessServerXmlWithMultipleSpringBootNodes() throws IOException
273281
@Test
274282
public void testServerConfigDocumentForLCLS() throws IOException, PluginExecutionException {
275283
ServerConfigDocument configDocument = new ServerConfigDocument(new TestLogger(), null,
276-
WLP_DIR.toFile(),WLP_USER_DIR.toFile(),SERVER_CONFIG_DIR.toFile());
277-
assertEquals("ServerConfigDocument Liberty Property file map is not created properly ", 8, configDocument.getLibertyDirPropertyFiles().size());
284+
WLP_DIR.toFile(), WLP_USER_DIR.toFile(), SERVER_CONFIG_DIR.toFile(), SERVER_CONFIG_DIR.toFile());
285+
assertEquals("ServerConfigDocument Liberty Property file map is not created properly ", 9, configDocument.getLibertyDirPropertyFiles().size());
278286
assertEquals("ServerConfigDocument http.port variable is not assigned properly ", "1111", configDocument.getProperties().getProperty("http.port"));
279287
assertEquals("ServerConfigDocument includeLocation default property is not assigned properly ", "includes", configDocument.getDefaultProperties().getProperty("includeLocation"));
288+
assertEquals("ServerConfigDocument ${server.config.dir} property is not assigned properly ", SERVER_CONFIG_DIR.toFile().getCanonicalPath(), configDocument.getProperties().getProperty(ServerFeatureUtil.SERVER_CONFIG_DIR));
280289
}
281290

282291
@Test
@@ -285,6 +294,7 @@ public void testProcessServerXmlWithMultipleSpringBootNodesInMultipleConfigFiles
285294
File serverConfigDir = SERVER_CONFIG_DIR.toFile();
286295
Map<String, File> libertyDirPropMap = new HashMap<String, File>();
287296
libertyDirPropMap.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverConfigDir);
297+
libertyDirPropMap.put(ServerFeatureUtil.SERVER_OUTPUT_DIR, serverConfigDir);
288298
libertyDirPropMap.put(ServerFeatureUtil.WLP_INSTALL_DIR, WLP_DIR.toFile());
289299
libertyDirPropMap.put(ServerFeatureUtil.WLP_USER_DIR, WLP_USER_DIR.toFile());
290300
libertyDirPropMap.put(ServerFeatureUtil.SHARED_CONFIG_DIR, SHARED_CONFIG_DIR.toFile());

src/test/java/io/openliberty/tools/common/plugins/util/LibertyPropFilesUtilityTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class LibertyPropFilesUtilityTest {
3737
File sharedStackGroupDir;
3838
File sharedAppDir;
3939
File sharedConfigDir;
40+
File serverOutputDir;
4041

4142
@Before
4243
public void setUp() throws IOException {
@@ -48,12 +49,13 @@ public void setUp() throws IOException {
4849
sharedStackGroupDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/shared/stackGroups");
4950
sharedAppDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/shared/app");
5051
sharedConfigDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/shared/config");
52+
serverOutputDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer");
5153
}
5254

5355
@Test
5456
public void testGetLibertyDirectoryPropertyFiles() throws Exception {
5557

56-
Map<String, File> libProperties = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new TestLogger(), installDir, userDir, serverDir);
58+
Map<String, File> libProperties = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new TestLogger(), installDir, userDir, serverDir, serverOutputDir);
5759
// verify the libPropFiles
5860
assertFalse("Liberty Directory Property files map should not be empty", libProperties.isEmpty());
5961
assertEquals(libProperties.get(ServerFeatureUtil.WLP_INSTALL_DIR).getCanonicalPath(), installDir.getCanonicalPath());
@@ -71,12 +73,12 @@ public void testGetLibertyDirectoryPropertyFiles() throws Exception {
7173
public void testGetLibertyDirectoryPropertyFilesEmptyResult() throws Exception {
7274

7375
Map<String, File> libProperties = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new TestLogger(), installDir, userDir,
74-
new File("src/test/resources/invalidPath"));
76+
new File("src/test/resources/invalidPath"), serverOutputDir);
7577
// should be empty because serverDir does not exist
7678
assertTrue("Liberty Directory Property files map should be empty since invalid serverDirectory is specified",
7779
libProperties.isEmpty());
7880

79-
libProperties = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new TestLogger(), installDir, new File("src/test/resources/invalidPath\u0000"), serverDir);
81+
libProperties = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new TestLogger(), installDir, new File("src/test/resources/invalidPath\u0000"), serverDir, serverOutputDir);
8082

8183
// verify the libPropFiles
8284
assertTrue("Liberty Directory Property files map should be empty since invalid userDirectory is specified",

0 commit comments

Comments
 (0)