Files
jackson3-by-example/exceptions/scripts/migrate.sh
T

49 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Runs both migrations on throwaway copies of migration/before and records the diffs, the build
# result and the behaviour tests. Writes output/30..36.
set -uo pipefail
cd "$(dirname "$0")/.."
MODULE=$PWD
MVN="${MVN:-mvn} ${MVN_ARGS:-}"
WORK=$(mktemp -d)
clean() { grep -vE "Picked up|^WARNING" | sed "s#$WORK#<work>#g; s#$HOME#~#g"; }
summary() { # compiler errors or the surefire verdict, without timings
clean | grep -E '^\[ERROR\].*\.java|Tests run:|Tests in error|^\[ERROR\] |BUILD' | sed -E 's/, Time elapsed: [0-9.]+ s//; s/ -- Time elapsed.*(<<<.*)/ \1/' | head -30
}
(cd migration/before && $MVN -B test 2>&1 | summary) > output/30-before-jackson2-tests.txt
rm -rf migration/before/target
# --- A: OpenRewrite ---
cp -r migration/before "$WORK/rewrite"
(cd "$WORK/rewrite" && git init -q && git add -A && git -c user.email=x@x -c user.name=x commit -qm before \
&& $MVN -B -U org.openrewrite.maven:rewrite-maven-plugin:6.46.1:run \
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-jackson:1.29.0 \
-Drewrite.activeRecipes=org.openrewrite.java.jackson.UpgradeJackson_2_3 > "$WORK/rewrite.log" 2>&1)
grep -E 'BUILD|Changes have been made| org\.openrewrite' "$WORK/rewrite.log" | clean > output/31-openrewrite-run.txt
(cd "$WORK/rewrite" && git diff --no-color -- pom.xml src) > output/32-openrewrite.diff.txt
(cd "$WORK/rewrite" && $MVN -B test 2>&1 | summary) > output/33-openrewrite-tests.txt
# --- B: sed ---
cp -r migration/before "$WORK/regex"
(cd "$WORK/regex" && git init -q && git add -A && git -c user.email=x@x -c user.name=x commit -qm before)
"$MODULE/scripts/migrate-regex.sh" "$WORK/regex"
{
echo "\$ scripts/migrate-regex.sh <copy>; mvn test"
(cd "$WORK/regex" && $MVN -B test 2>&1 | summary)
echo
echo "\$ scripts/review-catches.sh <copy>"
"$MODULE/scripts/review-catches.sh" "$WORK/regex"
} > output/34-regex.txt
# --- C: sed, then fix only what the compiler points at ---
sed -i '/Order orDefault/,/Order load/ s/catch (IOException e)/catch (tools.jackson.core.JacksonException e)/' "$WORK/regex/src/main/java/com/ankurm/orders/OrderCodec.java"
{
echo "\$ # after fixing the single compile error (orDefault now catches JacksonException)"
(cd "$WORK/regex" && $MVN -B test 2>&1 | summary)
} > output/35-regex-after-compile-fix.txt
# --- D: the OpenRewrite result plus the hand fixes ---
(cd migration/after && $MVN -B test 2>&1 | summary) > output/36-after-hand-fixes-tests.txt
rm -rf migration/after/target
echo "work dir kept at $WORK"