Skip to content

Commit

Permalink
Merge pull request #324 from cnescatlab/dev
Browse files Browse the repository at this point in the history
Release 4.1.2
  • Loading branch information
Sancretor authored Jun 13, 2022
2 parents b86f8ea + dfa7385 commit b32babe
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 171 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sonar-cnes-report-plugin",
"license": "GPL-3.0",
"version": "4.1.1",
"version": "4.1.2",
"devDependencies": {
"@babel/core": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.8.3",
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.cnes.sonar</groupId>
<artifactId>cnesreport</artifactId>
<version>4.1.1</version>
<version>4.1.2</version>
<packaging>sonar-plugin</packaging>

<name>SonarQube CNES Report</name>
Expand Down Expand Up @@ -166,7 +166,7 @@
<!-- openxml generation -->
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
<version>4.1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public File export(Object data, String path, String filename)
final Report report = (Report) data;

// get issues
final List<Issue> issues = report.getIssues();
final List<Issue> issues = report.getIssues().getIssuesList();
String message = "key\tproject\tcomponent\ttype\tseverity\tmessage\tline\tstatus\t";
LOGGER.info(message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static List<List<String>> getTypes(Report report) {
for (String type : types) {
// List of items for each line of the table
final List<String> row = new ArrayList<>();
for (Issue issue : report.getIssues()) {
for (Issue issue : report.getIssues().getIssuesList()) {
if (issue.getType().equals(type)) {
// increment the count of the severity
countPerSeverity.put(issue.getSeverity(),
Expand All @@ -100,46 +100,61 @@ public static List<List<String>> getTypes(Report report) {
* @return issues list
*/
public static List<List<String>> getIssues(Report report) {
final List<List<String>> issues = new ArrayList<>(); // result to return
final List<List<String>> formattedIssues = new ArrayList<>(); // result to return

// Get the issues' id
final Map<String, Long> items = report.getIssuesFacets();
final Map<String, Long> items = report.getIssues().getIssuesFacets();

Map<String, Long> sortedItems = new TreeMap<>(new RuleComparator(report));
sortedItems.putAll(items);

List<String> formattedIssue = null;
Rule rule = null;
Issue issue = null;

for (Map.Entry<String, Long> v : sortedItems.entrySet()) { // construct each issues
final List<String> issue = new ArrayList<>();
final Rule rule = report.getRule(v.getKey());
formattedIssue = new ArrayList<>();
rule = report.getRule(v.getKey());
issue = report.getIssues().getFirstIssueMatchingRule(v.getKey());

if (rule != null) { // if the rule is found, fill information
// add name
issue.add(rule.getName());
formattedIssue.add(rule.getName());
// add description
formattedIssue.add(rule.getHtmlDesc()
.replaceAll(DELETE_HTML_TAGS_REGEX, StringManager.EMPTY));
// add type
formattedIssue.add(rule.getType());
// add severity
formattedIssue.add(rule.getSeverity());
} else if (issue != null) { // if if comes from an external analyzer
// add name
formattedIssue.add(issue.getRule());
// add description
issue.add(rule.getHtmlDesc()
formattedIssue.add(issue.getMessage()
.replaceAll(DELETE_HTML_TAGS_REGEX, StringManager.EMPTY));
// add type
issue.add(rule.getType());
formattedIssue.add(issue.getType());
// add severity
issue.add(rule.getSeverity());
// add number
issue.add(Long.toString(v.getValue()));
} else { // else set just known information
formattedIssue.add(issue.getSeverity());
}else { // else set just known information
// add name
issue.add(v.getKey());
formattedIssue.add(v.getKey());
// add description
issue.add(QUESTION_MARK);
formattedIssue.add(QUESTION_MARK);
// add type
issue.add(QUESTION_MARK);
formattedIssue.add(QUESTION_MARK);
// add severity
issue.add(QUESTION_MARK);
// add number
issue.add(Long.toString(v.getValue()));
formattedIssue.add(QUESTION_MARK);
}

issues.add(issue);
// add number
formattedIssue.add(Long.toString(v.getValue()));

formattedIssues.add(formattedIssue);
}

return issues;
return formattedIssues;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlException;

import java.awt.image.BufferedImage;
import java.io.IOException;
Expand Down Expand Up @@ -112,10 +111,9 @@ private DocXTools() {}
* @param document word document
* @param facets resources as facets
* @throws IOException ...
* @throws XmlException ...
*/
public static void fillCharts(XWPFDocument document, Report report)
throws IOException, XmlException {
throws IOException {

final Facets facets = report.getFacets();
final TimeFacets timeFacets = report.getTimeFacets();
Expand All @@ -127,6 +125,7 @@ public static void fillCharts(XWPFDocument document, Report report)

// browse chart list to find placeholders (based on locale) in title
// and provide them adapted resources

for (XWPFChartSpace chartSpace : chartSpaces) {

final String currentChartTitle = chartSpace.getTitle();
Expand Down
105 changes: 29 additions & 76 deletions src/main/java/fr/cnes/sonar/report/exporters/docx/XWPFChartSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,18 @@
import fr.cnes.sonar.report.model.Value;
import fr.cnes.sonar.report.model.TimeValue;

import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.xwpf.usermodel.XWPFChart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumVal;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrVal;
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
import org.openxmlformats.schemas.drawingml.x2006.chart.impl.ChartSpaceDocumentImpl;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Custom class to handle chart spaces
Expand All @@ -47,25 +41,17 @@
public class XWPFChartSpace {

/**
* Encapsulated POI version of chart space
* Encapsulated POI version of chart
*/
private ChartSpaceDocument chartSpace;

/**
* {@link PackagePart} to save the current ChartSpaceDocument
*/
private PackagePart packagePart;

private static final Logger LOGGER = Logger.getLogger(XWPFChartSpace.class.getName());
private XWPFChart chart;

/**
* Basic constructor based on ChartSpaceDocumentImpl
* @param ctChartSpace a prebuilt chart space
* @param chartPackagePart the package part corresponding to the chart
*/
public XWPFChartSpace(final ChartSpaceDocument ctChartSpace, final PackagePart chartPackagePart) {
this.chartSpace = ctChartSpace;
this.packagePart = chartPackagePart;
public XWPFChartSpace(final XWPFChart chart) {
this.chart = chart;
}

/**
Expand All @@ -76,57 +62,42 @@ public XWPFChartSpace(final ChartSpaceDocument ctChartSpace, final PackagePart c
* @throws IOException When reading files
* @throws XmlException When reading files
*/
public static List<XWPFChartSpace> getChartSpaces(final XWPFDocument document)
throws IOException, XmlException {
// gather charts documents
final List<POIXMLDocumentPart> charts = Lists.newArrayList();
// results list to return at the end
final List<XWPFChartSpace> result = Lists.newArrayList();

// get parts related to charts
for(final POIXMLDocumentPart p : document.getRelations()) {
if(p.toString().contains("/word/charts/")) {
charts.add(p);
}
}
public static List<XWPFChartSpace> getChartSpaces(final XWPFDocument document) {

// gather charts
final List<XWPFChartSpace> charts = Lists.newArrayList();

// get chart spaces inside previous parts
for(final POIXMLDocumentPart p : charts) {
try {
final InputStream inputStream = p.getPackagePart().getInputStream();
final ChartSpaceDocument c = ChartSpaceDocument.Factory.parse(inputStream);
result.add(new XWPFChartSpace(c, p.getPackagePart()));
} catch(final ClassCastException e){
LOGGER.log(Level.WARNING, "Error while getting charts, cannot convert XMLObject into ChartSpaceDocument", e);
for (POIXMLDocumentPart part : document.getRelations()) {
if (part instanceof XWPFChart) {
charts.add(new XWPFChartSpace((XWPFChart) part));
}
}

return result;
return charts;
}

/**
* Getter for chartSpace
* @return a CTChartSpace
* Getter for chart
* @return a XWPFChart
*/
public ChartSpaceDocument getChartSpace() {
return this.chartSpace;
public XWPFChart getChart() {
return this.chart;
}

/**
* Setter for chartSpace
* @param ctChartSpace new chartSpace value
* Setter for chart
* @param XWPFChart new chart value
*/
public void setChartSpace(final ChartSpaceDocumentImpl ctChartSpace) {
this.chartSpace = ctChartSpace;
public void setChartSpace(final XWPFChart pChart) {
this.chart = pChart;
}

/**
* Retrieve the chart's title value
* @return a string containing the raw title
*/
public String getTitle() {
return chartSpace.getChartSpace().getChart().getTitle().getTx()
.getRich().getPList().get(0).getRList().get(0).getT();
return chart.getCTChart().getTitle().getTx().getRich().getPList().get(0).getRList().get(0).getT();
}

/**
Expand All @@ -135,19 +106,7 @@ public String getTitle() {
* @throws IOException error when writing the chart's file
*/
public void setTitle(final String newTitle) throws IOException {
chartSpace.getChartSpace().getChart().getTitle().getTx().getRich()
.getPList().get(0).getRList().get(0).setT(newTitle);
this.save();
}

/**
* Save modifications on Chart, must be called for each Chart
* @throws IOException When saving chart in the output stream
*/
public void save() throws IOException {
final OutputStream outputStream = packagePart.getOutputStream();
chartSpace.save(outputStream);
outputStream.close();
chart.getCTChart().getTitle().getTx().getRich().getPList().get(0).getRList().get(0).setT(newTitle);
}

/**
Expand All @@ -156,7 +115,7 @@ public void save() throws IOException {
* @throws IOException when writing the file
*/
public void setValues(List<Value> values) throws IOException {
final CTPlotArea ctPlotArea = chartSpace.getChartSpace().getChart().getPlotArea();
final CTPlotArea ctPlotArea = chart.getCTChart().getPlotArea();

// if the chart is a pie chart we continue
if(!ctPlotArea.getPieChartList().isEmpty()) {
Expand Down Expand Up @@ -190,9 +149,6 @@ public void setValues(List<Value> values) throws IOException {
}
}
// otherwise we do not support other type for now

// finally we save modifications
this.save();
}

/**
Expand All @@ -201,7 +157,7 @@ public void setValues(List<Value> values) throws IOException {
* @throws IOException when writing the file
*/
public void setTimeValues(List<TimeValue> values) throws IOException {
final CTPlotArea ctPlotArea = chartSpace.getChartSpace().getChart().getPlotArea();
final CTPlotArea ctPlotArea = chart.getCTChart().getPlotArea();

// if the chart is a scatter chart we continue
if(!ctPlotArea.getScatterChartList().isEmpty()) {
Expand All @@ -218,11 +174,11 @@ public void setTimeValues(List<TimeValue> values) throws IOException {
// format date values
final CTNumData xNumCache = ctPlotArea.getScatterChartList().get(0)
.getSerList().get(0).getXVal().getNumRef().getNumCache();
xNumCache.setFormatCode("m/d/yyyy\\ h:mm");
xNumCache.setFormatCode("dd/mm/yyyy\\ hh:mm");

// format date axis
final CTNumFmt dateAxisFormat = ctPlotArea.getValAxList().get(1).getNumFmt();
dateAxisFormat.setFormatCode("m/d/yyyy\\ h:mm");
final CTNumFmt dateAxisFormat = ctPlotArea.getValAxList().get(0).getNumFmt();
dateAxisFormat.setFormatCode("dd/mm/yyyy\\ hh:mm");

// write resources in the scatter chart
for (int i = 0 ; i < values.size() ; i++) {
Expand All @@ -244,9 +200,6 @@ public void setTimeValues(List<TimeValue> values) throws IOException {
}
}
// otherwise we do not support other type for now

// finally we save modifications
this.save();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public File export(Object data, String path, String filename)
final XSSFSheet metricsSheet = (XSSFSheet) workbook.getSheet(METRICS_SHEET_NAME);

// write selected resources in the file
XlsXTools.addSelectedData(report.getIssues(), selectedSheet, SELECTED_TABLE_NAME);
XlsXTools.addSelectedData(report.getIssues().getIssuesList(), selectedSheet, SELECTED_TABLE_NAME);

// write selected resources in the file
XlsXTools.addSelectedData(report.getUnconfirmed(), unconfirmedSheet, UNCONFIRMED_TABLE_NAME);
Expand Down
Loading

0 comments on commit b32babe

Please sign in to comment.