plugins {
    id "jacoco"
    id "org.jetbrains.intellij" version "0.7.3"
    id "com.github.hierynomus.license" version "0.15.0"
    id "com.github.gradle-git-version-calculator" version "1.1.0"
    id 'net.researchgate.release' version '2.6.0'
    id "com.gradle.plugin-publish" version "0.10.1"
    id "com.github.spotbugs" version "3.0.0"
    id "org.sonarqube" version "2.8"
    id 'signing'
}

repositories {
    mavenCentral()
}

tasks{
    runPluginVerifier {
        ideVersions = "2021.1"
    }
}

group = "org.wso2.lsp4intellij"
version = gitVersionCalculator.calculateVersion("v")

intellij {
    version '2021.1'
    type 'IC'
    updateSinceUntilBuild false
}

dependencies {
    compile group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.15.0'
    compile group: 'com.vladsch.flexmark', name: 'flexmark', version: '0.34.60'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
    testCompile group: 'junit', name: 'junit', version: '4.13.2'
    testCompile group: 'org.mockito', name: 'mockito-core', version: '3.9.0'
    testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.9'
    testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.9'
}

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java']
        }
    }
}

sourceCompatibility = 11
targetCompatibility = 11

license {
    header = rootProject.file("resources/license/HEADER.txt")
    ext["year"] = Calendar.getInstance().get(Calendar.YEAR)
    ext["author"] = "WSO2 Inc. (http://www.wso2.org)"
    strictCheck = true
    skipExistingHeaders = true
    mapping("java", "SLASHSTAR_STYLE")
    exclude("/**/*.png")
}

spotbugsMain {
    it.effort "max"
    it.reportLevel "high"
    it.reports {
        xml.enabled false
        html.enabled true
    }
    def excludeFile = file('spotbugs-exclude.xml')
    if(excludeFile.exists()) {
        it.excludeFilter = excludeFile
    }
    classpath += sourceSets."${(it.name - ~/^spotbugs/).uncapitalize()}".with { it.compileClasspath + project.configurations."${it.compileOnlyConfigurationName}" }
}

spotbugsTest {
    it.enabled = false
}

check {
    dependsOn(tasks.jacocoTestReport)
}

jacocoTestReport {
    reports {
        xml.enabled = true
        xml.destination = new File("$buildDir/reports/jacoco/test/jacoco.xml")
    }
}

sonarqube {
    properties {
        property("sonar.sourceEncoding", "UTF-8")
        property("sonar.host.url", "https://sonarcloud.io")
        property("sonar.organization", "ballerina-platform")
        property("sonar.projectKey", "ballerina-platform_lsp4intellij")
        property("sonar.projectName", "LSP4IntelliJ")
        property("sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/jacoco/test/jacoco.xml")
    }
}

release {
    failOnCommitNeeded = true
    failOnPublishNeeded = true
    failOnSnapshotDependencies = true
    failOnUnversionedFiles = true
    failOnUpdateNeeded = true
    revertOnFail = true
    preCommitText = ''
    preTagCommitMessage = '[Gradle Release Plugin] - pre tag commit: '
    tagCommitMessage = '[Gradle Release Plugin] - creating tag: '
    newVersionCommitMessage = '[Gradle Release Plugin] - new version commit: '
    tagTemplate = '${version}'
    versionPropertyFile = 'gradle.properties'
    buildTasks = ['jar']

    git {
        requireBranch = 'release-stage'
        pushToRemote = 'upstream'
        commitVersionFileOnly = false
        signTag = false
    }
}
