Refactor Path Handling (#3041)
# Description of Changes Please provide a summary of the changes, including: What was changed: - Refactored path constructions in multiple classes (e.g., SPDFApplication.java, InstallationPathConfig.java, RuntimePathConfig.java) to use Java NIO’s Paths.get() and Path.of() instead of manual string concatenation. Why the change was made: - To improve code readability, maintainability, and robustness by leveraging modern Java NIO utilities. - To ensure better portability across different operating systems by avoiding hardcoded file separators. Challenges encountered: - Maintaining backward compatibility while transitioning from manual string concatenation to using Paths for file path construction. - Ensuring that the refactored path resolution works consistently across all supported environments (Windows, macOS, Linux, and Docker). @Frooodle can you check the docker path `/.dockerenv`? --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
This commit is contained in:
@@ -83,18 +83,17 @@ public class SPDFApplication {
|
||||
Map<String, String> propertyFiles = new HashMap<>();
|
||||
|
||||
// External config files
|
||||
log.info("Settings file: {}", InstallationPathConfig.getSettingsPath());
|
||||
if (Files.exists(Paths.get(InstallationPathConfig.getSettingsPath()))) {
|
||||
propertyFiles.put(
|
||||
"spring.config.additional-location",
|
||||
"file:" + InstallationPathConfig.getSettingsPath());
|
||||
String settingsPath = InstallationPathConfig.getSettingsPath();
|
||||
log.info("Settings file: {}", settingsPath);
|
||||
if (Files.exists(Paths.get(settingsPath))) {
|
||||
propertyFiles.put("spring.config.additional-location", "file:" + settingsPath);
|
||||
} else {
|
||||
log.warn(
|
||||
"External configuration file '{}' does not exist.",
|
||||
InstallationPathConfig.getSettingsPath());
|
||||
log.warn("External configuration file '{}' does not exist.", settingsPath);
|
||||
}
|
||||
|
||||
if (Files.exists(Paths.get(InstallationPathConfig.getCustomSettingsPath()))) {
|
||||
String customSettingsPath = InstallationPathConfig.getCustomSettingsPath();
|
||||
log.info("Custom settings file: {}", customSettingsPath);
|
||||
if (Files.exists(Paths.get(customSettingsPath))) {
|
||||
String existingLocation =
|
||||
propertyFiles.getOrDefault("spring.config.additional-location", "");
|
||||
if (!existingLocation.isEmpty()) {
|
||||
@@ -102,11 +101,9 @@ public class SPDFApplication {
|
||||
}
|
||||
propertyFiles.put(
|
||||
"spring.config.additional-location",
|
||||
existingLocation + "file:" + InstallationPathConfig.getCustomSettingsPath());
|
||||
existingLocation + "file:" + customSettingsPath);
|
||||
} else {
|
||||
log.warn(
|
||||
"Custom configuration file '{}' does not exist.",
|
||||
InstallationPathConfig.getCustomSettingsPath());
|
||||
log.warn("Custom configuration file '{}' does not exist.", customSettingsPath);
|
||||
}
|
||||
Properties finalProps = new Properties();
|
||||
|
||||
@@ -128,7 +125,7 @@ public class SPDFApplication {
|
||||
try {
|
||||
Files.createDirectories(Path.of(InstallationPathConfig.getTemplatesPath()));
|
||||
Files.createDirectories(Path.of(InstallationPathConfig.getStaticPath()));
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
log.error("Error creating directories: {}", e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user