data-jpa-3-to-4: Spring Data JPA 3.5 vs 4.2 side by side - package moves, nullness, Specification, keyset, Page JSON, Jackson 3, test slices, real transcripts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7N4ZDbUtA3ofqAqRV
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
3f061c5e5d
commit
7a2bcc1eb6
@@ -0,0 +1,36 @@
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
/**
|
||||
* Prints the public methods each named type declares, flagging {@code @Deprecated} ones.
|
||||
* Run it once per classpath (Boot 3.5 and Boot 4) and diff the two files.
|
||||
* Usage: java -cp "$(cat cp.txt)" ApiDump.java org.springframework.data.jpa.repository.JpaRepository ...
|
||||
*/
|
||||
public class ApiDump {
|
||||
public static void main(String[] args) {
|
||||
for (String name : args) {
|
||||
System.out.println("== " + name);
|
||||
try {
|
||||
Class<?> c = Class.forName(name, false, Thread.currentThread().getContextClassLoader());
|
||||
if (c.isAnnotationPresent(Deprecated.class)) System.out.println(" (type is @Deprecated)");
|
||||
Arrays.stream(c.getDeclaredMethods())
|
||||
.filter(m -> Modifier.isPublic(m.getModifiers()) && !m.isSynthetic() && !m.isBridge())
|
||||
.map(m -> " " + sig(m) + (m.isAnnotationPresent(Deprecated.class) ? " @Deprecated" : ""))
|
||||
.sorted().forEach(System.out::println);
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.out.println(" NOT ON THIS CLASSPATH");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String sig(Method m) {
|
||||
return (Modifier.isStatic(m.getModifiers()) ? "static " : "")
|
||||
+ simple(m.getGenericReturnType()) + " " + m.getName() + "("
|
||||
+ Arrays.stream(m.getGenericParameterTypes()).map(ApiDump::simple).collect(Collectors.joining(", ")) + ")";
|
||||
}
|
||||
|
||||
static String simple(Type t) {
|
||||
return t.getTypeName().replaceAll("[a-z][\\w]*\\.", "").replace('$', '.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
"""Prints the fully qualified name and jar of each simple type name found on a classpath file."""
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
wanted = sys.argv[2:]
|
||||
found = {}
|
||||
for jar in open(sys.argv[1]).read().strip().split(':'):
|
||||
for n in zipfile.ZipFile(jar).namelist():
|
||||
simple = n.rsplit('/', 1)[-1][:-6]
|
||||
if n.endswith('.class') and n.startswith('org/springframework/boot/') and simple in wanted:
|
||||
found.setdefault(simple, []).append('%s (%s)' % (n[:-6].replace('/', '.'), jar.rsplit('/', 1)[1]))
|
||||
for w in wanted:
|
||||
for line in found.get(w, ['%s: not on this classpath' % w]):
|
||||
print(' ' + line)
|
||||
@@ -0,0 +1,7 @@
|
||||
"""Counts class files in a jar whose bytes contain a string."""
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
z = zipfile.ZipFile(sys.argv[1])
|
||||
needle = sys.argv[2].encode()
|
||||
print(sum(1 for n in z.namelist() if n.endswith('.class') and needle in z.read(n)))
|
||||
@@ -0,0 +1,24 @@
|
||||
"""Top-level types that vanished between two jars, split into 'moved' (same simple name elsewhere) and 'gone'."""
|
||||
import collections
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
|
||||
def classes(path):
|
||||
return {n[:-6].replace('/', '.') for n in zipfile.ZipFile(path).namelist()
|
||||
if n.endswith('.class') and not n.startswith('META-INF') and 'package-info' not in n and '$' not in n}
|
||||
|
||||
|
||||
old, new = classes(sys.argv[1]), classes(sys.argv[2])
|
||||
added = collections.defaultdict(list)
|
||||
for c in new - old:
|
||||
added[c.rsplit('.', 1)[1]].append(c)
|
||||
gone = sorted(old - new)
|
||||
print('moved:')
|
||||
for c in gone:
|
||||
if c.rsplit('.', 1)[1] in added:
|
||||
print(' %s -> %s' % (c, ', '.join(sorted(added[c.rsplit('.', 1)[1]]))))
|
||||
print('no type of the same name in the new jar:')
|
||||
for c in gone:
|
||||
if c.rsplit('.', 1)[1] not in added:
|
||||
print(' ' + c)
|
||||
@@ -0,0 +1,12 @@
|
||||
"""Edits a copy of boot4/pom.xml to use the OpenFeign fork of Querydsl instead of com.querydsl."""
|
||||
import sys
|
||||
|
||||
VERSION = '7.8'
|
||||
path = sys.argv[1]
|
||||
s = open(path).read()
|
||||
s = s.replace('<groupId>com.querydsl</groupId>', '<groupId>io.github.openfeign.querydsl</groupId>')
|
||||
s = s.replace('<artifactId>querydsl-jpa</artifactId>\n <version>${querydsl.version}</version>\n <classifier>jakarta</classifier>',
|
||||
'<artifactId>querydsl-jpa</artifactId>\n <version>%s</version>' % VERSION)
|
||||
s = s.replace('<artifactId>querydsl-apt</artifactId>\n <version>${querydsl.version}</version>',
|
||||
'<artifactId>querydsl-apt</artifactId>\n <version>%s</version>' % VERSION)
|
||||
open(path, 'w').write(s)
|
||||
Executable
+116
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in ../output. Needs JDK 25 and Maven on the PATH.
|
||||
# Optional: PG_URL=jdbc:postgresql://localhost:5432/postgres PG_USER=postgres PG_PASSWORD=... for output 16.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
MODULE="$PWD"
|
||||
OUT="$MODULE/output"
|
||||
mkdir -p "$OUT"
|
||||
WORK="$(mktemp -d)"
|
||||
PG_ARGS=()
|
||||
if [ -n "${PG_URL:-}" ]; then
|
||||
PG_ARGS=(-Dpg.url="$PG_URL" -Dpg.user="${PG_USER:-postgres}" -Dpg.password="${PG_PASSWORD:-}")
|
||||
fi
|
||||
|
||||
echo "== tests on both generations (they write output/02..16)"
|
||||
for g in boot3 boot4; do
|
||||
(cd "$g" && mvn -B -q clean test "${PG_ARGS[@]}")
|
||||
(cd "$g" && mvn -B -q dependency:build-classpath -Dmdep.outputFile="$WORK/cp-$g.txt")
|
||||
done
|
||||
|
||||
scrub() { sed -e "s#$MODULE/##g" -e "s#$WORK#<tmp>#g" -e "s#$HOME#~#g" -e '/^Picked up /d'; }
|
||||
cp_of() { cat "$WORK/cp-$1.txt"; }
|
||||
jar_of() { tr ':' '\n' < "$WORK/cp-$1.txt" | grep "/$2-[0-9][^/]*\.jar$" | head -1; }
|
||||
|
||||
echo "== 01 package moves and removals, read from the jars"
|
||||
{
|
||||
for a in spring-data-commons spring-data-jpa; do
|
||||
echo "== $a: $(basename "$(jar_of boot3 $a)") -> $(basename "$(jar_of boot4 $a)")"
|
||||
python3 -I scripts/jar_moves.py "$(jar_of boot3 $a)" "$(jar_of boot4 $a)"
|
||||
done
|
||||
echo "== Boot types that tests and configuration import"
|
||||
for g in boot3 boot4; do
|
||||
echo "-- $g"
|
||||
python3 -I scripts/find_types.py "$WORK/cp-$g.txt" DataJpaTest TestEntityManager AutoConfigureTestDatabase \
|
||||
WebMvcTest EntityScan HibernatePropertiesCustomizer Jackson2ObjectMapperBuilderCustomizer JsonMapperBuilderCustomizer
|
||||
done
|
||||
} > "$OUT/01-package-moves.txt"
|
||||
|
||||
echo "== 17 public repository API on both generations"
|
||||
J=org.springframework.data.jpa
|
||||
TYPES="$J.repository.JpaRepository $J.repository.JpaSpecificationExecutor $J.domain.Specification \
|
||||
$J.domain.PredicateSpecification $J.domain.DeleteSpecification $J.domain.UpdateSpecification"
|
||||
for g in boot3 boot4; do
|
||||
java -cp "$(cp_of $g)" scripts/ApiDump.java $TYPES 2>/dev/null > "$WORK/api-$g.txt"
|
||||
done
|
||||
{ diff -u --label boot3 --label boot4 "$WORK/api-boot3.txt" "$WORK/api-boot4.txt" || true; } > "$OUT/17-repository-api.diff.txt"
|
||||
cp "$WORK/api-boot4.txt" "$OUT/18-repository-api-boot4.txt"
|
||||
|
||||
echo "== 19 Boot 3 style sources against both classpaths"
|
||||
{
|
||||
for f in broken/boot3-style/*.java; do
|
||||
for g in boot3 boot4; do
|
||||
mkdir -p "$WORK/classes"
|
||||
echo "=== $(basename "$f") on $g"
|
||||
if javac -proc:none -Xlint:deprecation,removal -Xmaxerrs 20 -d "$WORK/classes" \
|
||||
-cp "$g/target/classes:$(cp_of $g)" "$f" > "$WORK/javac.txt" 2>&1; then
|
||||
echo "compiles"
|
||||
else
|
||||
echo "DOES NOT COMPILE"
|
||||
fi
|
||||
scrub < "$WORK/javac.txt" | grep -E 'error:|warning:|symbol:|location:|^[0-9]+ (error|warning)' || true
|
||||
done
|
||||
done
|
||||
} > "$OUT/19-compile-errors.txt"
|
||||
|
||||
echo "== 20 the metamodel processor coordinate on Boot 4"
|
||||
{
|
||||
variant() { # $1 label, $2 python expression that edits the pom
|
||||
d="$WORK/variant-$3"; mkdir -p "$d/boot4"
|
||||
cp -r common "$d/"; cp boot4/pom.xml "$d/boot4/"
|
||||
python3 -I -c "import sys;p=sys.argv[1];s=open(p).read();$2;open(p,'w').write(s)" "$d/boot4/pom.xml"
|
||||
echo "=== $1"
|
||||
if (cd "$d/boot4" && mvn -B clean compile > mvn.log 2>&1); then echo "BUILD SUCCESS"; else echo "BUILD FAILURE"; fi
|
||||
grep -E 'relocat|has been relocated|^\[ERROR\] (Failed|.*cannot find symbol|.*Resolution)|version can neither|version is missing' "$d/boot4/mvn.log" \
|
||||
| sed -e "s#$d/##g" | scrub | cut -c1-400 | sort -u | head -8
|
||||
echo "Book_ generated: $(find "$d/boot4/target" -name 'Book_.java' 2>/dev/null | wc -l) file(s)"
|
||||
}
|
||||
OLD="s=s.replace('<artifactId>hibernate-processor</artifactId>','<artifactId>hibernate-jpamodelgen</artifactId>')"
|
||||
variant "old artifactId hibernate-jpamodelgen, version \${hibernate.version}" "$OLD" a
|
||||
variant "old artifactId hibernate-jpamodelgen, no <version> (relying on Boot's BOM)" \
|
||||
"$OLD;s=s.replace('<artifactId>hibernate-jpamodelgen</artifactId>\n <version>\${hibernate.version}</version>','<artifactId>hibernate-jpamodelgen</artifactId>')" b
|
||||
variant "new artifactId hibernate-processor, no <version>" \
|
||||
"s=s.replace('<artifactId>hibernate-processor</artifactId>\n <version>\${hibernate.version}</version>','<artifactId>hibernate-processor</artifactId>')" c
|
||||
} > "$OUT/20-metamodel-processor.txt"
|
||||
|
||||
echo "== 21 querydsl and a record @Embeddable, then the OpenFeign fork on Boot 4"
|
||||
{
|
||||
qd() { # $1 label, $2 generation, $3 'openfeign' or empty, $4 'record' or empty, $5 maven goal
|
||||
d="$(mktemp -d "$WORK/qd-XXXX")"; cp -r common "$d/"; mkdir -p "$d/$2" "$d/output"; cp "$2/pom.xml" "$d/$2/"
|
||||
[ "$3" = openfeign ] && python3 -I scripts/openfeign.py "$d/$2/pom.xml"
|
||||
[ "$4" = record ] && { echo "package com.ankurm.jpamig.domain;"; cat broken/querydsl-record/Invoice.java; } \
|
||||
> "$d/common/src/main/java/com/ankurm/jpamig/domain/Invoice.java"
|
||||
echo "=== $1"
|
||||
if (cd "$d/$2" && mvn -B clean $5 > mvn.log 2>&1); then echo "BUILD SUCCESS"; else echo "BUILD FAILURE"; fi
|
||||
grep -E 'Fatal error compiling|Tests run: [0-9]+, F[^-]*$' "$d/$2/mvn.log" | sed -e "s#$d/##g" | scrub | sed -E 's/^.*(Fatal error compiling.*)$/\1/' | cut -c1-200 | head -3
|
||||
}
|
||||
qd "com.querydsl 5.1.0 + record @Embeddable, Boot 3.5" boot3 "" record compile
|
||||
qd "com.querydsl 5.1.0 + record @Embeddable, Boot 4.2" boot4 "" record compile
|
||||
qd "io.github.openfeign.querydsl 7.8 + record @Embeddable, Boot 4.2" boot4 openfeign record compile
|
||||
qd "io.github.openfeign.querydsl 7.8, whole test suite, Boot 4.2" boot4 openfeign "" test
|
||||
} > "$OUT/21-querydsl.txt"
|
||||
|
||||
echo "== 22 the native query parser switch"
|
||||
{
|
||||
for g in boot3 boot4; do
|
||||
jar="$(jar_of $g spring-data-jpa)"
|
||||
n=$(python3 -I scripts/jar_grep.py "$jar" 'spring.data.jpa.query.native.parser')
|
||||
echo "$(basename "$jar"): class files containing the string spring.data.jpa.query.native.parser: $n"
|
||||
done
|
||||
echo "=== how 3.5 reads it (javap -c)"
|
||||
javap -c -p -cp "$(jar_of boot3 spring-data-jpa)" 'org.springframework.data.jpa.repository.query.QueryEnhancerFactory$NativeQueryEnhancer' \
|
||||
| grep -A1 'String spring.data.jpa.query.native.parser' | sed -E 's/^ +[0-9]+: //; s/#[0-9]+ +//'
|
||||
|
||||
} > "$OUT/22-native-parser-property.txt"
|
||||
|
||||
echo "done"
|
||||
Reference in New Issue
Block a user