-
-
Save kmila/6d2dc7f3bccd9a8749bb to your computer and use it in GitHub Desktop.
adapted from builddoctor/maven-antsy-color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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="[0;34m" | |
#local RED="[0;31m" | |
#local LIGHT_RED="[1;31m" | |
#local LIGHT_GRAY="[0;37m" | |
#local LIGHT_GREEN="[1;32m" | |
#local LIGHT_BLUE="[1;34m" | |
#local LIGHT_CYAN="[1;36m" | |
#local YELLOW="[1;33m" | |
#local WHITE="[1;37m" | |
local GRAY="[1;30m" | |
local NO_COLOUR="[0m" | |
# 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