|
| 1 | +#!/bin/bash |
| 2 | +# Verify that the full-sources JAR contains all expected source files. |
| 3 | +# Usage: ./scripts/verify-full-sources-jar.sh [path-to-jar] |
| 4 | +# |
| 5 | +# Works whether MMCoreJ_wrap is its own repo (for future) or a subdirectory of |
| 6 | +# mmCoreAndDevices. |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +JAR_FILE="${1:-target/MMCoreJ-*-full-sources.jar}" |
| 11 | + |
| 12 | +# Files that may be omitted from the JAR despite being in git. |
| 13 | +ALLOWED_MISSING=( |
| 14 | + 'Makefile.am' |
| 15 | + 'build.xml' |
| 16 | + '*.vcxproj' |
| 17 | + '*.vcxproj.filters' |
| 18 | +) |
| 19 | + |
| 20 | +# Subprojects to check for source files. |
| 21 | +SUBPROJECTS=( |
| 22 | + 'subprojects/mmcore' |
| 23 | + 'subprojects/mmdevice' |
| 24 | +) |
| 25 | + |
| 26 | +# Expand glob if needed |
| 27 | +JAR_FILE=$(echo $JAR_FILE) |
| 28 | + |
| 29 | +if [[ ! -f "$JAR_FILE" ]]; then |
| 30 | + echo "ERROR: JAR file not found: $JAR_FILE" |
| 31 | + echo "Run 'mvn package' first." |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +echo "Verifying: $JAR_FILE" |
| 36 | + |
| 37 | +# Verify subprojects exist on filesystem (required as reference for JAR verification) |
| 38 | +for subproj in "${SUBPROJECTS[@]}"; do |
| 39 | + if [[ ! -d "$subproj" ]]; then |
| 40 | + echo "ERROR: Required subproject directory not found: $subproj" |
| 41 | + echo "Run 'meson setup' before 'mvn package'." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + if [[ ! -f "$subproj/meson.build" ]]; then |
| 45 | + echo "ERROR: Subproject missing meson.build: $subproj" |
| 46 | + echo "Subproject may be incomplete or corrupted." |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | +done |
| 50 | + |
| 51 | +# Create temp files for comparison |
| 52 | +JAR_CONTENTS=$(mktemp) |
| 53 | +EXPECTED_FILES=$(mktemp) |
| 54 | +trap "rm -f $JAR_CONTENTS $EXPECTED_FILES" EXIT |
| 55 | + |
| 56 | +# Detect if we're in a subdirectory of a larger git repo. |
| 57 | +# If so, we need to strip the prefix from git ls-files output. |
| 58 | +# Empty if at root, "subdir/" if in subdir: |
| 59 | +GIT_PREFIX=$(git rev-parse --show-prefix) |
| 60 | + |
| 61 | +# List JAR contents (excluding META-INF/) |
| 62 | +jar tf "$JAR_FILE" | grep -v 'META-INF' | sort > "$JAR_CONTENTS" |
| 63 | + |
| 64 | +# Helper to strip the git prefix from paths |
| 65 | +strip_prefix() { |
| 66 | + if [[ -n "$GIT_PREFIX" ]]; then |
| 67 | + sed "s|^${GIT_PREFIX}||" |
| 68 | + else |
| 69 | + cat |
| 70 | + fi |
| 71 | +} |
| 72 | + |
| 73 | +# Helper to filter out allowed missing files |
| 74 | +filter_allowed_missing() { |
| 75 | + local result |
| 76 | + result=$(cat) |
| 77 | + for pattern in "${ALLOWED_MISSING[@]}"; do |
| 78 | + # Convert glob pattern to grep -v pattern |
| 79 | + # e.g., *.vcxproj -> \.vcxproj$ |
| 80 | + local regex=$(echo "$pattern" | sed 's/\./\\./g' | sed 's/\*/.*/g') |
| 81 | + result=$(echo "$result" | grep -v "$regex" || true) |
| 82 | + done |
| 83 | + echo "$result" |
| 84 | +} |
| 85 | + |
| 86 | +# Build expected file list from git |
| 87 | +{ |
| 88 | + # All files tracked by git in this directory |
| 89 | + git ls-files --full-name | strip_prefix |
| 90 | + |
| 91 | + # subprojects (from submodules - have their own .git) |
| 92 | + for subproj in "${SUBPROJECTS[@]}"; do |
| 93 | + if [[ -d "$subproj" ]]; then |
| 94 | + if [[ -e "$subproj/.git" ]]; then |
| 95 | + # Submodule: query its own git |
| 96 | + git -C "$subproj" ls-files --full-name | sed "s|^|$subproj/|" |
| 97 | + else |
| 98 | + # Not a git repo: enumerate all files on disk |
| 99 | + # (meson.build existence already verified above) |
| 100 | + find "$subproj" -type f |
| 101 | + fi |
| 102 | + fi |
| 103 | + done |
| 104 | +} | sort -u > "$EXPECTED_FILES" |
| 105 | + |
| 106 | +# Compare (filtering out allowed missing files) |
| 107 | +MISSING=$(comm -23 "$EXPECTED_FILES" "$JAR_CONTENTS" | filter_allowed_missing) |
| 108 | + |
| 109 | +if [[ -n "$MISSING" ]]; then |
| 110 | + echo "ERROR: The following expected source files are missing from the JAR:" |
| 111 | + echo "$MISSING" |
| 112 | + exit 1 |
| 113 | +fi |
| 114 | + |
| 115 | +echo "OK: All expected source files are present in the JAR." |
| 116 | +# Optionally show extra files in JAR (not an error, just informational) |
| 117 | +# Filter out directory entries (end with /) and blank lines |
| 118 | +EXTRA=$(comm -13 "$EXPECTED_FILES" "$JAR_CONTENTS" | grep -v '/$' | grep -v '^$' || true) |
| 119 | +if [[ -n "$EXTRA" ]]; then |
| 120 | + echo "Note: JAR contains additional files not in git (this is OK):" |
| 121 | + echo "$EXTRA" |
| 122 | +fi |
| 123 | + |
| 124 | +exit 0 |
0 commit comments