Skip to content

Instantly share code, notes, and snippets.

@kmila
Forked from evocateur/mvncolor.sh
Last active August 29, 2015 14:06
Show Gist options
  • Save kmila/6d2dc7f3bccd9a8749bb to your computer and use it in GitHub Desktop.
Save kmila/6d2dc7f3bccd9a8749bb to your computer and use it in GitHub Desktop.
adapted from builddoctor/maven-antsy-color
#!/usr/bin/env bash
unalias mvn
unalias maven
unset -f mvn-color
alias maven="command mvn"
# Wrapper function for Maven's mvn command.
mvn-color()
{
local BOLD=`tput bold`
local UNDERLINE_ON=`tput smul`
local UNDERLINE_OFF=`tput rmul`
local TEXT_BLACK=`tput setaf 0`
local TEXT_RED=`tput setaf 1`
local TEXT_GREEN=`tput setaf 2`
local TEXT_YELLOW=`tput setaf 3`
local TEXT_BLUE=`tput setaf 4`
local TEXT_MAGENTA=`tput setaf 5`
local TEXT_CYAN=`tput setaf 6`
local TEXT_WHITE=`tput setaf 7`
local BACKGROUND_BLACK=`tput setab 0`
local BACKGROUND_RED=`tput setab 1`
local BACKGROUND_GREEN=`tput setab 2`
local BACKGROUND_YELLOW=`tput setab 3`
local BACKGROUND_BLUE=`tput setab 4`
local BACKGROUND_MAGENTA=`tput setab 5`
local BACKGROUND_CYAN=`tput setab 6`
local BACKGROUND_WHITE=`tput setab 7`
local RESET_FORMATTING=`tput sgr0`
#local BLUE=""
#local RED=""
#local LIGHT_RED=""
#local LIGHT_GRAY=""
#local LIGHT_GREEN=""
#local LIGHT_BLUE=""
#local LIGHT_CYAN=""
#local YELLOW=""
#local WHITE=""
local GRAY=""
local NO_COLOUR=""
# Filter mvn output using sed
maven "$@" | sed -e "s/\(\[INFO\]\)/${GRAY}\1${NO_COLOUR}/g" \
-e "s/\(Reactor .*:\)/${GRAY}\1${NO_COLOUR}/g" \
-e "s/\(\[INFO\]\ BUILD SUCCESSFUL\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \
-e "s/\(\[debug\].*\)/${TEXT_CYAN}\1${RESET_FORMATTING}/g" \
-e "s/\(@\.*\)/${BOLD}\1${RESET_FORMATTING}/g" \
-e "s/\\(maven-\)\(.*\)\(-plugin.*\)\(@\)/${GRAY}\1${NO_COLOUR}${BOLD}\2${RESET_FORMATTING}${GRAY}\3${NO_COLOUR}${BOLD}\4${RESET_FORMATTING}/g" \
-e "s/\(\[WARNING\]\)\(.*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}${TEXT_YELLOW}\2${RESET_FORMATTING}/g" \
-e "s/\(\[ERROR\].*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}/g" \
-e "s/\(\(BUILD \)\{0,1\}FAILURE.*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}/g" \
-e "s/\(\(BUILD \)\{0,1\}SUCCESS.*\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \
-e "s/\([-]\{3,\}\)/${GRAY}\1${NO_COLOUR}/g" \
-e "s/\([\.]\{3,\}\)/${GRAY}\1${NO_COLOUR}/g" \
-e "s/\(T E S T S\)/${GRAY}\1${NO_COLOUR}/g" \
-e "s/\(Results\)/${GRAY}\1${NO_COLOUR}/g" \
-e "s/\(Building .*: \)\(.*\)/\1${TEXT_CYAN}\2${RESET_FORMATTING}/g" \
-e "s/\(Total time: \)\(.*\)/\1${TEXT_CYAN}\2${RESET_FORMATTING}/g" \
-e "s/\(Finished at: .*\)/${GRAY}\1${NO_COLOUR}/g" \
-e "s/\(Final Memory: .*\)/${GRAY}\1${NO_COLOUR}/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"
MVN_EXIT=${PIPESTATUS[0]}
# Make sure formatting is reset
echo -ne ${RESET_FORMATTING}
return $MVN_EXIT
}
# Override the mvn command with the colorized one.
alias mvn="mvn-color"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment