55import java .nio .file .Files ;
66import java .nio .file .Path ;
77import java .util .List ;
8+ import java .util .Map ;
9+ import java .util .stream .Collectors ;
810
11+ import org .apache .commons .collections4 .CollectionUtils ;
912import org .apache .maven .execution .MavenSession ;
1013import org .apache .maven .plugin .AbstractMojo ;
1114import org .apache .maven .plugins .annotations .Mojo ;
1215import org .apache .maven .plugins .annotations .Parameter ;
1316import org .apache .maven .project .MavenProject ;
17+ import org .slf4j .Logger ;
18+ import org .slf4j .LoggerFactory ;
1419
1520import at .aau .jacoco .JacocoCoverageCollector ;
1621import at .aau .jacoco .JacocoCoverageFilter ;
1722import at .aau .jacoco .model .Method ;
1823import at .aau .jacoco .model .Package ;
1924import at .aau .metrics .CkMetricCollector ;
25+ import at .aau .metrics .MethodMatcher ;
2026import at .aau .metrics .MetricUtils ;
2127import at .aau .metrics .RiskMetricCalculator ;
28+ import at .aau .model .ClassMetricType ;
2229import at .aau .model .MethodWithRisk ;
2330import at .aau .model .MetricsData ;
2431
2532@ Mojo (name = "test-gap-scanner" )
2633public class TestGapScannerMojo extends AbstractMojo {
2734
35+ private static final Logger log = LoggerFactory .getLogger (CkMetricCollector .class );
36+
2837 @ Parameter (defaultValue = "${project.build.directory}/site/jacoco/jacoco.xml" )
2938 private String coverageReportPath ;
3039
40+ @ Parameter (defaultValue = "${project.build.directory}/site/code-maat/revisions.csv" )
41+ private String maatRevisionsPath ;
42+
43+ @ Parameter (defaultValue = "${project.build.directory}/site/code-maat/soc.csv" )
44+ private String maatSocPath ;
45+
3146 @ Parameter (defaultValue = "${project}" , readonly = true , required = true )
3247 private MavenProject project ;
3348
@@ -44,14 +59,28 @@ private static List<Method> getUntestedMethods(Path coverageReport) throws Excep
4459 public void execute () {
4560 Path projectBaseDirPath = project .getBasedir ().toPath ();
4661 Path coverageReport = Path .of (coverageReportPath );
62+ Path maatRevisions = Path .of (maatRevisionsPath );
63+ Path maatSoc = Path .of (maatSocPath );
4764
4865 if (Files .notExists (coverageReport )) {
49- getLog ().warn ("Coverage report not found at " + coverageReport );
66+ getLog ().warn ("Coverage report not found at " + coverageReportPath );
67+
68+ return ;
69+ }
70+
71+ if (Files .notExists (maatRevisions )) {
72+ getLog ().warn ("Maat revisions report not found at " + maatRevisionsPath );
5073
5174 return ;
5275 }
5376
54- getLog ().info ("Valid coverage report found, processing..." );
77+ if (Files .notExists (maatSoc )) {
78+ getLog ().warn ("Maat SoC report not found at " + maatSocPath );
79+
80+ return ;
81+ }
82+
83+ getLog ().info ("Valid reports found, processing..." );
5584
5685 List <Method > uncoveredMethods ;
5786
@@ -64,11 +93,26 @@ public void execute() {
6493
6594 getLog ().info ("Calculating risk scores for untested classes..." );
6695
67- List <MetricsData > methodMetricsData = CkMetricCollector .collectMetrics (projectBaseDirPath );
96+ List <MetricsData > methodMetricsData = CkMetricCollector .collectCkMetrics (projectBaseDirPath );
6897 List <MetricsData > untestedMethodsMetricsData =
6998 MetricUtils .getUntestedMethodMetrics (uncoveredMethods , methodMetricsData );
70- List <MetricsData > normalizedMetricsData =
71- RiskMetricCalculator .normalizeMetricsData (untestedMethodsMetricsData );
99+
100+ List <MetricsData > metricsData = MethodMatcher .methodDescriptorFromMaat (maatRevisions , ClassMetricType .REVS );
101+
102+ Map <String , List <MetricsData >> classNameToMetricsDataMap = untestedMethodsMetricsData .stream ()
103+ .collect (Collectors .groupingBy (MetricsData ::getClassName , Collectors .toList ()));
104+
105+ for (MetricsData metricData : metricsData ) {
106+ List <MetricsData > mapEntries = classNameToMetricsDataMap .get (metricData .getClassName ());
107+
108+ if (CollectionUtils .isNotEmpty (mapEntries )) {
109+ MetricsData firstEntry = mapEntries .get (0 );
110+
111+ firstEntry .addClassMetrics (metricData .getClassMetrics ());
112+ }
113+ }
114+
115+ List <MetricsData > normalizedMetricsData = RiskMetricCalculator .normalizeMetricsData (untestedMethodsMetricsData );
72116 List <MethodWithRisk > descendingMethodRiskScores =
73117 RiskMetricCalculator .getDescendingMethodRiskScores (normalizedMetricsData );
74118
@@ -80,8 +124,7 @@ public void execute() {
80124
81125 String rank = String .format ("%d:" , i + 1 );
82126 String descriptor = String .format (" FQN: %s" , matchingClass .getMethodDescriptor ());
83- String symbol =
84- String .format (" Symbol: %s" , matchingClass .getMethodDescriptor ().getSymbol ());
127+ String symbol = String .format (" Symbol: %s" , matchingClass .getMethodDescriptor ().getSymbol ());
85128 String risk = String .format (" Risk: %.2f" , matchingClass .getRisk ());
86129
87130 outputBuilder .append (rank ).append (System .lineSeparator ());
@@ -96,6 +139,8 @@ public void execute() {
96139
97140 private void writeToFile (Path filePath , String content ) {
98141 try {
142+ log .info ("Writing report to file: '{}'" , filePath );
143+
99144 Files .writeString (filePath , content , StandardCharsets .UTF_8 );
100145 } catch (IOException e ) {
101146 getLog ().error ("Error writing content to file; abort - [filePath='{}']" + filePath , e );
0 commit comments