diff --git a/src/main/java/stirling/software/SPDF/SPDFApplication.java b/src/main/java/stirling/software/SPDF/SPDFApplication.java index 61dfaddd..02b621fa 100644 --- a/src/main/java/stirling/software/SPDF/SPDFApplication.java +++ b/src/main/java/stirling/software/SPDF/SPDFApplication.java @@ -83,18 +83,17 @@ public class SPDFApplication { Map 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()); } diff --git a/src/main/java/stirling/software/SPDF/config/InstallationPathConfig.java b/src/main/java/stirling/software/SPDF/config/InstallationPathConfig.java index af6076a9..557a152e 100644 --- a/src/main/java/stirling/software/SPDF/config/InstallationPathConfig.java +++ b/src/main/java/stirling/software/SPDF/config/InstallationPathConfig.java @@ -1,6 +1,7 @@ package stirling.software.SPDF.config; import java.io.File; +import java.nio.file.Paths; import lombok.extern.slf4j.Slf4j; @@ -46,26 +47,29 @@ public class InstallationPathConfig { if (Boolean.parseBoolean(System.getProperty("STIRLING_PDF_DESKTOP_UI", "false"))) { String os = System.getProperty("os.name").toLowerCase(); if (os.contains("win")) { - return System.getenv("APPDATA") + File.separator + "Stirling-PDF" + File.separator; + return Paths.get( + System.getenv("APPDATA"), // parent path + "Stirling-PDF") + .toString() + + File.separator; } else if (os.contains("mac")) { - return System.getProperty("user.home") - + File.separator - + "Library" - + File.separator - + "Application Support" - + File.separator - + "Stirling-PDF" + return Paths.get( + System.getProperty("user.home"), + "Library", + "Application Support", + "Stirling-PDF") + .toString() + File.separator; } else { - return System.getProperty("user.home") - + File.separator - + ".config" - + File.separator - + "Stirling-PDF" + return Paths.get( + System.getProperty("user.home"), // parent path + ".config", + "Stirling-PDF") + .toString() + File.separator; } } - return "./"; + return "." + File.separator; } public static String getPath() { diff --git a/src/main/java/stirling/software/SPDF/config/RuntimePathConfig.java b/src/main/java/stirling/software/SPDF/config/RuntimePathConfig.java index 3ad42732..037c1dde 100644 --- a/src/main/java/stirling/software/SPDF/config/RuntimePathConfig.java +++ b/src/main/java/stirling/software/SPDF/config/RuntimePathConfig.java @@ -1,8 +1,7 @@ package stirling.software.SPDF.config; -import java.io.File; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Configuration; @@ -33,52 +32,48 @@ public class RuntimePathConfig { this.properties = properties; this.basePath = InstallationPathConfig.getPath(); - String pipelinePath = basePath + "pipeline" + File.separator; - String watchedFoldersPath = pipelinePath + "watchedFolders" + File.separator; - String finishedFoldersPath = pipelinePath + "finishedFolders" + File.separator; - String webUiConfigsPath = pipelinePath + "defaultWebUIConfigs" + File.separator; + this.pipelinePath = Path.of(basePath, "pipeline").toString(); + String defaultWatchedFolders = Path.of(this.pipelinePath, "watchedFolders").toString(); + String defaultFinishedFolders = Path.of(this.pipelinePath, "finishedFolders").toString(); + String defaultWebUIConfigs = Path.of(this.pipelinePath, "defaultWebUIConfigs").toString(); Pipeline pipeline = properties.getSystem().getCustomPaths().getPipeline(); - if (pipeline != null) { - if (!StringUtils.isEmpty(pipeline.getWatchedFoldersDir())) { - watchedFoldersPath = pipeline.getWatchedFoldersDir(); - } - if (!StringUtils.isEmpty(pipeline.getFinishedFoldersDir())) { - finishedFoldersPath = pipeline.getFinishedFoldersDir(); - } - if (!StringUtils.isEmpty(pipeline.getWebUIConfigsDir())) { - webUiConfigsPath = pipeline.getWebUIConfigsDir(); - } - } - this.pipelinePath = pipelinePath; - this.pipelineWatchedFoldersPath = watchedFoldersPath; - this.pipelineFinishedFoldersPath = finishedFoldersPath; - this.pipelineDefaultWebUiConfigs = webUiConfigsPath; + this.pipelineWatchedFoldersPath = + resolvePath( + defaultWatchedFolders, + pipeline != null ? pipeline.getWatchedFoldersDir() : null); + this.pipelineFinishedFoldersPath = + resolvePath( + defaultFinishedFolders, + pipeline != null ? pipeline.getFinishedFoldersDir() : null); + this.pipelineDefaultWebUiConfigs = + resolvePath( + defaultWebUIConfigs, + pipeline != null ? pipeline.getWebUIConfigsDir() : null); boolean isDocker = isRunningInDocker(); // Initialize Operation paths - String weasyPrintPath = isDocker ? "/opt/venv/bin/weasyprint" : "weasyprint"; - String unoConvertPath = isDocker ? "/opt/venv/bin/unoconvert" : "unoconvert"; + String defaultWeasyPrintPath = isDocker ? "/opt/venv/bin/weasyprint" : "weasyprint"; + String defaultUnoConvertPath = isDocker ? "/opt/venv/bin/unoconvert" : "unoconvert"; - // Check for custom operation paths Operations operations = properties.getSystem().getCustomPaths().getOperations(); - if (operations != null) { - if (!StringUtils.isEmpty(operations.getWeasyprint())) { - weasyPrintPath = operations.getWeasyprint(); - } - if (!StringUtils.isEmpty(operations.getUnoconvert())) { - unoConvertPath = operations.getUnoconvert(); - } - } + this.weasyPrintPath = + resolvePath( + defaultWeasyPrintPath, + operations != null ? operations.getWeasyprint() : null); + this.unoConvertPath = + resolvePath( + defaultUnoConvertPath, + operations != null ? operations.getUnoconvert() : null); + } - // Assign operations final fields - this.weasyPrintPath = weasyPrintPath; - this.unoConvertPath = unoConvertPath; + private String resolvePath(String defaultPath, String customPath) { + return StringUtils.isNotBlank(customPath) ? customPath : defaultPath; } private boolean isRunningInDocker() { - return Files.exists(Paths.get("/.dockerenv")); + return Files.exists(Path.of("/.dockerenv")); } } diff --git a/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java b/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java index 704fd013..ba4a02f0 100644 --- a/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java +++ b/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java @@ -1,7 +1,5 @@ package stirling.software.SPDF.config.security.database; -import java.io.File; - import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Qualifier; @@ -37,8 +35,8 @@ public class DatabaseConfig { DATASOURCE_DEFAULT_URL = "jdbc:h2:file:" + InstallationPathConfig.getConfigPath() - + File.separator + "stirling-pdf-DB-2.3.232;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"; + log.debug("Database URL: {}", DATASOURCE_DEFAULT_URL); this.applicationProperties = applicationProperties; this.runningEE = runningEE; } diff --git a/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java b/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java index fb6e43eb..34202cff 100644 --- a/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java +++ b/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java @@ -230,7 +230,11 @@ public class GeneralWebController { // Extract font names from external directory fontNames.addAll( getFontNamesFromLocation( - "file:" + InstallationPathConfig.getStaticPath() + "fonts/*")); + "file:" + + InstallationPathConfig.getStaticPath() + + "fonts" + + File.separator + + "*")); return fontNames; } diff --git a/src/main/java/stirling/software/SPDF/utils/FileMonitor.java b/src/main/java/stirling/software/SPDF/utils/FileMonitor.java index 6a815d8c..214f430e 100644 --- a/src/main/java/stirling/software/SPDF/utils/FileMonitor.java +++ b/src/main/java/stirling/software/SPDF/utils/FileMonitor.java @@ -49,7 +49,8 @@ public class FileMonitor { this.pathFilter = pathFilter; this.readyForProcessingFiles = ConcurrentHashMap.newKeySet(); this.watchService = FileSystems.getDefault().newWatchService(); - this.rootDir = Path.of(runtimePathConfig.getPipelineWatchedFoldersPath()).toAbsolutePath(); + log.info("Monitoring directory: {}", runtimePathConfig.getPipelineWatchedFoldersPath()); + this.rootDir = Path.of(runtimePathConfig.getPipelineWatchedFoldersPath()); } private boolean shouldNotProcess(Path path) {