How to use Sonar Runner on selected files? - sonarqube

I want to run Sonar Runner only on some selected files only. I'm using SonarRunner Ant.
My project directory structure is :
MyProject
|
|-----src
|-----java
|-----A
|-----B
| |---<files>.java
|
|-----C
| |---<files>.java
|
|-----hello.java
Now I want to run Sonar Runner only on hello.java file.
sonar.sources=../../../MyProject/src // takes the source directory
sonar.sources=../../../MyProject/src/java/A/hello.java didn't work
sonar.exclusions=**/**/*.java // excludes all java files
// now I want to include only hello.java file
// didn't find any parameter for inclusion, but tried the following
sonar.inclusions=hello.java // didn't work
sonar.inclusions=java/A/hello.java // didn't work
Referred this article for analysis parameters.
One solution which crossed my mind is : exclusion of all the files but the required ones.
But here the structure is just a small part. In real I have more than 250 java files, and want to generate report for, say, 10 files only. Then, by this approach, excluding 240+ files doesn't look a good idea.
Is there anyway to generate sonar report on selected files, other than the mentioned approach?

If you're looking for specific files, you might try the same syntax as is listed to explicitly exclude files (Narrowing the Focus - at the bottom)
#Absolute Path
To define an absolute path, start the pattern with "file:"
#Exclude all the *.cs files included in /path_to_my_project/myProject/src/generated and its subdirectories
sonar.exclusions=file:/path_to_my_project/myProject/src/generated/**/*.cs
#Exclude all the java classes contained in a src/generated/java directory and its subdirectories
sonar.exclusions=file:**/src/generated/java/**/*.java

Related

Excluding specific set of files from lint issue report

I am using gometalinterv2 in my Go project for linting. After the lint report is generated, the report file is linked to sonarqube for analysis and presentation.
I want to exclude some files like *_test.go from linting. I know there is a --exclude flag for gometalinterv2 to exclude folders. But since _test.go files are in the same folder/package as the source code, this won't work.
So is there any way to achieve this (either at linting stage or in sonar properties file)?
Add config file .gometalinter.json to the root of your project and specify rules for excluding:
{
"exclude": [
".*_test.go",
"/any/folder/"
]
}
I found another way after I marked #bayrinet's answer. The files (not just folders) to be excluded can also be passed to the command using the exclude flag like below -
>gometalinter.v2 ./... --exclude=somefolder --exclude=.*_test.go

Checkstyle and Maven's Standard Directory Layout

I'm following Maven's Standard Directory Layout for my project.
Is there a preferred directory to put my checkstyle.xml file? I've seen it on at least 3 possible locations:
src/main/resources/checkstyle.xml
src/main/checkstyle/checkstyle.xml - Example: Joda-Time
src/checkstyle/checkstyle.xml - Example: Spring Boot
Since this is mostly a file for developers, the first option gives me doubts. Would it make sense to include checkstyle.xml into the JAR file?
Thanks,
Fede
Putting checkstyle.xml in src directory doesn't really make sense, as it is not part of source code.
The most common convention I've observed in my projects is putting it into config/checkstyle/checkstyle.xml. Thousands of projects use it (filename:checkstyle.xml path:config/checkstyle) and Gradle uses this location by default.

grunt/compass exclude files from compiling

I'm currently developing a magento theme. I'm using grunt-compass and grunt-watch to compile my scss files. I would like to speed up the process with excluding styles-IE8.scss for compiling (because it's not used in developing environment).
I could (of course) rename to _styles-IE8.scss and rename it back for production, but isn't there a better way to define which files to compile and which not?
If you are using grunt-contrib-compass, in your Gruntfile.js you can use the specify option to exclude files.
Lets you specify which files you want to compile. Useful if you don't want to compile the whole folder. Globbing supported. Ignores filenames starting with underscore. Paths are relative to the Gruntfile.
ex:
compass: {
options: {
specify: "!/path/to/styles-IE8.scss"
}
}
Then, depending on the environment you can set specify dynamically.

Flattening TeamCity artefacts folder structure

I have a TeamCity (9.0.2) build configuration which contains the following artefact path pattern:
App\Agent\**\bin\%env.Configuration%\** => Deployment\AgentBuildPackage.%env.ApplicationVersion.EMX%.%system.build.number%.zip
which will create a file named something like AgentBuildPackage.4.5.0.185.zip in an artefact folder named Deployment
The current structure is like this:
Deployment/
AgentBuildPackage.4.5.0.185.zip/
MyFirstServiceFolder/
bin/
Debug|Release/
All the Files
The artefact archive contains all the folders it finds under App\Agent which is great. What I can't figure out is how to flatten those individual folders so they no longer contain the /bin/Release sub-folders.
What I want is
Deployment/
AgentBuildPackage.4.5.0.185.zip/
MyFirstServiceFolder/
All the Files
Can anyone tell me how please?
You can specify target folders within your target archive by using the ! character after the name of the .zip file. Like this:
folderA\** => output.zip!/afolder/
Depending on how many service folders you have, this could be quite verbose, as you'll need to do it for each one, but it should do what you've described:
App\Agent\MyFirstServiceFolder\bin\%env.Configuration%\** => Deployment\AgentBuildPackage.%env.ApplicationVersion.EMX%.%system.build.number%.zip!/MyFirstServiceFolder/
Here's the documentation page on specifying artifact paths if you haven't seen it yet: https://confluence.jetbrains.com/display/TCD9/Configuring+General+Settings#ConfiguringGeneralSettings-PathsPatterns

Sonar project-properties file

I am using OCLint on an Objective C project to obtain a SonarQube profile.
Now my IOS Objective C project contains a src directory with multiple sub src directories. In my sonar-project.properties file there is a following entry
sonar.sources=MySrcFolder/
Now within this src folder i want to run the sonar profile on multiple subfolders and exclude some third party src folders. Can anyone help me with this ? As it stands now, sonar runs the profile on all src in any of the above folders subfolders ?
You can do it only with sonar.sources property or with the sonar.exclusions and sonar.inclusions properties.
Example:
MySrcFolder
src1
src2
src3
src4
If you want to analyze only src1 and src3 then,
1) sonar.sources=MySrcFolder/src1,MySrcFolder/src3
OR
2)
sonar.sources=MySrcFolder
sonar.exclusions=src2/**,src4/**
OR
3)
sonar.sources=MySrcFolder
sonar.inclusions=src1/**,src3/**
Following rules are applied in the exclusions and inclusions properties:
* Match zero or more characters
** Match zero or more directories
? Match a single character
file: Prefix to define a pattern based on absolute path
For more details: http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus
Add below lines to sonar-scanner-v.x.x/conf/sonar-scanner.properties file. Use
Comma-separated paths to analysis multiple modules or projects.
sonar.sources= mainDir/subDir/src, mainDir/subDir/subDir/src,...
Or
Set base directory with **sonar.projectBaseDir** param.
Thanks to the param, you can give relative path to sonar.sources's params.
Then
Run sonar-scanner.bat file in mainDir or root in directory of above sources.

Resources