buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    // This plugin allows you to build plugins for IntelliJ platform using specific
    // IntelliJ SDK and bundled plugins.
    // See https://github.com/JetBrains/gradle-intellij-plugin
    id 'org.jetbrains.intellij' version '0.4.21'

    // Kotlin
    id "org.jetbrains.kotlin.jvm" version "1.3.72"
}

apply plugin: 'java'
apply plugin: 'kotlin'

version "${project.version}.${project.buildCounter}"

sourceCompatibility = 1.8
targetCompatibility = 1.8

// ----------------------------------------------------------------------
intellij {
    pluginName 'snakecharm'
    version ideVersion

    def isPyCharm = ideVersion.contains('PY') || ideVersion.contains('PC')

    plugins=[] // add "terminal", xdebug plugin?
    if (ideVersion.contains('PC')) {
        plugins += ['python-ce']
    } else if (ideVersion.contains('PY')) {
        plugins += ['python']
    } else {
        plugins += [pythonPlugin]
    }

    sandboxDirectory "${project.rootDir}/.sandbox${isPyCharm ? "_pycharm" : "" }"
    // ideaDependencyCachePath  "${project.rootDir}/.idea_distrib_cache"  // Useful for Windows due to short cmdline path
    updateSinceUntilBuild false
    instrumentCode Boolean.valueOf(instrumentPluginCode)
    downloadSources Boolean.valueOf(downloadIdeSources)
    intellijRepo "https://www.jetbrains.com/intellij-repository"
}

publishPlugin {
    channels publishChannels.split(',')
    token findProperty('intellijPublishToken') ?: 'no_token_given'
}

patchPluginXml {
    // Use change notes on github
    //changeNotes """ """
    sinceBuild "${project.sinceBuild}"
    untilBuild "${project.untilBuild}"
}

compileKotlin {
  kotlinOptions {
    jvmTarget = "1.8"
  }
}

compileTestKotlin {
  kotlinOptions {
    jvmTarget = "1.8"
  }
}

repositories {
    mavenCentral()
}
                       
dependencies {
    testImplementation 'io.cucumber:cucumber-java:5.6.0'
    testImplementation 'io.cucumber:cucumber-junit:5.6.0'
}

task cucumber() {
    // Cucumber tests are executed using `AllCucumberFeaturesTest` JUnit runner
    // this task is an alternative if `AllCucumberFeaturesTest` stop working for
    // some reason, normally we don't need this
    dependsOn assemble, compileTestKotlin
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"

            classpath =  project.sourceSets.test.runtimeClasspath

            args = ['--plugin', 'pretty', '--glue', 'features.glue', '--tags', 'not @ignore', 'src/test/resources']
        }
    }
}

test {
    reports {
        // turn off html reports... windows can't handle certain cucumber test name characters.
        junitXml.enabled = true
        html.enabled = false
    }

    include '**/*Test.class'
    // exclude '**/AllCucumberFeaturesTest.class'  // Uncomment to disable gradle tests

}

wrapper {
    gradleVersion = '6.2.1'
    distributionUrl = "https://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}