From 59ca0851a958fc69088e148b6813637098a5ea6d Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Wed, 7 Jun 2023 19:21:23 -0400 Subject: [PATCH] Allow configuration dir to be overridden by system property --- .../java/com/github/theprez/manzan/ManzanMainApp.java | 8 ++++++++ .../github/theprez/manzan/configuration/Config.java | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/camel/src/main/java/com/github/theprez/manzan/ManzanMainApp.java b/camel/src/main/java/com/github/theprez/manzan/ManzanMainApp.java index f300416..e8e1e88 100644 --- a/camel/src/main/java/com/github/theprez/manzan/ManzanMainApp.java +++ b/camel/src/main/java/com/github/theprez/manzan/ManzanMainApp.java @@ -10,6 +10,7 @@ import com.github.theprez.jcmdutils.StringUtils; import com.github.theprez.manzan.configuration.ApplicationConfig; +import com.github.theprez.manzan.configuration.Config; import com.github.theprez.manzan.configuration.DataConfig; import com.github.theprez.manzan.configuration.DestinationConfig; import com.github.theprez.manzan.routes.ManzanRoute; @@ -33,6 +34,13 @@ public static void main(final String... _args) throws Exception { printVersionInfo(); return; } + + for(final String arg:_args) { + if(arg.startsWith("--configdir=")) { + System.setProperty(Config.DIRECTORY_OVERRIDE_PROPERTY, arg.replaceFirst("^[^=]+=", "")); + } + } + // Standard for a Camel deployment. Start by getting a CamelContext object. final CamelContext context = new DefaultCamelContext(); System.out.println("Apache Camel version " + context.getVersion()); diff --git a/camel/src/main/java/com/github/theprez/manzan/configuration/Config.java b/camel/src/main/java/com/github/theprez/manzan/configuration/Config.java index 9a4f15f..82843cd 100644 --- a/camel/src/main/java/com/github/theprez/manzan/configuration/Config.java +++ b/camel/src/main/java/com/github/theprez/manzan/configuration/Config.java @@ -10,13 +10,22 @@ public abstract class Config { + public static final String DIRECTORY_OVERRIDE_PROPERTY = "manzan.configdir"; + protected static boolean isIBMi() { final String osName = System.getProperty("os.name", "Misty"); return "os400".equalsIgnoreCase(osName) || "os/400".equalsIgnoreCase(osName); } protected static File getConfigFile(final String _name) throws IOException { - final File configDir = isIBMi() ? new File("/QOpenSys/etc/manzan") : new File(".").getAbsoluteFile(); + final File configDir; + final String configDirOverride = System.getProperty(DIRECTORY_OVERRIDE_PROPERTY); + if(StringUtils.isNonEmpty(configDirOverride)) { + configDir = new File(configDirOverride).getAbsoluteFile(); + } else { + configDir = isIBMi() ? new File("/QOpenSys/etc/manzan") : new File(".").getAbsoluteFile(); + } + if (!configDir.isDirectory()) { if (!configDir.mkdirs()) { throw new IOException("Cound not create configuration directory " + configDir.getAbsolutePath());