diff --git a/build.sh b/build.sh new file mode 100755 index 0000000000..19dd5d0f66 --- /dev/null +++ b/build.sh @@ -0,0 +1,1120 @@ +#!/bin/bash +################################################################################ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +set -e # Exit on error +trap 'handle_error $? $LINENO $BASH_LINENO "$BASH_COMMAND" $(printf "::%s" ${FUNCNAME[@]:-})' ERR + +# Error handling function +handle_error() { + local exit_code=$1 + local line_no=$2 + local bash_lineno=$3 + local last_command=$4 + local func_trace=$5 + + cat << "EOF" + _____ ____ ____ ___ ____ + | ____| _ \| _ \ / _ \| _ \ + | _| | |_) | |_) | | | | |_) | + | |___| _ <| _ <| |_| | _ < + |_____|_| \_\_| \_\\___/|_| \_\ + +EOF + echo "Error occurred in:" + echo " Command: $last_command" + echo " Line: $line_no" + echo " Exit code: $exit_code" + if [ ! -z "$func_trace" ]; then + echo " Function trace: $func_trace" + fi + exit $exit_code +} + +# Function to detect color support +setup_colors() { + # Only use colors if connected to a terminal + if [ -t 1 ]; then + # Check if NO_COLOR is set (https://no-color.org/) + if [ -z "${NO_COLOR+x}" ]; then + # Check if terminal supports colors + if [ -n "$TERM" ] && [ "$TERM" != "dumb" ]; then + # Check if tput is available + if command -v tput > /dev/null && tput setaf 1 >&/dev/null; then + RED='\033[0;31m' + GREEN='\033[0;32m' + YELLOW='\033[1;33m' + BLUE='\033[0;34m' + MAGENTA='\033[0;35m' + CYAN='\033[0;36m' + GRAY='\033[0;90m' + BOLD='\033[1m' + NC='\033[0m' # No Color + + # Unicode symbols (only if terminal likely supports UTF-8) + if [ "$TERM" != "linux" ] && [ -n "$LANG" ] && [ "$LANG" != "C" ]; then + CHECK_MARK="✔" + CROSS_MARK="✘" + ARROW="➜" + WARNING="⚠" + INFO="ℹ" + else + CHECK_MARK="(+)" + CROSS_MARK="(x)" + ARROW="(>)" + WARNING="(!)" + INFO="(i)" + fi + + HAS_COLORS=1 + fi + fi + fi + fi + + # If colors are not supported or disabled, use plain text without escape sequences + if [ -z "${HAS_COLORS+x}" ]; then + RED='' + GREEN='' + YELLOW='' + BLUE='' + MAGENTA='' + CYAN='' + GRAY='' + BOLD='' + NC='' + + # Use ASCII alternatives without escape sequences + CHECK_MARK="(+)" + CROSS_MARK="(x)" + ARROW="(>)" + WARNING="(!)" + INFO="(i)" + + HAS_COLORS=0 + fi +} + +# Initialize colors early +setup_colors + +# Function to print section headers +print_section() { + local text="$1" + local text_length=${#text} + local total_width=80 # Standard terminal width + local padding_length=$(( (total_width - text_length - 4) / 2 )) # -4 for the borders and spaces + local left_padding="" + local right_padding="" + + # Create padding strings of spaces for the text line + for ((i=0; i/dev/null 2>&1 +} + +# Comprehensive function to check all requirements +check_requirements() { + print_section "System Requirements Check" + local has_warnings=false + local has_errors=false + + # 1. Required Tools Check + print_status "info" "Checking required tools..." + local required_tools=("mvn" "java" "tar" "gzip" "dot") + local missing_tools=() + + echo "Required tools:" + for tool in "${required_tools[@]}"; do + if command_exists "$tool"; then + case "$tool" in + java) + java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}') + if [[ "$java_version" =~ ^1[1-9]\. || "$java_version" =~ ^[2-9][0-9]\. ]]; then + print_status "success" "✓ Java ${java_version}" + else + print_status "error" "✗ Java ${java_version} (version 11 or higher required)" + echo "Please install Java 11 or higher:" + if [[ "$(uname -sm)" == "Darwin arm64" ]]; then + echo "Apple Silicon (M1/M2) detected, recommended options:" + echo " - Download native arm64 build from: https://adoptium.net/ (recommended)" + echo " - Using Homebrew: brew install --cask temurin" + echo " - Azul Zulu: https://www.azul.com/downloads/?os=macos&architecture=arm-64-bit" + echo "Note: For best performance, ensure you're using an arm64 native JDK" + else + echo " - Download from: https://adoptium.net/ (recommended)" + echo " - Or use your system's package manager:" + echo " - macOS: brew install --cask temurin" + echo " - Ubuntu/Debian: sudo apt install openjdk-11-jdk" + echo " - CentOS/RHEL: sudo yum install java-11-openjdk-devel" + fi + echo " - See BUILDING.md in the project root for more details" + has_errors=true + fi + ;; + mvn) + if [ "$MAVEN_OFFLINE" = false ]; then + mvn_version=$(mvn --version | head -n 1) + print_status "success" "✓ ${mvn_version}" + else + print_status "success" "✓ Maven (offline mode enabled)" + fi + ;; + dot) + dot_version=$(dot -V 2>&1) + print_status "success" "✓ GraphViz: ${dot_version}" + # Set GRAPHVIZ_DOT if not already set + if [ -z "$GRAPHVIZ_DOT" ]; then + export GRAPHVIZ_DOT=$(command -v dot) + MVN_OPTS="$MVN_OPTS -Dgraphviz.dot.path=$GRAPHVIZ_DOT" + fi + ;; + *) + print_status "success" "✓ ${tool}" + ;; + esac + else + missing_tools+=("$tool") + print_status "error" "✗ ${tool} not found" + case "$tool" in + java) + echo "Please install Java 11 or higher:" + if [[ "$(uname -sm)" == "Darwin arm64" ]]; then + echo "Apple Silicon (M1/M2) detected, recommended options:" + echo " - Download native arm64 build from: https://adoptium.net/ (recommended)" + echo " - Using Homebrew: brew install --cask temurin" + echo " - Azul Zulu: https://www.azul.com/downloads/?os=macos&architecture=arm-64-bit" + echo "Note: For best performance, ensure you're using an arm64 native JDK" + else + echo " - Download from: https://adoptium.net/ (recommended)" + echo " - Or use your system's package manager:" + echo " - macOS: brew install --cask temurin" + echo " - Ubuntu/Debian: sudo apt install openjdk-11-jdk" + echo " - CentOS/RHEL: sudo yum install java-11-openjdk-devel" + fi + echo " - See BUILDING.md in the project root for more details" + ;; + mvn) + echo "Please install Maven 3.6 or higher:" + echo " - Download from: https://maven.apache.org/download.cgi" + echo " - Or use your system's package manager:" + echo " - macOS: brew install maven" + echo " - Ubuntu/Debian: sudo apt install maven" + echo " - CentOS/RHEL: sudo yum install maven" + echo " - See installation guide: https://maven.apache.org/install.html" + echo " - See BUILDING.md in the project root for more details" + ;; + dot) + echo "Please install GraphViz (required for documentation generation):" + echo " - Project page: https://graphviz.org/download/" + echo " - Package managers:" + echo " - macOS: brew install graphviz" + echo " - Ubuntu/Debian: sudo apt install graphviz" + echo " - CentOS/RHEL: sudo yum install graphviz" + echo " - See BUILDING.md in the project root for more details" + ;; + tar|gzip) + echo "Please install required system utilities:" + echo " - macOS: These should be pre-installed" + echo " - Ubuntu/Debian: sudo apt install tar gzip" + echo " - CentOS/RHEL: sudo yum install tar gzip" + ;; + esac + has_errors=true + fi + done + echo + + # 3. System Resources Check + print_status "info" "Checking system resources..." + + # Memory check + if command_exists free; then + available_memory=$(free -m | awk '/^Mem:/{print $2}') + if [ "$available_memory" -lt 2048 ]; then + print_status "warning" "✗ Memory: ${available_memory}MB available (2048MB recommended)" + echo "Tips to free up memory:" + echo " - Close unnecessary applications" + echo " - Clear browser cache and tabs" + echo " - Check for memory-intensive processes: top or htop" + echo " - If using a VM, consider increasing its memory allocation" + has_warnings=true + else + print_status "success" "✓ Memory: ${available_memory}MB available" + fi + else + print_status "warning" "? Memory check not available" + echo "Note: Memory check is not available on macOS by default" + echo "You can install htop for memory monitoring: brew install htop" + has_warnings=true + fi + + # Disk space check + if command_exists df; then + available_disk=$(df -m . | awk 'NR==2 {print $4}') + if [ "$available_disk" -lt 1024 ]; then + print_status "warning" "✗ Disk space: ${available_disk}MB available (1024MB recommended)" + echo "Tips to free up disk space:" + echo " - Clear Maven cache: rm -rf ~/.m2/repository" + echo " - Clear Docker images/containers if using Docker" + echo " - Use 'du -sh *' to identify large directories" + echo " - Consider running: mvn clean" + has_warnings=true + else + print_status "success" "✓ Disk space: ${available_disk}MB available" + fi + else + print_status "warning" "? Disk space check not available" + has_warnings=true + fi + echo + + # 4. Configuration Check + print_status "info" "Checking configuration..." + + # Maven settings check + if [ ! -f ~/.m2/settings.xml ]; then + print_status "warning" "✗ Maven settings.xml not found" + echo "Tips for Maven configuration:" + echo " - Create a minimal settings.xml:" + echo " mkdir -p ~/.m2" + echo " echo '\${user.home}/.m2/repository' > ~/.m2/settings.xml" + echo " - Or copy the example from: https://maven.apache.org/settings.html" + echo " - See also: BUILDING.md in the project root for project-specific settings" + has_warnings=true + else + print_status "success" "✓ Maven settings.xml found" + fi + + # Debug port check if debug mode is enabled + if [ "$DEBUG" = true ]; then + if ! [[ "$KARAF_DEBUG_PORT" =~ ^[0-9]+$ ]] || [ "$KARAF_DEBUG_PORT" -lt 1024 ] || [ "$KARAF_DEBUG_PORT" -gt 65535 ]; then + print_status "error" "✗ Debug port: $KARAF_DEBUG_PORT (invalid)" + echo "Please specify a valid port with --debug-port option" + echo "Common debug ports: 5005 (default), 8000, 8453" + has_errors=true + elif command_exists nc && nc -z localhost "$KARAF_DEBUG_PORT" 2>/dev/null; then + print_status "error" "✗ Debug port: $KARAF_DEBUG_PORT (already in use)" + echo "Tips:" + echo " - Choose a different port with --debug-port option" + echo " - Check what's using the port: lsof -i :$KARAF_DEBUG_PORT" + echo " - Kill the process using the port if necessary" + has_errors=true + else + print_status "success" "✓ Debug port: $KARAF_DEBUG_PORT available" + fi + fi + + # Karaf home check if deployment is enabled + if [ "$DEPLOY" = true ]; then + if [ -z "$CONTEXT_SERVER_KARAF_HOME" ]; then + print_status "error" "Karaf home directory not set for deployment" + has_errors=true + elif [ ! -d "$CONTEXT_SERVER_KARAF_HOME" ]; then + print_status "error" "Karaf home directory does not exist: $CONTEXT_SERVER_KARAF_HOME" + has_errors=true + elif [ ! -w "$CONTEXT_SERVER_KARAF_HOME" ]; then + print_status "error" "Karaf home directory not writable: $CONTEXT_SERVER_KARAF_HOME" + has_errors=true + else + print_status "success" "Karaf home directory validated: $CONTEXT_SERVER_KARAF_HOME" + fi + fi + + # 5. Option Validation + print_status "info" "Validating options..." + + if [ "$SKIP_TESTS" = true ] && [ "$RUN_INTEGRATION_TESTS" = true ]; then + print_status "error" "Cannot use --skip-tests and --integration-tests together" + has_errors=true + fi + + if [ ! -z "$SINGLE_TEST" ] && [ "$RUN_INTEGRATION_TESTS" = false ]; then + print_status "error" "Single test specified (--single-test) but integration tests are not enabled. Use --integration-tests to run the test." + has_errors=true + fi + + if [ "$IT_DEBUG" = true ] && [ "$RUN_INTEGRATION_TESTS" = false ]; then + print_status "error" "Integration test debug (--it-debug) enabled but integration tests are not enabled. Use --integration-tests to run the test." + has_errors=true + fi + + if [ "$IT_DEBUG" = true ]; then + if ! [[ "$IT_DEBUG_PORT" =~ ^[0-9]+$ ]] || [ "$IT_DEBUG_PORT" -lt 1024 ] || [ "$IT_DEBUG_PORT" -gt 65535 ]; then + print_status "error" "✗ Integration test debug port: $IT_DEBUG_PORT (invalid)" + echo "Please specify a valid port with --it-debug-port option" + echo "Common debug ports: 5006 (default), 8000, 8453" + has_errors=true + elif command_exists nc && nc -z localhost "$IT_DEBUG_PORT" 2>/dev/null; then + print_status "error" "✗ Integration test debug port: $IT_DEBUG_PORT (already in use)" + echo "Tips:" + echo " - Choose a different port with --it-debug-port option" + echo " - Check what's using the port: lsof -i :$IT_DEBUG_PORT" + echo " - Kill the process using the port if necessary" + has_errors=true + else + print_status "success" "✓ Integration test debug port: $IT_DEBUG_PORT available" + fi + fi + + if [ "$MAVEN_OFFLINE" = true ]; then + if [ "$PURGE_MAVEN_CACHE" = true ]; then + print_status "error" "Cannot use --purge-maven-cache in offline mode" + has_errors=true + fi + if [ "$USE_MAVEN_CACHE" = false ]; then + print_status "warning" "Using --no-maven-cache with offline mode may cause build failures" + has_warnings=true + fi + fi + + # Final status and prompts + echo + if [ "$has_errors" = true ]; then + print_status "error" "Critical requirements not met. Please fix the errors above." + echo + echo "For more information and help:" + echo " - Read BUILDING.md in the project root directory" + echo " - Visit Apache Unomi website: https://unomi.apache.org/" + echo " - Check the troubleshooting guide: https://unomi.apache.org/contribute/building-and-deploying.html" + echo " - Ask for help on the mailing list: dev@unomi.apache.org" + echo " - Report issues: https://issues.apache.org/jira/browse/UNOMI" + exit 1 + fi + + if [ "$has_warnings" = true ]; then + print_status "warning" "Some non-critical requirements not met" + echo "You can proceed, but you may encounter issues during the build" + echo "See warnings above for recommendations" + echo "For more information, check BUILDING.md in the project root" + prompt_continue "Continue despite warnings?" + else + print_status "success" "All requirements checked successfully" + fi +} + +# Construct Maven command +MVN_CMD="mvn" +MVN_OPTS="" + +# Add Maven debug option +if [ "$MAVEN_DEBUG" = true ]; then + MVN_OPTS="$MVN_OPTS -X" + echo "Maven debug output enabled" +fi + +# Add Maven offline option +if [ "$MAVEN_OFFLINE" = true ]; then + MVN_OPTS="$MVN_OPTS -o" + echo "Maven offline mode enabled" + + # Warn if purge cache is enabled with offline mode + if [ "$PURGE_MAVEN_CACHE" = true ]; then + echo "Warning: Purging Maven cache while in offline mode may cause build failures" + read -p "Continue anyway? (y/N) " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + fi +fi + +# Add Maven cache option +if [ "$USE_MAVEN_CACHE" = false ]; then + MVN_OPTS="$MVN_OPTS -Dmaven.build.cache.enabled=false" +fi + +# Verify Maven settings +if [ ! -f ~/.m2/settings.xml ]; then + echo "Warning: Maven settings.xml not found at ~/.m2/settings.xml" + read -p "Continue anyway? (y/N) " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi +fi + +# Add profile options +PROFILES="" +if [ "$RUN_INTEGRATION_TESTS" = true ]; then + if [ "$USE_OPENSEARCH" = true ]; then + MVN_OPTS="$MVN_OPTS -Duse.opensearch=true -P opensearch" + echo "Running integration tests with OpenSearch" + else + echo "Running integration tests with ElasticSearch" + fi + MVN_OPTS="$MVN_OPTS -P integration-tests" + + # Add single test option if specified + if [ ! -z "$SINGLE_TEST" ]; then + MVN_OPTS="$MVN_OPTS -Dit.test=$SINGLE_TEST" + echo "Running single integration test: $SINGLE_TEST" + fi + + # Add integration test debug options if enabled + if [ "$IT_DEBUG" = true ]; then + DEBUG_OPTS="port=$IT_DEBUG_PORT" + if [ "$IT_DEBUG_SUSPEND" = true ]; then + DEBUG_OPTS="$DEBUG_OPTS,hold:true" + echo "Integration test debug enabled with suspend (port: $IT_DEBUG_PORT)" + else + DEBUG_OPTS="$DEBUG_OPTS,hold:false" + echo "Integration test debug enabled (port: $IT_DEBUG_PORT)" + fi + MVN_OPTS="$MVN_OPTS -Dit.karaf.debug=$DEBUG_OPTS" + fi + + # Add migration test exclusion if specified + if [ "$SKIP_MIGRATION_TESTS" = true ]; then + MVN_OPTS="$MVN_OPTS -Dit.test.exclude.pattern=**/migration/**/*IT.java" + echo "Skipping migration tests" + fi +else + if [ "$SKIP_TESTS" = true ]; then + PROFILES="$PROFILES,!integration-tests,!run-tests" + MVN_OPTS="$MVN_OPTS -DskipTests" + fi + + # Warn if single test was specified but integration tests are not enabled + if [ ! -z "$SINGLE_TEST" ]; then + print_status "warning" "Single test specified but integration tests are not enabled. Use --integration-tests to run the test." + fi +fi + +if [ ! -z "$PROFILES" ]; then + # Remove leading comma if present + PROFILES=${PROFILES#,} + MVN_OPTS="$MVN_OPTS -P$PROFILES" +fi + +# Add GraphViz path to Maven options if manually specified +if [ ! -z "$GRAPHVIZ_DOT" ]; then + MVN_OPTS="$MVN_OPTS -Dgraphviz.dot.path=$GRAPHVIZ_DOT" +fi + +# Progress tracking functions +start_timer() { + start_time=$(date +%s) +} + +get_elapsed_time() { + local end_time=$(date +%s) + local elapsed=$((end_time - start_time)) + printf "%02d:%02d" $((elapsed/60)) $((elapsed%60)) +} + +# Build command +cat << "EOF" + ____ _ _ _____ _ ____ + | _ \| | | |_ _| | | _ \ + | |_) | | | | | | | | | | | | + | _ <| | | | | | | | | | | | + | |_) | |__| |_| |_| |____| |_| | + |____/ \____/|_____|______|____/ + +EOF +echo "Building..." +echo "Estimated time: 3-5 minutes for build, 50-60 minutes with integration tests" +start_timer + +# Build phases with enhanced output +total_steps=2 +current_step=0 + +print_progress $((++current_step)) $total_steps "Cleaning previous build..." +if [ "$HAS_COLORS" -eq 1 ]; then + echo -e "${GRAY}Running: $MVN_CMD clean $MVN_OPTS${NC}" +else + echo "Running: $MVN_CMD clean $MVN_OPTS" +fi +$MVN_CMD clean $MVN_OPTS || { + print_status "error" "Maven clean failed" + exit 1 +} + +print_progress $((++current_step)) $total_steps "Compiling and installing artifacts..." +if [ "$HAS_COLORS" -eq 1 ]; then + echo -e "${GRAY}Running: $MVN_CMD install $MVN_OPTS${NC}" +else + echo "Running: $MVN_CMD install $MVN_OPTS" +fi +$MVN_CMD install $MVN_OPTS || { + print_status "error" "Maven install failed" + exit 1 +} + +print_status "success" "Build completed in $(get_elapsed_time)" + +# Deployment section with enhanced output +if [ "$DEPLOY" = true ]; then + # Validate Karaf home directory + if [ -z "$CONTEXT_SERVER_KARAF_HOME" ]; then + print_status "error" "Karaf home directory not set. Use --karaf-home option." + exit 1 + fi + if [ ! -d "$CONTEXT_SERVER_KARAF_HOME" ]; then + print_status "error" "Karaf home directory does not exist: $CONTEXT_SERVER_KARAF_HOME" + exit 1 + fi + if [ ! -w "$CONTEXT_SERVER_KARAF_HOME/deploy" ]; then + print_status "error" "No write permission to Karaf deploy directory: $CONTEXT_SERVER_KARAF_HOME/deploy" + exit 1 + fi + + if [ "$HAS_COLORS" -eq 1 ]; then + echo -e "${MAGENTA}" + cat << "EOF" + ____ _____ ____ _ _____ __ + | _ \| ____| _ \| | / _ \ \ / / + | | | | _| | |_) | | | | | \ V / + | |_| | |___| __/| |__| |_| || | + |____/|_____|_| |_____\___/ |_| + +EOF + echo -e "${NC}" + else + cat << "EOF" + ____ _____ ____ _ _____ __ + | _ \| ____| _ \| | / _ \ \ / / + | | | | _| | |_) | | | | | \ V / + | |_| | |___| __/| |__| |_| || | + |____/|_____|_| |_____\___/ |_| + +EOF + fi + + start_timer + total_deploy_steps=3 + current_step=0 + + print_progress $((++current_step)) $total_deploy_steps "Copying KAR package..." + if [ ! -f "kar/target/unomi-kar-$UNOMI_VERSION.kar" ]; then + print_status "error" "KAR file not found: kar/target/unomi-kar-$UNOMI_VERSION.kar" + exit 1 + fi + cp -v kar/target/unomi-kar-$UNOMI_VERSION.kar $CONTEXT_SERVER_KARAF_HOME/deploy/ || { + print_status "error" "Failed to copy KAR file to deploy directory" + exit 1 + } + print_status "success" "KAR package copied successfully" + + print_progress $((++current_step)) $total_deploy_steps "Purging Karaf Maven repository..." + if [ -d "$CONTEXT_SERVER_KARAF_HOME/data/maven/repository" ]; then + rm -rf "$CONTEXT_SERVER_KARAF_HOME/data/maven/repository/"* || { + print_status "error" "Failed to purge Karaf Maven repository" + exit 1 + } + print_status "success" "Karaf Maven repository purged" + else + print_status "info" "Karaf Maven repository not found, skipping purge" + fi + + print_progress $((++current_step)) $total_deploy_steps "Purging Karaf temporary files..." + if [ -d "$CONTEXT_SERVER_KARAF_HOME/data/tmp" ]; then + rm -rf "$CONTEXT_SERVER_KARAF_HOME/data/tmp/"* || { + print_status "error" "Failed to purge Karaf temporary directory" + exit 1 + } + print_status "success" "Karaf temporary files purged" + else + print_status "info" "Karaf temporary directory not found, skipping purge" + fi + + print_status "success" "Deployment completed in $(get_elapsed_time)" +fi + +# Karaf startup section +if [ "$NO_KARAF" = false ]; then + if [ "$HAS_COLORS" -eq 1 ]; then + echo -e "${GREEN}" + cat << "EOF" + _ __ _ ____ _ _____ + | |/ / / \ | _ \ / \ | ___| + | ' / / _ \ | |_) | / _ \ | |_ + | . \ / ___ \| _ < / ___ \| _| + |_|\_\/_/ \_\_| \_\/_/ \_\_| +EOF + echo -e "${NC}" + else + cat << "EOF" + _ __ _ ____ _ _____ + | |/ / / \ | _ \ / \ | ___| + | ' / / _ \ | |_) | / _ \ | |_ + | . \ / ___ \| _ < / ___ \| _| + |_|\_\/_/ \_\_| \_\/_/ \_\_| +EOF + fi + + total_karaf_steps=4 # Increased for additional checks + current_step=0 + + # Check Karaf environment + print_progress $((++current_step)) $total_karaf_steps "Checking Karaf environment..." + if [ ! -d "package/target" ]; then + print_status "error" "Build directory not found. Did the build complete successfully?" + exit 1 + fi + + pushd package/target || { + print_status "error" "Failed to change directory to package/target" + exit 1 + } + + # Verify Unomi version is set + if [ -z "$UNOMI_VERSION" ]; then + print_status "error" "UNOMI_VERSION is not set" + exit 1 + fi + + print_progress $((++current_step)) $total_karaf_steps "Uncompressing Unomi package..." + if [ ! -f "unomi-$UNOMI_VERSION.tar.gz" ]; then + print_status "error" "Unomi package not found: unomi-$UNOMI_VERSION.tar.gz" + exit 1 + fi + tar zxvf unomi-$UNOMI_VERSION.tar.gz + + print_progress $((++current_step)) $total_karaf_steps "Installing optional databases..." + if [ -f "../../GeoLite2-City.mmdb" ]; then + print_status "info" "Installing GeoLite2 City database..." + cp -v ../../GeoLite2-City.mmdb unomi-$UNOMI_VERSION/etc || { + print_status "error" "Failed to copy GeoLite2 database" + exit 1 + } + else + print_status "info" "GeoLite2 City database not found (optional)" + fi + + if [ -f "../../allCountries.zip" ]; then + print_status "info" "Installing Geonames countries database..." + cp -v ../../allCountries.zip unomi-$UNOMI_VERSION/etc || { + print_status "error" "Failed to copy Geonames database" + exit 1 + } + else + print_status "info" "Geonames countries database not found (optional)" + fi + + cd unomi-$UNOMI_VERSION/bin || { + print_status "error" "Failed to change directory to Karaf bin directory" + exit 1 + } + + print_progress $((++current_step)) $total_karaf_steps "Starting Karaf..." + if [ "$DEBUG" = true ]; then + print_status "info" "Debug mode enabled (port: $KARAF_DEBUG_PORT, suspend: $KARAF_DEBUG_SUSPEND)" + if command -v nc >/dev/null 2>&1; then + if nc -z localhost "$KARAF_DEBUG_PORT" 2>/dev/null; then + print_status "error" "Port $KARAF_DEBUG_PORT is already in use" + exit 1 + fi + fi + export KARAF_DEBUG=true + export JAVA_DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=$KARAF_DEBUG_SUSPEND,address=$KARAF_DEBUG_PORT" + fi + + if [ ! -x "./karaf" ]; then + print_status "error" "Karaf executable not found or not executable" + exit 1 + fi + + if [ ! -z "$AUTO_START" ]; then + print_status "info" "Configuring auto-start for $AUTO_START" + export KARAF_OPTS="-Dunomi.autoStart=$AUTO_START" + else + print_status "info" "Use [unomi:start] to start Unomi after Karaf initialization" + fi + + ./karaf || { + print_status "error" "Karaf failed to start" + exit 1 + } + popd || true +else + print_status "info" "Skipping Karaf startup (--no-karaf specified)" + if [ ! -z "$AUTO_START" ]; then + print_status "info" "Note: auto-start ($AUTO_START) will be applied when Karaf is started manually" + fi +fi + +cat << "EOF" + ____ ___ _ _ _____ _ + | _ \ / _ \| \ | | ____| | + | | | | | | | \| | _| | | + | |_| | |_| | |\ | |___|_| + |____/ \___/|_| \_|_____(_) + +EOF +echo "Operation completed successfully." diff --git a/buildAndRun.sh b/buildAndRun.sh deleted file mode 100755 index df085ae5c1..0000000000 --- a/buildAndRun.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -################################################################################ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -echo Building... -DIRNAME=`dirname "$0"` -PROGNAME=`basename "$0"` -if [ -f "$DIRNAME/setenv.sh" ]; then - . "$DIRNAME/setenv.sh" -fi -mvn clean install -P integration-tests,rat -if [ $? -ne 0 ] -then - exit 1; -fi -pushd package/target -echo Uncompressing Unomi package... -tar zxvf unomi-$UNOMI_VERSION.tar.gz -cd unomi-$UNOMI_VERSION/bin -echo Apache Unomi features installed, use [unomi:start] to start it. -./karaf debug -popd - diff --git a/buildAndRunNoTests.sh b/buildAndRunNoTests.sh deleted file mode 100755 index e3b2ecea84..0000000000 --- a/buildAndRunNoTests.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -################################################################################ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -echo Building... -DIRNAME=`dirname "$0"` -PROGNAME=`basename "$0"` -if [ -f "$DIRNAME/setenv.sh" ]; then - . "$DIRNAME/setenv.sh" -fi -mvn clean install -P \!integration-tests,rat,\!run-tests -DskipTests -if [ $? -ne 0 ] -then - exit 1; -fi -pushd package/target -echo Uncompressing Unomi package... -tar zxvf unomi-$UNOMI_VERSION.tar.gz -if [ -f "../../GeoLite2-City.mmdb" ]; then - echo Installing GeoLite2 City database... - cp ../../GeoLite2-City.mmdb unomi-$UNOMI_VERSION/etc -fi -if [ -f "../../allCountries.zip" ]; then - echo Installing Geonames countries database... - cp ../../allCountries.zip unomi-$UNOMI_VERSION/etc -fi -cd unomi-$UNOMI_VERSION/bin -echo echo Apache Unomi features installed, use [unomi:start] to start it. -./karaf debug -popd - diff --git a/compileDeploy.sh b/compileDeploy.sh deleted file mode 100755 index f1a5110935..0000000000 --- a/compileDeploy.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh -################################################################################ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -echo Setting up environment... -DIRNAME=`dirname "$0"` -PROGNAME=`basename "$0"` -if [ -f "$DIRNAME/setenv.sh" ]; then - . "$DIRNAME/setenv.sh" -fi -if [ "x$CONTEXT_SERVER_KARAF_HOME" = "x" ]; then - CONTEXT_SERVER_KARAF_HOME=~/java/deployments/context-server/apache-karaf-$KARAF_VERSION - export CONTEXT_SERVER_KARAF_HOME -fi -echo Compiling... -mvn clean install -echo Deploying KAR package to $CONTEXT_SERVER_KARAF_HOME/deploy... -cp kar/target/unomi-kar-$UNOMI_VERSION.kar $CONTEXT_SERVER_KARAF_HOME/deploy/ -echo Purging Karaf local Maven repository, exploded KAR directory and temporary directory... -rm -rf $CONTEXT_SERVER_KARAF_HOME/data/maven/repository/* -rm -rf $CONTEXT_SERVER_KARAF_HOME/data/tmp/* -echo Compilation and deployment completed successfully. diff --git a/generate-package.sh b/generate-package.sh deleted file mode 100755 index 73084b931c..0000000000 --- a/generate-package.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -################################################################################ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -echo Building... -mvn clean install -P !integration-tests,rat -echo Package building completed. diff --git a/manual/src/main/asciidoc/building-and-deploying.adoc b/manual/src/main/asciidoc/building-and-deploying.adoc index c91c860523..12dfd91045 100644 --- a/manual/src/main/asciidoc/building-and-deploying.adoc +++ b/manual/src/main/asciidoc/building-and-deploying.adoc @@ -14,6 +14,11 @@ === Building +Apache Unomi 3.x provides a convenient `build.sh` script that simplifies the build process with +enhanced error handling, preflight validation, and deployment options. See the +<> section below for details. Alternatively, you can build using Maven +directly as described in this section. + ==== Initial Setup . Install J2SE 17 SDK (or later), which can be downloaded from @@ -64,6 +69,96 @@ TIP: On a non-English Windows env, the Asciidoctor Maven Plugin may fail to + . The distributions will be available under "package/target" directory. +==== Using the build.sh script + +Apache Unomi 3.x provides a unified `build.sh` script that simplifies the build, deployment, and execution process. +This script replaces multiple legacy build scripts and provides enhanced error handling, colorized output, and +comprehensive environment validation. + +The `build.sh` script offers the following features: + +* **Preflight validation**: Automatically checks for required tools (Java, Maven, GraphViz), system resources + (memory, disk space), Maven settings, and port availability +* **Flexible build options**: Support for skipping tests, running integration tests, using OpenSearch, debug modes, + and more +* **Deployment helpers**: Automatically copies KAR packages to Karaf deploy directory and purges caches +* **Enhanced output**: Colorized, structured output with progress indicators (respects `NO_COLOR` environment variable) + +To use the script: + +. Get the code: `git clone https://github.com/apache/unomi.git` +. Change to the top level directory of Apache Unomi source distribution. +. Make the script executable (if needed): `chmod +x build.sh` +. Run the script with your desired options: ++ +[source] +---- +./build.sh --help +---- ++ +This will display all available options and usage examples. + +Common usage examples: + +* Build with integration tests using OpenSearch: ++ +[source] +---- +./build.sh --integration-tests --use-opensearch +---- ++ +* Build in debug mode: ++ +[source] +---- +./build.sh --debug --debug-port 5006 --debug-suspend +---- ++ +* Deploy to specific Karaf instance: ++ +[source] +---- +./build.sh --deploy --karaf-home ~/apache-karaf +---- ++ +* Build without Karaf and auto-start OpenSearch: ++ +[source] +---- +./build.sh --no-karaf --auto-start opensearch +---- ++ +* Run a single integration test: ++ +[source] +---- +./build.sh --integration-tests --single-test org.apache.unomi.itests.graphql.GraphQLEventIT +---- ++ +* Debug a single integration test: ++ +[source] +---- +./build.sh --integration-tests --single-test org.apache.unomi.itests.graphql.GraphQLEventIT --it-debug --it-debug-suspend +---- ++ +* Run without colored output: ++ +[source] +---- +NO_COLOR=1 ./build.sh +---- ++ +or ++ +[source] +---- +export NO_COLOR=1 +./build.sh +---- ++ +For a complete list of options and examples, run `./build.sh --help`. + ==== Installing an ElasticSearch server Starting with version 1.2, Apache Unomi no longer embeds an ElasticSearch server as this is no longer supported by