<commit_before>require 'nokogiri'
require 'set'

class MavenPartitioner
  POM_XML = 'pom.xml'

  def initialize(build)
    @build = build
  end

  def maven_modules
    return @maven_modules if @maven_modules
    top_level_pom = Nokogiri::XML(File.read(POM_XML))
    @maven_modules = top_level_pom.css('project>modules>module').map { |mvn_module| mvn_module.text }
  end

  def partitions
    group_modules(maven_modules)
  end

  def pom_for(mvn_module)
    Nokogiri::XML(File.read("#{mvn_module}/pom.xml"))
  end

  def group_modules(mvn_modules)
    module_groups = {}
    mvn_modules.each do |mvn_module|
      (module_groups[mvn_module.split('/').first] ||= []) << mvn_module
    end

    module_groups.values.map { |modules| partition_info(modules) }
  end

  def partition_info(mvn_modules)
    upload_artifacts = @build.project.main? &&
        @build.repository.url.end_with?("square/java.git") &&
        mvn_modules.any? { |module_name| (!!deployable_modules_map[module_name]) }

    {
      'type' => 'maven',
      'files' => mvn_modules,
      'upload_artifacts' => upload_artifacts<commit_msg>use group_by and remove unnecessary git add .<commit_after>require 'nokogiri'
require 'set'

class MavenPartitioner
  POM_XML = 'pom.xml'

  def initialize(build)
    @build = build
  end

  def maven_modules
    return @maven_modules if @maven_modules
    top_level_pom = Nokogiri::XML(File.read(POM_XML))
    @maven_modules = top_level_pom.css('project>modules>module').map { |mvn_module| mvn_module.text }
  end

  def partitions
    group_modules(maven_modules)
  end

  def pom_for(mvn_module)
    Nokogiri::XML(File.read("#{mvn_module}/pom.xml"))
  end

  def group_modules(mvn_modules)
    mvn_modules.group_by {|m| m.split("/").first }.values.map { |modules| partition_info(modules) }
  end

  def partition_info(mvn_modules)
    upload_artifacts = @build.project.main? &&
        @build.repository.url.end_with?("square/java.git") &&
        mvn_modules.any? { |module_name| deployable_modules_map[module_name] }

    {
      'type' => 'maven',
      'files' => mvn_modules,
      'upload_artifacts' => upload_artifacts
{'fraction_non_alphanumeric': 0.12687265917602997, 'fraction_numerical': 0.0, 'mean_word_length': 3.9582366589327145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3677319', 'n_tokens_mistral': 800, 'n_tokens_neox': 762, 'n_words': 124}