<commit_before>package com.blogspot.toomuchcoding.testprofiler
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import groovy.util.logging.Slf4j
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.TaskAction

@PackageScope
@CompileStatic
@Slf4j
class ReportMerger extends DefaultTask {

    TestProfilerPluginExtension testProfilerPluginExtension
    @InputDirectory File mergedTestProfilingSummaryDir

    @TaskAction
    void testsProfileSummaryReport() {
        File mergedTestProfilingSummary = new File(getMergedTestProfilingSummaryDir(), getTestProfilerPluginExtension().mergedSummaryFileName)
        if(!mergedTestProfilingSummary.exists()) {
            log.debug("No test data has been stored - skipping profile summary report creation")
            return
        }
        log.debug("Will store merged test profiling summary in [${mergedTestProfilingSummary}]")
        String fileContent = mergedTestProfilingSummary.text
        log.trace("Saving file [$mergedTestProfilingSummary] content [$fileContent]")
        mergedTestProfilingSummary.text = getTestProfilerPluginExtension().outputReportHeaders
        Set<ReportRow> reportRows = new TreeSet<ReportRow>(getTestProfilerPluginExtension().comparator as Comparator<ReportRow>)
        appendReportRow(fileContent, reportRows)
        mergedTestProfilingSummary << reportRows.collect(rowFromReport()).join('\n')
        println "Your combined report is available here [$mergedTestProfilingSummary]"
    }

    private void appendReportRow(String fileContent, Set<ReportRow> reportRows) {
        fileContent.split('\n').findAll { !it.contains(getTestProfilerPluginExtension().getOutputReportHeaders()) }.each { String string ->
            String[] row = string.split(getTestProfilerPluginExtension().separator)
            log.debug("Converting row $row")
            reportRows << new ReportRow(row[0], new TestExecutionResult(row[1], row[2], row[3] as Double), row[4] as Double)
        }
    }

    Closure<String> rowFromReport() {
        return getTestProfilerPluginExtension().rowFromReport.curry(getTestProfilerPluginExtension())
    }
}<commit_msg>Refactored the code to support parallel<commit_after>package com.blogspot.toomuchcoding.testprofiler
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import groovy.util.logging.Slf4j
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.TaskAction

@PackageScope
@CompileStatic
@Slf4j
class ReportMerger extends DefaultTask {

    TestProfilerPluginExtension testProfilerPluginExtension
    @InputDirectory File mergedTestProfilingSummaryDir

    @TaskAction
    void testsProfileSummaryReport() {
        File mergedTestProfilingSummary = new File(getMergedTestProfilingSummaryDir(), getTestProfilerPluginExtension().mergedSummaryFileName)
        if(!mergedTestProfilingSummary.exists()) {
            log.debug("No test data has been stored - skipping profile summary report creation")
            return
        }
        log.debug("Will store merged test profiling summary in [${mergedTestProfilingSummary}]")
        String fileContent = mergedTestProfilingSummary.text
        log.trace("Saving file [$mergedTestProfilingSummary] content [$fileContent]")
        mergedTestProfilingSummary.text = getTestProfilerPluginExtension().outputReportHeaders
        Set<ReportRow> reportRows = new TreeSet<ReportRow>(getTestProfilerPluginExtension().comparator as Comparator<ReportRow>)
        appendReportRow(fileContent, reportRows)
        mergedTestProfilingSummary << reportRows.collect(rowFromReport()).join('\n')
        println "Your combined report is available here [$mergedTestProfilingSummary]"
    }

    private void appendReportRow(String fileContent, Set<ReportRow> reportRows) {
        fileContent.split('\n')
                .each { String string ->
            String[] row = string.split(getTestProfilerPluginExtension().separator)
            log.debug("Converting row $row")
            try {
                reportRows << new ReportRow(row[0], new TestExecutionResult(row[1], row[2], row[3] as Double), row[4] as Double)
            } catch (NumberFormatException e) {
                log.warn("Exception occurred while trying to parse a report row", e)
            }
        }
    }

    Closure<String> rowFromReport() {
        return getTestProfilerPluginExtension().rowFromReport.curry(getTestProfilerPluginExtension())
    }
}
{'fraction_non_alphanumeric': 0.0872631115028647, 'fraction_numerical': 0.003085059497576025, 'mean_word_length': 4.134615384615385, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 15, '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': '5398377', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1162, 'n_words': 250}