#!/usr/bin/env bash # Writes docs/output/14-legacy-1x.txt: what happens to the code in the 1.x version of the article. # Needs network access to Maven Central. It runs deliberately failing builds, so it never exits non-zero # because of them. set -uo pipefail cd "$(dirname "$0")/.." mkdir -p docs/output target/legacy OUT=docs/output/14-legacy-1x.txt CENTRAL=https://repo1.maven.org/maven2/org/springframework/ai latest() { curl -s "$CENTRAL/$1/maven-metadata.xml" | grep -o '[^<]*' | sed 's/.*>//'; } first_errors() { grep -E 'ERROR.*(is missing|Could not|error:)|error:' | sed 's/^\[ERROR\] *//' | sort -u | head -"${1:-6}"; } { echo "# The 1.x article's code, against 1.1.0 and 2.0.1" echo echo "## The starter artifact ids in the 1.x article: latest version ever published" echo "spring-ai-openai-spring-boot-starter latest: $(latest spring-ai-openai-spring-boot-starter)" echo "spring-ai-pgvector-store-spring-boot-starter latest: $(latest spring-ai-pgvector-store-spring-boot-starter)" echo "the ids that replaced them:" echo "spring-ai-starter-model-openai latest: $(latest spring-ai-starter-model-openai)" echo "spring-ai-starter-vector-store-pgvector latest: $(latest spring-ai-starter-vector-store-pgvector)" for v in 1.1.0 2.0.1; do echo echo "## mvn validate on the article's dependency block with spring-ai-bom $v" mvn -B -f legacy-1x/pom.xml validate -Dspring-ai.version=$v 2>&1 | first_errors 3 done # Compile the two Spring AI calls against the 1.1.0 jars, then against 2.0.1. for m in spring-ai-commons spring-ai-pdf-document-reader; do [ -f target/legacy/$m-1.1.0.jar ] || curl -s -o target/legacy/$m-1.1.0.jar "$CENTRAL/$m/1.1.0/$m-1.1.0.jar" done mvn -B -q dependency:build-classpath -Dmdep.outputFile=target/classpath.txt >/dev/null 2>&1 OTHERS="$(tr ':' '\n' < target/classpath.txt | grep -v '/spring-ai-' | paste -sd:)" CP21="$(cat target/classpath.txt)" CP11="target/legacy/spring-ai-commons-1.1.0.jar:target/legacy/spring-ai-pdf-document-reader-1.1.0.jar:$OTHERS" for v in 1.1.0 2.0.1; do echo echo "## javac legacy-1x/src/LegacyIngestion.java against Spring AI $v" if [ "$v" = 1.1.0 ]; then CP="$CP11"; else CP="$CP21"; fi rm -rf target/legacy/out && mkdir -p target/legacy/out if RESULT="$(javac -proc:none -Xmaxerrs 10 -d target/legacy/out -cp "$CP" legacy-1x/src/LegacyIngestion.java 2>&1)"; then echo "(compiles)" else echo "$RESULT" | grep -A2 'error:' | grep -v '^--$' fi done } > "$OUT" echo "wrote $OUT"