danielpalme / ReportGenerator

ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.
https://reportgenerator.io
Apache License 2.0
2.56k stars 279 forks source link

Error while converting jacoco report to cobertura #665

Closed pranavbhatt closed 4 months ago

pranavbhatt commented 4 months ago

Hi Team,

I am getting the following error while trying to convert a jacoco report to cobertura in azure devops pipeline:

2024-04-23T07:47:15: Error during reading report '/mnt/vss/_work/1/s/sources/dev/report/target/jacoco/jacoco.xml' (Size: 40.6MB): An item with the same key has already been added. Key: 39
2024-04-23T07:47:16: Writing report file '/mnt/vss/_work/1/a/publish/coverage/Cobertura.xml'
2024-04-23T07:47:16: Writing report file '/mnt/vss/_work/1/a/publish/coverage/index.html'
2024-04-23T07:47:16: Report generation took 3.4 seconds
##[debug]Exit code 0 received from tool '/usr/bin/dotnet'

I have the following task in my pipeline:

        - task: reportgenerator@5
          displayName: Jacoco Report Converter
          condition: always()
          continueOnError: true
          inputs:
            reports: '$(Build.SourcesDirectory)/sources/dev/report/target/jacoco/jacoco.xml'
            targetdir: '$(Build.SourcesDirectory)/publish/coverage'
            sourceDirs: '$(Build.SourcesDirectory)/sources/dev'
            reporttypes: 'HtmlInline_AzurePipelines;Cobertura'

I have a sample jacoco coverage file which I can send for further inspect if needed.

danielpalme commented 4 months ago

Could you please share your JaCoCo file? You can send it privately via email: reportgenerator@palmmedia.de

pranavbhatt commented 4 months ago

@danielpalme sent the link to take a look at the jacoco file.

danielpalme commented 4 months ago

Problem here is that the class SurveyRequestDateHelper appears twice in the JaCoCo file.

If you update to the latest release 5.2.5, it will work with the duplicate class as well.

pranavbhatt commented 4 months ago

Thank you @danielpalme I will rename one of the files to check if it works and report back.

pranavbhatt commented 4 months ago

@danielpalme

danielpalme commented 4 months ago

When you are using PublishCodeCoverageResults@1 please read these instructions: https://github.com/danielpalme/ReportGenerator/wiki/Integration#attention

By default the report gets regenerated by PublishCodeCoverageResults@1

pranavbhatt commented 4 months ago

I ran reportGenerator plugin first to convert the jacoco to cobertura Task

        - task: reportgenerator@5
          displayName: Jacoco Report Converter
          condition: succeeded()
          continueOnError: true
          inputs:
            reports: '$(Build.SourcesDirectory)/sources/dev/awareai-test-coverage-report/target/jacoco/jacoco.xml'
            targetdir: '$(Build.ArtifactStagingDirectory)/publish/coverage'
            sourceDirs: '$(Build.SourcesDirectory)/sources/dev'
            reporttypes: 'HtmlInline_AzurePipelines;Cobertura'

Debug Log

##[debug]   -license:
/usr/bin/dotnet /mnt/vss/_work/_tasks/reportgenerator_be803a55-9253-4895-a525-be570d86f161/5.2.5/tools/net6.0/ReportGenerator.dll -reports:/mnt/vss/_work/1/s/sources/dev/awareai-test-coverage-report/target/jacoco/jacoco.xml -targetdir:/mnt/vss/_work/1/a/publish/coverage -reporttypes:HtmlInline_AzurePipelines;Cobertura -sourcedirs:/mnt/vss/_work/1/s/sources/dev -historydir: -plugins: -assemblyfilters:+* -classfilters:+* -filefilters:+* -verbosity:Info -title: -tag:20240425.5+MAN_4521932-reportgen_#18509423 -license:
##[debug]Agent environment resources - Disk: / Available 190916.00 MB out of 253873.00 MB, Memory: Used 14064.00 MB out of 32094.00 MB, CPU: Usage 2.53%

...
2024-04-25T09:26:16: File 'ActComponentValueExtensionDao.java' does not exist (any more). <<< files not present 
2024-04-25T09:26:16: File 'ActConversationDaoJpa.java' does not exist (any more).

>>> continues for all files <<<
...
2024-04-25T09:26:25: Writing report file '/mnt/vss/_work/1/a/publish/coverage/Cobertura.xml'
2024-04-25T09:26:26: Writing report file '/mnt/vss/_work/1/a/publish/coverage/index.html'
2024-04-25T09:26:26: Report generation took 15.3 seconds
##[debug]Exit code 0 received from tool '/usr/bin/dotnet'
##[debug]STDIO streams have closed for tool '/usr/bin/dotnet'

Publish Task

        - task: PublishCodeCoverageResults@1
          displayName: 'Publish code coverage'
          continueOnError: true
          condition: succeeded()
          inputs:
            summaryFileLocation: '$(Build.ArtifactStagingDirectory)/publish/coverage/Cobertura.xml'
            pathToSources: '$(Build.SourcesDirectory)/sources/dev'
            reportDirectory: '$(Build.ArtifactStagingDirectory)/publish/coverage'
            codeCoverageTool: Cobertura
            failIfCoverageEmpty: true
          env:
            DISABLE_COVERAGE_AUTOGENERATE: 'true' # Local environment variable

Debug Log

##[debug]codeCoverageTool=Cobertura
##[debug]summaryFileLocation=/mnt/vss/_work/1/a/publish/coverage/Cobertura.xml
##[debug]reportDirectory=/mnt/vss/_work/1/a/publish/coverage
##[debug]additionalCodeCoverageFiles=undefined
##[debug]failIfCoverageEmpty=true
##[debug]System.DefaultWorkingDirectory=/mnt/vss/_work/1/s
##[debug]pathToSources=/mnt/vss/_work/1/s/sources/dev
##[debug]disable.coverage.autogenerate=true  <<<< auto generate disabled 
##[debug]disabling auto generation
pranavbhatt commented 4 months ago

I also tried directly using PublishCodeCoverageResults@1:

  1. with autogenerate disabled : produces a jacoco report, which is clickable but all html styling is stripped out.
  2. without autogenerate disabled: produces a cobertura report which is not clickable and has the message : File Doesn't exits. I will upload the screenshot in the folder for both cases.
danielpalme commented 4 months ago

Your setup seems correct. Are you sure, that the sourcedirs is correct: sourceDirs: '$(Build.SourcesDirectory)/sources/dev'?

Does (for example) the following file exist: /mnt/vss/_work/1/s/sources/dev/com/awareai/analytics/activepivot/ClientCubeManagerData.java?

I tried your conriguration on my machine and it works for me. I created a dummy file com/awareai/analytics/activepivot/ClientCubeManagerData.java and it was correctly read by ReportGenerator.

Regarding PublishCodeCoverageResults@1: With autogenerate disabled: This report looks like the default JaCoCo report

pranavbhatt commented 4 months ago
danielpalme commented 4 months ago

You'll need to supply a list of directories (separated by ;).

pranavbhatt commented 4 months ago

@danielpalme It worked after supplying a ; list of directories. It would be nice to have something like : sourceDirs: '$(Build.SourcesDirectory)/sources/dev/**/src/main/java'.

Some users have used this pattern, but i think it doesn't work.