<commit_before>#!/usr/bin/env groovy
@Grab(group = 'com.github.zafarkhaja', module = 'java-semver', version = '0.9.0')
import com.github.zafarkhaja.semver.Version

def executeOnShell(String command, Closure closure = null) {
  executeOnShell(command, new File(System.properties.'user.dir'), closure)
}

def executeOnShell(String command, File workingDir, Closure closure = null) {
  println command
  def process = new ProcessBuilder(['sh', '-c', command])
    .directory(workingDir)
    .redirectErrorStream(true)
    .start()
  def cl = closure
  if (cl == null) {
    cl = { println it }
  }
  process.inputStream.eachLine cl
  process.waitFor()
  if (process.exitValue() > 0) {
    System.exit(process.exitValue())
  }
}

void ask(String prompt, String defaultValue = 'Y', Closure cl) {
  def promptValue = System.console().readLine(prompt + ' ').trim()
  if (promptValue.empty) {
    promptValue = defaultValue
  }
  if (promptValue.toUpperCase() == 'Y') {
    cl.call()
  }
}

executeOnShell 'git pull'

ask('Execute Build?: [Y]') {
  executeOnShell './gradlew clean check install'
}

def projectProps = './gradlew :pact-jvm-consumer_2.11:properties'.execute().text.split('\n').inject([:]) { acc, v ->
  if (v ==~ /\w+: .*/) {
    def kv = v.split(':')
    acc[kv[0].trim()] = kv[1].trim()
  }
  acc
}

def version = projectProps.version
<commit_msg>add java version check to release script<commit_after>#!/usr/bin/env groovy
@Grab(group = 'com.github.zafarkhaja', module = 'java-semver', version = '0.9.0')
import com.github.zafarkhaja.semver.Version

def executeOnShell(String command, Closure closure = null) {
  executeOnShell(command, new File(System.properties.'user.dir'), closure)
}

def executeOnShell(String command, File workingDir, Closure closure = null) {
  println "==>: $command"
  def process = new ProcessBuilder(['sh', '-c', command])
    .directory(workingDir)
    .redirectErrorStream(true)
    .start()
  def cl = closure
  if (cl == null) {
    cl = { println it }
  }
  process.inputStream.eachLine cl
  process.waitFor()
  if (process.exitValue() > 0) {
    System.exit(process.exitValue())
  }
}

void ask(String prompt, String defaultValue = 'Y', Closure cl) {
  def promptValue = System.console().readLine(prompt + ' ').trim()
  if (promptValue.empty) {
    promptValue = defaultValue
  }
  if (promptValue.toUpperCase() == 'Y') {
    cl.call()
  }
}

executeOnShell 'git pull'

def javaVersion
executeOnShell("./gradlew --version 2>/dev/null | awk '/^JVM:/ { print \$2 }'") {
  javaVersion = Version.valueOf(it.trim().replace('_', '+b'))
}
if (!javaVersion?.satisfies('>=1.8.0')) {
  ask("You are building against Java $javaVersion. Do you want to exit?: [Y]") {
    System.exit(1)
  }
}

ask('Execute Build?: [Y]') {
  executeOnShell './gradlew clean check install'
}

def projectProps = './gradlew :pact-jvm-consumer_2.11:properties'.execute().text.split('\n').inject([:]) { acc, v ->
  if (v ==~ /\w+: .*/) {
    def kv = v.split(':')
    acc[kv[0].trim()] = kv[1].trim()
  }
  acc
}

def version = projectProps.version

{'fraction_non_alphanumeric': 0.17560497056899935, 'fraction_numerical': 0.007848266841072597, 'mean_word_length': 3.802197802197802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2596670', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1063, 'n_words': 241}