Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CLI output name handling by adding file extensions #2914

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9641a68
FileExtensionHandler added + Tests #2800
charlotteKehm Jul 27, 2022
f1ae74a
solution for path problem #2800
charlotteKehm Jul 27, 2022
6ccc508
case: path without filename considered #2800
charlotteKehm Jul 27, 2022
047b54d
CodeMaatImporter + CSVImporter fixed #2800
charlotteKehm Jul 27, 2022
53c0a66
RawTextParser + TokeiImporter fixed #2800
charlotteKehm Jul 27, 2022
8693581
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Jul 28, 2022
269c8ec
minor refactoring to prevent files from being created while testing #…
charlotteKehm Jul 28, 2022
8f99e18
pipeline fehler #2800
charlotteKehm Jul 28, 2022
dff5cab
write jsons in terminal for golden_test.sh #2800
charlotteKehm Jul 29, 2022
d2dbc3c
updated changes with review remarks #2800
charlotteKehm Aug 1, 2022
8bf7570
fix test #2800
charlotteKehm Aug 1, 2022
be64b7a
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
charlotteKehm Aug 1, 2022
0e4dc9a
remove test boolean #2800
charlotteKehm Aug 2, 2022
7dd2bee
remove comment, sysout variable
Chrisp485 Aug 3, 2022
f9e46f7
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 8, 2022
e25446e
refacotor OutputFileHandler.kt, adjust parsers
Chrisp485 Aug 8, 2022
0be9773
Merge branch 'fix/2800/improving-cli-output-name-by-adding-file-exten…
Chrisp485 Aug 8, 2022
a97416d
refactor RawText Parser and adjust tests
Chrisp485 Aug 9, 2022
a1169a3
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 9, 2022
1baf638
remove sysout from golden_test.sh
Chrisp485 Aug 9, 2022
76cfe80
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 10, 2022
5e52669
Add tests to GitLogParser and SVNLogParser
MW-Friedrich Aug 10, 2022
c9aa2aa
Refactor SVNLogParser.kt for linter correctness
MW-Friedrich Aug 10, 2022
5656ec1
Fix file ending for CrococosmoImporter
MW-Friedrich Aug 11, 2022
d03e872
Fix path-separator not correctly added in OutputFileHandler
MW-Friedrich Aug 12, 2022
c9d88a2
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 12, 2022
845ea45
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 12, 2022
2cdaec7
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 12, 2022
af8c3b9
Update CHANGELOG.md
MW-Friedrich Aug 12, 2022
da8671a
Merge remote-tracking branch 'origin/fix/2800/improving-cli-output-na…
MW-Friedrich Aug 12, 2022
5085376
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 12, 2022
e420dca
Fix EdgeFilter and MergeFilter not using the new OutputFileHandler
MW-Friedrich Aug 16, 2022
bd180ab
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 16, 2022
dce89fc
Merge remote-tracking branch 'origin/fix/2800/improving-cli-output-na…
MW-Friedrich Aug 16, 2022
e6d79cc
Refactor a test for linter happiness
MW-Friedrich Aug 16, 2022
864bcd0
Add a test for the EdgeFilter
MW-Friedrich Aug 16, 2022
afefb61
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 16, 2022
c1ee009
Merge remote-tracking branch 'origin/fix/2800/improving-cli-output-na…
MW-Friedrich Aug 16, 2022
b7b28ff
Refactor test for MergeFilter to JUnit
MW-Friedrich Aug 17, 2022
88ad7dd
Fix StructureModifier not using new OutputFileHandler
MW-Friedrich Aug 17, 2022
817b464
Merge branch 'main' into fix/2800/improving-cli-output-name-by-adding…
MW-Friedrich Aug 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,24 +1,24 @@
package de.maibornwolff.codecharta.importer.csv

import de.maibornwolff.codecharta.serialization.OutputFileHandler
import de.maibornwolff.codecharta.serialization.ProjectSerializer
import de.maibornwolff.codecharta.tools.interactiveparser.InteractiveParser
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import picocli.CommandLine
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.io.InputStream
import java.io.OutputStreamWriter
import java.io.Writer
import java.io.PrintStream
import java.util.concurrent.Callable

@CommandLine.Command(
name = "csvimport",
description = ["generates cc.json from csv with header"],
footer = ["Copyright(c) 2022, MaibornWolff GmbH"]
)
class CSVImporter : Callable<Void>, InteractiveParser {
class CSVImporter(
private val output: PrintStream = System.out,
private val test: Boolean = false) : Callable<Void>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
private var help = false
Expand All @@ -32,8 +32,11 @@ class CSVImporter : Callable<Void>, InteractiveParser {
@CommandLine.Option(names = ["-nc", "--not-compressed"], description = ["save uncompressed output File"])
private var compress = true

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

@CommandLine.Option(names = ["--systemout"], description = ["write output in terminal"])
private var systemout = false

@CommandLine.Parameters(arity = "1..*", paramLabel = "FILE", description = ["sourcemonitor csv files"])
private var files: List<File> = mutableListOf()
Expand All @@ -44,22 +47,14 @@ class CSVImporter : Callable<Void>, InteractiveParser {
val csvProjectBuilder = CSVProjectBuilder(pathSeparator, csvDelimiter)
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())
val filePath = outputFile ?: "notSpecified"
if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(project,
OutputFileHandler.checkAndFixFileExtension(filePath))
else ProjectSerializer.serializeProject(project, OutputFileHandler.writer(outputFile ?: "", systemout || test, output))

return null
}

private fun writer(): Writer {
return if (outputFile == null) {
OutputStreamWriter(System.out)
} else {
BufferedWriter(FileWriter(outputFile))
}
}

companion object {
@JvmStatic
fun main(args: Array<String>) {
Expand Down
@@ -1,35 +1,38 @@
package de.maibornwolff.codecharta.importer.sourcemonitor

import de.maibornwolff.codecharta.importer.csv.CSVProjectBuilder
import de.maibornwolff.codecharta.serialization.OutputFileHandler
import de.maibornwolff.codecharta.serialization.ProjectSerializer
import de.maibornwolff.codecharta.tools.interactiveparser.InteractiveParser
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import de.maibornwolff.codecharta.translator.MetricNameTranslator
import picocli.CommandLine
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.io.InputStream
import java.io.OutputStreamWriter
import java.io.Writer
import java.io.PrintStream
import java.util.concurrent.Callable

@CommandLine.Command(
name = "sourcemonitorimport",
description = ["generates cc.json from sourcemonitor csv"],
footer = ["Copyright(c) 2020, MaibornWolff GmbH"]
)
class SourceMonitorImporter : Callable<Void>, InteractiveParser {
class SourceMonitorImporter(
private val output: PrintStream = System.out,
private val test: Boolean = false) : Callable<Void>, InteractiveParser {

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

@CommandLine.Option(names = ["-nc", "--not-compressed"], description = ["save uncompressed output File"])
private var compress = true

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

@CommandLine.Option(names = ["--systemout"], description = ["write output in terminal"])
private var systemout = false

@CommandLine.Parameters(arity = "1..*", paramLabel = "FILE", description = ["sourcemonitor csv files"])
private var files: List<File> = mutableListOf()
Expand All @@ -44,9 +47,10 @@ class SourceMonitorImporter : Callable<Void>, InteractiveParser {
CSVProjectBuilder(pathSeparator, csvDelimiter, "File Name", sourceMonitorReplacement)
files.map { it.inputStream() }.forEach<InputStream> { csvProjectBuilder.parseCSVStream(it) }
val project = csvProjectBuilder.build()
val filePath = outputFile?.absolutePath ?: "notSpecified"
val filePath = outputFile ?: "notSpecified"

if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(project, filePath) else ProjectSerializer.serializeProject(project, writer())
if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(project,
OutputFileHandler.checkAndFixFileExtension(filePath)) else ProjectSerializer.serializeProject(project, OutputFileHandler.writer(outputFile ?: "", systemout || test, output))

return null
}
Expand Down Expand Up @@ -78,14 +82,6 @@ class SourceMonitorImporter : Callable<Void>, InteractiveParser {
return MetricNameTranslator(replacementMap.toMap(), prefix)
}

private fun writer(): Writer {
return if (outputFile == null) {
OutputStreamWriter(System.out)
} else {
BufferedWriter(FileWriter(outputFile))
}
}

companion object {
@JvmStatic
fun main(args: Array<String>) {
Expand Down
Expand Up @@ -42,8 +42,8 @@ class ParserDialogTest {

val cmdLine = CommandLine(CSVImporter())
val parseResult = cmdLine.parseArgs(*parserArguments.toTypedArray())
Assertions.assertThat(parseResult.matchedOption("output-file").getValue<File>().name)
.isEqualTo(outputFileName)
Assertions.assertThat(parseResult.matchedOption("output-file").getValue<String>()
.equals(outputFileName))
Assertions.assertThat(parseResult.matchedOption("delimiter").getValue<Char>()).isEqualTo(delimiter[0])
Assertions.assertThat(parseResult.matchedOption("path-separator").getValue<Char>()).isEqualTo(pathSeparator[0])
Assertions.assertThat(parseResult.matchedOption("not-compressed").getValue<Boolean>()).isEqualTo(isCompressed)
Expand Down Expand Up @@ -73,8 +73,7 @@ class ParserDialogTest {

val cmdLine = CommandLine(CSVImporter())
val parseResult = cmdLine.parseArgs(*parserArguments.toTypedArray())
Assertions.assertThat(parseResult.matchedOption("output-file").getValue<File>().name)
.isEqualTo(outputFileName)
Assertions.assertThat(parseResult.matchedOption("output-file").getValue<String>().equals(outputFileName))
Assertions.assertThat(parseResult.matchedOption("delimiter").getValue<Char>()).isEqualTo(delimiter[0])
Assertions.assertThat(parseResult.matchedOption("path-separator").getValue<Char>()).isEqualTo(pathSeparator[0])
Assertions.assertThat(parseResult.matchedOption("not-compressed").getValue<Boolean>()).isEqualTo(isCompressed)
Expand Down
Expand Up @@ -40,8 +40,7 @@ class ParserDialogTest {

val cmdLine = CommandLine(SourceMonitorImporter())
val parseResult = cmdLine.parseArgs(*parserArguments.toTypedArray())
Assertions.assertThat(parseResult.matchedOption("output-file").getValue<File>().name)
.isEqualTo(outputFileName)
Assertions.assertThat(parseResult.matchedOption("output-file").getValue<String>().equals(outputFileName))
Assertions.assertThat(parseResult.matchedOption("not-compressed")).isNull()
Assertions.assertThat(parseResult.matchedPositional(0).getValue<ArrayList<File>>()[0].name).isEqualTo(fileName)
}
Expand Down
Expand Up @@ -2,36 +2,39 @@ package de.maibornwolff.codecharta.importer.codemaat

import de.maibornwolff.codecharta.model.AttributeType
import de.maibornwolff.codecharta.model.AttributeTypes
import de.maibornwolff.codecharta.serialization.OutputFileHandler
import de.maibornwolff.codecharta.serialization.ProjectSerializer
import de.maibornwolff.codecharta.tools.interactiveparser.InteractiveParser
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface
import de.maibornwolff.codecharta.translator.MetricNameTranslator
import picocli.CommandLine
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.io.InputStream
import java.io.OutputStreamWriter
import java.io.Writer
import java.io.PrintStream
import java.util.concurrent.Callable

@CommandLine.Command(
name = "codemaatimport",
description = ["generates cc.json from codemaat coupling csv"],
footer = ["Copyright(c) 2022, MaibornWolff GmbH"]
)
class CodeMaatImporter : Callable<Void>, InteractiveParser {
class CodeMaatImporter(
private val output: PrintStream = System.out,
private val test: Boolean = false) : Callable<Void>, InteractiveParser {

@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 = ["-o", "--output-file"], description = ["output File"])
private var outputFile: String? = null

@CommandLine.Option(names = ["-nc", "--not-compressed"], description = ["save uncompressed output File"])
private var compress = true

@CommandLine.Option(names = ["--systemout"], description = ["write output in terminal"])
private var systemout = false

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

Expand All @@ -46,12 +49,12 @@ class CodeMaatImporter : Callable<Void>, InteractiveParser {
files.map { it.inputStream() }.forEach<InputStream> { csvProjectBuilder.parseCSVStream(it) }
val project = csvProjectBuilder.build()

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

if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(
project,
filePath
) else ProjectSerializer.serializeProject(project, writer())
OutputFileHandler.checkAndFixFileExtension(filePath)
) else ProjectSerializer.serializeProject(project, OutputFileHandler.writer(outputFile ?: "", systemout || test, output))

return null
}
Expand All @@ -78,14 +81,6 @@ class CodeMaatImporter : Callable<Void>, InteractiveParser {
return AttributeTypes(attributeTypes.toMutableMap(), type)
}

private fun writer(): Writer {
return if (outputFile == null) {
OutputStreamWriter(System.out)
} else {
BufferedWriter(FileWriter(outputFile!!))
}
}

companion object {
@JvmStatic
fun main(args: Array<String>) {
Expand Down
Expand Up @@ -40,7 +40,7 @@ class ParserDialogTest {

val cmdLine = CommandLine(CodeMaatImporter())
val parseResult = cmdLine.parseArgs(*parserArguments.toTypedArray())
Assertions.assertThat(parseResult.matchedOption("output-file").getValue<File>().name).isEqualTo(outputFileName)
Assertions.assertThat(parseResult.matchedOption("output-file").getValue<String>().equals(outputFileName))
Assertions.assertThat(parseResult.matchedOption("not-compressed").getValue<Boolean>()).isEqualTo(isCompressed)
Assertions.assertThat(parseResult.matchedPositional(0).getValue<List<File>>()[0].name).isEqualTo(fileName)
}
Expand Down
Expand Up @@ -36,7 +36,8 @@ class CrococosmoImporter : Callable<Void> {

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

if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(it.value, filePath)
if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(it.value,
filePath)
else ProjectSerializer.serializeProject(it.value, writer(suffix))
}

Expand Down
Expand Up @@ -7,6 +7,7 @@ import de.maibornwolff.codecharta.importer.gitlogparser.input.metrics.MetricsFac
import de.maibornwolff.codecharta.importer.gitlogparser.parser.LogParserStrategy
import de.maibornwolff.codecharta.importer.gitlogparser.parser.git.GitLogNumstatRawParserStrategy
import de.maibornwolff.codecharta.model.Project
import de.maibornwolff.codecharta.serialization.OutputFileHandler
import de.maibornwolff.codecharta.serialization.ProjectDeserializer
import de.maibornwolff.codecharta.serialization.ProjectSerializer
import de.maibornwolff.codecharta.tools.interactiveparser.InteractiveParser
Expand All @@ -19,7 +20,6 @@ import picocli.CommandLine
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.io.OutputStreamWriter
import java.io.PrintStream
import java.nio.charset.Charset
import java.nio.file.Files
Expand All @@ -34,7 +34,8 @@ import java.util.stream.Stream
class GitLogParser(
private val input: InputStream = System.`in`,
private val output: PrintStream = System.out,
private val error: PrintStream = System.err
private val error: PrintStream = System.err,
private val test: Boolean = false
) : Callable<Void>, InteractiveParser {

@CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"])
Expand All @@ -51,8 +52,11 @@ class GitLogParser(
)
private var nameFile: File? = null

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

@CommandLine.Option(names = ["--systemout"], description = ["write output in terminal"])
private var systemout = false

@CommandLine.Option(names = ["-nc", "--not-compressed"], description = ["save uncompressed output File"], arity = "0")
private var compress = true
Expand Down Expand Up @@ -109,14 +113,12 @@ class GitLogParser(
if (pipedProject != null) {
project = MergeFilter.mergePipedWithCurrentProject(pipedProject, project)
}
if (outputFile.isNotEmpty()) {
if (compress) ProjectSerializer.serializeAsCompressedFile(
val filePath = outputFile ?: "notSpecified"
if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(
project,
outputFile
) else ProjectSerializer.serializeProjectAndWriteToFile(project, outputFile)
} else {
ProjectSerializer.serializeProject(project, OutputStreamWriter(output))
}
OutputFileHandler.checkAndFixFileExtension(filePath)
)
else ProjectSerializer.serializeProject(project, OutputFileHandler.writer(outputFile ?: "", systemout || test, output))

return null
}
Expand Down
@@ -1,44 +1,52 @@
package de.maibornwolff.codecharta.importer.jasome

import de.maibornwolff.codecharta.serialization.OutputFileHandler
import de.maibornwolff.codecharta.serialization.ProjectSerializer
import picocli.CommandLine
import java.io.File
import java.io.Writer
import java.io.PrintStream
import java.util.concurrent.Callable

@CommandLine.Command(
name = "jasomeimport",
description = ["generates cc.json from jasome xml file"],
footer = ["Copyright(c) 2020, MaibornWolff GmbH"]
)
class JasomeImporter : Callable<Void> {
class JasomeImporter(
private val output: PrintStream = System.out,
private val test: Boolean = false) : Callable<Void> {

@CommandLine.Parameters(arity = "1", paramLabel = "FILE", description = ["file to parse"])
private var file: File? = null

@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 = ["-o", "--output-file"], description = ["output File"])
private var outputFile: String? = null

@CommandLine.Option(names = ["--systemout"], description = ["write output in terminal"])
private var systemout = false

@CommandLine.Option(names = ["-nc", "--not-compressed"], description = ["save uncompressed output File"])
private var compress = true

override fun call(): Void? {
val jasomeProject = JasomeDeserializer().deserializeJasomeXML(file!!.inputStream())
val project = JasomeProjectBuilder().add(jasomeProject).build()
val filePath = outputFile?.absolutePath ?: "notSpecified"
val filePath = outputFile ?: "notSpecified"

if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(project, filePath) else ProjectSerializer.serializeProject(project, writer())
if (compress && filePath != "notSpecified") ProjectSerializer.serializeAsCompressedFile(project,
OutputFileHandler.checkAndFixFileExtension(filePath)) else ProjectSerializer.serializeProject(project, OutputFileHandler.writer(outputFile ?: "", systemout || test, output))
charlotteKehm marked this conversation as resolved.
Show resolved Hide resolved

return null
}

/**
private fun writer(): Writer {
return outputFile?.writer() ?: System.out.writer()
}

**/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this.

companion object {

@JvmStatic
Expand Down