<commit_before>package de.maibornwolff.codecharta.importer.codemaat

import de.maibornwolff.codecharta.model.AttributeType
import de.maibornwolff.codecharta.model.AttributeTypes
import de.maibornwolff.codecharta.serialization.ProjectSerializer
import de.maibornwolff.codecharta.translator.MetricNameTranslator
import picocli.CommandLine
import java.io.*
import java.util.concurrent.Callable

@CommandLine.Command(name = "codemaatimport", description = ["generates cc.json from codemaat coupling csv"],
        footer = ["Copyright(c) 2020, MaibornWolff GmbH"])
class CodeMaatImporter: Callable<Void> {

    @CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
    private var help = false

    @CommandLine.Option(names = ["-o", "--output-file"], description = ["output File (or empty for stdout)"])
    private var outputFile: File? = null

    @CommandLine.Parameters(arity = "1..*", paramLabel = "FILE", description = ["codemaat coupling csv files"])
    private var files: List<File> = mutableListOf()

    private val pathSeparator = '/'

    private val csvDelimiter = ','

    @Throws(IOException::class)
    override fun call(): Void? {
        val csvProjectBuilder =
                CSVProjectBuilder(pathSeparator, csvDelimiter, codemaatReplacement, attributeTypes)
        files.map { it.inputStream() }.forEach<InputStream> { csvProjectBuilder.parseCSVStream(it) }
        val project = csvProjectBuilder.build()

        ProjectSerializer.serializeProject(project, writer())

        return null
    }

    private val codemaatReplacement: MetricNameTranslator
        get() {
            val prefix = ""<commit_msg>Add compressed output for codemaatimporter #848<commit_after>package de.maibornwolff.codecharta.importer.codemaat

import de.maibornwolff.codecharta.model.AttributeType
import de.maibornwolff.codecharta.model.AttributeTypes
import de.maibornwolff.codecharta.serialization.ProjectSerializer
import de.maibornwolff.codecharta.translator.MetricNameTranslator
import picocli.CommandLine
import java.io.*
import java.util.concurrent.Callable

@CommandLine.Command(name = "codemaatimport", description = ["generates cc.json from codemaat coupling csv"],
        footer = ["Copyright(c) 2020, MaibornWolff GmbH"])
class CodeMaatImporter: Callable<Void> {

    @CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
    private var help = false

    @CommandLine.Option(names = ["-o", "--output-file"], description = ["output File (or empty for stdout)"])
    private var outputFile: File? = null

    @CommandLine.Option(names = ["-c"], description = ["compress output File to gzip format"])
    private var compress = false

    @CommandLine.Parameters(arity = "1..*", paramLabel = "FILE", description = ["codemaat coupling csv files"])
    private var files: List<File> = mutableListOf()

    private val pathSeparator = '/'

    private val csvDelimiter = ','

    @Throws(IOException::class)
    override fun call(): Void? {
        val csvProjectBuilder =
                CSVProjectBuilder(pathSeparator, csvDelimiter, codemaatReplacement, attributeTypes)
        files.map { it.inputStream() }.forEach<InputStream> { csvProjectBuilder.parseCSVStream(it) }
        val project = csvProjectBuilder.build()

        val filePath = outputFile?.absolutePath ?: "notSpecified"

        if(compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(project,filePath) else   ProjectSerializer.serializeProject(project, writer())




        return null
    }

    private val codemaatReplacement: MetricNameTranslator
        get() {
            val prefix = ""
{'fraction_non_alphanumeric': 0.11200644641418211, 'fraction_numerical': 0.0034918076819769003, 'mean_word_length': 4.157894736842105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5331407', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1061, 'n_words': 251}