import java.util.zip.*
import java.io.*
import com.jetbrains.plugin.blockmap.core.BlockMap
import com.jetbrains.plugin.blockmap.core.FileHash
import com.fasterxml.jackson.databind.ObjectMapper

buildscript {
    repositories {
       mavenCentral()
    }
    dependencies {
       classpath group: 'org.jetbrains.intellij', name: 'blockmap', version: '1.0.5'
       // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
       classpath group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.3'
    }
}

task antProperties {
  onlyIf {
    buildNumber().find()
  } 
  doLast {
    ant.properties.'ci.build.num' = "${buildNumber().find() ? buildNumber()[0][4] : '9999'}".toString()
    ant.properties.'ci.build.tag' = "${buildNumber().find() ? buildNumber()[0][4] : 'SNAPSHOT'}".toString()
    ant.properties.'ci.mps.release' = "${buildNumber().find() ? buildNumber()[0][1] : '232'}".toString()
  }
}


task setup(dependsOn: [':setup', antProperties]) {
}

ant.importBuild('build.xml') {antTarget ->
    'mpscore-'+antTarget
}
// ensure 'generate' runs before 'classes' ('generate' is NOT optional)
'mpscore-compileJava' {
  dependsOn {
    'mpscore-generate'
  }  
  mustRunAfter {
    'mpscore-generate'
  }
}

'mpscore-declare-mps-tasks' {
  dependsOn {
    'setup'
  }
}

'mpscore-generate' {
  dependsOn {
    ':coderules-assemble'
  }
}

assemble {
  dependsOn {
    'mpscore-assemble'
  }
}

check {
  dependsOn {
    'mpscore-check'
  }
}

