#!/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. Needs unzip and python3 for the configuration-metadata part. 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 # The three 1.x configuration keys, read from the configuration metadata inside the auto-configuration jar. echo echo "## the 1.x configuration keys in the metadata of spring-ai-autoconfigure-model-openai" for v in 1.1.0 2.0.1; do J=target/legacy/spring-ai-autoconfigure-model-openai-$v.jar [ -f "$J" ] || curl -s -o "$J" "$CENTRAL/spring-ai-autoconfigure-model-openai/$v/spring-ai-autoconfigure-model-openai-$v.jar" unzip -p "$J" META-INF/spring-configuration-metadata.json | python3 -c ' import json, sys v = sys.argv[1] props = {p["name"]: p for p in json.load(sys.stdin)["properties"]} for k in ("spring.ai.openai.chat.options.model", "spring.ai.openai.chat.options.temperature", "spring.ai.openai.embedding.options.model"): p = props.get(k) state = "unknown" if p is None else ("deprecated, use " + p["deprecation"]["replacement"] if "deprecation" in p else "current") print("%-6s %-46s %s" % (v, k, state)) ' "$v" done } > "$OUT" echo "wrote $OUT"