<commit_before>/*
 * Copyright 2018, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package io.spine.tools.gradle.compiler;

import com.google.common.annotations.VisibleForTesting;
import io.spine.tools.gradle.SpinePlugin;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.ResolvedConfiguration;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.PluginContainer;
import org.gradle.api.tasks.TaskCollection;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.compile.CompileOptions;
import org.gradle.api.tasks.compile.JavaCompile;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static io.spine.tools.gradle.ConfigurationName.CLASSPATH;
import static io.spine.tools.gradle.compiler.SpineCheckerExtension.getUseValidatingBuilder;

/**
 * A Gradle plugin which configures the project to run Spine checks during compilation stage.
 *
 * <p>To work, this plugin requires <a href="https://github.com/tbroyer/gradle-errorprone-plugin">
 * the Error Prone plugin</a> applied to the project, as the Spine checks are based on the Error
 * Prone custom checks.
 *
 * <p>The plugin adds a {@code spine-checker} dependency to the project's {@code
 * annotationProcessor} configuration. For older Gradle versions (pre {@code 4.6}), where there is
 * no such configuration, the plugin creates it.
 *
 * <p>Dependency has the same version as the project's {@code spine-model-compiler} plugin
 * dependency.
 *
 * <p>Checks severity may be configured for all checks:
 *
 * <pre>
 * {@code
 *
 *   modelCompiler {
 *      spineCheckSeverity = OFF
 *   }
 * }
 * </pre>
 * or for the specific ones:
 *
 *  <pre>
 * {@code
 *
 *   spineChecker {
 *      useValidatingBuilder = ERROR
 *   }
 * }
 * </pre>
 *
 * <p>The latter overrides the former.
 *
 * @author <NAME>
 * @see io.spine.validate.ValidatingBuilder
 */
public class SpineCheckerPlugin extends SpinePlugin {

    private static final String ERROR_PRONE_PLUGIN_ID = "net.ltgt.errorprone";
    private static final String EXTENSION_NAME = "spineChecker";

    @VisibleForTesting
    static final String PREPROCESSOR_CONFIG_NAME = "annotationProcessor";

    @VisibleForTesting
    static final String SPINE_TOOLS_GROUP = "io.spine.tools";

    @VisibleForTesting
    static final String SPINE_CHECKER_MODULE = "spine-checker";

    @VisibleForTesting
    static final String MODEL_COMPILER_PLUGIN_NAME = "spine-model-compiler";

    static String extensionName() {
        return EXTENSION_NAME;
    }

    @Override
    public void apply(Project project) {
        project.getExtensions()
               .create(extensionName(), SpineCheckerExtension.class);
        Configuration preprocessorConfig = setupPreprocessorConfig(project);
        boolean addedSuccessfully = addSpineCheckerDependency(preprocessorConfig, project);
        if (addedSuccessfully) {
            addConfigureSeverityAction(project);
        }<commit_msg>Switch variables order<commit_after>/*
 * Copyright 2018, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package io.spine.tools.gradle.compiler;

import com.google.common.annotations.VisibleForTesting;
import io.spine.tools.gradle.SpinePlugin;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.ResolvedConfiguration;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.PluginContainer;
import org.gradle.api.tasks.TaskCollection;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.compile.CompileOptions;
import org.gradle.api.tasks.compile.JavaCompile;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static io.spine.tools.gradle.ConfigurationName.CLASSPATH;
import static io.spine.tools.gradle.compiler.SpineCheckerExtension.getUseValidatingBuilder;

/**
 * A Gradle plugin which configures the project to run Spine checks during compilation stage.
 *
 * <p>To work, this plugin requires <a href="https://github.com/tbroyer/gradle-errorprone-plugin">
 * the Error Prone plugin</a> applied to the project, as the Spine checks are based on the Error
 * Prone custom checks.
 *
 * <p>The plugin adds a {@code spine-checker} dependency to the project's {@code
 * annotationProcessor} configuration. For older Gradle versions (pre {@code 4.6}), where there is
 * no such configuration, the plugin creates it.
 *
 * <p>Dependency has the same version as the project's {@code spine-model-compiler} plugin
 * dependency.
 *
 * <p>Checks severity may be configured for all checks:
 *
 * <pre>
 * {@code
 *
 *   modelCompiler {
 *      spineCheckSeverity = OFF
 *   }
 * }
 * </pre>
 * or for the specific ones:
 *
 *  <pre>
 * {@code
 *
 *   spineChecker {
 *      useValidatingBuilder = ERROR
 *   }
 * }
 * </pre>
 *
 * <p>The latter overrides the former.
 *
 * @author <NAME>
 * @see io.spine.validate.ValidatingBuilder
 */
public class SpineCheckerPlugin extends SpinePlugin {

    private static final String EXTENSION_NAME = "spineChecker";
    private static final String ERROR_PRONE_PLUGIN_ID = "net.ltgt.errorprone";

    @VisibleForTesting
    static final String PREPROCESSOR_CONFIG_NAME = "annotationProcessor";

    @VisibleForTesting
    static final String SPINE_TOOLS_GROUP = "io.spine.tools";

    @VisibleForTesting
    static final String SPINE_CHECKER_MODULE = "spine-checker";

    @VisibleForTesting
    static final String MODEL_COMPILER_PLUGIN_NAME = "spine-model-compiler";

    static String extensionName() {
        return EXTENSION_NAME;
    }

    @Override
    public void apply(Project project) {
        project.getExtensions()
               .create(extensionName(), SpineCheckerExtension.class);
        Configuration preprocessorConfig = setupPreprocessorConfig(project);
        boolean addedSuccessfully = addSpineCheckerDependency(preprocessorConfig, project);
        if (addedSuccessfully) {
            addConfigureSeverityAction(project);
        }
{'fraction_non_alphanumeric': 0.08760806916426513, 'fraction_numerical': 0.00138328530259366, 'mean_word_length': 4.3259668508287294, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '2502213', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2385, 'n_words': 754}