Skip to content

Instantly share code, notes, and snippets.

@xlson
Created November 3, 2010 15:55
Show Gist options
  • Select an option

  • Save xlson/661256 to your computer and use it in GitHub Desktop.

Select an option

Save xlson/661256 to your computer and use it in GitHub Desktop.
Finding file ending and classifier of release artifacts in groovy using regexp
def fileNames = '''groovycsv-0.2-javadoc.jar.asc
groovycsv-0.2-javadoc.jar.asc
groovycsv-0.2-sources.jar.asc
groovycsv-0.2.ear.asc'''.split("\n")
def project = new Expando()
project.name = 'groovycsv'
def version='0.2'
def findClassifierPattern = /$project.name-$version(?:-(.+))?\.(\w+\.asc)/
for(filename in fileNames) {
assert filename ==~ findClassifierPattern
(filename =~ findClassifierPattern).find { full, classifier, fileEnding ->
println "Full: $full"
println "Classifier: $classifier"
println "File ending: $fileEnding"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment