Giter Site home page Giter Site logo

bazel-sonarqube's People

Contributors

adincebic avatar jjjhhhlll avatar zetten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bazel-sonarqube's Issues

got unexpected keyword arguments: test_srcs, test_targets, test_reports when execute "bazel run" command

Hi ,@Zetten.
Luckily to see your code, and it's very helpful for our current work. But as i`m a fresher on both sonarqube and bazel, so I got some errors when i referring to your features. Could you please help have a look ? thanks!
My command is:
bazel run //:sq -- -Dsonar.host.url=MY_URL -Dsonar.login=MY_ACCOUNT -Dsonar.password=MY_PASSWORD
Then got this error:

_ERROR: Traceback (most recent call last):
File "/opt/code/serp/bepcloudbazel/bepcloud/bepcloud-parent/bepcloud-common/BUILD", line 78, column 11, in
sq_project(
File "/root/.cache/bazel/bazel_root/b522ef4008cbaf1fbce240d7f801c5b6/external/bazel_sonarqube/defs.bzl", line 160, column 5, in sq_project
def sq_project(
Error: sq_project() got unexpected keyword arguments: test_srcs, test_targets, test_reports
ERROR: /opt/code/serp/bepcloudbazel/bepcloud/BUILD.bazel:28:10: Target '//bepcloud-parent/bepcloud-common:bepcloud_common_1_0_0_RELEASE' contains an error and its package is in error and referenced by '//:sq'
ERROR: Analysis of target '//:sq' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.324s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)

While my parent BUILD.bazel file is :

_package(default_visibility = ["//visibility:public"],)

filegroup(
name = "git",
srcs = glob(
[".git/"],
exclude = [".git/
/["], # gitk creates temp files with []
),
tags = ["manual"],
)

filegroup(
name = "coverage_report",
srcs = ["bazel-out/_coverage/_coverage_report.dat"], # Created manually
tags = ["manual"],
visibility = ["//visibility:public"],
)

filegroup(
name = "test_reports",
srcs = glob(["bazel-testlogs/**/test.xml"]), # Created manually
tags = ["manual"],
visibility = ["//visibility:public"],
)

load("@bazel_sonarqube//:defs.bzl", "sonarqube")

sonarqube(
name = "sq",
project_key = "bepcloud-common-bazel:common",
project_name = "bepcloud-common-bazel",
srcs = glob(["src/main/java/**/*.java"]),
targets = [
"//bepcloud-parent/bepcloud-common:bepcloud_common_1_0_0_RELEASE"
],
coverage_report = ":coverage_report",
scm_info = [":git"],
tags = ["manual"],
)_

My componet BUILD file is:

_load("@bazel_sonarqube//:defs.bzl", "sq_project")

sq_project(
name = "bepcloud-common-component",
project_key = "bepcloud-common:component",
project_name = "bepcloud-commom :: Component",
srcs = [
"src/main/java/**/*.java",
],
targets = [
"bepcloud_common_1_0_0_RELEASE",
],
test_srcs = ["src/test/java/com/huawei/bepcloud/validater/TestCompareValidater.java"],
test_targets = [
"TestCompareValidater.java",
],
test_reports = ["//:test_reports"],
tags = ["manual"],
visibility = ["//visibility:public"],
)_

Please help with Jenkins plugin. java.lang.OutOfMemoryError: Java heap space

Hi guys,

I have borrowed the Jenkinsfile code from here https://github.com/cgi-eoss/libeopp/blob/master/Jenkinsfile#L99

stage('sonarqube') { 
  withSonarQubeEnv() {    
    sh "bazel run //:sq -- -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN} -Dsonar.projectVersion=${kcpVersion}"
  }
  waitForQualityGate( abortPipeline: true )
}

And after analysis successfully completed it hanging about 2.5minutes and pipeline fails

java.lang.OutOfMemoryError: Java heap space
Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 6c3dceb8-cd03-4eb4-a5c5-583554eeae0f
Caused: java.io.IOException: Remote call on JNLP4-connect connection from 100.96.12.165/100.96.12.165:49872 failed
	at hudson.remoting.Channel.call(Channel.java:1004)
	at hudson.FilePath.act(FilePath.java:1192)
	at hudson.FilePath.act(FilePath.java:1181)
	at hudson.FilePath.list(FilePath.java:2131)
	at hudson.FilePath.list(FilePath.java:2114)
	at hudson.FilePath.list(FilePath.java:2098)
	at hudson.plugins.sonar.utils.SonarUtils.extractReportTask(SonarUtils.java:96)
	at hudson.plugins.sonar.utils.SonarUtils.addBuildInfoTo(SonarUtils.java:136)
	at hudson.plugins.sonar.SonarBuildWrapper$AddBuildInfo.tearDown(SonarBuildWrapper.java:230)
	at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Callback.finished(CoreWrapperStep.java:207)
	at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Execution2$Callback2.finished(CoreWrapperStep.java:150)
	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution$TailCall.lambda$onSuccess$0(GeneralNonBlockingStepExecution.java:140)
	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:77)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Finished: FAILURE

Sonar project dashboard is empty after using the bazel run command

Steps to reproduce

  1. Configure the bazel-sonar plugin in th WORKSPACE file
  2. Create the target
  3. generate the coverage.dat file from the target
  4. Use the command
    bazel run //:sonar_coverage -- -Dsonar.host.url=<host> -Dsonar.login=<token>
    Expected:
    Project created in sonar dashboard with analysis results
    Actual:
    Project is created but the analysis is empty

Breaks With Bazel 6.0.0

The CC_EXTENSIONS field under 'Constants' has been removed and when using Bazel 6.0.0 with the Bazel sonar extension, it fails with the missing field exception.

Along with CC_EXTENSIONS, Coverage.getOnlyTheseCcSources has been removed.

Since my project doesn't have any C++ projects and is only Java, I tried just removing all of this C++ code and that resulted in Sonar failing to parse the output file due to "Look at SonarQube documentation to know the expected XML format. ParseError at [row,col]:[1,1]". Not sure if it was something I did on my end or if something about the C++ code made this not happen before. I need to investigate further when I have some time.

Fail to generate coverage and cannot run a report without it.

Trying to follow the example project you mentioned in issue #1

WORKSPACE

http_archive(
    name = "bazel_sonarqube",
    sha256 = "336b9b9953257d927ba74ff9423f21b4d406be48dfcb7dc9ab21adedbc91709d",
    strip_prefix = "bazel-sonarqube-7b84f80f5d852cab94e8148cbf2255136078e466",
    urls = ["https://github.com/Zetten/bazel-sonarqube/archive/7b84f80f5d852cab94e8148cbf2255136078e466.zip"],
)

load("@bazel_sonarqube//:repositories.bzl", "bazel_sonarqube_repositories")

bazel_sonarqube_repositories()

Added the following ~/.bazelrc

coverage --collect_code_coverage
coverage --combined_report=lcov
coverage --coverage_report_generator=@bazel_sonarqube//:sonarqube_coverage_generator

running bazel coverage //... produces the following error

bazel_sonarqube/BUILD.bazel:16:1: declared output 'external/bazel_sonarqube/coverage.launcher' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely)

If I try to remove coverage_report from the sonarqube rule, I get the following error

object of type 'NoneType' has no field 'short_path'

It's probably worth mentioning that I get the same thing if targets is removed. However, I was able to set it to an empty list.

Sonarqube executable target do not dereference its runfiles symlinks.

Hi,

I cannot get the scm information uplodaed on the SonarQube server.
Simple code snippet using the bazel examples.

This is the BUILD file under the root directory, same location of the .git.

filegroup(
    name = "git",
    srcs = glob(
        [".git/**"],
        exclude = [".git/**/*[*"],  # gitk creates temp files with []
    ),
    visibility = ["//visibility:public"],
)

Following is instead the BUILD under the java-tutorial folder.

load("@rules_java//java:defs.bzl", "java_binary")

java_binary(
    name = "ProjectRunner",
    srcs = glob(["src/main/java/com/example/*.java"]),
)

load("@rules_java//java:defs.bzl", "java_test")

java_test(
    name = "ProjectRunnerTest",
    srcs = ["src/test/java/com/example/GreatingTest.java"],
    test_class = "com.example.GreatingTest",
    deps = [
        "//java-tutorial:ProjectRunner",
        
    ],
)

filegroup(
    name = "coverage_report",
    srcs = ["bazel-out/_coverage/_coverage_report.dat"], # Created manually
    tags = ["manual"],
    visibility = ["//visibility:public"],
)

load("@bazel_sonarqube//:defs.bzl", "sonarqube")

sonarqube(
    name = "sq",
    project_key = "com.example.project:project",
    project_name = "My Project",
    srcs = glob(["src/main/java/com/example/*.java"]),
    coverage_report = ":coverage_report",
    targets = [
        "//java-tutorial:ProjectRunner",
    ],
    scm_info = ["//:git"],
    tags = ["manual"],
    sq_properties_template = "example-prop_copy.tpl",
)

Sonarqube cannot read from the .git directory, scm files are not are not readable.

INFO: SCM Publisher SCM provider for this project is: git
INFO: SCM Publisher 2 source files to be analyzed
INFO: SCM Publisher 0/2 source files have been analyzed (done) | time=93ms
WARN: Missing blame information for the following files:
WARN: * java-tutorial/src/main/java/com/example/Greeting.java
WARN: * java-tutorial/src/main/java/com/example/ProjectRunner.java
WARN: This may lead to missing/broken features in SonarQube

More info.

INFO: Base dir: /root/.cache/bazel/_bazel_root/c094d1e8783f928ddd8321888260df40/execroot/main/bazel-out/k8-fastbuild/bin/java-tutorial/sq.runfiles/main

ls -la /root/.cache/bazel/_bazel_root/c094d1e8783f928ddd8321888260df40/execroot/main/bazel-out/k8-fastbuild/bin/java-tutorial/sq.runfiles/main
total 24
drwxr-xr-x 6 root root 4096 Nov 12 18:58 .
drwxr-xr-x 5 root root 4096 Nov 12 18:58 ..
drwxr-xr-x 7 root root 4096 Nov 12 18:45 .git
drwxr-xr-x 3 root root 4096 Nov 12 18:59 .scannerwork
drwxr-xr-x 4 root root 4096 Nov 12 18:10 external
drwxr-xr-x 4 root root 4096 Nov 12 18:58 java-tutorial

git blame java-tutorial/src/main/java/com/example/Greeting.java
fatal: no such path 'bazel-out/k8-fastbuild/bin/java-tutorial/sq.runfiles/main/java-tutorial/src/main/java/com/example/Greeting.java' in HEAD

The .git has broken links!!!

the correct one seem to be under /.cache/bazel/_bazel_root/c094d1e8783f928ddd8321888260df40/execroot/main

/.cache/bazel/_bazel_root/c094d1e8783f928ddd8321888260df40/execroot/main# git blame java-tutorial/src/main/java/com/example/Greeting.java
001bd290 (Serge Pomorski 2017-06-06 14:38:22 -0400 1) package com.example;
001bd290 (Serge Pomorski 2017-06-06 14:38:22 -0400 2)
7cfc2470 (Xùdōng Yáng 2020-05-12 20:33:50 +1000 3) public class Greeting {
00000000 (Not Committed Yet 2020-11-12 19:08:53 +0100 4) public static String sayHi() {
001bd290 (Serge Pomorski 2017-06-06 14:38:22 -0400 5) System.out.println("Hi!");
00000000 (Not Committed Yet 2020-11-12 19:08:53 +0100 6) return "Hi!";
001bd290 (Serge Pomorski 2017-06-06 14:38:22 -0400 7) }
001bd290 (Serge Pomorski 2017-06-06 14:38:22 -0400 8) }
001bd290 (Serge Pomorski 2017-06-06 14:38:22 -0400 9)

Can you suggest a work around/fix ?

Thanks.

Error on sonar qube report generation.

It is failing every time at

INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=7ms
INFO: Sensor Generic Coverage Report
INFO: Parsing /home/harora37/.cache/bazel/_bazel_harora37/4fbb135611fce4db8e7b78725d5f3b27/execroot/aid_templating_engine/bazel-out/_coverage/_coverage_report.dat
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 4.639s
INFO: Final Memory: 12M/68M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Error during parsing of the generic coverage report '/home/harora37/.cache/bazel/_bazel_harora37/4fbb135611fce4db8e7b78725d5f3b27/execroot/aid_templating_engine/bazel-out/_coverage/_coverage_report.dat'. Look at SonarQube documentation to know the expected XML format.
ERROR: Caused by: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

BUILD file

sonarqube(
    name = "sq",
    project_key = "//:engine",
    project_name = "Template Engine",
    srcs = [
#        "Hello.java",
        "engine",
    ],
    targets = [
        "//:engine",
    ],
    modules = {
#        "//path/to/component:sq_mycomponent": "path/to/component",
    },
    coverage_report = "//:coverage_report",
    scm_info = ["//:git"],
   )

and I am running sonarQube on docker. Some time I see XML on console but nothing comes to Sonar Qube web GUI

empty _coverage_report.dat generated when integrated with GO project

my project has all go sources.

so I added following new lines to my project space files.

VERSIONS

MACOS 10.15.7 CATALINA
Command> ./bazel version
Bazelisk version: v1.11.0
Bazelisk version: v1.11.0
WARNING: Running Bazel server needs to be killed, because the startup options are different.
Starting local Bazel server and connecting to it...
Build label: 5.1.1
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Apr 8 15:57:36 2022 (1649433456)
Build timestamp: 1649433456
Build timestamp as int: 1649433456

WORKSPACE

load("@bazel_sonarqube//:repositories.bzl", "bazel_sonarqube_repositories")
bazel_sonarqube_repositories()

load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
stardoc_repositories()

BUILD.bazel

load("@bazel_sonarqube//:defs.bzl", "sonarqube_coverage_generator_binary")
sonarqube_coverage_generator_binary()

#This re-exports the java_binary, to ensure it gets built with runfiles for the host configuration
   genrule(
   name = "sonarqube_coverage_generator",
   outs = ["coverage.launcher"],
   cmd = "ln -snf $(readlink $(location :SonarQubeCoverageGenerator)) $@",
   executable = 1,
   tags = ["no-cache"],  # successful execution even when --remote_cache is involved
   tools = [":SonarQubeCoverageGenerator"],
   visibility = ["//visibility:public"],
   )
   alias(
   name = "sonar_scanner",
   actual = "@org_sonarsource_scanner_cli_sonar_scanner_cli//:sonar_scanner",
   visibility = ["//visibility:public"],
   )
   filegroup(
   name = "git",
   srcs = glob(
   [".git/**"],
   exclude = [".git/**/*[*"],  # gitk creates temp files with []
   ),
   tags = ["manual"],
   )
   filegroup(
   name = "coverage_report",
   srcs = ["bazel-out/_coverage/_coverage_report.dat"],  # Created manually
   tags = ["manual"],
   visibility = ["//visibility:public"],
   )
   filegroup(
   name = "test_reports",
   srcs = glob(["bazel-testlogs/**/test.xml"]),  # Created manually
   tags = ["manual"],
   visibility = ["//visibility:public"],
   )
   load("@bazel_sonarqube//:defs.bzl", "sonarqube")
   sonarqube(
   name = "sonarqube",
   srcs = [],
   coverage_report = ":coverage_report",
   modules = {
   "//src/services/guava": "",
   },
   project_key = "Main_Project_Root_Key",
   project_name = "Main_Project_Root_Name",
   scm_info = [":git"],
   tags = ["manual"],
   targets = [],
   )

src/services/guava/BUILD.bazel

load("@bazel_sonarqube//:defs.bzl", "sq_project")
sq_project(
    name = "sq_subproject",
    srcs = ["//src/services/guava/server:server"],
    project_key = "Project_Root_dev",
    project_name = "guava",
    tags = ["manual"],
    targets = ["//src/services/guava/server:server"],
    test_reports = ["//:test_reports"],
    test_srcs = ["//src/services/guava/server:server_test"],
    test_targets = ["//src/services/guava/server:server_test"],
    visibility = ["//visibility:public"],
)

wkspc/deps/http.bzl

    "bazel_sonarqube": {
        "name": "bazel_sonarqube",
        "sha256": "b50d5faebc72fc1796ca010f0df795aa6943813e9770f0c0a2e950cf75bf3465",
        "strip_prefix": "bazel-sonarqube-37261de24f80b661bbc4726e3382ef43e9d66a6e",
        "urls": ["https://github.com/Zetten/bazel-sonarqube/archive/37261de24f80b661bbc4726e3382ef43e9d66a6e.zip"],
    },

After above changes I ran

bazel coverage --config=gocov //src/services/guava/... --collect_code_coverage   --combined_report=lcov   --coverage_report_generator=@bazel_sonarqube//:sonarqube_coverage_generator

output shows file has zero content.

INFO: Analyzed 33 targets (0 packages loaded, 0 targets configured).
INFO: Found 28 targets and 5 test targets...
INFO: LCOV coverage report is located at /private/var/tmp/_bazel_userme/e6e1d0cbd051dd43ed59dca5541f019d/execroot/product/bazel-out/_coverage/_coverage_report.dat
 and execpath is bazel-out/_coverage/_coverage_report.dat
INFO: Elapsed time: 2.539s, Critical Path: 2.10s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
cat /private/var/tmp/_bazel_userme/e6e1d0cbd051dd43ed59dca5541f019d/execroot/product/bazel-out/_coverage/_coverage_report.dat
# <<< Print nothing
ls -ltr 
-r-xr-xr-x  1 userme  wheel  0 Dec 21 20:54 /private/var/tmp/_bazel_userme/e6e1d0cbd051dd43ed59dca5541f019d/execroot/product/bazel-out/_coverage/_coverage_report.dat

any hint what I might be missing why is the lcov report empty and why is generator not generating report that sonarqube supports?

I can generate aggregate coverage report with below option

 bazel coverage --config=gocov //src/services/secrets/...

.bazelrc

coverage:gocov --collect_code_coverage --combined_report=lcov --coverage_report_generator="//src/cmd/gocoverage-lcov:gocoverage-lcov"

output shows file has size but is not in sq format. unfortunately

-r-xr-xr-x  1 userme  wheel  6992 Dec 21 21:19 bazel-out/_coverage/_coverage_report.dat

FindBugs sensor expecting classes folder and not the output jar

Hi @Zetten

I am testing this plugin on a Java codebase against a SonarQube server with the FindBugs sensor enabled in its Quality Profile. When I run the scanner in my project I end up seeing this error:

INFO: Sensor FindBugs Sensor [findbugs]
WARN: Findbugs needs sources to be compiled. Please build project before executing sonar or check the location of compiled classes to make it possible for Findbugs to analyse your (sub)project (/private/var/tmp/_bazel_fcandalija/0d91d8aee3d7bf9d86d406d9d8f9627c/<path to my project>).
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 25.609s
INFO: Final Memory: 49M/188M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Can not execute Findbugs
ERROR: Caused by: One (sub)project contains Java source files that are not compiled (/private/var/tmp/_bazel_fcandalija/0d91d8aee3d7bf9d86d406d9d8f9627c/<path to my project>).
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

It looks like the error happens because the FindBugs sensor is expecting the sonar.java.binaries property to be pointing to the directory containing all the *.class files, instead of to the output jar file, which is what the code is currently doing:

"{JAVA_BINARIES}": ",".join([parent_path + j.short_path for j in java_files["output_jars"].to_list()]),

Indeed, the Sonar documentation defines sonar.java.binaries as:

Screen Shot 2021-01-21 at 9 19 49 AM

Any idea how could we access the *.class files directory to see if this error is fixed? I checked on the JavaInfo provider and there's nothing in the outputs. I am quite new with Bazel and still not sure how this could be achieved.

Thanks for the plugin and the help!

NodeJS location

Since Bazel is able to download its own dependencies, including JDK & NodeJS, would it be possible to automatically use the Node.JS downloaded by Bazel (when provided through the Node rules) ?

Currently having issues with no node found :

INFO: Sensor SonarTS [typescript]
ERROR: Failed to get Node.js version.No TypeScript files will be analyzed. You can exclude TypeScript files from analysis with 'sonar.exclusions' property.
java.io.IOException: Cannot run program "node": error=2, No such file or directory

The workaround defining sonar.nodejs.executable manually linked to the node install downloaded by Bazel doesn't appear to work either.

Bazel 7.1.1 and intermittent class not found

Hi,

We experienced random errors when using

$BAZEL_BIN coverage --build_tests_only --combined_report=lcov --coverage_report_generator=@bazel_sonarqube//:sonarqube_coverage_generator --strategy=CoverageReport=local,remote

(15:09:42) ERROR: : Coverage report generation failed: (Exit 1): coverage.launcher failed: error executing CoverageReport command
(cd /home/runner/.cache/bazel/_bazel_runner/bccdf71c163d013389bc1939108453cd/execroot/_main &&
exec env -
bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/bazel_sonarqube/coverage.launcher '--reports_file=bazel-out/_coverage/lcov_files.tmp' '--output_file=bazel-out/_coverage/_coverage_report.dat')

Configuration: system
Error: Could not find or load main class com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator
Caused by: java.lang.ClassNotFoundException: com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator

We changed to use :SonarQubeCoverageGenerator instead and that seems a lot more stable. Any idea why?

Split modules into full projects into SQ

Would it be possible to have a parameter requesting the creation of a sonarqube project per module, rather than an aggregation into a single project ? (and/or a mixed mode ... kinda a MERGED, MIXED, SPLIT flag ?)

Thanks !

Coverage numbers are coming as 0 in sonarqube

Hello, This isssue is started coming recently where my coverage report is getting generated properly with following command however after running "bazel run //:sonar-target" the coverage numbers are coming as 0 for every module.

Command:

bazel coverage <module-name>...

my bazelrc file

coverage --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
coverage --collect_code_coverage
coverage --combined_report=lcov
coverage --coverage_report_generator=//tools/bazel/sonarqube:sonarqube_coverage_generator
coverage --experimental_fetch_all_coverage_outputs
coverage --experimental_strict_java_deps=off
coverage --cache_test_results=yes
coverage --test_output=summary
coverage --build_runfile_links

Report is getting generated at location "bazel-out/_coverage/_coverage_report.dat" with following content. (Pasted some random lines here)

        <lineToCover lineNumber="19" covered="true"/>
        <lineToCover lineNumber="21" covered="true"/>
        <lineToCover lineNumber="38" covered="true" branchesToCover="2" coveredBranches="1"/>
        <lineToCover lineNumber="39" covered="false"/>
        <lineToCover lineNumber="41" covered="true"/>
        <lineToCover lineNumber="42" covered="true"/>
        <lineToCover lineNumber="44" covered="true" branchesToCover="2" coveredBranches="1"/>
        <lineToCover lineNumber="45" covered="false"/>
        <lineToCover lineNumber="46" covered="false"/>
        <lineToCover lineNumber="49" covered="true"/>
        <lineToCover lineNumber="50" covered="true" branchesToCover="2" coveredBranches="1"/>
        <lineToCover lineNumber="51" covered="true" branchesToCover="2" coveredBranches="1"/>
        <lineToCover lineNumber="52" covered="false"/>

Any idea where should i look into ?

Issues while creating test coverage report

when i try to run the command to generate test coverage
bazel test //... --collect_code_coverage \ --combined_report=lcov \ --coverage_report_generator=@bazel_sonarqube//:sonarqube_coverage_generator

It fails with the following error,

Aug 19, 2020 2:10:50 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator getGcovInfoFiles
INFO: No gcov info file found.
Aug 19, 2020 2:10:50 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator getProfdataFileOrNull
INFO: No .profdata file found.
Aug 19, 2020 2:10:50 PM com.google.devtools.coverageoutputgenerator.SonarQubeCoverageGenerator main
WARNING: There was no coverage found.
ERROR: output '_coverage/_coverage_report.dat' was not created
ERROR: not all outputs were created or valid
FAILED: Build did NOT complete successfully
//11-commons-test:CategoryTimeoutRuleTest PASSED in 3.5s
//11-commons-test:ConcurrentTest PASSED in 2.5s
//11-commons-test:ExtendsCategoryEnforcerTest PASSED in 2.3s
//11-commons-test:FakeClockTest PASSED in 3.2s
//11-commons-test:OwnerMetadataTest PASSED in 2.6s
//11-commons-test:ScmSecretTest PASSED in 3.1s

Executed 6 out of 6 tests: 6 tests pass.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.
All tests passed but there were other errors during the build.
FAILED: Build did NOT complete successfully

Dereferencing Bazel Runfile Symlinks 'invalid command code' error

When executing the run step, this results in no blame history being found by the sonar analyzer.

At the the start of the run step a see many of these sed errors:

Dereferencing bazel runfiles symlinks for accurate SCM resolution...
sed: 1: "./git/[path] ...": invalid command code .

I am running this on a Mac OSX with bazel running as sudo. Is there something I am missing and/or have configured incorrectly?

P.S. really appreciate this project, it unlocked the door for me to justify exploring Bazel for my organization :)

Sonarqube does not show unit tests but shows unit tests coverage

When I run the sonarqube analysis on my java project, It generates the unit tests coverage but the Unit tests section is empty on sonarqube.

Test coverage is generated from the coverage report which was the result of following command
bazel test //... --collect_code_coverage --combined_report=lcov --coverage_report_generator=@bazel_sonarqube//:sonarqube_coverage_generator

Gen rule for re-exporting java_binary does not work with "worker" spawn_strategy

I am using following strategies in my .bazelrc file

common --spawn_strategy=remote,worker,local

however the gen rule than does not produce a valid output:

ERROR: /Users/adin.cebic/developer/myProject/BUILD.bazel:10:8: declared output 'coverage.launcher' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely)
ERROR: /Users/adin.cebic/developer/myProject/BUILD.bazel:10:8: Executing genrule //:sonarqube_coverage_generator [for tool] failed: not all outputs were created or valid

If I modify my .bazelrc file to use "sandboxed" instead of "worker" strategy, than it works fine.

what feature it provide?

seems to me I can build with bazel and just use sonar.java.binaries=target/classes to make it work with sonar-scanner. What is the reason to have this plugin?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.