Add database configuration via command-line arguments

A new configuration setup now allows specifying a path for database properties via command-line arguments during application startup. This update also changes the call signature for `DatabaseConnection.initialize()` method to accept a path argument. Similarly, methods in `PropertiesLoader`, `PropertiesWriter`, and `MailSettings` classes were also updated to use the specified path when working with properties files. The `TestForm` class's tests were updated accordingly to handle these changes.
This commit is contained in:
2024-04-28 21:25:09 +02:00
parent 2f1d24598b
commit 49af4a3067
8 changed files with 150 additions and 66 deletions
@@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Properties;
@@ -13,15 +15,21 @@ public class PropertiesLoader {
private static final Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
public static Optional<Properties> loadProperties(String fileName) {
public static Optional<Properties> loadProperties(String path, String fileName) {
Properties prop = new Properties();
Optional<File> currentJarPath = JarPath.getCurrentJarDir();
if (currentJarPath.isEmpty()) {
logger.error("Unable to find jar path to load properties (" + fileName + ")");
return Optional.empty();
File file;
if (path.isEmpty()) {
Optional<File> currentJarPath = JarPath.getCurrentJarDir();
if (currentJarPath.isEmpty()) {
logger.error("Unable to find jar path to load properties (" + fileName + ")");
return Optional.empty();
}
file = new File(currentJarPath.get(), fileName);
} else {
file = Path.of(URI.create("file://" + path + File.separator + fileName)).toFile();
}
File file = new File(currentJarPath.get(), fileName);
if (!file.exists()) {
logger.warn("Tried to load properties file that doesnt exists (" + fileName + ")");
return Optional.empty();