plugins {
    id 'java'
    id 'application'
    id 'jacoco'
    id "com.github.breadmoirai.github-release" version "2.2.12"
    id "com.github.jarmstrong.buildconfig" version "1.9.0"
    id "com.github.hierynomus.license" version "0.15.0"
}

group 'com.clouds42'
version '2.7.3'

sourceCompatibility = 11

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
    maven { url 'https://repo1.maven.org/maven2/' }
}


configurations {
    providedCompile
}

dependencies {
    def output = new ByteArrayOutputStream()
    def edtLocation = System.getenv('EDT_LOCATION')
    if (edtLocation == null) {
        def ringExecutable = 'ring.sh'
        if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
            ringExecutable = 'ring.cmd'
        }
        exec {
            commandLine ringExecutable, 'edt@2021.1.5', 'locations', 'list'
            standardOutput = output
        }
        edtLocation = output.toString().trim().split("\n")[0].trim() + '/plugins/'
    }
    println 'EDT location: ' + edtLocation

    compile group: 'info.picocli', name: 'picocli', version: '4.6.3'
    annotationProcessor 'info.picocli:picocli-codegen:4.6.3'

    compile group: 'org.slf4j', name: 'slf4j-api', version: '2.0.3'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.3'

    compile group: 'org.scala-sbt.ipcsocket', name: 'ipcsocket', version: '1.5.0'

    compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.common', version: '2.25.0'
    compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xmi', version: '2.16.0'
    compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xcore.lib', version: '1.6.0'

    compile group: 'org.eclipse.platform', name: 'org.eclipse.osgi', version: '3.17.200'

    compile group: 'org.eclipse.platform', name: 'org.eclipse.core.runtime', version: '3.24.100'
    compile group: 'org.eclipse.platform', name: 'org.eclipse.osgi.services', version: '3.10.200'
    compile group: 'org.eclipse.platform', name: 'org.eclipse.equinox.common', version: '3.16.0'


    compile group: 'org.eclipse.jetty', name: 'jetty-client', version: '11.0.12'

    compile group: 'com.google.guava', name: 'guava', version: '31.1-jre'

    compile group: 'com.google.inject', name: 'guice', version: '5.1.0'

    compile group: 'de.vandermeer', name:'asciitable', version: '0.3.2'

    implementation 'com.github.1c-syntax:mdclasses:0.10.3'
    compile group: 'io.github.1c-syntax', name: 'bsl-common-library', version: '0.3.0'

    implementation('com.github.1c-syntax:bsl-parser:0.21.0') {
        exclude group: "com.tunnelvisionlabs", module: "antlr4-annotations"
        exclude group: "com.ibm.icu", module: "*"
        exclude group: "org.antlr", module: "ST4"
        exclude group: "org.abego.treelayout", module: "org.abego.treelayout.core"
        exclude group: "org.antlr", module: "antlr-runtime"
        exclude group: "org.glassfish", module: "javax.json"
    }

    providedCompile fileTree(edtLocation) { include 'com._1c.g5.v8.dt.debug.*.jar' }

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
    testCompile 'org.xmlunit:xmlunit-core:2.9.0'
    testCompile 'org.xmlunit:xmlunit-matchers:2.9.0'
    testCompile 'com.fasterxml.jackson.core:jackson-core:2.13.4'
    testCompile 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
}

tasks.withType(JavaCompile) {
    sourceSets.main.compileClasspath += configurations.providedCompile
    options.compilerArgs += ["-Aproject=${project.group}/${project.name}"]
    options.encoding = 'UTF-8'
}

run {
    classpath += configurations.providedCompile
}

test {
    finalizedBy jacocoTestReport
    classpath += configurations.providedCompile
    useJUnitPlatform()
    testLogging.showStandardStreams = true
}

startScripts {
  unixStartScriptGenerator.template = resources.text.fromFile(project.getRootDir().getAbsolutePath() + '/scripts/unixStartScript.txt')
  windowsStartScriptGenerator.template = resources.text.fromFile(project.getRootDir().getAbsolutePath() + '/scripts/windowsStartScript.txt')
}

application {
    mainClassName = 'com.clouds42.Coverage41C'
}

jacocoTestReport {
    dependsOn test
}

buildConfig {
    className("BuildConfig")
    packageName("com.clouds42")
    buildConfigField("String", "APP_VERSION", "\"${project.version}\"")
    buildConfigField("long", "BUILD_TIME", "${System.currentTimeMillis()}L")
}

githubRelease {
    token findProperty('github.token')?: ""
    owner "proDOOMman"
    repo "Coverage41C"
    targetCommitish "master"
    releaseAssets.from(distZip.archiveFile)
    dryRun false
}

license {
    header = rootProject.file("HEADER.txt")

    ext["year"] = "2020-" + Calendar.getInstance().get(Calendar.YEAR)
    ext["name"] = "Kosolapov Stanislav aka proDOOMman <prodoomman@gmail.com>"
    ext["project"] = "Coverage41C"
    exclude("**/*.properties")
    exclude("**/*.xml")
    exclude("**/*.json")
    exclude("**/*.bsl")
    exclude("**/*.os")
    exclude("**/*.txt")
    exclude("**/*.java.orig")
    exclude("**/*.impl")
    exclude("**/BuildConfig.java")
    strictCheck = true
    mapping("java", "SLASHSTAR_STYLE")
}
