From 3e78829c6cda626f6a72dbcffd0ca58577105934 Mon Sep 17 00:00:00 2001 From: phanlezz Date: Tue, 9 Apr 2024 13:23:27 +0200 Subject: [PATCH 1/6] Add logger rename file extensions --- analysis/import/MetricGardenerImporter/build.gradle | 1 + ...profile-example.PNG => risk-profile-example.png} | Bin ...uspicious-metrics.PNG => suspicious-metrics.png} | Bin 3 files changed, 1 insertion(+) rename gh-pages/assets/images/docs/how-to/{risk-profile-example.PNG => risk-profile-example.png} (100%) rename gh-pages/assets/images/docs/how-to/{suspicious-metrics.PNG => suspicious-metrics.png} (100%) diff --git a/analysis/import/MetricGardenerImporter/build.gradle b/analysis/import/MetricGardenerImporter/build.gradle index 43e5b83d1a..dd4bc31aca 100644 --- a/analysis/import/MetricGardenerImporter/build.gradle +++ b/analysis/import/MetricGardenerImporter/build.gradle @@ -14,6 +14,7 @@ dependencies { implementation group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: jersey_version implementation group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0' + implementation group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: junit5_version testImplementation group: 'org.assertj', name: 'assertj-core', version: assertj_version diff --git a/gh-pages/assets/images/docs/how-to/risk-profile-example.PNG b/gh-pages/assets/images/docs/how-to/risk-profile-example.png similarity index 100% rename from gh-pages/assets/images/docs/how-to/risk-profile-example.PNG rename to gh-pages/assets/images/docs/how-to/risk-profile-example.png diff --git a/gh-pages/assets/images/docs/how-to/suspicious-metrics.PNG b/gh-pages/assets/images/docs/how-to/suspicious-metrics.png similarity index 100% rename from gh-pages/assets/images/docs/how-to/suspicious-metrics.PNG rename to gh-pages/assets/images/docs/how-to/suspicious-metrics.png From ca7a75d31debe6a1b6470c632cd5de8cd631d7a9 Mon Sep 17 00:00:00 2001 From: phanlezz Date: Tue, 9 Apr 2024 14:00:02 +0200 Subject: [PATCH 2/6] Disable metric-gardener on-the-fly execution, docs, changelog --- analysis/CHANGELOG.md | 4 ++ analysis/README.md | 2 + .../import/MetricGardenerImporter/README.md | 2 + .../MetricGardenerImporter.kt | 42 ++++++++++--------- .../MetricGardenerImporterTest.kt | 2 + analysis/test/golden_test.sh | 8 ++-- gh-pages/_docs/04-13-metricgardener.md | 2 + 7 files changed, 38 insertions(+), 24 deletions(-) diff --git a/analysis/CHANGELOG.md b/analysis/CHANGELOG.md index 34d4f2d52b..5feb0be622 100644 --- a/analysis/CHANGELOG.md +++ b/analysis/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/) - Bump node version from 16 to 18 [#3452](https://github.com/MaibornWolff/codecharta/pull/3452) +### Changed + +- Temporarily disabled metric-gardener on-the-fly execution [#3542](https://github.com/MaibornWolff/codecharta/pull/3542) + ## [1.122.1] - 2024-02-26 ### Changed diff --git a/analysis/README.md b/analysis/README.md index 61d9583f8e..df9af3b60c 100644 --- a/analysis/README.md +++ b/analysis/README.md @@ -12,6 +12,8 @@ CodeCharta analysis tools generally follow the pipes and filters architecture pr Components that import data from an external source, e.g. SonarQube, and generate visualisation data. +> Attention: The direct execution of metric-gardener has been temporarily disabled. + | Source | Project | | ------------------ | -------------------------------------------------------------------------------- | | CodeMaat CSV | [CodeMaatImporter](import/CodeMaatImporter/README.md) | diff --git a/analysis/import/MetricGardenerImporter/README.md b/analysis/import/MetricGardenerImporter/README.md index f06a331fbd..b812e83ba3 100644 --- a/analysis/import/MetricGardenerImporter/README.md +++ b/analysis/import/MetricGardenerImporter/README.md @@ -1,5 +1,7 @@ # MetricGardener Importer +> Attention: The direct execution of metric-gardener has been temporarily disabled. Please provide the JSON files directly. + This importer allows to use metrics calculated by [MetricGardener](https://github.com/MaibornWolff/metric-gardener), a multi-language code parser based on [tree-sitter](https://github.com/tree-sitter/tree-sitter). The importer can be used to parse files locally or to just import a MetricGardener.json file and convert it into a regular CodeCharta.cc.json diff --git a/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt b/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt index dd4252e7d4..527910cf5e 100644 --- a/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt +++ b/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt @@ -2,7 +2,6 @@ package de.maibornwolff.codecharta.importer.metricgardenerimporter import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import de.maibornwolff.codecharta.importer.metricgardenerimporter.json.MetricGardenerProjectBuilder -import de.maibornwolff.codecharta.importer.metricgardenerimporter.model.MetricGardenerException import de.maibornwolff.codecharta.importer.metricgardenerimporter.model.MetricGardenerNodes import de.maibornwolff.codecharta.model.AttributeDescriptor import de.maibornwolff.codecharta.model.AttributeGenerator @@ -79,25 +78,28 @@ class MetricGardenerImporter( } if (!isJsonFile) { - val tempMgOutput = File.createTempFile("MGOutput", ".json") - tempMgOutput.deleteOnExit() - - val npm = if (isWindows()) "npm.cmd" else "npm" - val commandToExecute = listOf( - npm, "exec", "-y", "metric-gardener", "--", "parse", - inputFile!!.absolutePath, "--output-path", tempMgOutput.absolutePath - ) - println("Running metric gardener, this might take some time for larger inputs...") - val processExitCode = ProcessBuilder(commandToExecute) - // Not actively discarding or redirecting the output of MetricGardener loses performance on larger folders - .redirectOutput(ProcessBuilder.Redirect.DISCARD) - .redirectError(ProcessBuilder.Redirect.INHERIT) - .start() - .waitFor() - inputFile = tempMgOutput - if (processExitCode != 0) { - throw MetricGardenerException("Error while executing metric gardener! Process returned with status $processExitCode.") - } + println("Direct metric-gardener execution has been temporarily disabled.") + return null + +// val tempMgOutput = File.createTempFile("MGOutput", ".json") +// tempMgOutput.deleteOnExit() +// +// val npm = if (isWindows()) "npm.cmd" else "npm" +// val commandToExecute = listOf( +// npm, "exec", "-y", "metric-gardener", "--", "parse", +// inputFile!!.absolutePath, "--output-path", tempMgOutput.absolutePath +// ) +// println("Running metric gardener, this might take some time for larger inputs...") +// val processExitCode = ProcessBuilder(commandToExecute) +// // Not actively discarding or redirecting the output of MetricGardener loses performance on larger folders +// .redirectOutput(ProcessBuilder.Redirect.DISCARD) +// .redirectError(ProcessBuilder.Redirect.INHERIT) +// .start() +// .waitFor() +// inputFile = tempMgOutput +// if (processExitCode != 0) { +// throw MetricGardenerException("Error while executing metric gardener! Process returned with status $processExitCode.") +// } } val metricGardenerNodes: MetricGardenerNodes = mapper.readValue(inputFile!!.reader(Charset.defaultCharset()), MetricGardenerNodes::class.java) diff --git a/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt b/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt index cf8b53ae22..20f41ad3d5 100644 --- a/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt +++ b/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt @@ -12,6 +12,7 @@ import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import org.junit.jupiter.params.ParameterizedTest @@ -85,6 +86,7 @@ class MetricGardenerImporterTest { assertTrue(file.exists()) } + @Disabled @Test fun `should create file when MG needs to run first`() { main( diff --git a/analysis/test/golden_test.sh b/analysis/test/golden_test.sh index c84a13774a..4ad082e8b3 100755 --- a/analysis/test/golden_test.sh +++ b/analysis/test/golden_test.sh @@ -117,10 +117,10 @@ check_metricgardener() { "${CCSH}" metricgardenerimport "${DATA}/metricgardener.json" -o "${ACTUAL_METRICGARDENER_JSON}" --is-json-file validate "${ACTUAL_METRICGARDENER_JSON}.cc.json.gz" - echo " -- expect MetricGardenerImporter to produce valid cc.json file when no MG.json was available" - ACTUAL_METRICGARDENER_JSON2="${INSTALL_DIR}/actual_metricgardenerparser2" - "${CCSH}" metricgardenerimport "${DATA}/metric-gardener-Example" -o "${ACTUAL_METRICGARDENER_JSON2}" - validate "${ACTUAL_METRICGARDENER_JSON2}.cc.json.gz" + # echo " -- expect MetricGardenerImporter to produce valid cc.json file when no MG.json was available" + # ACTUAL_METRICGARDENER_JSON2="${INSTALL_DIR}/actual_metricgardenerparser2" + # "${CCSH}" metricgardenerimport "${DATA}/metric-gardener-Example" -o "${ACTUAL_METRICGARDENER_JSON2}" + # validate "${ACTUAL_METRICGARDENER_JSON2}.cc.json.gz" } check_sonar() { diff --git a/gh-pages/_docs/04-13-metricgardener.md b/gh-pages/_docs/04-13-metricgardener.md index 749ca646b7..9661f0ccc0 100644 --- a/gh-pages/_docs/04-13-metricgardener.md +++ b/gh-pages/_docs/04-13-metricgardener.md @@ -3,6 +3,8 @@ permalink: /docs/metricgardener-importer title: "MetricGardener Importer" --- +> Attention: The direct execution of metric-gardener has been temporarily disabled. + This importer allows to use metrics calculated by [MetricGardener](https://github.com/MaibornWolff/metric-gardener), a multi-language code parser based on [tree-sitter](https://github.com/tree-sitter/tree-sitter). The importer can be used to parse files locally or to just import a MetricGardener.json file and convert it into a regular CodeCharta.cc.json From 9115d922c414afba109414d99b65c6acbae8665f Mon Sep 17 00:00:00 2001 From: phanlezz Date: Tue, 9 Apr 2024 14:33:43 +0200 Subject: [PATCH 3/6] Disable error checking test --- .../metricgardenerimporter/MetricGardenerImporterTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt b/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt index 20f41ad3d5..3efad60db9 100644 --- a/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt +++ b/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt @@ -142,6 +142,7 @@ class MetricGardenerImporterTest { Assertions.assertThat(errContent.toString()).contains("Input invalid file for MetricGardenerImporter, stopping execution") } + @Disabled @Test fun `should stop execution if error happens while executing metric gardener`() { val npm = if (System.getProperty("os.name").contains("win", ignoreCase = true)) "npm.cmd" else "npm" From 8658a472fcd3d0c53336b11e6de588415ec0ea28 Mon Sep 17 00:00:00 2001 From: phanlezz Date: Tue, 9 Apr 2024 15:34:26 +0200 Subject: [PATCH 4/6] Add test, throws exception --- .../MetricGardenerImporter.kt | 27 +---------------- .../MetricGardenerImporterTest.kt | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt b/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt index 527910cf5e..45c71d5d14 100644 --- a/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt +++ b/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt @@ -78,28 +78,7 @@ class MetricGardenerImporter( } if (!isJsonFile) { - println("Direct metric-gardener execution has been temporarily disabled.") - return null - -// val tempMgOutput = File.createTempFile("MGOutput", ".json") -// tempMgOutput.deleteOnExit() -// -// val npm = if (isWindows()) "npm.cmd" else "npm" -// val commandToExecute = listOf( -// npm, "exec", "-y", "metric-gardener", "--", "parse", -// inputFile!!.absolutePath, "--output-path", tempMgOutput.absolutePath -// ) -// println("Running metric gardener, this might take some time for larger inputs...") -// val processExitCode = ProcessBuilder(commandToExecute) -// // Not actively discarding or redirecting the output of MetricGardener loses performance on larger folders -// .redirectOutput(ProcessBuilder.Redirect.DISCARD) -// .redirectError(ProcessBuilder.Redirect.INHERIT) -// .start() -// .waitFor() -// inputFile = tempMgOutput -// if (processExitCode != 0) { -// throw MetricGardenerException("Error while executing metric gardener! Process returned with status $processExitCode.") -// } + throw IllegalArgumentException("Direct metric-gardener execution has been temporarily disabled.") } val metricGardenerNodes: MetricGardenerNodes = mapper.readValue(inputFile!!.reader(Charset.defaultCharset()), MetricGardenerNodes::class.java) @@ -111,10 +90,6 @@ class MetricGardenerImporter( return null } - private fun isWindows(): Boolean { - return System.getProperty("os.name").contains("win", ignoreCase = true) - } - override fun getDialog(): ParserDialogInterface = ParserDialog override fun isApplicable(resourceToBeParsed: String): Boolean { val supportedLanguageFileEndings = getSupportedLanguageFileEndings() diff --git a/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt b/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt index 3efad60db9..a91a1db2d2 100644 --- a/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt +++ b/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt @@ -22,6 +22,7 @@ import picocli.CommandLine import java.io.ByteArrayOutputStream import java.io.File import java.io.PrintStream +import kotlin.test.assertFailsWith @TestInstance(TestInstance.Lifecycle.PER_CLASS) class MetricGardenerImporterTest { @@ -147,19 +148,36 @@ class MetricGardenerImporterTest { fun `should stop execution if error happens while executing metric gardener`() { val npm = if (System.getProperty("os.name").contains("win", ignoreCase = true)) "npm.cmd" else "npm" val metricGardenerInvalidCommand = listOf( - npm, "exec", "metric-gardener", - "--", "parse", "this/path/is/invalid", "-o", "MGout.json" + npm, "exec", "metric-gardener", + "--", "parse", "this/path/is/invalid", "-o", "MGout.json" ) val metricGardenerInvalidInputProcess = ProcessBuilder(metricGardenerInvalidCommand) mockkConstructor(ProcessBuilder::class) every { anyConstructed().start().waitFor() } returns metricGardenerInvalidInputProcess - .redirectError(ProcessBuilder.Redirect.DISCARD) - .start() - .waitFor() + .redirectError(ProcessBuilder.Redirect.DISCARD) + .start() + .waitFor() System.setErr(PrintStream(errContent)) CommandLine(MetricGardenerImporter()).execute("src").toString() System.setErr(originalErr) - Assertions.assertThat(errContent.toString()).contains("Error while executing metric gardener! Process returned with status") + Assertions.assertThat(errContent.toString()) + .contains("Error while executing metric gardener! Process returned with status") } + + @Test + fun `should stop execution if no MG json is present`() { + System.setErr(PrintStream(errContent)) + main( + arrayOf( + "src/test/resources/MetricGardenerRawFile.kt", "-nc", + "-o=src/test/resources/import-result-mg" + ) + ) + System.setErr(originalErr) + Assertions.assertThat(errContent.toString()) + .contains("Direct metric-gardener execution has been temporarily disabled.") + + } + } From 78605e26143d3f639c7493ea2d3b857b00a0ae78 Mon Sep 17 00:00:00 2001 From: phanlezz Date: Tue, 9 Apr 2024 15:42:27 +0200 Subject: [PATCH 5/6] Change format --- .../metricgardenerimporter/MetricGardenerImporterTest.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt b/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt index a91a1db2d2..5b28a01cb4 100644 --- a/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt +++ b/analysis/import/MetricGardenerImporter/src/test/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporterTest.kt @@ -22,7 +22,6 @@ import picocli.CommandLine import java.io.ByteArrayOutputStream import java.io.File import java.io.PrintStream -import kotlin.test.assertFailsWith @TestInstance(TestInstance.Lifecycle.PER_CLASS) class MetricGardenerImporterTest { @@ -177,7 +176,5 @@ class MetricGardenerImporterTest { System.setErr(originalErr) Assertions.assertThat(errContent.toString()) .contains("Direct metric-gardener execution has been temporarily disabled.") - } - } From 0c68d109a218e436a836bf0e81e3f02723102766 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf <65733509+phanlezz@users.noreply.github.com> Date: Wed, 10 Apr 2024 08:31:07 +0200 Subject: [PATCH 6/6] Add sonar change --- .../metricgardenerimporter/MetricGardenerImporter.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt b/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt index 45c71d5d14..54a4e7c8e7 100644 --- a/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt +++ b/analysis/import/MetricGardenerImporter/src/main/kotlin/de/maibornwolff/codecharta/importer/metricgardenerimporter/MetricGardenerImporter.kt @@ -77,9 +77,8 @@ class MetricGardenerImporter( throw IllegalArgumentException("Input invalid file for MetricGardenerImporter, stopping execution...") } - if (!isJsonFile) { - throw IllegalArgumentException("Direct metric-gardener execution has been temporarily disabled.") - } + require(isJsonFile) { "Direct metric-gardener execution has been temporarily disabled." } + val metricGardenerNodes: MetricGardenerNodes = mapper.readValue(inputFile!!.reader(Charset.defaultCharset()), MetricGardenerNodes::class.java) val metricGardenerProjectBuilder = MetricGardenerProjectBuilder(metricGardenerNodes)