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

Enable software-metrics #58

Merged
merged 2 commits into from
Oct 28, 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
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions doc/dependency-graph.puml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
@enduml
8 changes: 3 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<parent>
<groupId>edu.hm.hafner</groupId>
<artifactId>codingstyle-pom</artifactId>
<version>4.16.0</version>
<version>5.2.0</version>
<relativePath/>
</parent>

<groupId>edu.hm.hafner</groupId>
<artifactId>quality-monitor</artifactId>
<version>1.12.0-SNAPSHOT</version>
<version>1.12.0</version>
<packaging>jar</packaging>

<scm>
Expand All @@ -27,9 +27,7 @@
<module.name>${project.groupId}.quality.monitor</module.name>
<docker-image-tag>${project.version}</docker-image-tag>

<java.version>17</java.version>

<autograding-model.version>3.36.0</autograding-model.version>
<autograding-model.version>4.0.0</autograding-model.version>
<testcontainers.version>1.20.2</testcontainers.version>
<github-api.version>1.326</github-api.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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")
Expand All @@ -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)))
Expand All @@ -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",
Expand Down Expand Up @@ -199,16 +240,18 @@ 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<? extends GenericContainer<?>> container) throws TimeoutException {
private String readStandardOut(final GenericContainer<? extends 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();
}
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
]
}
""";

Expand Down Expand Up @@ -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",
Expand All @@ -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 = """
Expand Down
Loading