将Go源代码和覆盖率导入SonarQube

huangapple go评论81阅读模式
英文:

Importing Go source and coverage into SonarQube

问题

我有一个Go项目,我想使用SonarRunner将其导入到SonarQube 5.1中。

我知道Go不是SonarQube支持的语言之一,所以我设置了属性

sonar.import_unknown_files=true

以实现一些基本级别的导入-它完成了工作。该项目还使用Cobertura格式生成了代码覆盖率,使用了https://github.com/axw/gocov/和https://github.com/AlekSi/gocov-xml。

我尝试使用以下设置导入XML,但没有成功:

sonar.core.codeCoveragePlugin=cobertura
sonar.cobertura.reportPath=coverage.xml

因此,该项目在Sonar仪表板上显示为灰色框。是否有人做过类似的事情并使其工作?这是因为Go是不受支持的语言吗?

非常感谢!

Andy

英文:

I have a Go project that I would like to import into SonarQube 5.1, using SonarRunner.

I know it's not one of SonarQube's supported languages so I have set the property

sonar.import_unknown_files=true

to accomplish some basic level of import - and it does the job. The project also has code coverage in Cobertura format, generated using https://github.com/axw/gocov/ and https://github.com/AlekSi/gocov-xml.

I have not been successful in getting this XML to import with settings:

sonar.core.codeCoveragePlugin=cobertura
sonar.cobertura.reportPath=coverage.xml

Hence the project appears as a gray box on the Sonar dashboard. Has anyone done something similar and got it working? Is it because Go is an unsupported language?

Many thanks!

Andy

答案1

得分: 1

自从2019年7月的SonarQube 7.9版本开始,Go语言正式得到支持。这包括了Go的代码覆盖率。而且它在社区版中也得到了支持!

自从SonarQube 6.7版本起就有了40条针对Go的规则

但是,遗留的SonarSource/sonar-go,即SonarQube的Go分析器,现在已经成为SonarQube LTS的一部分,即SonarSource/slang(SonarSource语言)。这是一个用于快速开发SonarQube代码分析器的框架。请参见MMF-1670(将Go迁移到SLANG)。

> SonarGo依赖于在统一语言编写语言解析器的构思阶段早期开发的UAST技术,这后来导致了SLANG的创建。
>
>为了统一我们使用的技术,减少维护成本,并从更多功能中受益,我们需要将当前的SonarGO实现迁移到仅依赖于SLANG框架的GO插件

请参见其Go代码覆盖率SLang问题,特别是:SONARSLANG-399

sonarqube {
  properties {
    property 'sonar.sources', '.'
    property 'sonar.exclusions', '**/*_test.go,**/generate_source.go,**/*_generated.go,**/build/**,**/.gogradle/**'
    property 'sonar.tests', '.'
    property 'sonar.test.inclusions', '**/*_test.go'
    property 'sonar.test.exclusions', '**/build/**,**/.gogradle/**'
    property 'sonar.go.tests.reportPaths', "${project.projectDir}/.gogradle/reports/test-report.out"
    property 'sonar.go.coverage.reportPaths', "${project.projectDir}/.gogradle/reports/coverage/profiles/github.com%2FSonarSource%2Fsonar-go%2Fuast-generator-go.out"
  }
}

SONARSLANG-408("[Go]导入Go覆盖报告")目前仍在进行中。(但在撰写本文时只有4小时的时间)

英文:

Since SonarQube 7.9 (July 2019), the go language is officially supported.
That includes code coverage for Go.
And it is supported in the community edition!

40 rules for Go were present since SonarQube 6.7 .

But the legacy SonarSource/sonar-go, the Go Analyzer for SonarQube, is now SonarQube LTS) par of SonarSource/slang (SonarSource Language), which is a framework to quickly develop code analyzers for SonarQube.
See MMF-1670 (Migrate Go to SLANG)

> SonarGo is relying on the UAST technology developed early in the ideation phase of an unified language to write language parsers, which later led to the creation of SLANG.
>
>In order to unify the technologies we use, reduce the maintain cost, and benefit from more features, we need to migrate the current SonarGO implementation to a GO plugin relying solely on the SLANG framework.

See its Go code coverage SLang issues, in particular: SONARSLANG-399

sonarqube {
  properties {
    property 'sonar.sources', '.'
    property 'sonar.exclusions', '**/*_test.go,**/generate_source.go,**/*_generated.go,**/build/**,**/.gogradle/**'
    property 'sonar.tests', '.'
    property 'sonar.test.inclusions', '**/*_test.go'
    property 'sonar.test.exclusions', '**/build/**,**/.gogradle/**'
    property 'sonar.go.tests.reportPaths', "${project.projectDir}/.gogradle/reports/test-report.out"
    property 'sonar.go.coverage.reportPaths', "${project.projectDir}/.gogradle/reports/coverage/profiles/github.com%2FSonarSource%2Fsonar-go%2Fuast-generator-go.out"
  }
}

SONARSLANG-408 ("[Go] Import Go Cover report") is still in progress though.
(But is only 4 hours old, at the time of writing)

答案2

得分: 0

是的,据我所知,SonarQube Cobertura插件只允许导入Java(以及可能支持的基于JVM的语言)的覆盖率报告。

然而,如果你愿意对覆盖率结果文件进行一些转换,Generic Test Coverage插件可能适合你的需求。

英文:

Yes, to my knowledge the SonarQube Cobertura plugin only allows to import coverage reports for Java (and maybe supported JVM based languages).

However, if you are willing to do some transformation on your coverage result file, the Generic Test Coverage plugin might suit your needs.

huangapple
  • 本文由 发表于 2015年6月3日 04:40:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/30606175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定