-
Notifications
You must be signed in to change notification settings - Fork 985
Expand file tree
/
Copy pathrun-example.sh
More file actions
executable file
·99 lines (87 loc) · 2.81 KB
/
run-example.sh
File metadata and controls
executable file
·99 lines (87 loc) · 2.81 KB
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
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
# ====================================================================
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ====================================================================
#
# This software consists of voluntary contributions made by many
# individuals on behalf of the Apache Software Foundation. For more
# information on the Apache Software Foundation, please see
# <http://www.apache.org/>.
set -e
usage() {
cat <<EOF
usage: $(basename "$0") [-p project] [class] [-- args]
-p project module name (default: httpclient5)
-h, --help show this help
-v, --verbose print the full Java invocation
if class omitted, list available examples.
samples:
./run-example.sh ReactiveClientFullDuplexExchange
./run-example.sh ClientChunkEncodedPost pom.xml
./run-example.sh -p httpclient5-fluent FluentAsync
EOF
}
project=httpclient5
verbose=false
# parse options
while [[ $# -gt 0 ]]; do
case $1 in
-p) project=$2; shift 2;;
-h|--help) usage; exit 0;;
-v|--verbose) verbose=true; shift;;
--) shift; break;;
-*)
echo "unknown option: $1" >&2
usage >&2
exit 1
;;
*) break;;
esac
done
classname=$1
shift || true
args=("$@")
# list examples if no classname
if [[ -z $classname ]]; then
find "$project/src/test/java" -type f -name '*.java' | grep '/examples/' \
| sed -e 's|\.java$||' \
| xargs basename | sort
exit 0
fi
# compile tests and build classpath
cpfile=$(mktemp)
trap 'rm -f "$cpfile"' EXIT
./mvnw -q -pl "$project" -am test-compile dependency:build-classpath \
-DincludeScope=test -Dmdep.outputFile="$cpfile"
# assemble classpath
cp="$project/target/test-classes:$project/target/classes:$(cat "$cpfile")"
# find fully qualified classname
fqn=$(find "$project/src/test/java" -name "${classname}.java" | head -n1)
if [[ -z $fqn ]]; then
echo "example not found: $classname" >&2
usage >&2
exit 1
fi
fqn=${fqn#"$project/src/test/java/"}
fqn=${fqn%.java}
fqn=${fqn//\//.}
# run it
if [[ "$verbose" = true ]]; then
echo java -cp "$cp" "$fqn" "${args[@]}" >&2
fi
java -cp "$cp" "$fqn" "${args[@]}"