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

4.1.0 analysis-report.docx corrupt #309

Closed
un0tec opened this issue Mar 2, 2022 · 3 comments · Fixed by #315
Closed

4.1.0 analysis-report.docx corrupt #309

un0tec opened this issue Mar 2, 2022 · 3 comments · Fixed by #315
Labels
bug Something isn't working done This issue was solved but not merged in master
Milestone

Comments

@un0tec
Copy link
Contributor

un0tec commented Mar 2, 2022

Hi all,

4.1.0 - Standalone mode - analysis-report.docx corrupted. Microsoft Office shows that the file cannot be opened due to an error in the content.
4.0.0 - Standalone mode - analysis-report.docx is generated correctly and Microsoft Office opens the file without problems.

After making a fork of the project and debugging the code, I have been able to verify that the problem is when loading the images of the Measures section in the template.

Stacktrace:

Class: DocXExporter.java
Method: replaceSimplePlaceholders()
[...]
Class: PlaceHolders.java
Method: loadPlaceholdersMap() > for (Measure m : report.getMeasures())

If the code that replaces the images is commented, the generated file works correctly.

// Synthesis placeholders
//        for (Measure m : report.getMeasures()) {
//            final String placeholder = getPlaceHolderName(m.getMetric());
//            String value;
//
//            // convert the metric value to a PNG if possible
//            if (m.getMetric().contains(RATING)) {
//                value = numberToLetter(m.getValue());
//            } else if (m.getMetric().contains(STATUS)) {
//                value = formatStatus(m.getValue());
//            } else {
//                value = m.getValue();
//            }
//
//            replacementValues.put(
//                    placeholder,
//                    value);
//        }
        
//     MOCK 
        //replacementValues.put("XX-SECURITYREVIEW-XX", "E.png");
        replacementValues.put("XX-DUPLICATION-XX", "1.0");
        replacementValues.put("XX-XXXXXXXXXXXXXXX-XX", "20");
        replacementValues.put("XX-COMMENTDENSITY-XX", "31.0");
        //replacementValues.put("XX-SECURITY-XX", "C.png");
        replacementValues.put("XX-LINES-XX", "1343");
        //replacementValues.put("XX-QUALITYGATE-XX", "OK.png");
        //replacementValues.put("XX-RELIABILITY-XX", "E.png");
        replacementValues.put("XX-COVERAGE-XX", "0.0");
        //replacementValues.put("XX-MAINTAINABILITY-XX", "A.png");

If the images of the mocked code are uncommented, the file is generated corrupted.

I have tried to debug the code where the images are replaced in the template (DocXTools.java > replaceInParagraph()), but I can't identify what causes the error.

As I said, version 4.0.0 generates the file correctly. I have tried to check the differences between both versions, but the code has been refactored or moved between files and it is difficult to trace it.

Regards.

@un0tec un0tec added the bug Something isn't working label Mar 2, 2022
@un0tec
Copy link
Contributor Author

un0tec commented Mar 2, 2022

The commit that causes the file to generate corrupt with the images is 95cde12, commits prior to this one work correctly.

un0tec added a commit to un0tec/sonar-cnes-report that referenced this issue Mar 2, 2022
@Sancretor
Copy link
Contributor

Hi @un0tec
Wow, thanks a lot for your contribution ! It's truely appreciated !
I'll have a look into it next week.

@Sancretor Sancretor added this to the 4.2.0 milestone Mar 4, 2022
@un0tec
Copy link
Contributor Author

un0tec commented Mar 4, 2022

Hi @Sancretor

I made a pull request to solve it, it was complicated to identify it but really easy to solve the problem.

Regards!

@Sancretor Sancretor added the done This issue was solved but not merged in master label Mar 9, 2022
@Sancretor Sancretor modified the milestones: 4.2.0, 4.1.1 Apr 26, 2022
@Sancretor Sancretor mentioned this issue Apr 26, 2022
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working done This issue was solved but not merged in master
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants