|
| 1 | +``#!/bin/bash |
| 2 | + |
| 3 | +# Build script for all Ignition SDK example projects |
| 4 | +# Automatically detects Maven (pom.xml) or Gradle (build.gradle/build.gradle.kts) projects |
| 5 | + |
| 6 | +set -e # Exit on any error |
| 7 | + |
| 8 | +# Color output for better readability |
| 9 | +RED='\033[0;31m' |
| 10 | +GREEN='\033[0;32m' |
| 11 | +YELLOW='\033[1;33m' |
| 12 | +BLUE='\033[0;34m' |
| 13 | +NC='\033[0m' # No Color |
| 14 | + |
| 15 | +# Track overall success |
| 16 | +overall_success=0 |
| 17 | +successful_builds=() |
| 18 | +failed_builds=() |
| 19 | + |
| 20 | +# Get list of directories (excluding hidden and special directories) |
| 21 | +directories=$(find . -maxdepth 1 -type d ! -name "." ! -name "..*" ! -name ".git" ! -name ".idea" | sort) |
| 22 | + |
| 23 | +echo -e "${BLUE}========================================${NC}" |
| 24 | +echo -e "${BLUE}Building All Ignition SDK Examples${NC}" |
| 25 | +echo -e "${BLUE}========================================${NC}" |
| 26 | +echo "" |
| 27 | + |
| 28 | +for dir in $directories; do |
| 29 | + project_name=$(basename "$dir") |
| 30 | + |
| 31 | + echo -e "${YELLOW}>>> Building: ${project_name}${NC}" |
| 32 | + |
| 33 | + cd "$dir" |
| 34 | + |
| 35 | + # Detect project type and build accordingly |
| 36 | + if [ -f "pom.xml" ]; then |
| 37 | + echo -e "${BLUE}Detected Maven project${NC}" |
| 38 | + if mvn clean package; then |
| 39 | + echo -e "${GREEN}✓ ${project_name} built successfully${NC}" |
| 40 | + successful_builds+=("$project_name") |
| 41 | + else |
| 42 | + echo -e "${RED}✗ ${project_name} build failed${NC}" |
| 43 | + failed_builds+=("$project_name") |
| 44 | + overall_success=1 |
| 45 | + fi |
| 46 | + elif [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then |
| 47 | + echo -e "${BLUE}Detected Gradle project${NC}" |
| 48 | + if ./gradlew clean build; then |
| 49 | + echo -e "${GREEN}✓ ${project_name} built successfully${NC}" |
| 50 | + successful_builds+=("$project_name") |
| 51 | + else |
| 52 | + echo -e "${RED}✗ ${project_name} build failed${NC}" |
| 53 | + failed_builds+=("$project_name") |
| 54 | + overall_success=1 |
| 55 | + fi |
| 56 | + else |
| 57 | + echo -e "${YELLOW}⚠ No build file found (pom.xml, build.gradle, or build.gradle.kts)${NC}" |
| 58 | + echo -e "${YELLOW}⚠ Skipping ${project_name}${NC}" |
| 59 | + fi |
| 60 | + |
| 61 | + cd .. |
| 62 | + echo "" |
| 63 | +done |
| 64 | + |
| 65 | +# Print summary |
| 66 | +echo -e "${BLUE}========================================${NC}" |
| 67 | +echo -e "${BLUE}Build Summary${NC}" |
| 68 | +echo -e "${BLUE}========================================${NC}" |
| 69 | +echo -e "${GREEN}Successful builds: ${#successful_builds[@]}${NC}" |
| 70 | +for project in "${successful_builds[@]}"; do |
| 71 | + echo -e " ${GREEN}✓${NC} $project" |
| 72 | +done |
| 73 | + |
| 74 | +if [ ${#failed_builds[@]} -gt 0 ]; then |
| 75 | + echo "" |
| 76 | + echo -e "${RED}Failed builds: ${#failed_builds[@]}${NC}" |
| 77 | + for project in "${failed_builds[@]}"; do |
| 78 | + echo -e " ${RED}✗${NC} $project" |
| 79 | + done |
| 80 | +fi |
| 81 | + |
| 82 | +echo "" |
| 83 | +if [ $overall_success -eq 0 ]; then |
| 84 | + echo -e "${GREEN}========================================${NC}" |
| 85 | + echo -e "${GREEN}All builds completed successfully!${NC}" |
| 86 | + echo -e "${GREEN}========================================${NC}" |
| 87 | +else |
| 88 | + echo -e "${RED}========================================${NC}" |
| 89 | + echo -e "${RED}Some builds failed!${NC}" |
| 90 | + echo -e "${RED}========================================${NC}" |
| 91 | +fi |
| 92 | + |
| 93 | +exit $overall_success |
0 commit comments