<commit_before>package nebula.plugin.responsible.ide

import nebula.plugin.responsible.FacetDefinition
import nebula.plugin.responsible.TestFacetDefinition
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.SourceSet
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaModule

class IdeaPluginConfigurer implements IDEPluginConfigurer {
    private final Project project

    IdeaPluginConfigurer(Project project) {
        this.project = project
    }

    /**
     * {@inheritDoc}
     */
    @Override
    void configure(SourceSet sourceSet, FacetDefinition facet) {
        if(facet instanceof TestFacetDefinition) {
            configureIdeaPluginForTestSourceSet(sourceSet)
        }
        else {
            configureIdeaPluginForSourceSet(sourceSet)
        }
    }

    private void withIdeaModule(Closure c) {
        project.plugins.withType(IdeaPlugin) {
            project.idea { IdeaModel model ->
                c(model.module)
            }
        }
    }

    /**
     * Configures IDEA plugin to add given SourceSet to test source directories and implicit configurations to the TEST
     * scope.
     *
     * @param testSourceSet Test SourceSet
     */
    private void configureIdeaPluginForTestSourceSet(SourceSet testSourceSet) {
        withIdeaModule { IdeaModule module ->
            testSourceSet.allSource.srcDirs.each { srcDir ->
                module.testSourceDirs += srcDir
            }

            module.scopes.TEST.plus += getSourceSetCompileConfiguration(testSourceSet.name)
            module.scopes.TEST.plus += getSourceSetRuntimeConfiguration(testSourceSet.name)
        }
    }

    /**
     * Configures IDEA plugin to add given SourceSet to source directories and implicit configurations to the COMPILE
     * scope.
     *
     * @param sourceSet SourceSet
     */
    private void configureIdeaPluginForSourceSet(SourceSet sourceSet) {
        withIdeaModule { IdeaModule module ->
            sourceSet.allSource.srcDirs.each { srcDir ->
                module.sourceDirs += srcDir
            }

            module.scopes.COMPILE.plus += getSourceSetCompileConfiguration(sourceSet.name)
            module.scopes.COMPILE.plus += getSourceSetRuntimeConfiguration(sourceSet.name)
        }
    }

    private Configuration getSourceSetCompileConfiguration(String sourceSetName) {
        project.configurations.getByName("${sourceSetName}Compile")
    }

    private Configuration getSourceSetRuntimeConfiguration(String sourceSetName) {
        project.configurations.getByName("${sourceSetName}Runtime")
    }
}<commit_msg>Use built-in methods on SourceSet to resolve configurations by name.<commit_after>package nebula.plugin.responsible.ide

import nebula.plugin.responsible.FacetDefinition
import nebula.plugin.responsible.TestFacetDefinition
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.tasks.SourceSet
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaModule

class IdeaPluginConfigurer implements IDEPluginConfigurer {
    private final Project project

    IdeaPluginConfigurer(Project project) {
        this.project = project
    }

    /**
     * {@inheritDoc}
     */
    @Override
    void configure(SourceSet sourceSet, FacetDefinition facet) {
        if(facet instanceof TestFacetDefinition) {
            configureIdeaPluginForTestSourceSet(sourceSet)
        }
        else {
            configureIdeaPluginForSourceSet(sourceSet)
        }
    }

    private void withIdeaModule(Closure c) {
        project.plugins.withType(IdeaPlugin) {
            project.idea { IdeaModel model ->
                c(model.module)
            }
        }
    }

    /**
     * Configures IDEA plugin to add given SourceSet to test source directories and implicit configurations to the TEST
     * scope.
     *
     * @param testSourceSet Test SourceSet
     */
    private void configureIdeaPluginForTestSourceSet(SourceSet testSourceSet) {
        withIdeaModule { IdeaModule module ->
            testSourceSet.allSource.srcDirs.each { srcDir ->
                module.testSourceDirs += srcDir
            }

            module.scopes.TEST.plus += getConfiguration(testSourceSet.compileConfigurationName)
            module.scopes.TEST.plus += getConfiguration(testSourceSet.runtimeConfigurationName)
        }
    }

    /**
     * Configures IDEA plugin to add given SourceSet to source directories and implicit configurations to the COMPILE
     * scope.
     *
     * @param sourceSet SourceSet
     */
    private void configureIdeaPluginForSourceSet(SourceSet sourceSet) {
        withIdeaModule { IdeaModule module ->
            sourceSet.allSource.srcDirs.each { srcDir ->
                module.sourceDirs += srcDir
            }

            module.scopes.COMPILE.plus += getConfiguration(sourceSet.compileConfigurationName)
            module.scopes.COMPILE.plus += getConfiguration(sourceSet.runtimeConfigurationName)
        }
    }

    private Configuration getConfiguration(String sourceSetName) {
        project.configurations.getByName(sourceSetName)
    }
}
{'fraction_non_alphanumeric': 0.07468568211671983, 'fraction_numerical': 0.0, 'mean_word_length': 2.748241912798875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3318037', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1384, 'n_words': 272}