|
| 1 | +#!/bin/bash |
| 2 | +# Check that all extension jar modules are declared in agentscope-all and agentscope-bom |
| 3 | +# This prevents missing modules in the shaded uber-jar and BOM |
| 4 | +# |
| 5 | +# Rules: |
| 6 | +# - agentscope-all: Contains non-framework-specific extensions (shaded into uber-jar) |
| 7 | +# - agentscope-bom: Contains ALL modules (for version management) |
| 8 | + |
| 9 | +set -e |
| 10 | + |
| 11 | +ALL_POM="agentscope-distribution/agentscope-all/pom.xml" |
| 12 | +BOM_POM="agentscope-distribution/agentscope-bom/pom.xml" |
| 13 | + |
| 14 | +echo "Checking module sync between extensions, agentscope-all and agentscope-bom..." |
| 15 | +echo "" |
| 16 | + |
| 17 | +# Framework-specific modules that should NOT be included in agentscope-all |
| 18 | +# These are integration modules that users should depend on separately |
| 19 | +# But they SHOULD be in agentscope-bom for version management |
| 20 | +# |
| 21 | +# Detection rules (by keyword in module name): |
| 22 | +# - *starter* : Spring Boot starters |
| 23 | +# - *quarkus* : Quarkus extensions |
| 24 | +# - *micronaut* : Micronaut extensions |
| 25 | +EXCLUDED_KEYWORDS=("starter" "quarkus" "micronaut") |
| 26 | + |
| 27 | +# Two separate lists |
| 28 | +MODULES_FOR_ALL=() # Non-framework extensions -> shade into agentscope-all |
| 29 | +MODULES_FOR_BOM=() # All modules -> version management in BOM |
| 30 | +EXCLUDED_MODULES=() # Track which modules were excluded (for reporting) |
| 31 | + |
| 32 | +# Function to check if module should be excluded from agentscope-all |
| 33 | +# Returns 0 (true) if module contains any of the excluded keywords |
| 34 | +is_excluded() { |
| 35 | + local module=$1 |
| 36 | + for keyword in "${EXCLUDED_KEYWORDS[@]}"; do |
| 37 | + if [[ "$module" == *"$keyword"* ]]; then |
| 38 | + return 0 # true, is excluded |
| 39 | + fi |
| 40 | + done |
| 41 | + return 1 # false, not excluded |
| 42 | +} |
| 43 | + |
| 44 | +# Function to extract artifactId from pom.xml (excluding parent's artifactId) |
| 45 | +extract_artifact_id() { |
| 46 | + local pom=$1 |
| 47 | + awk ' |
| 48 | + /<parent>/ { in_parent=1 } |
| 49 | + /<\/parent>/ { in_parent=0; next } |
| 50 | + !in_parent && /<artifactId>/ { |
| 51 | + gsub(/.*<artifactId>/, "") |
| 52 | + gsub(/<\/artifactId>.*/, "") |
| 53 | + print |
| 54 | + exit |
| 55 | + } |
| 56 | + ' "$pom" |
| 57 | +} |
| 58 | + |
| 59 | +# Function to check packaging type (default is jar) |
| 60 | +get_packaging() { |
| 61 | + local pom=$1 |
| 62 | + local packaging=$(grep -o '<packaging>[^<]*</packaging>' "$pom" 2>/dev/null | sed 's/<[^>]*>//g' || echo "jar") |
| 63 | + echo "$packaging" |
| 64 | +} |
| 65 | + |
| 66 | +# Scan agentscope-extensions directory for jar modules |
| 67 | +echo "Scanning agentscope-extensions/ for jar modules..." |
| 68 | +for pom in $(find "agentscope-extensions" -name "pom.xml" -type f); do |
| 69 | + packaging=$(get_packaging "$pom") |
| 70 | + |
| 71 | + # Skip pom packaging (aggregator modules) |
| 72 | + if [ "$packaging" = "pom" ]; then |
| 73 | + continue |
| 74 | + fi |
| 75 | + |
| 76 | + artifact_id=$(extract_artifact_id "$pom") |
| 77 | + |
| 78 | + # Skip if no artifactId found |
| 79 | + if [ -z "$artifact_id" ]; then |
| 80 | + continue |
| 81 | + fi |
| 82 | + |
| 83 | + # All jar modules go to BOM list |
| 84 | + MODULES_FOR_BOM+=("$artifact_id") |
| 85 | + |
| 86 | + # Only non-excluded modules with agentscope-extensions-* prefix go to ALL list |
| 87 | + if [[ "$artifact_id" == agentscope-extensions-* ]]; then |
| 88 | + if is_excluded "$artifact_id"; then |
| 89 | + EXCLUDED_MODULES+=("$artifact_id") |
| 90 | + else |
| 91 | + MODULES_FOR_ALL+=("$artifact_id") |
| 92 | + fi |
| 93 | + elif is_excluded "$artifact_id"; then |
| 94 | + # Track non-extension excluded modules (e.g., starters) |
| 95 | + EXCLUDED_MODULES+=("$artifact_id") |
| 96 | + fi |
| 97 | +done |
| 98 | + |
| 99 | +# Remove duplicates and sort |
| 100 | +MODULES_FOR_ALL=($(printf '%s\n' "${MODULES_FOR_ALL[@]}" | sort -u)) |
| 101 | +MODULES_FOR_BOM=($(printf '%s\n' "${MODULES_FOR_BOM[@]}" | sort -u)) |
| 102 | +EXCLUDED_MODULES=($(printf '%s\n' "${EXCLUDED_MODULES[@]}" | sort -u)) |
| 103 | + |
| 104 | +# Add agentscope-core to BOM list (it's in a separate directory) |
| 105 | +MODULES_FOR_BOM+=("agentscope-core") |
| 106 | + |
| 107 | +echo "" |
| 108 | +echo "Modules to check for agentscope-all (${#MODULES_FOR_ALL[@]} extensions):" |
| 109 | +for m in "${MODULES_FOR_ALL[@]}"; do |
| 110 | + echo " - $m" |
| 111 | +done |
| 112 | + |
| 113 | +echo "" |
| 114 | +echo "Modules to check for agentscope-bom (${#MODULES_FOR_BOM[@]} total):" |
| 115 | +for m in "${MODULES_FOR_BOM[@]}"; do |
| 116 | + echo " - $m" |
| 117 | +done |
| 118 | + |
| 119 | +echo "" |
| 120 | +echo "Excluded from agentscope-all (detected by keywords: ${EXCLUDED_KEYWORDS[*]}):" |
| 121 | +for m in "${EXCLUDED_MODULES[@]}"; do |
| 122 | + echo " - $m" |
| 123 | +done |
| 124 | +echo "" |
| 125 | + |
| 126 | +# Check modules against agentscope-all and agentscope-bom |
| 127 | +MISSING_IN_ALL=() |
| 128 | +MISSING_IN_BOM=() |
| 129 | + |
| 130 | +# Check agentscope-all |
| 131 | +for module in "${MODULES_FOR_ALL[@]}"; do |
| 132 | + if ! grep -q "<artifactId>${module}</artifactId>" "$ALL_POM"; then |
| 133 | + MISSING_IN_ALL+=("$module") |
| 134 | + fi |
| 135 | +done |
| 136 | + |
| 137 | +# Check agentscope-bom |
| 138 | +for module in "${MODULES_FOR_BOM[@]}"; do |
| 139 | + if ! grep -q "<artifactId>${module}</artifactId>" "$BOM_POM"; then |
| 140 | + MISSING_IN_BOM+=("$module") |
| 141 | + fi |
| 142 | +done |
| 143 | + |
| 144 | +# Report results |
| 145 | +EXIT_CODE=0 |
| 146 | + |
| 147 | +if [ ${#MISSING_IN_ALL[@]} -gt 0 ]; then |
| 148 | + echo "==========================================" |
| 149 | + echo "ERROR: Missing in $ALL_POM:" |
| 150 | + echo "==========================================" |
| 151 | + echo "" |
| 152 | + echo "Add the following dependencies to shade into the uber-jar:" |
| 153 | + echo "" |
| 154 | + for m in "${MISSING_IN_ALL[@]}"; do |
| 155 | + echo " <dependency>" |
| 156 | + echo " <groupId>io.agentscope</groupId>" |
| 157 | + echo " <artifactId>${m}</artifactId>" |
| 158 | + echo " <scope>compile</scope>" |
| 159 | + echo " <optional>true</optional>" |
| 160 | + echo " </dependency>" |
| 161 | + echo "" |
| 162 | + done |
| 163 | + EXIT_CODE=1 |
| 164 | +fi |
| 165 | + |
| 166 | +if [ ${#MISSING_IN_BOM[@]} -gt 0 ]; then |
| 167 | + echo "==========================================" |
| 168 | + echo "ERROR: Missing in $BOM_POM:" |
| 169 | + echo "==========================================" |
| 170 | + echo "" |
| 171 | + echo "Add the following dependencies for version management:" |
| 172 | + echo "" |
| 173 | + for m in "${MISSING_IN_BOM[@]}"; do |
| 174 | + echo " <dependency>" |
| 175 | + echo " <groupId>io.agentscope</groupId>" |
| 176 | + echo " <artifactId>${m}</artifactId>" |
| 177 | + echo " <version>\${project.version}</version>" |
| 178 | + echo " </dependency>" |
| 179 | + echo "" |
| 180 | + done |
| 181 | + EXIT_CODE=1 |
| 182 | +fi |
| 183 | + |
| 184 | +if [ $EXIT_CODE -eq 0 ]; then |
| 185 | + echo "==========================================" |
| 186 | + echo "SUCCESS: All modules are properly synced!" |
| 187 | + echo "==========================================" |
| 188 | + echo "" |
| 189 | + echo "- agentscope-all: ${#MODULES_FOR_ALL[@]} extension modules" |
| 190 | + echo "- agentscope-bom: ${#MODULES_FOR_BOM[@]} total modules" |
| 191 | +fi |
| 192 | + |
| 193 | +exit $EXIT_CODE |
| 194 | + |
0 commit comments