<commit_before>package configurations

import jetbrains.buildServer.configs.kotlin.v2017_2.BuildFeatures
import jetbrains.buildServer.configs.kotlin.v2017_2.BuildStep
import jetbrains.buildServer.configs.kotlin.v2017_2.BuildSteps
import jetbrains.buildServer.configs.kotlin.v2017_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2017_2.CheckoutMode
import jetbrains.buildServer.configs.kotlin.v2017_2.FailureAction
import jetbrains.buildServer.configs.kotlin.v2017_2.ProjectFeatures
import jetbrains.buildServer.configs.kotlin.v2017_2.buildFeatures.commitStatusPublisher
import jetbrains.buildServer.configs.kotlin.v2017_2.buildSteps.GradleBuildStep
import jetbrains.buildServer.configs.kotlin.v2017_2.buildSteps.script
import model.CIBuildModel
import model.GradleSubproject
import model.OS
import model.TestCoverage

private val java7Homes = mapOf(
        OS.windows to """"-Djava7Home=%windows.java7.oracle.64bit%"""",
        OS.linux to "-Djava7Home=%linux.jdk.for.gradle.compile%",
        OS.macos to "-Djava7Home=%macos.java7.oracle.64bit%"
)

private val java9Homes = mapOf(
    OS.windows to """"-Djava9Home=%windows.java9.oracle.64bit%"""",
    OS.linux to "-Djava9Home=%linux.java9.oracle.64bit%",
    OS.macos to "-Djava9Home=%macos.java9.oracle.64bit%"
)


fun shouldBeSkipped(subProject: GradleSubproject, testConfig: TestCoverage): Boolean {
    // TODO: Hacky. We should really be running all the subprojects on macOS
    // But we're restricting this to just a subset of projects for now
    // since we only have a small pool of macOS agents
    return testConfig.os.ignoredSubprojects.contains(subProject.name)
}

val gradleParameters = listOf(
        "-PmaxParallelForks=%maxParallelForks%",
        "-s",
        "--daemon",
        "--continue",
        """-I "%teamcity.build.checkoutDir%/gradle/init-scripts/build-scan.init.gradle.kts"""",
        java7Homes[OS.linux]!!,
        java9Homes[OS.linux]!!
)

val m2CleanScriptUnixLike = """
    REPO=%teamcity.agent.jvm.user.home%/.m2/repository
    if [ -e ${'$'}REPO ] ; then
        tree ${'$'}REPO
        rm -rf ${'$'}REPO
        echo "${'$'}REPO was polluted during the build"
        return 1
    else
        echo "${'$'}REPO does not exist"
    fi
""".trimIndent()

val m2CleanScriptWindows = """
    IF exist %teamcity.agent.jvm.user.home%\.m2\repository (
        TREE %teamcity.agent.jvm.user.home%\.m2\repository
        RMDIR /S /Q %teamcity.agent.jvm.user.home%\.m2\repository
        EXIT 1
    )<commit_msg>Add task creation build ops flag to default Gradle parameters<commit_after>package configurations

import jetbrains.buildServer.configs.kotlin.v2017_2.BuildFeatures
import jetbrains.buildServer.configs.kotlin.v2017_2.BuildStep
import jetbrains.buildServer.configs.kotlin.v2017_2.BuildSteps
import jetbrains.buildServer.configs.kotlin.v2017_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2017_2.CheckoutMode
import jetbrains.buildServer.configs.kotlin.v2017_2.FailureAction
import jetbrains.buildServer.configs.kotlin.v2017_2.ProjectFeatures
import jetbrains.buildServer.configs.kotlin.v2017_2.buildFeatures.commitStatusPublisher
import jetbrains.buildServer.configs.kotlin.v2017_2.buildSteps.GradleBuildStep
import jetbrains.buildServer.configs.kotlin.v2017_2.buildSteps.script
import model.CIBuildModel
import model.GradleSubproject
import model.OS
import model.TestCoverage

private val java7Homes = mapOf(
        OS.windows to """"-Djava7Home=%windows.java7.oracle.64bit%"""",
        OS.linux to "-Djava7Home=%linux.jdk.for.gradle.compile%",
        OS.macos to "-Djava7Home=%macos.java7.oracle.64bit%"
)

private val java9Homes = mapOf(
    OS.windows to """"-Djava9Home=%windows.java9.oracle.64bit%"""",
    OS.linux to "-Djava9Home=%linux.java9.oracle.64bit%",
    OS.macos to "-Djava9Home=%macos.java9.oracle.64bit%"
)


fun shouldBeSkipped(subProject: GradleSubproject, testConfig: TestCoverage): Boolean {
    // TODO: Hacky. We should really be running all the subprojects on macOS
    // But we're restricting this to just a subset of projects for now
    // since we only have a small pool of macOS agents
    return testConfig.os.ignoredSubprojects.contains(subProject.name)
}

val gradleParameters = listOf(
        "-PmaxParallelForks=%maxParallelForks%",
        "-s",
        "--daemon",
        "--continue",
        """-I "%teamcity.build.checkoutDir%/gradle/init-scripts/build-scan.init.gradle.kts"""",
        java7Homes[OS.linux]!!,
        java9Homes[OS.linux]!!,
        "-Dorg.gradle.internal.tasks.createops"
)

val m2CleanScriptUnixLike = """
    REPO=%teamcity.agent.jvm.user.home%/.m2/repository
    if [ -e ${'$'}REPO ] ; then
        tree ${'$'}REPO
        rm -rf ${'$'}REPO
        echo "${'$'}REPO was polluted during the build"
        return 1
    else
        echo "${'$'}REPO does not exist"
    fi
""".trimIndent()

val m2CleanScriptWindows = """
    IF exist %teamcity.agent.jvm.user.home%\.m2\repository (
        TREE %teamcity.agent.jvm.user.home%\.m2\repository
        RMDIR /S /Q %teamcity.agent.jvm.user.home%\.m2\repository
        EXIT 1
    )
{'fraction_non_alphanumeric': 0.1256114263353551, 'fraction_numerical': 0.03247896693406378, 'mean_word_length': 3.7597765363128492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7591715', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1707, 'n_words': 312}