-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #465 from arunvenmany-ibm/varProcessing_lcls
Var processing lcls
- Loading branch information
Showing
5 changed files
with
175 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/io/openliberty/tools/common/plugins/util/LibertyPropFilesUtility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* (C) Copyright IBM Corporation 2024 | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.openliberty.tools.common.plugins.util; | ||
|
||
import io.openliberty.tools.common.CommonLoggerI; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class LibertyPropFilesUtility { | ||
|
||
|
||
public static Map<String, File> getLibertyDirectoryPropertyFiles(CommonLoggerI log, File installDir, File userDir, File serverDir) { | ||
Map<String, File> libertyDirectoryPropertyToFile = new HashMap<>(); | ||
|
||
if (serverDir.exists()) { | ||
try { | ||
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SERVER_CONFIG_DIR, serverDir.getCanonicalFile()); | ||
|
||
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.WLP_INSTALL_DIR, installDir.getCanonicalFile()); | ||
|
||
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.WLP_USER_DIR, userDir.getCanonicalFile()); | ||
|
||
File userExtDir = new File(userDir, "extension"); | ||
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.USR_EXTENSION_DIR, userExtDir.getCanonicalFile()); | ||
|
||
File userSharedDir = new File(userDir, "shared"); | ||
File userSharedAppDir = new File(userSharedDir, "app"); | ||
File userSharedConfigDir = new File(userSharedDir, "config"); | ||
File userSharedResourcesDir = new File(userSharedDir, "resources"); | ||
File userSharedStackGroupsDir = new File(userSharedDir, "stackGroups"); | ||
|
||
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_APP_DIR, userSharedAppDir.getCanonicalFile()); | ||
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_CONFIG_DIR, userSharedConfigDir.getCanonicalFile()); | ||
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_RESOURCES_DIR, userSharedResourcesDir.getCanonicalFile()); | ||
libertyDirectoryPropertyToFile.put(ServerFeatureUtil.SHARED_STACKGROUP_DIR, userSharedStackGroupsDir.getCanonicalFile()); | ||
|
||
return libertyDirectoryPropertyToFile; | ||
} catch (Exception e) { | ||
log.warn("The properties for directories could not be initialized because an error occurred when accessing the directories."); | ||
log.debug("Exception received: " + e.getMessage(), e); | ||
} | ||
} else { | ||
log.warn("The " + serverDir + " directory cannot be accessed. The properties for directories could not be initialized."); | ||
} | ||
return Collections.emptyMap(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/io/openliberty/tools/common/plugins/util/LibertyPropFilesUtilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* (C) Copyright IBM Corporation 2024. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.openliberty.tools.common.plugins.util; | ||
|
||
import io.openliberty.tools.common.TestLogger; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class LibertyPropFilesUtilityTest { | ||
|
||
File serverDir; | ||
File installDir; | ||
File userDir; | ||
File userExtensionDir; | ||
File sharedResourceDir; | ||
File sharedStackGroupDir; | ||
File sharedAppDir; | ||
File sharedConfigDir; | ||
|
||
@Before | ||
public void setUp() throws IOException { | ||
serverDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/servers/defaultServer"); | ||
installDir = new File("src/test/resources/serverConfig/liberty/wlp"); | ||
userDir = new File("src/test/resources/serverConfig/liberty/wlp/usr"); | ||
userExtensionDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/extension"); | ||
sharedResourceDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/shared/resources"); | ||
sharedStackGroupDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/shared/stackGroups"); | ||
sharedAppDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/shared/app"); | ||
sharedConfigDir = new File("src/test/resources/serverConfig/liberty/wlp/usr/shared/config"); | ||
} | ||
|
||
@Test | ||
public void testGetLibertyDirectoryPropertyFiles() throws Exception { | ||
|
||
Map<String, File> libProperties = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new TestLogger(), installDir, userDir, serverDir); | ||
// verify the libPropFiles | ||
assertFalse("Liberty Directory Property files map should not be empty", libProperties.isEmpty()); | ||
assertEquals(libProperties.get(ServerFeatureUtil.WLP_INSTALL_DIR).getCanonicalPath(), installDir.getCanonicalPath()); | ||
assertEquals(libProperties.get(ServerFeatureUtil.WLP_USER_DIR).getCanonicalPath(), userDir.getCanonicalPath()); | ||
assertEquals(libProperties.get(ServerFeatureUtil.SERVER_CONFIG_DIR).getCanonicalPath(), serverDir.getCanonicalPath()); | ||
assertEquals(libProperties.get(ServerFeatureUtil.USR_EXTENSION_DIR).getCanonicalPath(), userExtensionDir.getCanonicalPath()); | ||
assertEquals(libProperties.get(ServerFeatureUtil.SHARED_CONFIG_DIR).getCanonicalPath(), sharedConfigDir.getCanonicalPath()); | ||
assertEquals(libProperties.get(ServerFeatureUtil.SHARED_APP_DIR).getCanonicalPath(), sharedAppDir.getCanonicalPath()); | ||
assertEquals(libProperties.get(ServerFeatureUtil.SHARED_RESOURCES_DIR).getCanonicalPath(), sharedResourceDir.getCanonicalPath()); | ||
assertEquals(libProperties.get(ServerFeatureUtil.SHARED_STACKGROUP_DIR).getCanonicalPath(), sharedStackGroupDir.getCanonicalPath()); | ||
|
||
} | ||
|
||
@Test | ||
public void testGetLibertyDirectoryPropertyFilesEmptyResult() throws Exception { | ||
|
||
Map<String, File> libProperties = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new TestLogger(), installDir, userDir, | ||
new File("src/test/resources/invalidPath")); | ||
// should be empty because serverDir does not exist | ||
assertTrue("Liberty Directory Property files map should be empty since invalid serverDirectory is specified", | ||
libProperties.isEmpty()); | ||
|
||
libProperties = LibertyPropFilesUtility.getLibertyDirectoryPropertyFiles(new TestLogger(), installDir, new File("src/test/resources/invalidPath\u0000"), serverDir); | ||
|
||
// verify the libPropFiles | ||
assertTrue("Liberty Directory Property files map should be empty since invalid userDirectory is specified", | ||
libProperties.isEmpty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters