Skip to content

Commit 6f2658d

Browse files
committed
support Q2 arguments via q2.args environment
1 parent c03744f commit 6f2658d

File tree

1 file changed

+25
-11
lines changed
  • jpos/src/main/java/org/jpos/q2

1 file changed

+25
-11
lines changed

jpos/src/main/java/org/jpos/q2/Q2.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
import java.util.*;
8181
import java.util.concurrent.CountDownLatch;
8282
import java.util.concurrent.TimeUnit;
83+
import java.util.stream.Stream;
84+
8385
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
8486
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
8587
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
@@ -161,10 +163,11 @@ public class Q2 implements FileFilter, Runnable {
161163
private long shutdownHookDelay = 0L;
162164
public Q2 (String[] args) {
163165
super();
164-
this.args = args;
166+
parseCmdLine (args, true);
167+
this.args = environmentArgs(args);
165168
startTime = Instant.now();
166169
instanceId = UUID.randomUUID();
167-
parseCmdLine (args);
170+
parseCmdLine (this.args, false);
168171
libDir = new File (deployDir, "lib");
169172
dirMap = new TreeMap<>();
170173
deployDir.mkdirs ();
@@ -710,7 +713,7 @@ private static String getLicensee() {
710713
}
711714
return s;
712715
}
713-
private void parseCmdLine (String[] args) {
716+
private void parseCmdLine (String[] args, boolean environmentOnly) {
714717
CommandLineParser parser = new DefaultParser ();
715718

716719
Options options = new Options ();
@@ -743,6 +746,17 @@ private void parseCmdLine (String[] args) {
743746
System.setProperty("log4j2.formatMsgNoLookups", "true"); // log4shell prevention
744747

745748
CommandLine line = parser.parse (options, args);
749+
// set up envdir and env before other parts of the system, so env is available
750+
// force reload if any of the env options was changed
751+
if (line.hasOption("Ed")) {
752+
System.setProperty("jpos.envdir", line.getOptionValue("Ed"));
753+
}
754+
if (line.hasOption("E")) {
755+
System.setProperty("jpos.env", ISOUtil.commaEncode(line.getOptionValues("E")));
756+
}
757+
758+
if (environmentOnly)
759+
746760
if (line.hasOption ("v")) {
747761
displayVersion();
748762
System.exit (0);
@@ -753,14 +767,6 @@ private void parseCmdLine (String[] args) {
753767
System.exit (0);
754768
}
755769

756-
// set up envdir and env before other parts of the system, so env is available
757-
// force reload if any of the env options was changed
758-
if (line.hasOption("Ed")) {
759-
System.setProperty("jpos.envdir", line.getOptionValue("Ed"));
760-
}
761-
if (line.hasOption("E")) {
762-
System.setProperty("jpos.env", ISOUtil.commaEncode(line.getOptionValues("E")));
763-
}
764770

765771
if (line.hasOption ("c")) {
766772
cli = new CLI(this, line.getOptionValue("c"), line.hasOption("i"));
@@ -1237,4 +1243,12 @@ private void registerMicroMeter () {
12371243
new JvmThreadMetrics().bindTo(meterRegistry);
12381244
meterRegistry.add (prometheusRegistry);
12391245
}
1246+
1247+
public String[] environmentArgs (String[] args) {
1248+
String envArgs = Environment.getEnvironment().getProperty("${q2.args}", null);
1249+
return (envArgs != null ?
1250+
Stream.concat(
1251+
Arrays.stream(ISOUtil.commaDecode(envArgs)), Arrays.stream(args))
1252+
.toArray(String[]::new) : args);
1253+
}
12401254
}

0 commit comments

Comments
 (0)