-
Notifications
You must be signed in to change notification settings - Fork 3
/
dumpling.sh
executable file
·90 lines (81 loc) · 3.19 KB
/
dumpling.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
# https://github.com/olivergondza/bash-strict-mode
set -euo pipefail
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
#
# The MIT License
#
# Copyright (c) 2014 Red Hat, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# CLI Dumpling wrapper for unix. Read more: https://olivergondza.github.io/dumpling/cli.html
function download() {
url_prefix="https://oss.sonatype.org/content/repositories/releases/com/github/olivergondza/dumpling/dumpling-cli"
metadata_url="${url_prefix}/maven-metadata.xml"
latest=$(wget --no-check-certificate $metadata_url -O - 2> /dev/null | grep \<version\> | sed -e 's/^.*>\(.*\)<.*$/\1/' | tail -n 1)
jar_url="${url_prefix}/$latest/dumpling-cli-$latest-shaded.jar"
echo "Downloading Dumpling $latest now..." >&2
if ! wget --no-check-certificate -nv -O "$1" "$jar_url"; then
echo "Download failed" >&2
rm -f "$1"
exit 1
fi
}
function working_java() {
"$1" -version > /dev/null 2>&1
}
function run_java() {
exe=""
if working_java "java"; then
exe="java"
else
# Find interpreter examining running processes
candidates=$(ps -ef | awk '{ print $8 }' | grep bin/java\\b)
for candidate in "$candidates"; do
if working_java "$candidate"; then
exe=$candidate
break
fi
done
if [ "$exe" == "" ]; then
echo "No java interpreter found. Make sure there is one on PATH" >&2
exit 1
fi
fi
$exe "$@"
}
dir="$( cd "$( dirname "$0" )" && pwd )"
cli="$dir/cli"
if [ "$(ls "$cli"/target/dumpling-*-shaded.jar 2> /dev/null | wc -l)" != 1 ]; then
if grep -q "com.github.olivergondza.dumpling.cli.Main" "$cli/pom.xml" 2> /dev/null; then
echo "No dumpling.jar found, building it now..." >&2
mvn -q clean package -DskipTests
jar="$(ls "$cli"/target/dumpling-*-shaded.jar | head -n 1)"
else
jar="$dir/dumpling.jar"
if [ ! -f "$jar" ]; then
download "$jar"
fi
fi
else
jar="$(ls "$cli"/target/dumpling-*-shaded.jar | head -n 1)"
fi
# Performance optimization for single runtime queries, provide DUMPLING_OPTS to override
: ${DUMPLING_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xmx256M -Xms256M"}
run_java $DUMPLING_OPTS -jar "$jar" "$@"