Sonar tests and binaries properties, what do they do? - ant

In Sonar documentation there are two properties options, the sonar.tests and sonar.binaries.
# path to test source directories (optional)
sonar.tests=testDir1,testDir2
# path to project binaries (optional), for example directory of Java bytecode
sonar.binaries=binDir
Questions:
If sonar.tests and sonar.binaries are added to my Ant target, how do they show up in Sonar? What would be different in Sonar if I did/did not set these properties?
Should sonar.binaries contain both source binaries and test binaries, or only source?
Can .jar files be given to both properties instead of path to actual .class files and/or .java files?

Answers:
If you do not set those 2 properties, you won't have test results ("sonar.tests") nor violations detected by Findbugs or bytecode-based tools ("sonar.binaries").
"sonar.binaries" should contain only compiled sources, not tests
No. Only "sonar.libraries" can (and actually must) point to JAR files.

Related

How can I tell Which bazel aspect outputs are still relevant

As part of our efforts to create a bazel-maven transition interop tool (that creates maven sized jars from more granular sized bazel jars),
we have written an aspect that runs on bazel build of the entire bazel repo and writes important information to txt files outputs (e.g.: jar file paths, compile deps targets and runtime deps targets, etc.)
We ran across an issue where the repo's code was changed such that some of the txt file were not written anymore. But the old txt file from previous runs (before the code change) remained!
Is there a way to know that these txt files are no longer relevant?
You should be able to run with --build_event_json_file=file.json and try to locate generated artifacts. For example we use it on ci.bazel.io to locate actual test.xml file that were generated: https://github.com/bazelbuild/continuous-integration/blob/09975cbb487a84a62ca1e43aa43e7c6fe078f058/jenkins/lib/src/build/bazel/ci/BazelUtils.groovy#L218
The definition of the protocol can be found in build_event_stream.proto

Excluding contents of a folder anywhere in directory tree from analysis in Sonar

I have a ASP.net project that i need to run SonarQube analysis on and i have configured it with Jenkins to run the analysis. The analysis is running fine but it is including the bower_components and node_modules i have in the project. The way the project is structured there are multiple node_modules and bower_component folders in the projects folder structure. So i need to exclude them all in a pattern. I have added a SonarQubeSetting section to the .csproj file and i have the current values for exclusion.
<Target Name="BeforeBuild">
<ItemGroup>
<SonarQubeSetting Include="sonar.exclusions">
<Value>**\main-built.js,**\template-build.js,**\kendo*.js,**\bower_components\*,**\node_modules\*</Value>
</SonarQubeSetting>
</ItemGroup>
</Target>
Using **\bower_components\* **\node_modules\* did not work and the libraries are still picked up and scanned. How can i exclude folder (in my case node_modules & bower_components) content regardless of its location in the directory structure in sonar?
The last time I setup Sonar, I am pretty sure the sonar.exclusion property worked as expected... Perhaps your naming pattern is a little off. For example, how about a ** at the end rather than *. See this answer for examples and answers when using naming patterns.

Passing source and binaries directories to Sonar

I am setting up Sonar through Jenkins Sonar plugin and I have a couple of questions about the way Sonar interprets the directories I give it.
sources=srcDir1,srcDir2 : from what I understand this is where I pass source dir of my project. My project is actually a multiproject with many source dirs inside. Is it okay to give Sonar the root path to the project and Sonar will know to go deep and find each projects .java files ? Or do I have to give it each one of the source dirs ? Also if I have src/com/mycompany/myproj/... package structure do I have to give it the end path, or the src path is sufficient ?
binaries=binDir : Here I should give Sonar the path to the compiled .class code or the packed .jar / .war / .ear files so Findbugs will work. Same question here: I don't have a central place with all the compiled classes, so do I have to specify each one of the paths ?
The Sonar ANT task contains a section on how to configure Sonar to analysis a multi-module build:
http://docs.codehaus.org/display/SONAR/Analyzing+with+Ant+Task

Disable incremental compilation in javac Ant task

I need to easily test my annotation processors, so I prepared Ant script to launch javac with all the necessary options set. Unfortuantely, as stated in another thread:
By default the task compares the timestamps of .java and
corresponding .class files, and only tells the Java compiler to
recompile source files that are newer than their corresponding object
files, or that don't have an object file at all.
It's great for me most of the times but not when I need to test my annotation processor for which I need javac to be launched each time, no matter if corresponding .class file already exist.
Is there any way to disable this ant default behaviour? I looked through all options of javac task but found nothing. Is there any solution other then cleaning output directory?
Based on your quote if you delete the .class files, the compiler will be forced to recompile the .java file

TeamBuild, Code Coverage & testrun config files

I have team build script for CI and nightly builds, both of which runs unit tests with code coverage. I have specified the testrun config file and this include paths for the assemblies to instrument.
My problem is, the paths for the assemblies is absolute, eg:
<CodeCoverageItem
binaryFile="C:\build\Product\PROJECT\Integration\Binaries\Debug\BlahBlah.Cache.dll"
pdbFile="C:\build\Product\PROJECT\Integration\Binaries\Debug\BlahBlah.Cache.pdb"
instrumentInPlace="true" />
I would rather these used relative paths or I could specify $(OutDir) in there.
Has anyone solved this?
Thanks
Yes, you should be able to use relative paths - paths that are relative to the LocalTestRun.testrunconfig file (which is typically stored in the same folder as the solution file).

Resources