|
42 | 42 | exit 1 |
43 | 43 | fi |
44 | 44 |
|
| 45 | +# Cache `java -jar cmdline.jar help [...]` output to avoid paying JVM startup |
| 46 | +# (typically 150-500ms) for the capability probes on every encrypt/decrypt. |
| 47 | +# Keyed by the jar's mtime so a reinstall invalidates the cache. stderr is |
| 48 | +# discarded to keep JVM warnings (reflective-access, agent notices) out of logs. |
| 49 | +jar_help() { |
| 50 | + local jar="$SCRIPT_DIR/cmdline.jar" |
| 51 | + local mtime |
| 52 | + mtime=$(stat -c %Y "$jar" 2>/dev/null || stat -f %m "$jar" 2>/dev/null || echo 0) |
| 53 | + local key |
| 54 | + key=$(printf '%s' "$*" | tr -c 'a-zA-Z0-9' '_') |
| 55 | + local uid |
| 56 | + uid=$(id -u 2>/dev/null || echo default) |
| 57 | + local cache="${TMPDIR:-/tmp}/xtest-java-help-${uid}-${mtime}-${key}" |
| 58 | + if [ ! -f "$cache" ]; then |
| 59 | + java -jar "$jar" help "$@" >"$cache" 2>/dev/null |
| 60 | + fi |
| 61 | + cat "$cache" |
| 62 | +} |
| 63 | + |
45 | 64 | if [ "$1" == "supports" ]; then |
46 | 65 | case "$2" in |
47 | 66 | autoconfigure | ns_grants) |
@@ -130,7 +149,7 @@ args=( |
130 | 149 | ) |
131 | 150 |
|
132 | 151 | # when we added support for KAS allowlist, we changed the platform endpoint format to require scheme |
133 | | -if java -jar "$SCRIPT_DIR"/cmdline.jar help decrypt | grep kas-allowlist; then |
| 152 | +if jar_help decrypt | grep -q kas-allowlist; then |
134 | 153 | args+=("--platform-endpoint=$PLATFORMURL") |
135 | 154 | else |
136 | 155 | args+=("--platform-endpoint=$PLATFORMENDPOINT") |
@@ -192,7 +211,7 @@ if [ -n "$XT_WITH_TARGET_MODE" ]; then |
192 | 211 | args+=(--with-target-mode "$XT_WITH_TARGET_MODE") |
193 | 212 | fi |
194 | 213 |
|
195 | | -if java -jar "$SCRIPT_DIR"/cmdline.jar help | grep -q -- '--verbose'; then |
| 214 | +if jar_help | grep -q -- '--verbose'; then |
196 | 215 | args+=(--verbose) |
197 | 216 | fi |
198 | 217 |
|
|
0 commit comments