#!/bin/bash

set -e

echo "Starting unit tests and style checks..."

# Run Maven with tests and checkstyle
./mvnw clean verify -DskipITs

# Create reports directory if it doesn't exist
mkdir -p /var/app/reports

# Copy test reports
if [ -d "target/surefire-reports" ]; then
    cp -r target/surefire-reports /var/app/reports/
fi

# Copy checkstyle reports
if [ -d "target" ]; then
    if [ -f "target/checkstyle-result.xml" ]; then
        cp target/checkstyle-result.xml /var/app/reports/
    fi
fi

# Copy coverage reports
if [ -d "target/site/jacoco" ]; then
    cp -r target/site/jacoco /var/app/reports/
fi

echo "Unit tests and style checks completed successfully!"
