Skip to content

Instantly share code, notes, and snippets.

@weiserr
Created February 10, 2016 09:41

Revisions

  1. weiserr created this gist Feb 10, 2016.
    21 changes: 21 additions & 0 deletions colorized_maven.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # Wrapper function for Maven's mvn command.
    mvn-color()
    {
    # Formatting constants
    BOLD=$(echo -e "\e[1m")
    TEXT_RED=$(echo -e "\e[31m")
    TEXT_GREEN=$(echo -e "\e[32m")
    TEXT_YELLOW=$(echo -e "\e[33m")
    TEXT_BLUE=$(echo -e "\e[34m")
    RESET_FORMATTING=$(echo -e "\e[0m")

    # Filter mvn output using sed
    mvn-redirect $@ | sed -e "s/\(\[INFO\].*\)/${TEXT_BLUE}${BOLD}\1/g" \
    -e "s/\(\[WARNING\].*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}/g" \
    -e "s/\(\[ERROR\].*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}/g" \
    -e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${BOLD}${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${BOLD}${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${BOLD}${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${BOLD}${TEXT_YELLOW}\4${RESET_FORMATTING}/g"
    # Make sure formatting is reset
    echo -ne ${RESET_FORMATTING}
    }
    # Override the mvn command with the colorized one.
    alias mvn="mvn-color"