-
Notifications
You must be signed in to change notification settings - Fork 963
Expand file tree
/
Copy pathregen.sh
More file actions
executable file
·95 lines (83 loc) · 3.49 KB
/
Copy pathregen.sh
File metadata and controls
executable file
·95 lines (83 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
#
# Regenerates and validates the metadata key registry (tika-metadata-schema).
#
# Run this after adding, renaming, or removing a Property or PassthroughPrefix
# constant anywhere in tika-core or the standard parser bundle. It replaces the
# multi-step manual sequence in .skills/metadata-schema.md with one command:
# install the dependency modules, regenerate the three registry files, sanity
# check the diff, then run the gate tests.
#
# Usage:
# tika-metadata-schema/regen.sh [--skip-install] [--skip-tests]
#
# --skip-install skip the -am install step (only safe if no Property/
# PassthroughPrefix classes outside tika-metadata-schema
# changed since the last install)
# --skip-tests skip the final gate-test run, for a faster inner loop
#
# See tika-metadata-schema/README.md and .skills/metadata-schema.md for the
# design and the traps this script exists to route around.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$REPO_ROOT"
MVN_REPO_OPT="-Dmaven.repo.local=$REPO_ROOT/.local_m2_repo"
SKIP_INSTALL=0
SKIP_TESTS=0
for arg in "$@"; do
case "$arg" in
--skip-install) SKIP_INSTALL=1 ;;
--skip-tests) SKIP_TESTS=1 ;;
-h|--help)
sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//'
exit 0
;;
*)
echo "Unknown argument: $arg" >&2
exit 1
;;
esac
done
REGISTRY_DIR="tika-metadata-schema/src/main/resources/org/apache/tika/metadata"
REGISTRY_FILES=(
"$REGISTRY_DIR/metadata-keys.json"
"$REGISTRY_DIR/metadata-open-namespaces.json"
"$REGISTRY_DIR/metadata-key-fields.json"
)
if [ "$SKIP_INSTALL" -eq 0 ]; then
echo "==> Installing tika-metadata-schema + its dependency modules (tika-core, standard parsers)"
echo " so newly added Property/PassthroughPrefix classes are on the scan classpath."
echo " (skip with --skip-install if you already did this)"
./mvnw -Pfast -DskipTests -pl tika-metadata-schema -am install "$MVN_REPO_OPT"
fi
echo "==> Recording committed key counts, to catch an incomplete classpath scan later"
BEFORE_COUNTS=()
for f in "${REGISTRY_FILES[@]}"; do
if git cat-file -e "HEAD:$f" 2>/dev/null; then
BEFORE_COUNTS+=("$(git show "HEAD:$f" | wc -l)")
else
BEFORE_COUNTS+=("0")
fi
done
echo "==> Regenerating the registry (forked exec — see .skills/metadata-schema.md for why exec:java is unsafe)"
./mvnw -pl tika-metadata-schema -Pregen-metadata-schema process-classes "$MVN_REPO_OPT"
echo "==> Comparing key counts before/after (a large drop usually means classes failed to load):"
for i in "${!REGISTRY_FILES[@]}"; do
f="${REGISTRY_FILES[$i]}"
before="${BEFORE_COUNTS[$i]}"
after=$(wc -l < "$f")
line=" $f: $before -> $after lines"
if [ "$before" -gt 0 ] && [ "$after" -lt $((before * 90 / 100)) ]; then
echo "$line *** WARNING: >10% drop, check --skip-install and module installs ***"
else
echo "$line"
fi
done
echo "==> git diff of the registries (review before committing):"
git --no-pager diff --stat -- "${REGISTRY_FILES[@]}"
if [ "$SKIP_TESTS" -eq 0 ]; then
echo "==> Running gate tests (MetadataSchemaTest, MetadataFieldTableTest, MetadataNoUnderscoreTest, MetadataCoverageTest, ...)"
./mvnw -pl tika-metadata-schema test "$MVN_REPO_OPT"
fi
echo "==> Done. Review the diff above, then commit the Property/PassthroughPrefix change and the regenerated JSON together."