Skip to content

Commit eb037a7

Browse files
committed
broken
1 parent 21fd8a9 commit eb037a7

File tree

1 file changed

+171
-83
lines changed

1 file changed

+171
-83
lines changed

mvn-test-no-boilerplate.sh

Lines changed: 171 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,198 @@
1-
#!/bin/bash
2-
3-
# Strip Maven test boilerplate - show compile errors and test results only
4-
# Usage: ./mvn-test-no-boilerplate.sh [maven test arguments]
5-
#
6-
# Examples:
7-
# ./mvn-test-no-boilerplate.sh -Dtest=RefactorTests
8-
# ./mvn-test-no-boilerplate.sh -Dtest=RefactorTests#testList -Djava.util.logging.ConsoleHandler.level=INFO
9-
# ./mvn-test-no-boilerplate.sh -Dtest=RefactorTests#testList -Djava.util.logging.ConsoleHandler.level=FINER
1+
#!/bin/sh
102
#
11-
# For running tests in a specific module:
12-
# ./mvn-test-no-boilerplate.sh -pl json-java21-api-tracker -Dtest=CompilerApiLearningTest
13-
#
14-
# The script automatically detects if mvnd is available, otherwise falls back to mvn
15-
# Presets: pass a first arg token to run a curated flow. Currently supported:
16-
# run_schema_check_with_clean
17-
# - Cleans and then verifies only the json-java21-schema IT
18-
# - Runs JsonSchemaCheckIT in strict mode with CSV metrics
19-
# - Uses mvnd -q when available, prints DONE/FAILED based on exit status
20-
21-
# Detect if mvnd is available, otherwise use mvn
22-
if command -v mvnd &> /dev/null; then
23-
MVN_CMD="mvnd"
24-
else
25-
MVN_CMD="mvn"
3+
# Wrapper that trims Maven boilerplate output. Supports a preset to run the
4+
# strict JsonSchemaCheckIT with cleaning, metrics validation, and debugging.
5+
6+
set -eu
7+
8+
DEBUG=0
9+
if [ "${1-}" = "--debug" ]; then
10+
DEBUG=1
11+
shift
2612
fi
2713

28-
PRESET="$1"
29-
QUIET_FLAG=""
30-
DO_CLEAN=false
31-
MVN_ARGS=""
14+
if [ "$DEBUG" -eq 1 ]; then
15+
set -x
16+
fi
3217

33-
if [ "$PRESET" = "run_schema_check_with_clean" ]; then
34-
DO_CLEAN=true
35-
QUIET_FLAG="-q"
36-
# Ignore all user-supplied args for preset; use curated defaults
37-
echo "[INFO] Preset detected: run_schema_check_with_clean"
38-
echo "[INFO] Ignoring passed parameters; running curated schema IT flow"
39-
MVN_ARGS="-pl json-java21-schema -Dit.test=JsonSchemaCheckIT -Djson.schema.strict=true -Djson.schema.metrics=csv -Djava.util.logging.ConsoleHandler.level=INFO -DfailIfNoTests=false -e -DtrimStackTrace=false -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugins.failsafe=debug"
40-
shift # consume preset token
18+
if command -v mvnd >/dev/null 2>&1; then
19+
MVN_CMD="mvnd"
4120
else
42-
# No preset: forward all args as-is
43-
MVN_ARGS="$@"
21+
MVN_CMD="mvn"
4422
fi
4523

46-
echo "[INFO] Running: $MVN_CMD ${QUIET_FLAG} generate-test-resources failsafe:integration-test failsafe:verify ${MVN_ARGS}"
24+
PRESET=""
25+
DO_CLEAN=0
26+
QUIET_FLAG=""
27+
28+
if [ "${1-}" = "run_schema_check_with_clean" ]; then
29+
PRESET="run_schema_check_with_clean"
30+
shift
31+
if [ "$#" -gt 0 ]; then
32+
echo "[INFO] Preset ignoring additional arguments: $*"
33+
fi
34+
DO_CLEAN=1
35+
QUIET_FLAG=""
36+
set -- \
37+
generate-test-resources \
38+
failsafe:integration-test \
39+
failsafe:verify \
40+
-pl json-java21-schema \
41+
-DskipTests=true \
42+
-DskipITs=false \
43+
-Dit.test=JsonSchemaCheckIT \
44+
-Djson.schema.strict=true \
45+
-Djson.schema.metrics=csv \
46+
-Djava.util.logging.ConsoleHandler.level=INFO \
47+
-DfailIfNoTests=false \
48+
-e \
49+
-DtrimStackTrace=false \
50+
-Dorg.slf4j.simpleLogger.log.org.apache.maven.plugins.failsafe=debug
51+
fi
4752

48-
set -o pipefail
53+
if [ "$DEBUG" -eq 1 ]; then
54+
QUIET_FLAG=""
55+
fi
4956

50-
if $DO_CLEAN; then
51-
timeout 120 $MVN_CMD ${QUIET_FLAG} clean || exit $?
57+
TIMEOUT_SECS=600
58+
if ! command -v timeout >/dev/null 2>&1; then
59+
TIMEOUT_SECS=0
5260
fi
5361

54-
timeout 120 $MVN_CMD ${QUIET_FLAG} generate-test-resources failsafe:integration-test failsafe:verify ${MVN_ARGS} 2>&1 | awk '
55-
BEGIN {
56-
scanning_started = 0
57-
compilation_section = 0
58-
test_section = 0
62+
TMP_FILES=""
63+
cleanup() {
64+
# shellcheck disable=SC2317
65+
for file in $TMP_FILES; do
66+
if [ -f "$file" ]; then
67+
rm -f "$file"
68+
fi
69+
done
5970
}
60-
61-
# Skip all WARNING lines before project scanning starts
62-
/INFO.*Scanning for projects/ {
63-
scanning_started = 1
64-
print
65-
next
71+
trap cleanup EXIT INT TERM
72+
73+
filter_output() {
74+
awk '
75+
BEGIN {
76+
scanning_started = 0
77+
compilation_section = 0
78+
test_section = 0
79+
}
80+
/INFO.*Scanning for projects/ {
81+
scanning_started = 1
82+
print
83+
next
6684
}
67-
68-
# Before scanning starts, skip WARNING lines
6985
!scanning_started && /^WARNING:/ { next }
70-
71-
# Show compilation errors
72-
/COMPILATION ERROR/ { compilation_section = 1 }
73-
/BUILD FAILURE/ && compilation_section { compilation_section = 0 }
74-
75-
# Show test section
76-
/INFO.*T E S T S/ {
77-
test_section = 1
78-
print "-------------------------------------------------------"
79-
print " T E S T S"
80-
print "-------------------------------------------------------"
81-
next
86+
/COMPILATION ERROR/ {
87+
compilation_section = 1
88+
}
89+
/BUILD FAILURE/ && compilation_section {
90+
compilation_section = 0
91+
}
92+
/INFO.*T E S T S/ {
93+
test_section = 1
94+
print "-------------------------------------------------------"
95+
print " T E S T S"
96+
print "-------------------------------------------------------"
97+
next
8298
}
83-
84-
# In compilation error section, show everything
8599
compilation_section { print }
86-
87-
# In test section, show everything - let user control logging with -D arguments
88-
test_section {
100+
test_section { print }
101+
!test_section && scanning_started {
102+
if ($0 ~ /INFO.*Scanning/ || $0 ~ /INFO.*Building/ || $0 ~ /INFO.*resources/ || $0 ~ /INFO.*compiler/ || $0 ~ /INFO.*surefire/ || $0 ~ /INFO.*failsafe/ || $0 ~ /ERROR/ || $0 ~ /FAILURE/) {
103+
print
104+
}
105+
if ($0 ~ /WARNING.*COMPILATION/ || $0 ~ /ERROR.*/) {
89106
print
107+
}
108+
}
109+
' "$1"
90110
}
91111

92-
# Before test section starts, show important lines only
93-
!test_section && scanning_started {
94-
if (/INFO.*Scanning|INFO.*Building|INFO.*resources|INFO.*compiler|INFO.*surefire|INFO.*failsafe|ERROR|FAILURE/) {
95-
print
96-
}
97-
# Show compilation warnings/errors
98-
if (/WARNING.*COMPILATION|ERROR.*/) {
99-
print
100-
}
112+
run_maven_command() {
113+
CMD_LOG=$(mktemp -t mvn-wrapper-cmd.XXXXXX)
114+
TMP_FILES="$TMP_FILES $CMD_LOG"
115+
116+
if [ -n "$QUIET_FLAG" ]; then
117+
DISPLAY_CMD="$MVN_CMD $QUIET_FLAG $*"
118+
else
119+
DISPLAY_CMD="$MVN_CMD $*"
120+
fi
121+
echo "[INFO] Executing: $DISPLAY_CMD"
122+
123+
if [ "$TIMEOUT_SECS" -gt 0 ]; then
124+
if [ -n "$QUIET_FLAG" ]; then
125+
if timeout "$TIMEOUT_SECS" "$MVN_CMD" "$QUIET_FLAG" "$@" >"$CMD_LOG" 2>&1; then
126+
status=0
127+
else
128+
status=$?
129+
fi
130+
else
131+
if timeout "$TIMEOUT_SECS" "$MVN_CMD" "$@" >"$CMD_LOG" 2>&1; then
132+
status=0
133+
else
134+
status=$?
135+
fi
136+
fi
137+
else
138+
if [ -n "$QUIET_FLAG" ]; then
139+
if "$MVN_CMD" "$QUIET_FLAG" "$@" >"$CMD_LOG" 2>&1; then
140+
status=0
141+
else
142+
status=$?
143+
fi
144+
else
145+
if "$MVN_CMD" "$@" >"$CMD_LOG" 2>&1; then
146+
status=0
147+
else
148+
status=$?
149+
fi
150+
fi
151+
fi
152+
153+
if [ $status -eq 0 ]; then
154+
if [ "$DEBUG" -eq 1 ]; then
155+
cat "$CMD_LOG"
156+
else
157+
filter_output "$CMD_LOG"
158+
fi
159+
rm -f "$CMD_LOG"
160+
TMP_FILES=$(printf '%s\n' "$TMP_FILES" | tr ' ' '\n' | grep -v "$CMD_LOG" || true)
161+
else
162+
echo "[ERROR] Maven command failed (exit $status). Command output follows:"
163+
cat "$CMD_LOG"
164+
fi
165+
166+
return $status
101167
}
102-
'
103168

104-
STATUS=${PIPESTATUS[0]}
169+
if [ $DO_CLEAN -eq 1 ]; then
170+
if ! run_maven_command clean; then
171+
echo "[ERROR] Clean phase failed."
172+
exit 1
173+
fi
174+
fi
175+
176+
if ! run_maven_command "$@"; then
177+
echo "[ERROR] Maven execution failed."
178+
exit 1
179+
fi
180+
181+
STATUS=0
182+
if [ "$PRESET" = "run_schema_check_with_clean" ]; then
183+
CSV_PATH="json-java21-schema/target/json-schema-compat.csv"
184+
if [ ! -f "$CSV_PATH" ]; then
185+
echo "[ERROR] Expected metrics CSV not found at: $CSV_PATH"
186+
STATUS=2
187+
else
188+
echo "[INFO] Metrics CSV located at: $CSV_PATH"
189+
fi
190+
fi
191+
105192
if [ $STATUS -eq 0 ]; then
106193
echo DONE
107194
else
108195
echo FAILED
109196
fi
197+
110198
exit $STATUS

0 commit comments

Comments
 (0)