<commit_before>package net.ltgt.gradle.apt;

import groovy.util.Node;
import groovy.util.NodeList;
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.codehaus.groovy.runtime.MethodClosure;
import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.XmlProvider;
import org.gradle.api.internal.plugins.DslObject;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
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;
import org.gradle.plugins.ide.idea.model.IdeaProject;
import org.gradle.util.GradleVersion;

public class AptIdeaPlugin implements Plugin<Project> {
  @Override
  public void apply(final Project project) {
    project.getPlugins().apply(AptPlugin.class);
    project.getPlugins().apply(IdeaPlugin.class);
    project
        .getPlugins()
        .withType(
            JavaPlugin.class,
            new Action<JavaPlugin>() {
              @Override
              public void execute(JavaPlugin javaPlugin) {
                JavaPluginConvention javaConvention =
                    project.getConvention().getPlugin(JavaPluginConvention.class);
                SourceSet mainSourceSet =
                    javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                SourceSet testSourceSet =
                    javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

                configureIdeaModule(project, mainSourceSet, testSourceSet);
              }
            });
    configureIdeaProject(project);
  }

  private void configureIdeaModule(
      Project project, final SourceSet mainSourceSet, final SourceSet testSourceSet) {
    project.afterEvaluate(
        new Action<Project>() {
          @Override
          public void execute(Project project) {
            final IdeaModule ideaModule =
                project.getExtensions().getByType(IdeaModel.class).getModule();
            Set<File> excl = new LinkedHashSet<>();
            for (SourceSet sourceSet : new SourceSet[] {mainSourceSet, testSourceSet}) {
              File generatedSourcesDir =
                  new DslObject(sourceSet.getOutput())
                      .getConvention()
                      .getPlugin(AptPlugin.AptSourceSetOutputConvention.class)
                      .getGeneratedSourcesDir();
              for (File f = generatedSourcesDir;
                  f != null && !f.equals(project.getProjectDir());
                  f = f.getParentFile()) {
                excl.add(f);
              }
            }
            // For some reason, modifying the existing collections doesn't work.
            // We need to copy the values and then assign it back.
            Set<File> excludeDirs = new LinkedHashSet<>(ideaModule.getExcludeDirs());
            if (excl.contains(project.getBuildDir())
                && ideaModule.getExcludeDirs().contains(project.getBuildDir())) {
              ideaModule.getExcludeDirs().remove(project.getBuildDir());
              // Race condition: many of these will actually be created afterwards…
              File[] subdirs =
                  project
                      .getBuildDir()
                      .listFiles(
                          new FileFilter() {
                            @Override
                            public boolean accept(File pathname) {<commit_msg>Fix apt-idea plugin wrt excluded directories<commit_after>package net.ltgt.gradle.apt;

import groovy.util.Node;
import groovy.util.NodeList;
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.codehaus.groovy.runtime.MethodClosure;
import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.XmlProvider;
import org.gradle.api.internal.plugins.DslObject;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
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;
import org.gradle.plugins.ide.idea.model.IdeaProject;
import org.gradle.util.GradleVersion;

public class AptIdeaPlugin implements Plugin<Project> {
  @Override
  public void apply(final Project project) {
    project.getPlugins().apply(AptPlugin.class);
    project.getPlugins().apply(IdeaPlugin.class);
    project
        .getPlugins()
        .withType(
            JavaPlugin.class,
            new Action<JavaPlugin>() {
              @Override
              public void execute(JavaPlugin javaPlugin) {
                JavaPluginConvention javaConvention =
                    project.getConvention().getPlugin(JavaPluginConvention.class);
                SourceSet mainSourceSet =
                    javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                SourceSet testSourceSet =
                    javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

                configureIdeaModule(project, mainSourceSet, testSourceSet);
              }
            });
    configureIdeaProject(project);
  }

  private void configureIdeaModule(
      Project project, final SourceSet mainSourceSet, final SourceSet testSourceSet) {
    project.afterEvaluate(
        new Action<Project>() {
          @Override
          public void execute(Project project) {
            final IdeaModule ideaModule =
                project.getExtensions().getByType(IdeaModel.class).getModule();
            Set<File> excl = new LinkedHashSet<>();
            for (SourceSet sourceSet : new SourceSet[] {mainSourceSet, testSourceSet}) {
              File generatedSourcesDir =
                  new DslObject(sourceSet.getOutput())
                      .getConvention()
                      .getPlugin(AptPlugin.AptSourceSetOutputConvention.class)
                      .getGeneratedSourcesDir();
              for (File f = generatedSourcesDir;
                  f != null && !f.equals(project.getProjectDir());
                  f = f.getParentFile()) {
                excl.add(f);
              }
            }
            // For some reason, modifying the existing collections doesn't work.
            // We need to copy the values and then assign it back.
            Set<File> excludeDirs = new LinkedHashSet<>(ideaModule.getExcludeDirs());
            if (excl.contains(project.getBuildDir())
                && excludeDirs.contains(project.getBuildDir())) {
              excludeDirs.remove(project.getBuildDir());
              // Race condition: many of these will actually be created afterwards…
              File[] subdirs =
                  project
                      .getBuildDir()
                      .listFiles(
                          new FileFilter() {
                            @Override
                            public boolean accept(File pathname) {
{'fraction_non_alphanumeric': 0.09330111424352262, 'fraction_numerical': 0.0, 'mean_word_length': 2.2747252747252746, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5390869', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1913, 'n_words': 385}