<commit_before>package me.champeau.gradle.japicmp;

import japicmp.filter.Filter;
import me.champeau.gradle.japicmp.filters.FilterConfiguration;
import me.champeau.gradle.japicmp.report.RichReport;
import me.champeau.gradle.japicmp.report.RuleConfiguration;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.JavaVersion;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.CompileClasspath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.workers.IsolationMode;
import org.gradle.workers.WorkerConfiguration;
import org.gradle.workers.WorkerExecutor;
import org.gradle.util.GradleVersion;

import java.io.File;
import java.net.URISyntaxException;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@CacheableTask
public class JapicmpTask extends DefaultTask {

    private List<String> packageIncludes = new ArrayList<>();
    private List<String> packageExcludes = new ArrayList<>();
    private List<String> classIncludes = new ArrayList<>();
    private List<String> classExcludes = new ArrayList<>();
    private List<String> methodIncludes = new ArrayList<>();
    private List<String> methodExcludes = new ArrayList<>();
    private List<String> fieldIncludes = new ArrayList<>();
    private List<String> fieldExcludes = new ArrayList<>();
    private List<String> annotationIncludes = new ArrayList<>();
    private List<String> annotationExcludes = new ArrayList<>();
    private List<FilterConfiguration> includeFilters = new ArrayList<>();
    private List<FilterConfiguration> excludeFilters = new ArrayList<>();
    private String accessModifier = "public";
    private boolean onlyModified = false;
    private boolean onlyBinaryIncompatibleModified = false;
    private boolean failOnSourceIncompatibility = false;
    private File xmlOutputFile;
    private File htmlOutputFile;
    private File txtOutputFile;
    private boolean failOnModification = false;
    private boolean includeSynthetic = false;
    private FileCollection oldClasspath;
    private FileCollection newClasspath;
    private FileCollection oldArchives;
    private FileCollection newArchives;
    private boolean ignoreMissingClasses = false;
    private RichReport richReport;

    @TaskAction
    public void exec() {
        WorkerExecutor workerExecutor = getServices().get(WorkerExecutor.class);
        workerExecutor.submit(JApiCmpWorkerAction.class, new Action<WorkerConfiguration>() {
            @Override
            public void execute(final WorkerConfiguration workerConfiguration) {
                workerConfiguration.setIsolationMode(IsolationMode.PROCESS);
                Set<File> classpath = new HashSet<>();
                if (includeFilters != null) {
                    for (FilterConfiguration configuration : includeFilters) {
                        addClasspathFor(configuration.getFilterClass(), classpath);
                    }
                }
                if (excludeFilters != null) {
                    for (FilterConfiguration configuration : excludeFilters) {
                        addClasspathFor(configuration.getFilterClass(), classpath);
                    }
                }
                if (richReport != null) {
                    for (RuleConfiguration configuration : richReport.getRules()) {
                        addClasspathFor(configuration.getRuleClass(), classpath);
                    }
                }
                if (JavaVersion.current().isJava9Compatible()) {
                    classpath.addAll(resolveJaxb().getFiles());
                }
                if (GradleVersion.current().compareTo(GradleVersion.version("6.0")) >= 0) {
                    classpath.addAll(resolveGuava().getFiles());
                }
                workerConfiguration.setClasspath(classpath);
                List<JApiCmpWorkerAction.Archive> baseline = JapicmpTask.this.oldArchives != null ? toArchives(JapicmpTask.this.oldArchives) : inferArchives(oldClasspath);
                List<JApiCmpWorkerAction.Archive> current = JapicmpTask.this.newArchives != null ? toArchives(JapicmpTask.this.newArchives) : inferArchives(newClasspath);
                workerConfiguration.setDisplayName("JApicmp check comparing " + current + " with " + baseline);
                workerConfiguration.params(
                        // we use a single configuration object, instead of passing each parameter directly,
                        // because the worker API doesn't support "null" values
                        new JapiCmpWorkerConfiguration(
                                isIncludeSynthetic(),
                                isIgnoreMissingClasses(),
                                getPackageIncludes(),
                                getPackageExcludes(),<commit_msg>Rework additional japicmp classpath calculation for CC<commit_after>package me.champeau.gradle.japicmp;

import japicmp.filter.Filter;
import me.champeau.gradle.japicmp.filters.FilterConfiguration;
import me.champeau.gradle.japicmp.report.RichReport;
import me.champeau.gradle.japicmp.report.RuleConfiguration;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.JavaVersion;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.CompileClasspath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.workers.IsolationMode;
import org.gradle.workers.WorkerConfiguration;
import org.gradle.workers.WorkerExecutor;
import org.gradle.util.GradleVersion;

import java.io.File;
import java.net.URISyntaxException;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@CacheableTask
public class JapicmpTask extends DefaultTask {

    private final FileCollection additionalJapicmpClasspath;
    private List<String> packageIncludes = new ArrayList<>();
    private List<String> packageExcludes = new ArrayList<>();
    private List<String> classIncludes = new ArrayList<>();
    private List<String> classExcludes = new ArrayList<>();
    private List<String> methodIncludes = new ArrayList<>();
    private List<String> methodExcludes = new ArrayList<>();
    private List<String> fieldIncludes = new ArrayList<>();
    private List<String> fieldExcludes = new ArrayList<>();
    private List<String> annotationIncludes = new ArrayList<>();
    private List<String> annotationExcludes = new ArrayList<>();
    private List<FilterConfiguration> includeFilters = new ArrayList<>();
    private List<FilterConfiguration> excludeFilters = new ArrayList<>();
    private String accessModifier = "public";
    private boolean onlyModified = false;
    private boolean onlyBinaryIncompatibleModified = false;
    private boolean failOnSourceIncompatibility = false;
    private File xmlOutputFile;
    private File htmlOutputFile;
    private File txtOutputFile;
    private boolean failOnModification = false;
    private boolean includeSynthetic = false;
    private FileCollection oldClasspath;
    private FileCollection newClasspath;
    private FileCollection oldArchives;
    private FileCollection newArchives;
    private boolean ignoreMissingClasses = false;
    private RichReport richReport;

    public JapicmpTask() {
        getProject().getLayout();
        ConfigurableFileCollection classpath = getProject().files();
        if (JavaVersion.current().isJava9Compatible()) {
            classpath.from(resolveJaxb());
        }
        if (GradleVersion.current().compareTo(GradleVersion.version("6.0")) >= 0) {
            classpath.from(resolveGuava());
        }
        additionalJapicmpClasspath = classpath;
    }

    @TaskAction
    public void exec() {
        WorkerExecutor workerExecutor = getServices().get(WorkerExecutor.class);
        workerExecutor.submit(JApiCmpWorkerAction.class, new Action<WorkerConfiguration>() {
            @Override
            public void execute(final WorkerConfiguration workerConfiguration) {
                workerConfiguration.setIsolationMode(IsolationMode.PROCESS);
                Set<File> classpath = new HashSet<>();
                if (includeFilters != null) {
                    for (FilterConfiguration configuration : includeFilters) {
                        addClasspathFor(configuration.getFilterClass(), classpath);
                    }
                }
                if (excludeFilters != null) {
                    for (FilterConfiguration configuration : excludeFilters) {
                        addClasspathFor(configuration.getFilterClass(), classpath);
                    }
                }
                if (richReport != null) {
                    for (RuleConfiguration configuration : richReport.getRules()) {
                        addClasspathFor(configuration.getRuleClass(), classpath);
                    }
                }
                classpath.addAll(additionalJapicmpClasspath.getFiles());
                workerConfiguration.setClasspath(classpath);
                List<JApiCmpWorkerAction.Archive> baseline = JapicmpTask.this.oldArchives != null ? toArchives(JapicmpTask.this.oldArchives) : inferArchives(oldClasspath);
                List<JApiCmpWorkerAction.Archive> current = JapicmpTask.this.newArchives != null ? toArchives(JapicmpTask.this.newArchives) : inferArchives(newClasspath);
                workerConfiguration.setDisplayName("JApicmp check comparing " + current + " with " + baseline);
                workerConfiguration.params(
                        // we use a single configuration object, instead of passing each parameter directly,
                        // because the worker API doesn't support "null" values
                        new JapiCmpWorkerConfiguration(
                                isIncludeSynthetic(),
                                isIgnoreMissingClasses(),
                                getPackageIncludes(),
                                getPackageExcludes(),
{'fraction_non_alphanumeric': 0.08960146587265232, 'fraction_numerical': 0.0007329363261566652, 'mean_word_length': 2.979584396646008, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6886310', 'n_tokens_mistral': 2809, 'n_tokens_neox': 2661, 'n_words': 586}