Groovy web console

subscribe to the feed Subscribe
to this
site
sem var without prerelease and meta (via #groovywebconsole)
tweet this snippet Tweet
this
script

sem var without prerelease and meta

Published 3 months ago by juan tkaczyszyn
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
/**
 * Extract Version Numbers from String
 * (discards preRelease and metadata)
 *
 * @input String semantic version string
 * @return String stripped of preRelease and metadata
 */
def extractVersionNumbers( String input ) {
  input.findAll( /^\d+\.\d+\.\d+/ )[0]
}

/**
 * Create Map from two Lists
 *
 * @keys List of keys
 * @values List of values
 * @return Map
 */

def splitVersion(String version) {
    return extractVersionNumbers(version)
            .tokenize('.')
            .collect({versionChunk -> versionChunk.toInteger()})
}

splitVersion('1.2.3-rc1+local')