Skip to content

Commit

Permalink
Allow configuration dir to be overridden by system property
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePrez committed Dec 30, 2023
1 parent 89472e8 commit 59ca085
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 59ca085

Please sign in to comment.