-
-
Save turbanoff/a6dd72a35ef6042f4bdd to your computer and use it in GitHub Desktop.
Setup Colorized Maven 3.2.5 with logback
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
import static groovyx.gpars.GParsPool.* | |
//Automates steps to colorized maven 3.2.5 described in http://aheritier.net/united-colors-of-maven/ | |
//requires groovy 2.x | |
//groovy https://gist.github.com/fbricon/5763949/raw/colorizedMaven [optional/path/to/maven/] | |
def M2_HOME = (args && args.length > 0)?args[0]:System.getenv()["M2_HOME"] | |
println "Adding colorized output to $M2_HOME" | |
if (!M2_HOME) { | |
println "The maven directory can not be found" | |
return | |
} | |
def mvnLibDir = new File(M2_HOME, "lib") | |
if (!mvnLibDir.exists() || !mvnLibDir.isDirectory()) { | |
println "$mvnLibDir does not exist or is not a directory" | |
return | |
} | |
//inject api was introduced in maven 3.1.0 | |
def injectJar = new File(mvnLibDir, "javax.inject-1.jar") | |
if (!injectJar.exists()) { | |
println "This is not the maven you're looking for" | |
return | |
} | |
def slf4jVersion = "1.7.5" | |
def logbackVersion = "1.1.0" | |
def obsoleteJars = ["slf4j-simple-${slf4jVersion}.jar"] | |
def requiredJars = ["http://search.maven.org/remotecontent?filepath=ch/qos/logback/logback-classic/${logbackVersion}/logback-classic-${logbackVersion}.jar", | |
"http://search.maven.org/remotecontent?filepath=ch/qos/logback/logback-core/${logbackVersion}/logback-core-${logbackVersion}.jar"] | |
if (System.properties['os.name'].toLowerCase().contains('windows')) { | |
requiredJars << "http://search.maven.org/remotecontent?filepath=org/fusesource/jansi/jansi/1.11/jansi-1.11.jar" | |
} | |
//If proxy configuration is needed, uncoment this: | |
//System.properties.putAll( ["http.proxyHost":"proxy-host", "http.proxyPort":"proxy-port","http.proxyUserName":"user-name", "http.proxyPassword":"proxy-passwd"] ) | |
withPool { //parallel processing | |
obsoleteJars.eachParallel { jarName -> | |
def jar = new File(mvnLibDir, jarName) | |
if (jar.exists()) { | |
println "Deleting $jar" | |
jar.delete() | |
} | |
} | |
requiredJars.eachParallel { url -> | |
def jarName = url.split('/')[-1] | |
def jar = new File(mvnLibDir, jarName) | |
if (!jar.exists()) { | |
println "Downloading $url to $jar" | |
download(jar, url) | |
} | |
} | |
def logbackConfFile = new File(M2_HOME, "conf/logging/logback.xml") | |
if (!logbackConfFile.exists()) { | |
println "Writing logback configuration to $logbackConfFile" | |
def conf = """<configuration> | |
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |
<withJansi>true</withJansi> | |
<encoder> | |
<!-- | |
| | |
| If you wish to customize the coloured output you can refer | |
| to http://logback.qos.ch/manual/layouts.html#coloring | |
| | |
--> | |
<pattern>%highlight([%replace(%level){'WARN','WARNING'}]) %msg %n</pattern> | |
</encoder> | |
</appender> | |
<root level="INFO"> | |
<appender-ref ref="STDOUT" /> | |
</root> | |
</configuration> | |
""" | |
logbackConfFile << conf | |
} | |
println "Maven should now display colorized output" | |
} | |
def download(file, remoteUrl) { | |
def out = new BufferedOutputStream(new FileOutputStream(file)) | |
out << new URL(remoteUrl).openStream() | |
out.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment