updated java_show_classpath.sh

master
Hari Sekhon 3 days ago
parent 567fc35ab8
commit 86941e1d85

@ -56,7 +56,7 @@ fi
#fi #fi
is_jps_output(){ is_jps_output(){
# JPS output format # JPS output format
[[ "$1" =~ ^([[:digit:]]+)[[:space:]]+([[:alnum:]]*)$ ]] [[ "$1" =~ ^([[:digit:]]+)[[:space:]]+([[:alnum:]]*)$ ]]
} }
@ -69,22 +69,22 @@ show_cli_classpath(){
[[ "$cmd" =~ java ]] || return [[ "$cmd" =~ java ]] || return
args="${cmd#*java }" args="${cmd#*java }"
#cmd="$(replace_classpath_with_token "$cmd")" #cmd="$(replace_classpath_with_token "$cmd")"
echo echo
echo "command: $cmd" echo "command: $cmd"
echo echo
count=0 count=0
# XXX: will break upon directories in classpath containing a space, but this should be rare on unix systems # XXX: will break upon directories in classpath containing a space, but this should be rare on unix systems
classpaths="$(grep -Eo -- '-(cp|classpath)[=[:space:]]+(.+)[[:space:]]' <<< "$args" || die "Failed to find classpath in args '$args'")" classpaths="$(grep -Eo -- '-(cp|classpath)[=[:space:]]+(.+)[[:space:]]' <<< "$args" || die "Failed to find classpath in args '$args'")"
classpaths="${classpaths## }" classpaths="${classpaths## }"
classpaths="${classpaths##-cp}" classpaths="${classpaths##-cp}"
classpaths="${classpaths##-classpath}" classpaths="${classpaths##-classpath}"
classpaths="${classpaths##=}" classpaths="${classpaths##=}"
IFS=':' read -r -a classpaths <<< "$classpaths" IFS=':' read -r -a classpaths <<< "$classpaths"
for classpath in "${classpaths[@]}"; do for classpath in "${classpaths[@]}"; do
[ -z "$classpath" ] && continue [ -z "$classpath" ] && continue
echo "classpath: $classpath" echo "classpath: $classpath"
count=$((count + 1)) count=$((count + 1))
done done
[ $count -gt 0 ] && echo [ $count -gt 0 ] && echo
echo "$count classpath(s) found" echo "$count classpath(s) found"
echo echo
@ -97,7 +97,7 @@ show_jinfo_classpath(){
pid="${BASH_REMATCH[1]}" pid="${BASH_REMATCH[1]}"
# skip Jps itself which may be lingering in the process list from our call before this function # skip Jps itself which may be lingering in the process list from our call before this function
[ "${BASH_REMATCH[2]:-}" = Jps ] && return [ "${BASH_REMATCH[2]:-}" = Jps ] && return
if [ -z "${BASH_REMATCH[2]:-}" ]; then if [ -z "${BASH_REMATCH[2]:-}" ]; then
cmd+=" <embedded JVM no classname from JPS output>" cmd+=" <embedded JVM no classname from JPS output>"
fi fi
echo "JPS: $cmd" echo "JPS: $cmd"
@ -160,14 +160,14 @@ show_jinfo_classpath(){
} }
if ! process_list="$(jps 2>/dev/null)"; then if ! process_list="$(jps 2>/dev/null)"; then
echo "WARNING: jps failed, perhaps not in \$PATH? (\$PATH = $PATH)" >&2 echo "WARNING: jps failed, perhaps not in \$PATH? (\$PATH = $PATH)" >&2
echo "WARNING: Falling back to ps command, may be less accurate" >&2 echo "WARNING: Falling back to ps command, may be less accurate" >&2
process_list="$(ps -e -o pid,user,command)" process_list="$(ps -e -o pid,user,command)"
fi fi
while IFS= read -r line; do while IFS= read -r line; do
log "input: $line" log "input: $line"
if is_jps_output "$line"; then if is_jps_output "$line"; then
if [ -n "$command_regex" ]; then if [ -n "$command_regex" ]; then
if [[ "$line" =~ $command_regex ]]; then if [[ "$line" =~ $command_regex ]]; then
show_jinfo_classpath "$line" show_jinfo_classpath "$line"

Loading…
Cancel
Save