Backelite / sonar-objective-c

Sonar Plugin for Objective-C
197 stars 76 forks source link

Exception during unit test xml parse: Can not add the same measure twice on key=skipped_tests #33

Open orj opened 7 years ago

orj commented 7 years ago
18:43:22.967 ERROR: Error during SonarQube Scanner execution
org.sonar.api.utils.XmlParserException: Can not parse surefire reports
    at org.sonar.plugins.objectivec.tests.SurefireParser.parseFiles(SurefireParser.java:137)
    at org.sonar.plugins.objectivec.tests.SurefireParser.collect(SurefireParser.java:78)
    at org.sonar.plugins.objectivec.tests.SurefireSensor.collect(SurefireSensor.java:86)
    at org.sonar.plugins.objectivec.tests.SurefireSensor.analyse(SurefireSensor.java:80)
    at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:57)
    at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:49)
    at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:175)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:262)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:257)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:247)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
    at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:143)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:128)
    at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:118)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:117)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
    at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
    at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.UnsupportedOperationException: Can not add the same measure twice on [key=next]: DefaultMeasure[component=<null>,metric=Metric[id=<null>,key=skipped_tests,description=<null>,type=INT,direction=0,domain=<null>,name=skipped_tests,qualitative=false,userManaged=false,enabled=true,worstValue=<null>,bestValue=<null>,optimizedBestValue=false,hidden=false,deleteHistoricalData=false,decimalScale=<null>],value=0,fromCore=false]
    at org.sonar.scanner.sensor.DefaultSensorStorage.saveMeasure(DefaultSensorStorage.java:263)
    at org.sonar.scanner.index.DefaultIndex.addMeasure(DefaultIndex.java:155)
    at org.sonar.scanner.deprecated.DeprecatedSensorContext.saveMeasure(DeprecatedSensorContext.java:126)
    at org.sonar.scanner.deprecated.DeprecatedSensorContext.saveMeasure(DeprecatedSensorContext.java:120)
    at org.sonar.plugins.objectivec.tests.SurefireParser.saveClassMeasure(SurefireParser.java:167)
    at org.sonar.plugins.objectivec.tests.SurefireParser.parseFiles(SurefireParser.java:119)
    ... 32 more
18:43:22.968 DEBUG: Execution getVersion
18:43:22.969 DEBUG: Execution stop
MaximeArnstamm commented 7 years ago

I have the same problem. It happens when sonar tries to read TEST-report.xml. The same file read with the swift plugin doesn't break. There's a slight difference between the 2 versions of the SurefireParser.. Maybe it's linked somehow ?

MaximeArnstamm commented 7 years ago

Ok, i just tried replacing the SurefireParser from the Objc project with the one from the Swift project and it seems to work ok. As i didn't take the time to understand the underlying of it, i'm not going to create a pull request, but it did solve this particular problem.

orj commented 7 years ago

We've been trying to track down the issues. It appears to be that the plugin makes some assumptions about file names. Ie, doesn't support .mm test filenames and also assumes all underscores in suite names are replaced with + symbols in filenames.

This means that getUnitTestResource can return null and on the second occurrence of this Sonar's saveMeasure method throws.

My compatriot @cuva is looking into it further and we hope to provide back a pull request that works around some of these issues.

cuva commented 7 years ago

@MaximeArnstamm #34 should fix the issues mentioned above and a few more!

zippy1978 commented 6 years ago

Hi,

It should be ok with plugin version 0.6.2.

Let me know.

Gilles.