diff --git a/src/main/java/fr/cnes/sonar/report/exporters/MarkdownExporter.java b/src/main/java/fr/cnes/sonar/report/exporters/MarkdownExporter.java index 83c935c8..abeed452 100644 --- a/src/main/java/fr/cnes/sonar/report/exporters/MarkdownExporter.java +++ b/src/main/java/fr/cnes/sonar/report/exporters/MarkdownExporter.java @@ -32,14 +32,6 @@ public class MarkdownExporter implements IExporter { - /** - * Start index of the sub array in the headers array for the the second table - */ - private static final int HEADER_START_INDEX = 2; - /** - * End index of the sub array in the headers array for the the second table - */ - private static final int HEADER_END_INDEX = 5; /** * Placeholder for issues count table */ @@ -123,9 +115,9 @@ public File export(Object data, String path, String filename) throws IOException // Generate issue count table final List> types = DataAdapter.getTypes(report); - final String tableTypes = generateMDTable( - headerIssues.subList(HEADER_START_INDEX, HEADER_END_INDEX), - types); + final List headerIssuesCount = DataAdapter.getReversedIssuesSeverities(); + headerIssuesCount.add(0, StringManager.string("header.typeSlashSeverity")); + final String tableTypes = generateMDTable(headerIssuesCount, types); output = output.replace(ISSUES_COUNT_PLACEHOLDER, tableTypes); // Generate security hotspots table diff --git a/src/main/java/fr/cnes/sonar/report/exporters/docx/DataAdapter.java b/src/main/java/fr/cnes/sonar/report/exporters/docx/DataAdapter.java index ef17db24..6ae2b2da 100644 --- a/src/main/java/fr/cnes/sonar/report/exporters/docx/DataAdapter.java +++ b/src/main/java/fr/cnes/sonar/report/exporters/docx/DataAdapter.java @@ -353,32 +353,47 @@ public static List> getTypes(Report report) { final List> results = new ArrayList<>(); final String[] types = ISSUE_TYPES; - final String[] severities = ISSUE_SEVERITIES; - + final List severities = getReversedIssuesSeverities(); + + // accumulator for the number of occurrences for each severity + LinkedHashMap countPerSeverity = new LinkedHashMap<>(); + for (String severity : severities) { + countPerSeverity.put(severity, 0); + } + for(String type : types) { - for (String severity : severities) { - // accumulator for the number of occurrences - long nb = 0; - //List of items for each line of the table - final List item = new ArrayList<>(); - - // we sum all issues with a type and a severity - for(Issue issue : report.getIssues()) { - if(issue.getType().equals(type) && issue.getSeverity().equals(severity)) { - nb++; - } + //List of items for each line of the table + final List row = new ArrayList<>(); + for(Issue issue : report.getIssues()) { + if(issue.getType().equals(type)) { + // increment the count of the severity + countPerSeverity.put(issue.getSeverity(), + countPerSeverity.get(issue.getSeverity()) + 1); } - // we add it to the list - item.add(type); - item.add(severity); - item.add(String.valueOf(nb)); - // add the whole line to the results - results.add(item); } + // add data to the row + row.add(type); + for (String severity : severities) { + row.add(String.valueOf(countPerSeverity.get(severity))); + // reset the count + countPerSeverity.put(severity, 0); + } + // add row to the result + results.add(row); } return results; } + /** + * Getter for reversed ISSUE_SEVERITIES + * @return reversed ISSUE_SEVERITIES + */ + public static List getReversedIssuesSeverities() { + List issuesSeverities = new ArrayList<>(Arrays.asList(ISSUE_SEVERITIES)); + Collections.reverse(issuesSeverities); + return issuesSeverities; + } + /** * Prepare list of resources to be print in a table * Data are lines containing the number of security hotspots by review priority and security category diff --git a/src/main/java/fr/cnes/sonar/report/exporters/docx/DocXExporter.java b/src/main/java/fr/cnes/sonar/report/exporters/docx/DocXExporter.java index abfd4af4..c645b76a 100644 --- a/src/main/java/fr/cnes/sonar/report/exporters/docx/DocXExporter.java +++ b/src/main/java/fr/cnes/sonar/report/exporters/docx/DocXExporter.java @@ -73,14 +73,6 @@ public class DocXExporter implements IExporter { * Name of the property giving the path header's number */ private static final String HEADER_NUMBER = "header.number"; - /** - * Start index of the sub array in the headers array for the the second table - */ - private static final int HEADER_START_INDEX = 2; - /** - * End index of the sub array in the headers array for the the second table - */ - private static final int HEADER_END_INDEX = 5; /** * Overridden export for docX @@ -133,9 +125,9 @@ public File export(final Object data, final String path, final String filename) // Add issues count by type and severity final List> types = DataAdapter.getTypes(report); - DocXTools.fillTable(document, - headerIssues.subList(HEADER_START_INDEX, HEADER_END_INDEX), - types, COUNT_TABLE_PLACEHOLDER); + final List headerIssuesCount = DataAdapter.getReversedIssuesSeverities(); + headerIssuesCount.add(0, StringManager.string("header.typeSlashSeverity")); + DocXTools.fillTable(document, headerIssuesCount, types, COUNT_TABLE_PLACEHOLDER); // Add security hotspots final List> securityHotspots = DataAdapter.getSecurityHotspots(report); diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index d43f3045..808c737a 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -24,6 +24,7 @@ header.number=Number header.category=Category header.priority=Priority header.count=Count +header.typeSlashSeverity=Type / Severity header.categorySlashPriority=Category / Priority header.metric=Metric header.value=Value diff --git a/src/main/resources/messages_en_US.properties b/src/main/resources/messages_en_US.properties index d43f3045..808c737a 100644 --- a/src/main/resources/messages_en_US.properties +++ b/src/main/resources/messages_en_US.properties @@ -24,6 +24,7 @@ header.number=Number header.category=Category header.priority=Priority header.count=Count +header.typeSlashSeverity=Type / Severity header.categorySlashPriority=Category / Priority header.metric=Metric header.value=Value diff --git a/src/main/resources/messages_fr_FR.properties b/src/main/resources/messages_fr_FR.properties index 876a0a01..140a9179 100644 --- a/src/main/resources/messages_fr_FR.properties +++ b/src/main/resources/messages_fr_FR.properties @@ -24,6 +24,7 @@ header.number=Nombre header.category=Catégorie header.priority=Priorité header.count=Total +header.typeSlashSeverity=Type / Criticité header.categorySlashPriority=Catégorie / Priorité header.metric=Métrique header.value=Valeur diff --git a/src/test/ut/java/fr/cnes/sonar/report/CommonTest.java b/src/test/ut/java/fr/cnes/sonar/report/CommonTest.java index 03532041..9c00ba4c 100644 --- a/src/test/ut/java/fr/cnes/sonar/report/CommonTest.java +++ b/src/test/ut/java/fr/cnes/sonar/report/CommonTest.java @@ -117,6 +117,7 @@ public void before() { i2.setStatus("OPEN"); i2.setType("BUG"); i2.setRule("abcd:dcba"); + i4.setSeverity(MAJOR); i4.setType("BUG"); // Adding multiple time to test comparator (DataAdapter.RuleComparator) Issue issue;