SonarQube 7.5 that configured all tests rules and scanned with sonar scanners 3.2.0, but didn’t trigger S2699 rule

java
tests

(tianyuan) #1

My SonarQube 7.5 that configured all tests rules(including S2699)

sonar-project.properties file:
sonar.projectKey=org.sonarqube:sonarqube-scanner-test
sonar.projectName=sonarRuleTest
sonar.projectVersion=1.0
sonar.sources=src/main/java
sonar.tests=src/test/java
sonar.java.binaries=target
sonar.sourceEncoding=UTF-8
sonar.profile=sj_st_server

scan info:
INFO: Scanner configuration file: /usr/local/conf/sonar-scanner.properties

INFO: Project root configuration file: /Users/tianyuan/scm-purchase-app/scm-purchase-app-web/sonar-project.properties

INFO: SonarQube Scanner 3.2.0.1227

INFO: Java 1.8.0_121 Oracle Corporation (64-bit)

INFO: Mac OS X 10.12.3 x86_64

INFO: User cache: /Users/tianyuan/.sonar/cache

INFO: SonarQube server 7.5.0

INFO: Default locale: “zh_CN”, source code encoding: “UTF-8”

INFO: Publish mode

INFO: Load global settings

INFO: Load global settings (done) | time=84ms

INFO: Server id: BF41A1F2-AWhQlrQvTk3eHuOBjfLo

INFO: User cache: /Users/tianyuan/.sonar/cache

INFO: Load/download plugins

INFO: Load plugins index

INFO: Load plugins index (done) | time=49ms

INFO: Load/download plugins (done) | time=88ms

INFO: Loaded core extensions:

INFO: Process project properties

INFO: Execute project builders

INFO: Execute project builders (done) | time=3ms

INFO: Load project repositories

INFO: Load project repositories (done) | time=88ms

INFO: Load quality profiles

WARN: Ability to set quality profile from command line using ‘sonar.profile’ is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.

INFO: Load quality profiles (done) | time=40ms

INFO: Load active rules

INFO: Load active rules (done) | time=987ms

INFO: Load metrics repository

INFO: Load metrics repository (done) | time=19ms

INFO: Project key: org.sonarqube:sonarqube-scanner-test

INFO: Project base dir: /Users/tianyuan/scm-purchase-app/scm-purchase-app-web

INFO: ------------- Scan sonarRuleTest

INFO: Base dir: /Users/tianyuan/scm-purchase-app/scm-purchase-app-web

INFO: Working dir: /Users/tianyuan/scm-purchase-app/scm-purchase-app-web/.scannerwork

INFO: Source paths: src/main/java

INFO: Test paths: src/test/java

INFO: Source encoding: UTF-8, default locale: zh_CN

INFO: Index files

INFO: 224 files indexed

INFO: Quality profile for java: sj_st_server

INFO: Sensor JavaSquidSensor [java]

INFO: Configured Java source version (sonar.java.source): none

INFO: JavaClasspath initialization

WARN: Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property.

INFO: JavaClasspath initialization (done) | time=10ms

INFO: JavaTestClasspath initialization

WARN: Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property.

INFO: JavaTestClasspath initialization (done) | time=1ms

INFO: Java Main Files AST scan

INFO: 160 source files to be analyzed

INFO: 160/160 source files have been analyzed

INFO: Java Main Files AST scan (done) | time=9970ms

INFO: Java Test Files AST scan

INFO: 64 source files to be analyzed

INFO: Java Test Files AST scan (done) | time=1333ms

INFO: 64/64 source files have been analyzed

INFO: Sensor JavaSquidSensor [java] (done) | time=11829ms

INFO: Sensor JaCoCo XML Report Importer [jacoco]

INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=5ms

INFO: Sensor SurefireSensor [java]

INFO: parsing [/Users/tianyuan/scm-purchase-app/scm-purchase-app-web/target/surefire-reports]

INFO: Sensor SurefireSensor [java] (done) | time=202ms

INFO: Sensor JaCoCoSensor [java]

INFO: Sensor JaCoCoSensor [java] (done) | time=1ms

INFO: Sensor SonarJavaXmlFileSensor [java]

INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=2ms

INFO: Sensor Zero Coverage Sensor

INFO: Sensor Zero Coverage Sensor (done) | time=107ms

INFO: Sensor Java CPD Block Indexer

INFO: Sensor Java CPD Block Indexer (done) | time=264ms

INFO: SCM provider for this project is: git

INFO: 1 files to be analyzed

INFO: 0/1 files analyzed

WARN: Missing blame information for the following files:

WARN: * src/main/java/com/sankuai/sjst/scm/purchaseapp/service/impl/Junit4.java

WARN: This may lead to missing/broken features in SonarQube

INFO: 28 files had no CPD blocks

INFO: Calculating CPD for 132 files

INFO: CPD calculation finished

INFO: Analysis report generated in 401ms, dir size=3 MB

INFO: Analysis reports compressed in 501ms, zip size=1 MB

INFO: Analysis report uploaded in 33ms

INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=org.sonarqube%3Asonarqube-scanner-test

INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report

INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AWhUozNVTk3eHuOBjhyo

INFO: Task total time: 17.359 s

INFO: ------------------------------------------------------------------------

INFO: EXECUTION SUCCESS

INFO: ------------------------------------------------------------------------

INFO: Total time: 18.758s

INFO: Final Memory: 43M/1529M

INFO: ------------------------------------------------------------------------

after scan:


I found this Noncompliant code didn’t trigger S2699 rule

Anyone who can tell me why,Thanks


(Nicolas Peru) #2

In your log you can read :

This means that semantic analysis is very limited and thus most of the rules (and more specifically S2699) cannot properly work on method invocations.

You have to provide main and test classpath through properties : sonar.java.binaries sonar.java.libraries sonar.java.test.binaries sonar.java.test.libraries
as specified in https://docs.sonarqube.org/display/PLUG/Java+Plugin+and+Bytecode


(tianyuan) #3

It works,Thank you very much