Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Disable metric-gardener until a new version is released #3542

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions analysis/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
2 changes: 2 additions & 0 deletions analysis/import/MetricGardenerImporter/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions analysis/import/MetricGardenerImporter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,27 +77,8 @@ class MetricGardenerImporter(
throw IllegalArgumentException("Input invalid file for MetricGardenerImporter, stopping execution...")
}

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.")
}
}
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)
Expand All @@ -109,10 +89,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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +86,7 @@ class MetricGardenerImporterTest {
assertTrue(file.exists())
}

@Disabled
@Test
fun `should create file when MG needs to run first`() {
main(
Expand Down Expand Up @@ -140,23 +142,39 @@ 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"
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<ProcessBuilder>().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.")
}
}
8 changes: 4 additions & 4 deletions analysis/test/golden_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions gh-pages/_docs/04-13-metricgardener.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading