May 6, 2011

Maven Color Coding

Here is my bash script that will color code that output of maven. The goal is to highlight any important lines to make it easier to identify if something failed. I highlight all passed unit tests it green and red for the failing tests.

Enjoy,



#!/bin/sh


# other colors
#export COLOR_RED=`echo -e '\033[1;41m\033[37m'`
#export COLOR_GREEN=`echo -e '\033[1;42m\033[37m'`
#export COLOR_NORMAL=`echo -e '\033[0m'`
#export BACKGROUND_BLACK=`tput setab 0`
#export BACKGROUND_RED=`tput setab 1`
#export BACKGROUND_GREEN=`tput setab 2`
#export BACKGROUND_YELLOW=`tput setab 3`
#export BACKGROUND_BLUE=`tput setab 4`
#export BACKGROUND_MAGENTA=`tput setab 5`
#export BACKGROUND_CYAN=`tput setab 6`
#export BACKGROUND_WHITE=`tput setab 7`


export BOLD=`tput bold`
export UNDERLINE_ON=`tput smul`
export UNDERLINE_OFF=`tput rmul`
export TEXT_BLACK=`tput setaf 0`
export TEXT_RED=`tput setaf 1`
export TEXT_GREEN=`tput setaf 2`
export TEXT_YELLOW=`tput setaf 3`
export TEXT_BLUE=`tput setaf 4`
export TEXT_MAGENTA=`tput setaf 5`
export TEXT_CYAN=`tput setaf 6`
export TEXT_WHITE=`tput setaf 7`
export RESET_FORMATTING=`tput sgr0`


mvn $* | sed \
       -e "s/\(\[WARNING\].*\)/${TEXT_YELLOW}\1${RESET_FORMATTING}/g" \
       -e "s/\(\[ERROR\].*\)/${TEXT_RED}\1${RESET_FORMATTING}/g" \
       -e "s/\(.*Failures:\s*[123456789].*\)/$TEXT_RED\1$RESET_FORMATTING/i" \
       -e "s/\(.*Errors:\s*[123456789].*\)/$TEXT_RED\1$RESET_FORMATTING/i" \
       -e "s/\(.*Failures:\s*0,\s*Errors:\s*0.*\)/$TEXT_GREEN\1$RESET_FORMATTING/i" \
       -e "s/\(.*Errors:\s*0,\s*Failures:\s*0.*\)/$TEXT_GREEN\1$RESET_FORMATTING/i"

No comments: