<commit_before>package jetbrains.buildServer.dotnet.commands

import jetbrains.buildServer.dotNet.DotNetConstants
import jetbrains.buildServer.dotnet.CoverageConstants
import jetbrains.buildServer.dotnet.DotnetConstants
import jetbrains.buildServer.requirements.Requirement
import jetbrains.buildServer.requirements.RequirementQualifier
import jetbrains.buildServer.requirements.RequirementType
import jetbrains.buildServer.serverSide.InvalidProperty
import jetbrains.buildServer.serverSide.ProjectManager
import jetbrains.buildServer.tools.ServerToolManager
import jetbrains.buildServer.util.VersionComparatorUtil
import org.springframework.beans.factory.BeanFactory

class DotCoverCoverageType: CommandType() {
    override val name: String = CoverageConstants.PARAM_DOTCOVER

    override val description: String = "JetBrains dotCover"

    override val editPage: String = "editDotCoverParameters.jsp"

    override val viewPage: String = "viewDotCoverParameters.jsp"

    override fun validateProperties(properties: Map<String, String>) = sequence {
        yieldAll(super.validateProperties(properties))

        if (properties[CoverageConstants.PARAM_DOTCOVER_HOME].isNullOrBlank()) {
            yield(InvalidProperty(CoverageConstants.PARAM_DOTCOVER_HOME, DotnetConstants.VALIDATION_EMPTY))
        }
    }

    override fun getRequirements(parameters: Map<String, String>, factory: BeanFactory) = sequence {
        yieldAll(super.getRequirements(parameters, factory))

        if (isDocker(parameters)) return@sequence

        val requirements = mutableSetOf<Requirement>()
        if ("dotcover" != parameters["dotNetCoverage.tool"]) return@sequence
        val dotCoverHomeValue = parameters["dotNetCoverage.dotCover.home.path"] ?: return@sequence
        val toolManager = factory.getBean(ServerToolManager::class.java)
        val toolType = toolManager.findToolType("JetBrains.dotCover.CommandLineTools") ?: return@sequence
        val projectManager = factory.getBean(ProjectManager::class.java)
        val toolVersion = toolManager.resolveToolVersionReference(toolType, dotCoverHomeValue, projectManager.getRootProject()) ?: return@sequence
        if (VersionComparatorUtil.compare("2018.2", toolVersion.getVersion()) <= 0) {
            requirements.add(OUR_NET_461_REQUIREMENT)
        }

        if (requirements.isEmpty()) {
            requirements.add(OUR_MINIMAL_REQUIREMENT)
        }

        requirements.forEach { yield(it) }
    }

    companion object {
        private val OUR_MINIMAL_REQUIREMENT = Requirement(RequirementQualifier.EXISTS_QUALIFIER + "(" + DotNetConstants.DOTNET_FRAMEWORK_3_5.replace(".", "\\.") + "_.+|" + DotNetConstants.DOTNET_FRAMEWORK_4 + "\\.[\\d\\.]+_.+)", null, RequirementType.EXISTS)
        private val OUR_NET_461_REQUIREMENT = Requirement(RequirementQualifier.EXISTS_QUALIFIER + "(" + DotNetConstants.DOTNET_FRAMEWORK_4 + "\\.(6\\.|[7-9]|[\\d]{2,})[\\d\\.]*_.+)", null, RequirementType.EXISTS)
    }
}<commit_msg>TW-57428 Change dotCover requirements according to rule: dotCover 2018.2+ requires .net framework 4.6.1+<commit_after>package jetbrains.buildServer.dotnet.commands

import jetbrains.buildServer.dotNet.DotNetConstants
import jetbrains.buildServer.dotnet.CoverageConstants
import jetbrains.buildServer.dotnet.DotnetConstants
import jetbrains.buildServer.requirements.Requirement
import jetbrains.buildServer.requirements.RequirementQualifier
import jetbrains.buildServer.requirements.RequirementType
import jetbrains.buildServer.serverSide.InvalidProperty
import jetbrains.buildServer.serverSide.ProjectManager
import jetbrains.buildServer.tools.ServerToolManager
import jetbrains.buildServer.util.VersionComparatorUtil
import org.springframework.beans.factory.BeanFactory

class DotCoverCoverageType: CommandType() {
    override val name: String = CoverageConstants.PARAM_DOTCOVER

    override val description: String = "JetBrains dotCover"

    override val editPage: String = "editDotCoverParameters.jsp"

    override val viewPage: String = "viewDotCoverParameters.jsp"

    override fun validateProperties(properties: Map<String, String>) = sequence {
        yieldAll(super.validateProperties(properties))

        if (properties[CoverageConstants.PARAM_DOTCOVER_HOME].isNullOrBlank()) {
            yield(InvalidProperty(CoverageConstants.PARAM_DOTCOVER_HOME, DotnetConstants.VALIDATION_EMPTY))
        }
    }

    override fun getRequirements(parameters: Map<String, String>, factory: BeanFactory) = sequence {
        yieldAll(super.getRequirements(parameters, factory))

        if (isDocker(parameters)) return@sequence

        val requirements = mutableSetOf<Requirement>()
        requirements += OUR_MINIMAL_REQUIREMENT
        if ("dotcover" != parameters["dotNetCoverage.tool"]) return@sequence
        val dotCoverHomeValue = parameters["dotNetCoverage.dotCover.home.path"] ?: return@sequence
        val toolManager = factory.getBean(ServerToolManager::class.java)
        val toolType = toolManager.findToolType("JetBrains.dotCover.CommandLineTools") ?: return@sequence
        val projectManager = factory.getBean(ProjectManager::class.java)
        val toolVersion = toolManager.resolveToolVersionReference(toolType, dotCoverHomeValue, projectManager.getRootProject()) ?: return@sequence
        if (VersionComparatorUtil.compare("2018.2", toolVersion.getVersion()) <= 0) {
            requirements.clear()
            requirements.add(OUR_NET_461_REQUIREMENT)
        }

        requirements.forEach { yield(it) }
    }

    companion object {
        private val OUR_MINIMAL_REQUIREMENT = Requirement(RequirementQualifier.EXISTS_QUALIFIER + "(" + DotNetConstants.DOTNET_FRAMEWORK_3_5.replace(".", "\\.") + "_.+|" + DotNetConstants.DOTNET_FRAMEWORK_4 + "\\.[\\d\\.]+_.+)", null, RequirementType.EXISTS)
        private val OUR_NET_461_REQUIREMENT = Requirement(RequirementQualifier.EXISTS_QUALIFIER + "(" + DotNetConstants.DOTNET_FRAMEWORK_4 + "\\.(6\\.|[7-9]|[\\d]{2,})[\\d\\.]*_.+)", null, RequirementType.EXISTS)
    }
}
{'fraction_non_alphanumeric': 0.10439834024896266, 'fraction_numerical': 0.008796680497925312, 'mean_word_length': 4.777564717162033, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '23004', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1675, 'n_words': 268}