From c60dcbbe8707faacd05256bc9ee599dfb12b0713 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Mon, 28 Oct 2024 17:08:55 +0100 Subject: [PATCH 1/2] Enable software-metrics. --- pom.xml | 6 +- .../github/QualityMonitorDockerITest.java | 201 ++- .../grading/github/QualityMonitorITest.java | 44 +- src/test/resources/metrics/metrics.xml | 1339 +++++++++++++++++ 4 files changed, 1506 insertions(+), 84 deletions(-) create mode 100644 src/test/resources/metrics/metrics.xml diff --git a/pom.xml b/pom.xml index 6e89088..32fde09 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ edu.hm.hafner codingstyle-pom - 4.16.0 + 5.2.0 @@ -27,9 +27,7 @@ ${project.groupId}.quality.monitor ${project.version} - 17 - - 3.36.0 + 4.0.0 1.20.2 1.326 diff --git a/src/test/java/edu/hm/hafner/grading/github/QualityMonitorDockerITest.java b/src/test/java/edu/hm/hafner/grading/github/QualityMonitorDockerITest.java index f622063..be3b0a0 100644 --- a/src/test/java/edu/hm/hafner/grading/github/QualityMonitorDockerITest.java +++ b/src/test/java/edu/hm/hafner/grading/github/QualityMonitorDockerITest.java @@ -16,84 +16,115 @@ import static org.assertj.core.api.Assertions.*; /** - * Integration test for the quality monitor action. - * Starts the container and checks if the action runs as expected. + * Integration test for the quality monitor action. Starts the container and checks if the action runs as expected. * * @author Ullrich Hafner */ public class QualityMonitorDockerITest { private static final String CONFIGURATION = """ - { - "tests": { - "name": "JUnit", - "tools": [ - { - "id": "test", - "name": "Unittests", - "pattern": "**/target/*-reports/TEST*.xml" - } - ] - }, - "analysis": [ { - "name": "Style", - "id": "style", - "tools": [ - { - "id": "checkstyle", - "name": "CheckStyle", - "pattern": "**/checkstyle*.xml" - }, - { - "id": "pmd", - "name": "PMD", - "pattern": "**/pmd*.xml" - } - ] - }, - { - "name": "Bugs", - "id": "bugs", - "tools": [ - { - "id": "spotbugs", - "name": "SpotBugs", - "pattern": "**/spotbugs*.xml" - } - ] - } - ], - "coverage": [ - { - "name": "JaCoCo", - "tools": [ - { - "id": "jacoco", - "name": "Line Coverage", - "metric": "line", - "pattern": "**/jacoco.xml" - }, - { - "id": "jacoco", - "name": "Branch Coverage", - "metric": "branch", - "pattern": "**/jacoco.xml" - } - ] - }, - { - "name": "PIT", - "tools": [ - { - "id": "pit", - "name": "Mutation Coverage", - "metric": "mutation", - "pattern": "**/mutations.xml" - } - ] - } - ] - } + "tests": { + "name": "JUnit", + "tools": [ + { + "id": "test", + "name": "Unittests", + "pattern": "**/target/*-reports/TEST*.xml" + } + ] + }, + "analysis": [ + { + "name": "Style", + "id": "style", + "tools": [ + { + "id": "checkstyle", + "name": "CheckStyle", + "pattern": "**/checkstyle*.xml" + }, + { + "id": "pmd", + "name": "PMD", + "pattern": "**/pmd*.xml" + } + ] + }, + { + "name": "Bugs", + "id": "bugs", + "tools": [ + { + "id": "spotbugs", + "name": "SpotBugs", + "pattern": "**/spotbugs*.xml" + } + ] + } + ], + "coverage": [ + { + "name": "JaCoCo", + "tools": [ + { + "id": "jacoco", + "name": "Line Coverage", + "metric": "line", + "pattern": "**/jacoco.xml" + }, + { + "id": "jacoco", + "name": "Branch Coverage", + "metric": "branch", + "pattern": "**/jacoco.xml" + } + ] + }, + { + "name": "PIT", + "tools": [ + { + "id": "pit", + "name": "Mutation Coverage", + "metric": "mutation", + "pattern": "**/mutations.xml" + } + ] + } + ], + "metrics": [ + { + "name": "Toplevel Metrics", + "tools": [ + { + "name": "Cyclomatic Complexity", + "id": "metrics", + "pattern": "**/metrics.xml", + "metric": "CyclomaticComplexity" + }, + { + "name": "Cognitive Complexity", + "id": "metrics", + "pattern": "**/metrics.xml", + "metric": "CognitiveComplexity" + }, + { + "name": "Non Commenting Source Statements", + "id": "metrics", + "pattern": "**/metrics.xml", + "metric": "NCSS" + }, + { + "name": "N-Path Complexity", + "id": "metrics", + "pattern": "**/metrics.xml", + "metric": "NPathComplexity" + } + ] + } + ] + } + } """; private static final String WS = "/github/workspace/target/"; private static final String LOCAL_METRICS_FILE = "target/metrics.env"; @@ -113,7 +144,12 @@ void shouldGradeInDockerContainer() throws TimeoutException, IOException { "spotbugs=1", "style=2", "pmd=1", - "checkstyle=1"}; + "checkstyle=1", + "ncss=1200", + "npath-complexity=432", + "cognitive-complexity=172", + "cyclomatic-complexity=355" + }; assertThat(readStandardOut(container)) .contains("Obtaining configuration from environment variable CONFIG") @@ -136,7 +172,11 @@ void shouldGradeInDockerContainer() throws TimeoutException, IOException { "-> PMD Total: 1 warnings", "=> Style: 2 warnings (normal: 2)", "-> SpotBugs Total: 1 warnings", - "=> Bugs: 1 warning (low: 1)"}); + "=> Bugs: 1 warning (low: 1)", + "=> Cyclomatic Complexity: 355", + "=> Cognitive Complexity: 172", + "=> Non Commenting Source Statements: 1200", + "=> N-Path Complexity: 432"}); container.copyFileFromContainer("/github/workspace/metrics.env", LOCAL_METRICS_FILE); assertThat(Files.readString(Path.of(LOCAL_METRICS_FILE))) @@ -150,7 +190,8 @@ void shouldUseDefaultConfiguration() throws TimeoutException { startContainerWithAllFiles(container); assertThat(readStandardOut(container)) - .contains("No configuration provided (environment variable CONFIG not set), using default configuration") + .contains( + "No configuration provided (environment variable CONFIG not set), using default configuration") .contains(new String[] { "Processing 1 test configuration(s)", "-> Tests Total: TESTS: 1 tests", @@ -202,13 +243,15 @@ private GenericContainer createContainer() { return new GenericContainer<>(DockerImageName.parse("uhafner/quality-monitor:1.12.0-SNAPSHOT")); } - private String readStandardOut(final GenericContainer> container) throws TimeoutException { + private String readStandardOut(final GenericContainer> container) + throws TimeoutException { var waitingConsumer = new WaitingConsumer(); var toStringConsumer = new ToStringConsumer(); var composedConsumer = toStringConsumer.andThen(waitingConsumer); container.followOutput(composedConsumer); - waitingConsumer.waitUntil(frame -> frame.getUtf8String().contains("End " + QualityMonitor.QUALITY_MONITOR), 60, TimeUnit.SECONDS); + waitingConsumer.waitUntil(frame -> frame.getUtf8String().contains("End " + QualityMonitor.QUALITY_MONITOR), 60, + TimeUnit.SECONDS); return toStringConsumer.toUtf8String(); } @@ -217,10 +260,12 @@ private void startContainerWithAllFiles(final GenericContainer container) { container.withWorkingDirectory("/github/workspace") .withCopyFileToContainer(read("checkstyle/checkstyle-result.xml"), WS + "checkstyle-result.xml") .withCopyFileToContainer(read("jacoco/jacoco.xml"), WS + "site/jacoco/jacoco.xml") - .withCopyFileToContainer(read("junit/TEST-edu.hm.hafner.grading.AutoGradingActionTest.xml"), WS + "surefire-reports/TEST-Aufgabe3Test.xml") + .withCopyFileToContainer(read("junit/TEST-edu.hm.hafner.grading.AutoGradingActionTest.xml"), + WS + "surefire-reports/TEST-Aufgabe3Test.xml") .withCopyFileToContainer(read("pit/mutations.xml"), WS + "pit-reports/mutations.xml") .withCopyFileToContainer(read("pmd/pmd.xml"), WS + "pmd.xml") .withCopyFileToContainer(read("spotbugs/spotbugsXml.xml"), WS + "spotbugsXml.xml") + .withCopyFileToContainer(read("metrics/metrics.xml"), WS + "metrics.xml") .start(); } diff --git a/src/test/java/edu/hm/hafner/grading/github/QualityMonitorITest.java b/src/test/java/edu/hm/hafner/grading/github/QualityMonitorITest.java index e9e8522..542e03d 100644 --- a/src/test/java/edu/hm/hafner/grading/github/QualityMonitorITest.java +++ b/src/test/java/edu/hm/hafner/grading/github/QualityMonitorITest.java @@ -87,7 +87,38 @@ public class QualityMonitorITest extends ResourceTest { } ] } - ] + ], + "metrics": [ + { + "name": "Toplevel Metrics", + "tools": [ + { + "name": "Cyclomatic Complexity", + "id": "metrics", + "pattern": "**/src/**/metrics.xml", + "metric": "CyclomaticComplexity" + }, + { + "name": "Cognitive Complexity", + "id": "metrics", + "pattern": "**/src/**/metrics.xml", + "metric": "CognitiveComplexity" + }, + { + "name": "Non Commenting Source Statements", + "id": "metrics", + "pattern": "**/src/**/metrics.xml", + "metric": "NCSS" + }, + { + "name": "N-Path Complexity", + "id": "metrics", + "pattern": "**/src/**/metrics.xml", + "metric": "NPathComplexity" + } + ] + } + ] } """; @@ -133,6 +164,10 @@ void shouldGradeWithConfigurationFromEnvironment() { "=> PMD: 41 warnings (normal: 41)", "-> SpotBugs Total: 1 warnings", "=> SpotBugs: 1 bug (low: 1)", + "=> Cyclomatic Complexity: 355", + "=> Cognitive Complexity: 172", + "=> Non Commenting Source Statements: 1200", + "=> N-Path Complexity: 432", "mutation=8", "bugs=1", "tests=37", @@ -141,7 +176,12 @@ void shouldGradeWithConfigurationFromEnvironment() { "style=60", "spotbugs=1", "checkstyle=19", - "branch=10"}); + "branch=10", + "ncss=1200", + "npath-complexity=432", + "cognitive-complexity=172", + "cyclomatic-complexity=355" + }); } private static final String CONFIGURATION_WRONG_PATHS = """ diff --git a/src/test/resources/metrics/metrics.xml b/src/test/resources/metrics/metrics.xml new file mode 100644 index 0000000..585a2e7 --- /dev/null +++ b/src/test/resources/metrics/metrics.xml @@ -0,0 +1,1339 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From d588eb88a2f921cfe84ef34555c5e411d669b401 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Mon, 28 Oct 2024 17:10:18 +0100 Subject: [PATCH 2/2] Bump version to 1.12.0. --- action.yml | 2 +- doc/dependency-graph.puml | 4 ++-- pom.xml | 2 +- .../hm/hafner/grading/github/QualityMonitorDockerITest.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index b17a811..2358255 100644 --- a/action.yml +++ b/action.yml @@ -25,7 +25,7 @@ inputs: required: false runs: using: 'docker' - image: 'docker://uhafner/quality-monitor:1.12.0-SNAPSHOT' + image: 'docker://uhafner/quality-monitor:1.12.0' env: CONFIG: ${{ inputs.config }} CHECKS_NAME: ${{ inputs.checks-name }} diff --git a/doc/dependency-graph.puml b/doc/dependency-graph.puml index a3db82d..3a090f6 100644 --- a/doc/dependency-graph.puml +++ b/doc/dependency-graph.puml @@ -46,7 +46,7 @@ rectangle "coverage-model\n\n0.47.0" as edu_hm_hafner_coverage_model_jar rectangle "jackson-databind\n\n2.18.0" as com_fasterxml_jackson_core_jackson_databind_jar rectangle "jackson-annotations\n\n2.18.0" as com_fasterxml_jackson_core_jackson_annotations_jar rectangle "jackson-core\n\n2.18.0" as com_fasterxml_jackson_core_jackson_core_jar -rectangle "quality-monitor\n\n1.12.0-SNAPSHOT" as edu_hm_hafner_quality_monitor_jar +rectangle "quality-monitor\n\n1.12.0" as edu_hm_hafner_quality_monitor_jar rectangle "github-api\n\n1.326" as org_kohsuke_github_api_jar rectangle "codingstyle\n\n4.14.0" as edu_hm_hafner_codingstyle_jar rectangle "spotbugs-annotations\n\n4.8.6" as com_github_spotbugs_spotbugs_annotations_jar @@ -102,4 +102,4 @@ edu_hm_hafner_quality_monitor_jar -[#000000]-> com_google_errorprone_error_prone edu_hm_hafner_quality_monitor_jar -[#000000]-> org_apache_commons_commons_lang3_jar edu_hm_hafner_quality_monitor_jar -[#000000]-> commons_io_commons_io_jar edu_hm_hafner_quality_monitor_jar -[#000000]-> one_util_streamex_jar -@enduml \ No newline at end of file +@enduml diff --git a/pom.xml b/pom.xml index 32fde09..bc61c01 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ edu.hm.hafner quality-monitor - 1.12.0-SNAPSHOT + 1.12.0 jar diff --git a/src/test/java/edu/hm/hafner/grading/github/QualityMonitorDockerITest.java b/src/test/java/edu/hm/hafner/grading/github/QualityMonitorDockerITest.java index be3b0a0..b5c5f20 100644 --- a/src/test/java/edu/hm/hafner/grading/github/QualityMonitorDockerITest.java +++ b/src/test/java/edu/hm/hafner/grading/github/QualityMonitorDockerITest.java @@ -240,7 +240,7 @@ void shouldShowErrors() throws TimeoutException { } private GenericContainer createContainer() { - return new GenericContainer<>(DockerImageName.parse("uhafner/quality-monitor:1.12.0-SNAPSHOT")); + return new GenericContainer<>(DockerImageName.parse("uhafner/quality-monitor:1.12.0")); } private String readStandardOut(final GenericContainer> container)