Open Source Consultant, Software Developer and System Administrator

If you are interrested in hiring a consultant for the effective use of open source software on an enterprise grade, take a look around in the About section to see, what I have to offer.

Blog and snippets

Various snippets or code parts I found useful, so I keep them here for reference.

Pattern for the Vat ID

According to Wikipedia:

@Pattern(regexp=/(ATU[0-9]{8})|(BE0[0-9]{9})|(BE[0-9]{10})|(BG[0-9]{9})|(BG[0-9]{10})|(CY[0-9]{8}L)|(CZ[0-9]{8,10})|(DE[0-9]{9})|(DK[0-9]{8})|(EE[0-9]{9})|(EL[0-9]{9})|(ESX[0-9]{7}X)|(FI[0-9]{8})|(FRXX[0-9]{9})|(GB[0-9]{9})|(GB[0-9]{12})|(GBGD[0-9]{3})|(GBHA[0-9]{3})|(HR[0-9]{11})|(HU[0-9]{8})|(IE[0-9]S[0-9]{5}L)|(IT[0-9]{11})|(LT[0-9]{9})|(LT[0-9]{12})|(LU[0-9]{8})|(LV[0-9]{11})|(MT[0-9]{8})|(NL[0-9]{9}B[0-9][0-9])|(PL[0-9]{10})|(PT[0-9]{9})|(RO[0-9]{9})|(SE[0-9]{12})|(SI[0-9]{8})|(SK[0-9]{10})/)

Excluding deps in configurations, added by plugin, in gradle

The gradle-vaadin-plugin adds its configurations, that later get used to gather the deps for the client compile run, when it runs. So one can not safely create configs and exclude deps there beforehand. But gradle let's you do even this at a later time. This fragment gets rid of springboot-starter-web, as this pulls in java-validation 1.1, which won't compile the client due to GWT restrictions.

project.afterEvaluate {
        configurations.'vaadin-client' {
                exclude module: 'spring-boot-starter-web'
        }
}

See my springboot-groovy-vaadin-starter

Helper to search maven central from command line

If the query contains a : search for all version otherwise do a regular search for latest versions

assert args.size()==1, "Missing parameter"
def q=args[0]
if (q.contains(':')) {
    def (g,a) = q.split(':')
    q = "g:\"$g\"+AND+a:\"$a\"&core=gav"
}
def result = new groovy.json.JsonSlurper().parseText(
    "http://search.maven.org/solrsearch/select?q=$q&wt=json&rows=50".toURL().text
)
result.response.docs.each {
    println "compile '$it.g:$it.a:${it.latestVersion?:it.v}'"
}

Use @CompileStatic for the whole Gradle 2.1 project

Create a config groovyOptionsConfig.groovy:

withConfig(configuration) {
     ast(groovy.transform.CompileStatic)
}

and use in in your build.gradle:

compileGroovy {
     groovyOptions.configurationScript = file("groovyOptionsConfig.groovy")
}