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

Error while converting jacoco report to cobertura #665

Closed
pranavbhatt opened this issue Apr 23, 2024 · 12 comments
Closed

Error while converting jacoco report to cobertura #665

pranavbhatt opened this issue Apr 23, 2024 · 12 comments
Labels

Comments

@pranavbhatt
Copy link

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
Copy link
Owner

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

@pranavbhatt
Copy link
Author

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

@danielpalme
Copy link
Owner

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
Copy link
Author

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

@pranavbhatt
Copy link
Author

pranavbhatt commented Apr 25, 2024

@danielpalme

  • I was able to make it work by deleting the duplicate file, and after reading other issues I used PublishCodeCoverageResults@1 to generate the report. I am able to see the coverage in the Code Coverage Tab.
  • However, when I click on the individual classes i see the following message: File 'SomeFile.java' does not exist (any more)., I inspected the jacoco index.html by downloading it on my localmachine and I am able to browse individual files from jacoco html. Is it because pathToSources is not setup properly ?
  • I have uploaded some html screenshots for you to review, in the folder which I shared before.

@danielpalme
Copy link
Owner

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
Copy link
Author

pranavbhatt commented Apr 25, 2024

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
Copy link
Author

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
Copy link
Owner

danielpalme commented Apr 25, 2024

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
Copy link
Author

  • sourceDirs is pointing to top level directory .. but since it is a multi module java project there are atleast 13 other modules
  • is there a way we can use a pattern match * so that directories within the top level dir could be searched for the file, or do we need to give a comma separated list of all java source file directories?

@danielpalme
Copy link
Owner

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

@pranavbhatt
Copy link
Author

pranavbhatt commented Apr 26, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants