From 1bb59661367247eccbc800beddafa8dc400c37ac Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 9 Nov 2023 09:18:28 +0100 Subject: [PATCH 01/24] Resolve issues with question about filetype #3316 Adjusted the asked question as well as the functions returns to work in interactive mode --- .../codecharta/parser/rawtextparser/MetricCollector.kt | 4 +++- .../codecharta/parser/rawtextparser/ParserDialog.kt | 2 +- .../codecharta/parser/rawtextparser/RawTextParser.kt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt index 407284a7f1..6e2f57c237 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt @@ -58,7 +58,9 @@ class MetricCollector( } private fun isParsableFileExtension(path: String): Boolean { - return fileExtensions.isEmpty() || fileExtensions.contains(path.substringAfterLast(".")) + return fileExtensions.isEmpty() + || fileExtensions.contentEquals(arrayOf("")) + || fileExtensions.contains(path.substringAfterLast(".")) } private fun isPathExcluded(path: String): Boolean { diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index 81d9446b5d..c1286958b2 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -44,7 +44,7 @@ class ParserDialog { KInquirer.promptInput(message = "Do you want to exclude file/folder according to regex pattern?", default = "", hint = "regex1, regex2.. (leave empty if you don't want to exclude anything)") val fileExtensions: String = - KInquirer.promptInput(message = "Do you want to exclude file/folder according to regex pattern?", default = "", hint = "regex1, regex2.. (leave empty if you don't want to exclude anything)") + KInquirer.promptInput(message = "Do you only want to parse files with specific file-extensions? ", default = "", hint = "fileType1, fileType2.. (leave empty to include all file-extensions)") val withoutDefaultExcludes: Boolean = KInquirer.promptConfirm(message = "Do you want to include build, target, dist, resources and out folders as well as files/folders starting with '.'?", default = false) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt index f7345f3ae6..3cfc765376 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt @@ -62,7 +62,7 @@ class RawTextParser( @CommandLine.Option( names = ["-f", "--file-extensions"], - description = ["parse only files with specified extensions (defualt: any)"] + description = ["parse only files with specified extensions (default: any)"] ) private var fileExtensions: Array = arrayOf() From 82e2e01f69cdb97168ee23ba72659a71f1b6dd85 Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 9 Nov 2023 10:43:03 +0100 Subject: [PATCH 02/24] Add more tests for MetricCollector #3316 Specifically about the file extension option --- .../rawtextparser/MetricCollectorTest.kt | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt index 51f9986741..41f36655da 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt @@ -33,7 +33,7 @@ class MetricCollectorTest { } @Test - fun `Should exlude regex patterns`() { + fun `Should exclude regex patterns`() { val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, exclude = arrayOf(".*\\.xyz", "foobar")).parse() Assertions.assertThat(result.size).isEqualTo(1) @@ -41,10 +41,44 @@ class MetricCollectorTest { } @Test - fun `Should include only spedified File extensions`() { + fun `Should include only specified File extension with one given`() { val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("wrong")).parse() Assertions.assertThat(result.size).isEqualTo(1) Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") + Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_3.xyz") + Assertions.assertThat(result).doesNotContainKey("tabs.xyz") + } + + @Test + fun `Should include only specified File extensions with multiple given`() { + val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("wrong", "xyz")).parse() + + Assertions.assertThat(result.size).isEqualTo(4) + Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") + Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_3.xyz") + } + + @Test + fun `Should include all Files when no specific extensions were given (default for interactive mode)`() { + val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("")).parse() + + Assertions.assertThat(result.size).isEqualTo(4) + Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") + Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") + Assertions.assertThat(result).containsKey("/spaces/spaces_4.xyz") + Assertions.assertThat(result).containsKey("/tabs.xyz") + } + + @Test + fun `Should not produce an output and notify the user if the only specified extension was not found in the folder`() { + val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("wrong, abc")).parse() + + Assertions.assertThat(result.size).isEqualTo(0) + } + + @Test + fun `Should warn the user if one of the specified extensions was not found in the folder`() { + } } From 5d6177d9a38f9148e5827aba61ec7ab7886aed54 Mon Sep 17 00:00:00 2001 From: nereboss Date: Fri, 10 Nov 2023 11:51:47 +0100 Subject: [PATCH 03/24] Adjust RawTextParser to correctly handle filetypes #3316 Can handle multiple file extensions and file extensions starting with a dot --- .../codecharta/parser/rawtextparser/MetricCollector.kt | 1 + .../codecharta/parser/rawtextparser/RawTextParser.kt | 5 ++++- .../codecharta/rawtextparser/MetricCollectorTest.kt | 3 ++- .../src/test/resources/sampleproject/spaces/spaces_5.abc | 6 ++++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_5.abc diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt index 6e2f57c237..929fa2b02d 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt @@ -61,6 +61,7 @@ class MetricCollector( return fileExtensions.isEmpty() || fileExtensions.contentEquals(arrayOf("")) || fileExtensions.contains(path.substringAfterLast(".")) + || fileExtensions.contains(".${path.substringAfterLast(".")}") } private fun isPathExcluded(path: String): Boolean { diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt index 3cfc765376..47bc52ff44 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt @@ -62,7 +62,8 @@ class RawTextParser( @CommandLine.Option( names = ["-f", "--file-extensions"], - description = ["parse only files with specified extensions (default: any)"] + description = ["parse only files with specified extensions (default: any)"], + split = "\\s*,\\s*" ) private var fileExtensions: Array = arrayOf() @@ -94,6 +95,8 @@ class RawTextParser( if (!withoutDefaultExcludes) exclude += DEFAULT_EXCLUDES + println(fileExtensions[0]) + val parameterMap = assembleParameterMap() val results: Map = MetricCollector(inputFile!!, exclude, fileExtensions, parameterMap, metrics).parse() diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt index 41f36655da..28662bc934 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt @@ -56,7 +56,8 @@ class MetricCollectorTest { Assertions.assertThat(result.size).isEqualTo(4) Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") - Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_3.xyz") + Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") + Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_5.abc") } @Test diff --git a/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_5.abc b/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_5.abc new file mode 100644 index 0000000000..3aa9450cef --- /dev/null +++ b/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_5.abc @@ -0,0 +1,6 @@ +foo + bar + barx + +foox + barx From 5096d5e1ec75582b0735251d5f478255d46960aa Mon Sep 17 00:00:00 2001 From: nereboss Date: Fri, 10 Nov 2023 12:54:54 +0100 Subject: [PATCH 04/24] Adjust behaviour of metricCollector #3316 Does not produce an outout file when file extensions could not be found; also updated tests for this --- .../codecharta/parser/rawtextparser/RawTextParser.kt | 7 +++++-- .../codecharta/rawtextparser/MetricCollectorTest.kt | 12 +++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt index 47bc52ff44..f71fbccb8e 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt @@ -95,12 +95,15 @@ class RawTextParser( if (!withoutDefaultExcludes) exclude += DEFAULT_EXCLUDES - println(fileExtensions[0]) - val parameterMap = assembleParameterMap() val results: Map = MetricCollector(inputFile!!, exclude, fileExtensions, parameterMap, metrics).parse() + if (results.isEmpty()) { + System.err.println("\n\nERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") + return null + } + val pipedProject = ProjectDeserializer.deserializeProject(input) val project = ProjectGenerator().generate(results, pipedProject) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt index 28662bc934..3c1f40a3e9 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt @@ -64,7 +64,7 @@ class MetricCollectorTest { fun `Should include all Files when no specific extensions were given (default for interactive mode)`() { val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("")).parse() - Assertions.assertThat(result.size).isEqualTo(4) + Assertions.assertThat(result.size).isEqualTo(5) Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") Assertions.assertThat(result).containsKey("/spaces/spaces_4.xyz") @@ -72,14 +72,8 @@ class MetricCollectorTest { } @Test - fun `Should not produce an output and notify the user if the only specified extension was not found in the folder`() { - val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("wrong, abc")).parse() - + fun `Should produce empty result if no valid file extensions were given`() { + val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("none")).parse() Assertions.assertThat(result.size).isEqualTo(0) } - - @Test - fun `Should warn the user if one of the specified extensions was not found in the folder`() { - - } } From fe384258ba4f89f74b690daf4635697734aa5e20 Mon Sep 17 00:00:00 2001 From: nereboss Date: Fri, 10 Nov 2023 15:57:44 +0100 Subject: [PATCH 05/24] Added tests for RawTextParser for invalid file type #3316 --- .../rawtextparser/RawTextParserTest.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt index 7b3c2baadd..a4fdf25bf1 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt @@ -7,9 +7,7 @@ import de.maibornwolff.codecharta.parser.rawtextparser.RawTextParser.Companion.m import de.maibornwolff.codecharta.serialization.ProjectDeserializer import de.maibornwolff.codecharta.serialization.ProjectSerializer import de.maibornwolff.codecharta.util.InputHelper -import io.mockk.every -import io.mockk.mockkObject -import io.mockk.unmockkAll +import io.mockk.* import org.assertj.core.api.Assertions import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Test @@ -153,4 +151,25 @@ class RawTextParserTest { Assertions.assertThat(errContent.toString()).contains("Input invalid file for RawTextParser, stopping execution") } + + @Test + fun `Should not produce an output and notify the user if the only specified extension was not found in the folder`() { + + System.setErr(PrintStream(errContent)) + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/tabs.xyz", "--file-extensions=invalid")) + System.setErr(originalErr) + + Assertions.assertThat(result == "") + Assertions.assertThat(errContent.toString()).contains("ERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") + } + + @Test + fun `Should warn the user if one of the specified extensions was not found in the folder`() { + + } + + @Test + fun `Should not produce an output and notify the user if none of the specified extensions were found in the folder`() { + + } } From 641bd38fd40a6a9a3b6fdeeeb5f165ed9dfb163c Mon Sep 17 00:00:00 2001 From: nereboss Date: Mon, 13 Nov 2023 10:32:59 +0100 Subject: [PATCH 06/24] Adjust RawTextParser to correctly handle invalid file types #3316 Added warnings when a file extension was not found; also added multiple tests for that --- .../parser/rawtextparser/RawTextParser.kt | 21 ++++++++++++++++++- .../rawtextparser/MetricCollectorTest.kt | 8 +++++++ .../rawtextparser/RawTextParserTest.kt | 15 +++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt index f71fbccb8e..dbc53ebc21 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt @@ -98,12 +98,31 @@ class RawTextParser( val parameterMap = assembleParameterMap() val results: Map = MetricCollector(inputFile!!, exclude, fileExtensions, parameterMap, metrics).parse() + println("") if (results.isEmpty()) { - System.err.println("\n\nERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") + System.err.println() + System.err.println("ERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") return null } + val notFoundFileExtensions = mutableListOf() + for (fileExtension in fileExtensions) { + var isFileExtensionIncluded = false + for (relativeFileName in results.keys) { + if (relativeFileName.contains(fileExtension)) { + isFileExtensionIncluded = true + } + } + if (!isFileExtensionIncluded) { + notFoundFileExtensions.add(fileExtension) + } + } + if (notFoundFileExtensions.size != 0) { + System.err.println() + notFoundFileExtensions.forEach { System.err.println("WARNING: The specified file extension '$it' was not found within the given folder!") } + } + val pipedProject = ProjectDeserializer.deserializeProject(input) val project = ProjectGenerator().generate(results, pipedProject) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt index 3c1f40a3e9..efadcf121c 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt @@ -76,4 +76,12 @@ class MetricCollectorTest { val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("none")).parse() Assertions.assertThat(result.size).isEqualTo(0) } + + @Test + fun `Should produce the same result whether the user included a dot in the filetype or not`() { + val resultWithoutDot = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("wrong", "xyz")).parse() + val resultWithDot = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf(".wrong", ".xyz")).parse() + + Assertions.assertThat(resultWithoutDot == resultWithDot) + } } diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt index a4fdf25bf1..314104c1c9 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt @@ -154,9 +154,8 @@ class RawTextParserTest { @Test fun `Should not produce an output and notify the user if the only specified extension was not found in the folder`() { - System.setErr(PrintStream(errContent)) - val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/tabs.xyz", "--file-extensions=invalid")) + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/", "--file-extensions=invalid")) System.setErr(originalErr) Assertions.assertThat(result == "") @@ -165,11 +164,23 @@ class RawTextParserTest { @Test fun `Should warn the user if one of the specified extensions was not found in the folder`() { + System.setErr(PrintStream(errContent)) + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/tabs.xyz", "--file-extensions=xyz, invalid")) + System.setErr(originalErr) + + Assertions.assertThat(result != "").isTrue() + Assertions.assertThat(errContent.toString()).contains("WARNING: The specified file extension 'invalid' was not found within the given folder!") + Assertions.assertThat(errContent.toString()).doesNotContain("WARNING: The specified file extension 'xyz' was not found within the given folder!") } @Test fun `Should not produce an output and notify the user if none of the specified extensions were found in the folder`() { + System.setErr(PrintStream(errContent)) + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/", "--file-extensions=invalid1, invalid2, also_invalid")) + System.setErr(originalErr) + Assertions.assertThat(result == "") + Assertions.assertThat(errContent.toString()).contains("ERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") } } From ec9a47a49ab828bfe8760f3a461a67454cd1a259 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Mon, 13 Nov 2023 10:46:08 +0100 Subject: [PATCH 07/24] Fix assertions for invalid extension tests #3316 --- .../codecharta/rawtextparser/RawTextParserTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt index 314104c1c9..1a5e2ed144 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt @@ -158,7 +158,7 @@ class RawTextParserTest { val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/", "--file-extensions=invalid")) System.setErr(originalErr) - Assertions.assertThat(result == "") + Assertions.assertThat(result).isEmpty() Assertions.assertThat(errContent.toString()).contains("ERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") } @@ -168,7 +168,7 @@ class RawTextParserTest { val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/tabs.xyz", "--file-extensions=xyz, invalid")) System.setErr(originalErr) - Assertions.assertThat(result != "").isTrue() + Assertions.assertThat(result).isNotEmpty() Assertions.assertThat(errContent.toString()).contains("WARNING: The specified file extension 'invalid' was not found within the given folder!") Assertions.assertThat(errContent.toString()).doesNotContain("WARNING: The specified file extension 'xyz' was not found within the given folder!") @@ -180,7 +180,7 @@ class RawTextParserTest { val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/", "--file-extensions=invalid1, invalid2, also_invalid")) System.setErr(originalErr) - Assertions.assertThat(result == "") + Assertions.assertThat(result).isEmpty() Assertions.assertThat(errContent.toString()).contains("ERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") } } From c29c6835ee18fd6c9ab5aafed2ef51318a9c52b9 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Mon, 13 Nov 2023 11:03:32 +0100 Subject: [PATCH 08/24] Adjust outputfile for added sample project file #3316 --- .../test/resources/cc_projects/project_4.cc.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_4.cc.json b/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_4.cc.json index fc126495b6..bf9e6ce64e 100644 --- a/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_4.cc.json +++ b/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_4.cc.json @@ -1,5 +1,5 @@ { - "checksum": "8e426f4db76a5e9b3a72bcfadc338bd9", + "checksum": "1df41fd8cedec533737e0c5bf2990c70", "data": { "projectName": "", "nodes": [ @@ -37,6 +37,17 @@ "link": "", "children": [] }, + { + "name":"spaces_5.abc", + "type":"File", + "attributes": { + "indentation_level_0+":5.0, + "indentation_level_1+":3.0, + "indentation_level_2+":3.0 + }, + "link":"", + "children":[] + }, { "name": "spaces_xyz.wrong", "type": "File", From bdf503c147956eb1db1ee14cce88dc0d40b1c445 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 08:37:44 +0100 Subject: [PATCH 09/24] Replace error prints with logger calls #3316 --- .../parser/rawtextparser/RawTextParser.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt index dbc53ebc21..9d239c0e25 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt @@ -8,6 +8,7 @@ import de.maibornwolff.codecharta.tools.interactiveparser.InteractiveParser import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface import de.maibornwolff.codecharta.tools.interactiveparser.util.CodeChartaConstants import de.maibornwolff.codecharta.util.InputHelper +import mu.KotlinLogging import picocli.CommandLine import java.io.File import java.io.IOException @@ -27,6 +28,8 @@ class RawTextParser( private val error: PrintStream = System.err, ) : Callable, InteractiveParser { + private val logger = KotlinLogging.logger {} + private val DEFAULT_EXCLUDES = arrayOf("/out/", "/build/", "/target/", "/dist/", "/resources/", "/\\..*") @CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["displays this help and exits"]) @@ -98,11 +101,11 @@ class RawTextParser( val parameterMap = assembleParameterMap() val results: Map = MetricCollector(inputFile!!, exclude, fileExtensions, parameterMap, metrics).parse() - println("") + println() if (results.isEmpty()) { - System.err.println() - System.err.println("ERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") + println() + logger.error("No files with specified file extension(s) were found within the given folder - not generating an output file!") return null } @@ -119,8 +122,8 @@ class RawTextParser( } } if (notFoundFileExtensions.size != 0) { - System.err.println() - notFoundFileExtensions.forEach { System.err.println("WARNING: The specified file extension '$it' was not found within the given folder!") } + println() + notFoundFileExtensions.forEach { logger.warn("The specified file extension '$it' was not found within the given folder!") } } val pipedProject = ProjectDeserializer.deserializeProject(input) From 867ccd62afaa8e6bbcacc21d4b17c6080ba116f1 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 13:19:36 +0100 Subject: [PATCH 10/24] Add tests for error logging #3316 --- .../rawtextparser/RawTextParserTest.kt | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt index 1a5e2ed144..67d46d836a 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt @@ -7,7 +7,14 @@ import de.maibornwolff.codecharta.parser.rawtextparser.RawTextParser.Companion.m import de.maibornwolff.codecharta.serialization.ProjectDeserializer import de.maibornwolff.codecharta.serialization.ProjectSerializer import de.maibornwolff.codecharta.util.InputHelper -import io.mockk.* +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject +import io.mockk.slot +import io.mockk.unmockkAll +import io.mockk.verify +import mu.KLogger +import mu.KotlinLogging import org.assertj.core.api.Assertions import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Test @@ -154,33 +161,49 @@ class RawTextParserTest { @Test fun `Should not produce an output and notify the user if the only specified extension was not found in the folder`() { - System.setErr(PrintStream(errContent)) + mockkObject(KotlinLogging) + val loggerMock = mockk() + val lambdaSlot = slot<(() -> Unit)>() + val messagesLogged = mutableListOf() + every { KotlinLogging.logger(capture(lambdaSlot)) } returns loggerMock + every { loggerMock.error(capture(messagesLogged)) } returns Unit + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/", "--file-extensions=invalid")) - System.setErr(originalErr) Assertions.assertThat(result).isEmpty() - Assertions.assertThat(errContent.toString()).contains("ERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") + + verify { loggerMock.error(any()) } + Assertions.assertThat(messagesLogged).contains("No files with specified file extension(s) were found within the given folder - not generating an output file!") } @Test fun `Should warn the user if one of the specified extensions was not found in the folder`() { - System.setErr(PrintStream(errContent)) + mockkObject(KotlinLogging) + val loggerMock = mockk() + val lambdaSlot = slot<(() -> Unit)>() + val messagesLogged = mutableListOf() + every { KotlinLogging.logger(capture(lambdaSlot)) } returns loggerMock + every { loggerMock.warn(capture(messagesLogged)) } returns Unit + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/tabs.xyz", "--file-extensions=xyz, invalid")) - System.setErr(originalErr) Assertions.assertThat(result).isNotEmpty() - Assertions.assertThat(errContent.toString()).contains("WARNING: The specified file extension 'invalid' was not found within the given folder!") - Assertions.assertThat(errContent.toString()).doesNotContain("WARNING: The specified file extension 'xyz' was not found within the given folder!") - + Assertions.assertThat(messagesLogged).contains("The specified file extension 'invalid' was not found within the given folder!") + Assertions.assertThat(messagesLogged).doesNotContain("The specified file extension 'xyz' was not found within the given folder!") } @Test fun `Should not produce an output and notify the user if none of the specified extensions were found in the folder`() { - System.setErr(PrintStream(errContent)) + mockkObject(KotlinLogging) + val loggerMock = mockk() + val lambdaSlot = slot<(() -> Unit)>() + val messagesLogged = mutableListOf() + every { KotlinLogging.logger(capture(lambdaSlot)) } returns loggerMock + every { loggerMock.error(capture(messagesLogged)) } returns Unit + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/", "--file-extensions=invalid1, invalid2, also_invalid")) - System.setErr(originalErr) Assertions.assertThat(result).isEmpty() - Assertions.assertThat(errContent.toString()).contains("ERROR: No files with specified file extension(s) were found within the given folder - not generating an output file!") + Assertions.assertThat(messagesLogged).contains("No files with specified file extension(s) were found within the given folder - not generating an output file!") } } From ecfd5f34dfa2dca66047bd0962a1a46906e12d13 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 13:22:54 +0100 Subject: [PATCH 11/24] Adjust condition to match linting style #3316 --- .../codecharta/parser/rawtextparser/MetricCollector.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt index 929fa2b02d..cf6f1c4752 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/MetricCollector.kt @@ -58,10 +58,10 @@ class MetricCollector( } private fun isParsableFileExtension(path: String): Boolean { - return fileExtensions.isEmpty() - || fileExtensions.contentEquals(arrayOf("")) - || fileExtensions.contains(path.substringAfterLast(".")) - || fileExtensions.contains(".${path.substringAfterLast(".")}") + return fileExtensions.isEmpty() || + fileExtensions.contentEquals(arrayOf("")) || + fileExtensions.contains(path.substringAfterLast(".")) || + fileExtensions.contains(".${path.substringAfterLast(".")}") } private fun isPathExcluded(path: String): Boolean { From 5adbf07faa0d05d8c82662172b0075bbed484efa Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 13:23:44 +0100 Subject: [PATCH 12/24] Adjust tests for added file to sampleproject #3316 --- .../codecharta/rawtextparser/MetricCollectorTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt index efadcf121c..d04a837c25 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt @@ -19,7 +19,7 @@ class MetricCollectorTest { fun `Should collect information about all files within a project`() { val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile).parse() - Assertions.assertThat(result.size).isEqualTo(4) + Assertions.assertThat(result.size).isEqualTo(5) Assertions.assertThat(result).containsKey("/tabs.xyz") Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") Assertions.assertThat(result["/tabs.xyz"]?.metricMap).isNotEmpty @@ -36,7 +36,7 @@ class MetricCollectorTest { fun `Should exclude regex patterns`() { val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, exclude = arrayOf(".*\\.xyz", "foobar")).parse() - Assertions.assertThat(result.size).isEqualTo(1) + Assertions.assertThat(result.size).isEqualTo(2) Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") } From 3c225a134a4635b90218370f9d0512b4d8482af7 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 15:58:24 +0100 Subject: [PATCH 13/24] Adjust tests for added file to sampleproject #3316 --- .../codecharta/rawtextparser/MetricCollectorTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt index d04a837c25..c06cca4d0d 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt @@ -57,6 +57,7 @@ class MetricCollectorTest { Assertions.assertThat(result.size).isEqualTo(4) Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") + Assertions.assertThat(result).containsKey("/spaces/spaces_4.xyz") Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_5.abc") } @@ -68,6 +69,7 @@ class MetricCollectorTest { Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") Assertions.assertThat(result).containsKey("/spaces/spaces_4.xyz") + Assertions.assertThat(result).containsKey("/spaces/spaces_5.abc") Assertions.assertThat(result).containsKey("/tabs.xyz") } From e0bf7f4c41008d2f1c6f023e5a3ee0910943e0c8 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 15:59:40 +0100 Subject: [PATCH 14/24] Calrify questions for file-extensions and output-file #3316 --- .../codecharta/parser/rawtextparser/ParserDialog.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index c1286958b2..07e77f9119 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -18,7 +18,7 @@ class ParserDialog { ) val outputFileName: String = KInquirer.promptInput( - message = "What is the name of the output file?", + message = "What is the name of the output file (Press enter for console output)?", ) val isCompressed = (outputFileName.isEmpty()) || KInquirer.promptConfirm( @@ -44,7 +44,7 @@ class ParserDialog { KInquirer.promptInput(message = "Do you want to exclude file/folder according to regex pattern?", default = "", hint = "regex1, regex2.. (leave empty if you don't want to exclude anything)") val fileExtensions: String = - KInquirer.promptInput(message = "Do you only want to parse files with specific file-extensions? ", default = "", hint = "fileType1, fileType2.. (leave empty to include all file-extensions)") + KInquirer.promptInput(message = "Do you only want to parse files with specific file-extensions? ", default = "", hint = ".fileType1, .fileType2, fileType1, fileType2... (leave empty to include all file-extensions)") val withoutDefaultExcludes: Boolean = KInquirer.promptConfirm(message = "Do you want to include build, target, dist, resources and out folders as well as files/folders starting with '.'?", default = false) From d41797e3e54e807e74f252216db1b376f003c825 Mon Sep 17 00:00:00 2001 From: Ludwig Fritsch Date: Tue, 14 Nov 2023 15:59:58 +0100 Subject: [PATCH 15/24] Update documentation to include file-extensions #3316 --- analysis/parser/RawTextParser/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/README.md b/analysis/parser/RawTextParser/README.md index 7af0a9d173..93b1af9f8a 100644 --- a/analysis/parser/RawTextParser/README.md +++ b/analysis/parser/RawTextParser/README.md @@ -13,7 +13,8 @@ Usage: rawtextparser [-hv] [--withoutDefaultExcludes] [--maxIndentationLevel=] [--tabWidth=] [-o=] [-p=] [-e=]... [-m - [=...]]... FILE or FOLDER + [=...]]... [-f [= + ...]]... FILE or FOLDER generates cc.json from projects or source code files FILE or FOLDER file/project to parse --maxIndentationLevel= @@ -23,6 +24,8 @@ generates cc.json from projects or source code files include build, target, dist, resources and out folders as well as files/folders starting with '.' -e, --exclude= exclude file/folder according to regex pattern + -f, --file-extensions[=...] + parse only files with specified extensions -h, --help displays this help and exits -m, --metrics[=...] metrics to be computed (select all if not specified) From 4ca990e08ca141fc4eef5c66f3412cb9a56e63bc Mon Sep 17 00:00:00 2001 From: nereboss Date: Tue, 21 Nov 2023 14:20:02 +0100 Subject: [PATCH 16/24] Fix rebase conflicts #3316 --- CHANGELOG.md | 4 ++++ .../codecharta/parser/rawtextparser/ParserDialog.kt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92eef2e762..e580a46018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/) ## [unreleased] (Added 🚀 | Changed | Removed 🗑 | Fixed 🐞 | Chore 👨‍💻 👩‍💻) +## Fixed 🐞 + +- Fix RawTextParser producing incorrect output when no (or multiple) file extensions were specified in interactive mode [#3405](https://github.com/MaibornWolff/codecharta/pull/3405) + ## [1.120.1] - 2023-11-17 ### Removed 🗑 diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index 07e77f9119..a3b602d2f1 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -18,7 +18,7 @@ class ParserDialog { ) val outputFileName: String = KInquirer.promptInput( - message = "What is the name of the output file (Press enter for console output)?", + message = "What is the name of the output file (leave empty to print to stdout)?", ) val isCompressed = (outputFileName.isEmpty()) || KInquirer.promptConfirm( From 67c9f65e6dbda8d925e2b0bc19a210786c8f09e4 Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 16 Nov 2023 09:17:10 +0100 Subject: [PATCH 17/24] Small refactor against code smell found by sonar #3316 --- .../codecharta/parser/rawtextparser/RawTextParser.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt index 9d239c0e25..9cdc03aefb 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt @@ -121,7 +121,7 @@ class RawTextParser( notFoundFileExtensions.add(fileExtension) } } - if (notFoundFileExtensions.size != 0) { + if (notFoundFileExtensions.isNotEmpty()) { println() notFoundFileExtensions.forEach { logger.warn("The specified file extension '$it' was not found within the given folder!") } } From 26280166f6b9d0f69ed4561305326902f7016de1 Mon Sep 17 00:00:00 2001 From: nereboss Date: Fri, 17 Nov 2023 10:22:18 +0100 Subject: [PATCH 18/24] Refactor naming of file extension in sample project #3316 Also changed the assertion used to compare json files --- analysis/parser/RawTextParser/build.gradle | 1 + .../rawtextparser/MetricCollectorTest.kt | 52 ++++++++++--------- .../rawtextparser/RawTextParserTest.kt | 26 ++++------ .../resources/cc_projects/project_3.cc.json | 4 +- .../resources/cc_projects/project_4.cc.json | 10 ++-- .../{spaces_3.xyz => spaces_3.included} | 0 .../{spaces_4.xyz => spaces_4.included} | 0 .../{spaces_5.abc => spaces_5.includedtoo} | 0 ...z.wrong => spaces_x_not_included.excluded} | 0 .../sampleproject/{tabs.xyz => tabs.included} | 0 10 files changed, 46 insertions(+), 47 deletions(-) rename analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/{spaces_3.xyz => spaces_3.included} (100%) rename analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/{spaces_4.xyz => spaces_4.included} (100%) rename analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/{spaces_5.abc => spaces_5.includedtoo} (100%) rename analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/{spaces_xyz.wrong => spaces_x_not_included.excluded} (100%) rename analysis/parser/RawTextParser/src/test/resources/sampleproject/{tabs.xyz => tabs.included} (100%) diff --git a/analysis/parser/RawTextParser/build.gradle b/analysis/parser/RawTextParser/build.gradle index 0fd929b06a..1bef8c4eb0 100644 --- a/analysis/parser/RawTextParser/build.gradle +++ b/analysis/parser/RawTextParser/build.gradle @@ -12,6 +12,7 @@ dependencies { testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: junit5_version testImplementation group: 'org.assertj', name: 'assertj-core', version: assertj_version testImplementation group: 'io.mockk', name: 'mockk', version: mockk_version + testImplementation group: 'org.skyscreamer', name: 'jsonassert', version: '1.5.1' } test { diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt index c06cca4d0d..03c5b2c93f 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/MetricCollectorTest.kt @@ -8,11 +8,11 @@ import java.io.File class MetricCollectorTest { @Test fun `Should collect information about a single file`() { - val result = MetricCollector(File("src/test/resources/sampleproject/tabs.xyz").absoluteFile).parse() + val result = MetricCollector(File("src/test/resources/sampleproject/tabs.included").absoluteFile).parse() Assertions.assertThat(result.size).isEqualTo(1) - Assertions.assertThat(result).containsKey("/tabs.xyz") - Assertions.assertThat(result["/tabs.xyz"]?.metricMap).isNotEmpty + Assertions.assertThat(result).containsKey("/tabs.included") + Assertions.assertThat(result["/tabs.included"]?.metricMap).isNotEmpty } @Test @@ -20,9 +20,9 @@ class MetricCollectorTest { val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile).parse() Assertions.assertThat(result.size).isEqualTo(5) - Assertions.assertThat(result).containsKey("/tabs.xyz") - Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") - Assertions.assertThat(result["/tabs.xyz"]?.metricMap).isNotEmpty + Assertions.assertThat(result).containsKey("/tabs.included") + Assertions.assertThat(result).containsKey("/spaces/spaces_3.included") + Assertions.assertThat(result["/tabs.included"]?.metricMap).isNotEmpty } @Test @@ -34,31 +34,33 @@ class MetricCollectorTest { @Test fun `Should exclude regex patterns`() { - val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, exclude = arrayOf(".*\\.xyz", "foobar")).parse() + val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, exclude = arrayOf(".*\\.excluded$", "foobar")).parse() - Assertions.assertThat(result.size).isEqualTo(2) - Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") + Assertions.assertThat(result.size).isEqualTo(4) + Assertions.assertThat(result).containsKey("/spaces/spaces_3.included") + Assertions.assertThat(result).containsKey("/spaces/spaces_5.includedtoo") + Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_x_not_included.excluded") } @Test fun `Should include only specified File extension with one given`() { - val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("wrong")).parse() + val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("includedtoo")).parse() Assertions.assertThat(result.size).isEqualTo(1) - Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") - Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_3.xyz") - Assertions.assertThat(result).doesNotContainKey("tabs.xyz") + Assertions.assertThat(result).containsKey("/spaces/spaces_5.includedtoo") + Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_3.included") + Assertions.assertThat(result).doesNotContainKey("tabs.included") } @Test fun `Should include only specified File extensions with multiple given`() { - val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("wrong", "xyz")).parse() + val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("included", "includedtoo")).parse() Assertions.assertThat(result.size).isEqualTo(4) - Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") - Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") - Assertions.assertThat(result).containsKey("/spaces/spaces_4.xyz") - Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_5.abc") + Assertions.assertThat(result).containsKey("/spaces/spaces_3.included") + Assertions.assertThat(result).containsKey("/spaces/spaces_4.included") + Assertions.assertThat(result).containsKey("/spaces/spaces_5.includedtoo") + Assertions.assertThat(result).doesNotContainKey("/spaces/spaces_x_not_included.excluded") } @Test @@ -66,11 +68,11 @@ class MetricCollectorTest { val result = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("")).parse() Assertions.assertThat(result.size).isEqualTo(5) - Assertions.assertThat(result).containsKey("/spaces/spaces_xyz.wrong") - Assertions.assertThat(result).containsKey("/spaces/spaces_3.xyz") - Assertions.assertThat(result).containsKey("/spaces/spaces_4.xyz") - Assertions.assertThat(result).containsKey("/spaces/spaces_5.abc") - Assertions.assertThat(result).containsKey("/tabs.xyz") + Assertions.assertThat(result).containsKey("/spaces/spaces_x_not_included.excluded") + Assertions.assertThat(result).containsKey("/spaces/spaces_3.included") + Assertions.assertThat(result).containsKey("/spaces/spaces_4.included") + Assertions.assertThat(result).containsKey("/spaces/spaces_5.includedtoo") + Assertions.assertThat(result).containsKey("/tabs.included") } @Test @@ -81,8 +83,8 @@ class MetricCollectorTest { @Test fun `Should produce the same result whether the user included a dot in the filetype or not`() { - val resultWithoutDot = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("wrong", "xyz")).parse() - val resultWithDot = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf(".wrong", ".xyz")).parse() + val resultWithoutDot = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf("included", "includedtoo")).parse() + val resultWithDot = MetricCollector(File("src/test/resources/sampleproject").absoluteFile, fileExtensions = arrayOf(".included", ".includedtoo")).parse() Assertions.assertThat(resultWithoutDot == resultWithDot) } diff --git a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt index 67d46d836a..5960065576 100644 --- a/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt +++ b/analysis/parser/RawTextParser/src/test/kotlin/de/maibornwolff/codecharta/rawtextparser/RawTextParserTest.kt @@ -1,6 +1,5 @@ package de.maibornwolff.codecharta.rawtextparser -import com.google.gson.JsonParser import de.maibornwolff.codecharta.filter.mergefilter.MergeFilter import de.maibornwolff.codecharta.parser.rawtextparser.RawTextParser import de.maibornwolff.codecharta.parser.rawtextparser.RawTextParser.Companion.mainWithInOut @@ -22,6 +21,8 @@ import org.junit.jupiter.api.TestInstance import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource +import org.skyscreamer.jsonassert.JSONAssert +import org.skyscreamer.jsonassert.JSONCompareMode import picocli.CommandLine import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream @@ -44,7 +45,7 @@ class RawTextParserTest { fun provideValidInputFiles(): List { return listOf( Arguments.of("src/test/resources/sampleproject"), - Arguments.of("src/test/resources/sampleproject/tabs.xyz")) + Arguments.of("src/test/resources/sampleproject/tabs.included")) } } @@ -52,11 +53,9 @@ class RawTextParserTest { fun `should be able to process single file`() { val expectedResultFile = File("src/test/resources/cc_projects/project_3.cc.json").absoluteFile - val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/tabs.xyz")) + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/tabs.included")) - val resultJSON = JsonParser.parseString(result) - val expectedJson = JsonParser.parseReader(expectedResultFile.reader()) - Assertions.assertThat(resultJSON).isEqualTo(expectedJson) + JSONAssert.assertEquals(result, expectedResultFile.readText(), JSONCompareMode.NON_EXTENSIBLE) } @Test @@ -68,16 +67,14 @@ class RawTextParserTest { arrayOf("src/test/resources/sampleproject/", "--tab-width=2", "--max-indentation-level=2", "-e=tabs*.") ) - val resultJSON = JsonParser.parseString(result) - val expectedJson = JsonParser.parseReader(expectedResultFile.reader()) - Assertions.assertThat(resultJSON).isEqualTo(expectedJson) + JSONAssert.assertEquals(result, expectedResultFile.readText(), JSONCompareMode.NON_EXTENSIBLE) } @Test fun `should merge with piped project`() { val pipedProject = "src/test/resources/cc_projects/project_4.cc.json" val partialResult = "src/test/resources/cc_projects/project_3.cc.json" - val fileToParse = "src/test/resources/sampleproject/tabs.xyz" + val fileToParse = "src/test/resources/sampleproject/tabs.included" val input = File(pipedProject).bufferedReader().readLines().joinToString(separator = "\n") { it } val partialProject1 = ProjectDeserializer.deserializeProject(File(partialResult).inputStream()) val partialProject2 = ProjectDeserializer.deserializeProject(File(pipedProject).inputStream()) @@ -89,8 +86,7 @@ class RawTextParserTest { val result = executeForOutput(input, arrayOf(fileToParse)) - val resultJSON = JsonParser.parseString(result) - Assertions.assertThat(resultJSON).isEqualTo(JsonParser.parseString(expected.toString())) + JSONAssert.assertEquals(result, expected.toString(), JSONCompareMode.NON_EXTENSIBLE) } fun executeForOutput(input: String, args: Array = emptyArray()) = @@ -121,7 +117,7 @@ class RawTextParserTest { @Test fun `should be identified as applicable for given path being a file`() { - val isUsable = RawTextParser().isApplicable("src/test/resources/sampleproject/tabs.xyz") + val isUsable = RawTextParser().isApplicable("src/test/resources/sampleproject/tabs.included") Assertions.assertThat(isUsable).isTrue() } @@ -185,11 +181,11 @@ class RawTextParserTest { every { KotlinLogging.logger(capture(lambdaSlot)) } returns loggerMock every { loggerMock.warn(capture(messagesLogged)) } returns Unit - val result = executeForOutput("", arrayOf("src/test/resources/sampleproject/tabs.xyz", "--file-extensions=xyz, invalid")) + val result = executeForOutput("", arrayOf("src/test/resources/sampleproject", "--file-extensions=invalid, included")) Assertions.assertThat(result).isNotEmpty() Assertions.assertThat(messagesLogged).contains("The specified file extension 'invalid' was not found within the given folder!") - Assertions.assertThat(messagesLogged).doesNotContain("The specified file extension 'xyz' was not found within the given folder!") + Assertions.assertThat(messagesLogged).doesNotContain("The specified file extension 'included' was not found within the given folder!") } @Test diff --git a/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_3.cc.json b/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_3.cc.json index fd44905048..2ab6d4cba9 100644 --- a/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_3.cc.json +++ b/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_3.cc.json @@ -1,5 +1,5 @@ { - "checksum": "f8498bc9be2f883fb003073d51b17b8b", + "checksum": "4d50b12a539de0139c1bd0b85367e14b", "data": { "projectName": "", "nodes": [ @@ -10,7 +10,7 @@ "link": "", "children": [ { - "name": "tabs.xyz", + "name": "tabs.included", "type": "File", "attributes": { "indentation_level_0+": 6, diff --git a/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_4.cc.json b/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_4.cc.json index bf9e6ce64e..cbda7a7ada 100644 --- a/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_4.cc.json +++ b/analysis/parser/RawTextParser/src/test/resources/cc_projects/project_4.cc.json @@ -1,5 +1,5 @@ { - "checksum": "1df41fd8cedec533737e0c5bf2990c70", + "checksum": "eb374d0b890eb05b71595a5184a6d7e0", "data": { "projectName": "", "nodes": [ @@ -16,7 +16,7 @@ "link": "", "children": [ { - "name": "spaces_4.xyz", + "name": "spaces_4.included", "type": "File", "attributes": { "indentation_level_0+": 7, @@ -27,7 +27,7 @@ "children": [] }, { - "name": "spaces_3.xyz", + "name": "spaces_3.included", "type": "File", "attributes": { "indentation_level_0+": 5, @@ -38,7 +38,7 @@ "children": [] }, { - "name":"spaces_5.abc", + "name":"spaces_5.includedtoo", "type":"File", "attributes": { "indentation_level_0+":5.0, @@ -49,7 +49,7 @@ "children":[] }, { - "name": "spaces_xyz.wrong", + "name": "spaces_x_not_included.excluded", "type": "File", "attributes": { "indentation_level_0+": 4, diff --git a/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_3.xyz b/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_3.included similarity index 100% rename from analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_3.xyz rename to analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_3.included diff --git a/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_4.xyz b/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_4.included similarity index 100% rename from analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_4.xyz rename to analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_4.included diff --git a/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_5.abc b/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_5.includedtoo similarity index 100% rename from analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_5.abc rename to analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_5.includedtoo diff --git a/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_xyz.wrong b/analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_x_not_included.excluded similarity index 100% rename from analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_xyz.wrong rename to analysis/parser/RawTextParser/src/test/resources/sampleproject/spaces/spaces_x_not_included.excluded diff --git a/analysis/parser/RawTextParser/src/test/resources/sampleproject/tabs.xyz b/analysis/parser/RawTextParser/src/test/resources/sampleproject/tabs.included similarity index 100% rename from analysis/parser/RawTextParser/src/test/resources/sampleproject/tabs.xyz rename to analysis/parser/RawTextParser/src/test/resources/sampleproject/tabs.included From a53915c9a67b4cb2e8db7c6ef0fd95151ba350f5 Mon Sep 17 00:00:00 2001 From: nereboss Date: Fri, 17 Nov 2023 10:38:37 +0100 Subject: [PATCH 19/24] Move part of call function into helper function #3316 --- .../parser/rawtextparser/RawTextParser.kt | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt index 9cdc03aefb..7ab729c30c 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt @@ -109,6 +109,25 @@ class RawTextParser( return null } + logWarningsForNotFoundFileExtensions(results) + + val pipedProject = ProjectDeserializer.deserializeProject(input) + val project = ProjectGenerator().generate(results, pipedProject) + + ProjectSerializer.serializeToFileOrStream(project, outputFile, output, compress) + + return null + } + + private fun assembleParameterMap(): Map { + return mapOf( + "verbose" to verbose.toInt(), + "maxIndentationLevel" to maxIndentLvl, + "tabWidth" to tabWidth + ).filterValues { it != null }.mapValues { it.value as Int } + } + + private fun logWarningsForNotFoundFileExtensions(results: Map) { val notFoundFileExtensions = mutableListOf() for (fileExtension in fileExtensions) { var isFileExtensionIncluded = false @@ -125,21 +144,6 @@ class RawTextParser( println() notFoundFileExtensions.forEach { logger.warn("The specified file extension '$it' was not found within the given folder!") } } - - val pipedProject = ProjectDeserializer.deserializeProject(input) - val project = ProjectGenerator().generate(results, pipedProject) - - ProjectSerializer.serializeToFileOrStream(project, outputFile, output, compress) - - return null - } - - private fun assembleParameterMap(): Map { - return mapOf( - "verbose" to verbose.toInt(), - "maxIndentationLevel" to maxIndentLvl, - "tabWidth" to tabWidth - ).filterValues { it != null }.mapValues { it.value as Int } } override fun getDialog(): ParserDialogInterface = ParserDialog From 02962c5a79730730fc530e3e667e2698c0d91114 Mon Sep 17 00:00:00 2001 From: nereboss Date: Tue, 21 Nov 2023 09:31:23 +0100 Subject: [PATCH 20/24] Update flag and readme for rawtextparser #3316 --- analysis/parser/RawTextParser/README.md | 48 ++++++++++--------- .../parser/rawtextparser/RawTextParser.kt | 2 +- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/analysis/parser/RawTextParser/README.md b/analysis/parser/RawTextParser/README.md index 93b1af9f8a..daf694dcf2 100644 --- a/analysis/parser/RawTextParser/README.md +++ b/analysis/parser/RawTextParser/README.md @@ -9,31 +9,33 @@ This parser analyzes code regardless of the programming language used to generat ## Parameters ``` -Usage: rawtextparser [-hv] [--withoutDefaultExcludes] - [--maxIndentationLevel=] - [--tabWidth=] [-o=] - [-p=] [-e=]... [-m - [=...]]... [-f [= - ...]]... FILE or FOLDER +Usage: rawtextparser [-hv] [-nc] [--without-default-excludes] + [--max-indentation-level=] + [-o=] [--tab-width=] + [-e=]... [-fe=[\s*, + \s*...]]... [-m[=...]]... + FILE or FOLDER generates cc.json from projects or source code files - FILE or FOLDER file/project to parse - --maxIndentationLevel= - maximum Indentation Level (default 10) - --tabWidth= tab width used (estimated if not provided) - --withoutDefaultExcludes - include build, target, dist, resources and out folders - as well as files/folders starting with '.' - -e, --exclude= exclude file/folder according to regex pattern - -f, --file-extensions[=...] - parse only files with specified extensions - -h, --help displays this help and exits + FILE or FOLDER file/project to parse + -e, --exclude= exclude file/folder according to regex pattern + -fe, --file-extensions=[\s*,\s*...] + parse only files with specified extensions + (default: any) + -h, --help displays this help and exits -m, --metrics[=...] - metrics to be computed (select all if not specified) - -o, --outputFile= - output File (or empty for stdout) - -p, --projectName= - project name - -v, --verbose verbose mode + metrics to be computed (select all if not specified) + --max-indentation-level= + maximum Indentation Level (default 10) + -nc, --not-compressed save uncompressed output File + -o, --output-file= + output File (or empty for stdout) + --tab-width= + tab width used (estimated if not provided) + -v, --verbose verbose mode + --without-default-excludes + include build, target, dist, resources and out + folders as well as files/folders starting with + '.' ``` ## Examples diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt index 7ab729c30c..57abbed0bb 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/RawTextParser.kt @@ -64,7 +64,7 @@ class RawTextParser( private var exclude: Array = arrayOf() @CommandLine.Option( - names = ["-f", "--file-extensions"], + names = ["-fe", "--file-extensions"], description = ["parse only files with specified extensions (default: any)"], split = "\\s*,\\s*" ) From 1887c685c07281c635c2e9f468dd9087c6168c80 Mon Sep 17 00:00:00 2001 From: nereboss Date: Tue, 21 Nov 2023 12:23:38 +0100 Subject: [PATCH 21/24] Update readme and gh-pages #3316 --- analysis/parser/RawTextParser/README.md | 2 +- gh-pages/_docs/04-03-rawtextparser.md | 39 ++++++++++++------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/analysis/parser/RawTextParser/README.md b/analysis/parser/RawTextParser/README.md index daf694dcf2..6fb0614719 100644 --- a/analysis/parser/RawTextParser/README.md +++ b/analysis/parser/RawTextParser/README.md @@ -47,7 +47,7 @@ ccsh rawtextparser foo/bar/project ``` ``` -ccsh rawtextparser foo.txt --maxIndentationLevel=6 tabWidth=4 --metrics=IndentationLevel +ccsh rawtextparser foo.txt --max-indentation-level=6 tabWidth=4 --metrics=IndentationLevel ``` ``` diff --git a/gh-pages/_docs/04-03-rawtextparser.md b/gh-pages/_docs/04-03-rawtextparser.md index d69321d248..28e3b2e324 100644 --- a/gh-pages/_docs/04-03-rawtextparser.md +++ b/gh-pages/_docs/04-03-rawtextparser.md @@ -11,25 +11,24 @@ This parser analyzes code regardless of the programming language used to generat ## Usage and Parameters -| Parameter | description | -| -------------------------------------- | -------------------------------------------------------------------------------------------------- | -| `FILE or FOLDER` | file/project to parse | -| `--maxIndentationLevel=` | maximum Indentation Level (default 10) | -| `--tabWidth=` | tab width used (estimated if not provided) | -| `--withoutDefaultExcludes` | includes build, target, dist, resources and out folders as well as files/folders starting with '.' | -| `-e, --exclude=` | exclude file/folders according to regex pattern | -| `-h, --help` | displays help | -| `-m, --metrics[=...]` | metrics to be computed (select all if not specified) | -| `-o, --outputFile=` | output File (or empty for stdout) | -| `-nc, --not-compressed` | uncompresses outputfile to json format, if format of File is gzip | -| `-p, --projectName=` | project name | -| `-v, --verbose` | verbose mode | - -``` -Usage: rawtextparser [-chv] [--withoutDefaultExcludes] - [--maxIndentationLevel=] - [--tabWidth=] [-o=] [-c] - [-p=] [-e=]... [-m +| Parameter | description | +| ---------------------------------------- | -------------------------------------------------------------------------------------------------- | +| `FILE or FOLDER` | file/project to parse | +| `--max-indentation-level=` | maximum Indentation Level (default 10) | +| `--tab-width=` | tab width used (estimated if not provided) | +| `--without-default-excludes` | includes build, target, dist, resources and out folders as well as files/folders starting with '.' | +| `-e, --exclude=` | exclude file/folders according to regex pattern | +| `-h, --help` | displays help | +| `-m, --metrics[=...]` | metrics to be computed (select all if not specified) | +| `-o, --output-file=` | output File (or empty for stdout) | +| `-nc, --not-compressed` | uncompresses outputfile to json format, if format of File is gzip | +| `-v, --verbose` | verbose mode | + +``` +Usage: rawtextparser [-hv] [-nc] [--without-default-excludes] + [--max-indentation-level=] + [-o=] [--tab-width=] + [-e=]... [-f=]... [-m [=...]]... FILE or FOLDER ``` @@ -44,7 +43,7 @@ ccsh rawtextparser foo/bar/project ``` ``` -ccsh rawtextparser foo.txt --maxIndentationLevel=6 tabWidth=4 --metrics=IndentationLevel +ccsh rawtextparser foo.txt --max-indentation-level=6 tabWidth=4 --metrics=IndentationLevel ``` ``` From 72d961f6fdb6efec20687fbccd6d3a0c019cc212 Mon Sep 17 00:00:00 2001 From: nereboss Date: Tue, 21 Nov 2023 12:26:47 +0100 Subject: [PATCH 22/24] Fix typo in readme and gh-pages #3316 --- analysis/parser/RawTextParser/README.md | 2 +- gh-pages/_docs/04-03-rawtextparser.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/parser/RawTextParser/README.md b/analysis/parser/RawTextParser/README.md index 6fb0614719..aee844f5d1 100644 --- a/analysis/parser/RawTextParser/README.md +++ b/analysis/parser/RawTextParser/README.md @@ -47,7 +47,7 @@ ccsh rawtextparser foo/bar/project ``` ``` -ccsh rawtextparser foo.txt --max-indentation-level=6 tabWidth=4 --metrics=IndentationLevel +ccsh rawtextparser foo.txt --max-indentation-level=6 tab-width=4 --metrics=IndentationLevel ``` ``` diff --git a/gh-pages/_docs/04-03-rawtextparser.md b/gh-pages/_docs/04-03-rawtextparser.md index 28e3b2e324..6fb71b471c 100644 --- a/gh-pages/_docs/04-03-rawtextparser.md +++ b/gh-pages/_docs/04-03-rawtextparser.md @@ -43,7 +43,7 @@ ccsh rawtextparser foo/bar/project ``` ``` -ccsh rawtextparser foo.txt --max-indentation-level=6 tabWidth=4 --metrics=IndentationLevel +ccsh rawtextparser foo.txt --max-indentation-level=6 tab-width=4 --metrics=IndentationLevel ``` ``` From 6f368b49912289004ca0072b22a182321ab534ab Mon Sep 17 00:00:00 2001 From: nereboss Date: Tue, 21 Nov 2023 13:40:25 +0100 Subject: [PATCH 23/24] Add missing parameter to gh-pages #3316 --- .../codecharta/parser/rawtextparser/ParserDialog.kt | 2 +- gh-pages/_docs/04-03-rawtextparser.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt index a3b602d2f1..c41b78f8e8 100644 --- a/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt +++ b/analysis/parser/RawTextParser/src/main/kotlin/de/maibornwolff/codecharta/parser/rawtextparser/ParserDialog.kt @@ -44,7 +44,7 @@ class ParserDialog { KInquirer.promptInput(message = "Do you want to exclude file/folder according to regex pattern?", default = "", hint = "regex1, regex2.. (leave empty if you don't want to exclude anything)") val fileExtensions: String = - KInquirer.promptInput(message = "Do you only want to parse files with specific file-extensions? ", default = "", hint = ".fileType1, .fileType2, fileType1, fileType2... (leave empty to include all file-extensions)") + KInquirer.promptInput(message = "Do you only want to parse files with specific file-extensions? ", default = "", hint = "fileType1, fileType2... (leave empty to include all file-extensions)") val withoutDefaultExcludes: Boolean = KInquirer.promptConfirm(message = "Do you want to include build, target, dist, resources and out folders as well as files/folders starting with '.'?", default = false) diff --git a/gh-pages/_docs/04-03-rawtextparser.md b/gh-pages/_docs/04-03-rawtextparser.md index 6fb71b471c..e61247fa46 100644 --- a/gh-pages/_docs/04-03-rawtextparser.md +++ b/gh-pages/_docs/04-03-rawtextparser.md @@ -18,6 +18,7 @@ This parser analyzes code regardless of the programming language used to generat | `--tab-width=` | tab width used (estimated if not provided) | | `--without-default-excludes` | includes build, target, dist, resources and out folders as well as files/folders starting with '.' | | `-e, --exclude=` | exclude file/folders according to regex pattern | +| `-fe, --file-extensions` | include only files with the specified file extensions (include all if not specified) | | `-h, --help` | displays help | | `-m, --metrics[=...]` | metrics to be computed (select all if not specified) | | `-o, --output-file=` | output File (or empty for stdout) | From 35cb98bfbf75c7cae3763946ba65fe65806f1750 Mon Sep 17 00:00:00 2001 From: nereboss Date: Tue, 21 Nov 2023 14:22:36 +0100 Subject: [PATCH 24/24] Fix rebase conflicts #3316 --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e580a46018..05ae072c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/) ## [unreleased] (Added 🚀 | Changed | Removed 🗑 | Fixed 🐞 | Chore 👨‍💻 👩‍💻) -## Fixed 🐞 +### Changed + +- Changed short form of parameter `--file-extensions` of RawTextParser from `-f` to `-fe` [#3405](https://github.com/MaibornWolff/codecharta/pull/3405) +- Update readme and gh-pages for RawTextParser [#3405](https://github.com/MaibornWolff/codecharta/pull/3405) + +### Fixed 🐞 - Fix RawTextParser producing incorrect output when no (or multiple) file extensions were specified in interactive mode [#3405](https://github.com/MaibornWolff/codecharta/pull/3405)