当前位置: 首页 > 知识库问答 >
问题:

SonarQube 5.2-针对自定义Java规则未锁定的问题

陈宜修
2023-03-14

使用SonarQube 5.2和Sonar Java插件3.8,并使用Sonar Runner 2.4进行分析。

插件和java自定义示例从git下载(https://github.com/SonarSource/sonar-examples/tree/master/plugins/java-custom-rules),在服务器上构建和部署,并且规则在服务器上可见。规则是在“Sonar Way”配置文件(默认)下使用web激活的。还将创建一个新的测试概要文件,并向其中添加规则“在方法名称中避免品牌”,并将一个项目与之关联。

在分析来自(/src/test/file)的示例java代码时,所有默认java规则的问题都被锁定在服务器上,但没有锁定自定义规则的问题。日志中也没有显式错误。

声纳赛跑者。性质

sonar.host.url=http://localhost:9000
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar52?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=root
sonar.jdbc.password=ChangeIt
sonar.projectKey=TestSonarCustomRules
sonar.projectName=TestSonarCustomRules
sonar.projectVersion=1.0
sonar.sources=E:/Sonar Example/sonar-examples-master/plugins/java-custom-rules/src/test/files/

以下是分析日志:

E:\sonar-runner-2.4
SonarQube Runner 2.4 
Java 1.8.0_45 Oracle Corporation (64-bit) 
Windows 7 6.1 amd64 
INFO: Runner configuration file: E:\sonar-runner-2.4\conf\sonar-runner.properties 
INFO: Project configuration file: NONE 
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent) 
INFO: Work directory: E:\Sonar Example\sonar-examples-master\plugins\java-custom-rules\src\test\files\.\.sonar 
INFO: SonarQube Server 5.2 
18:56:49.391 INFO  - Load global repositories 
18:56:49.539 INFO  - Load global repositories (done) | time=145ms 
18:56:49.557 WARN  - Property 'sonar.jdbc.url' is not supported any more. There is no more DB connection to the SQ database. It will be ignored. 
18:56:49.558 WARN  - Property 'sonar.jdbc.username' is not supported any more. There is no more DB connection to the SQ database. It will be ignored. 
18:56:49.558 WARN  - Property 'sonar.jdbc.password' is not supported any more. There is no more DB connection to the SQ database. It will be ignored. 
18:56:49.560 INFO  - User cache: C:\Users\kapil.saxena\.sonar\cache 
18:56:49.777 INFO  - Load plugins index 
18:56:49.781 INFO  - Load plugins index (done) | time=4ms 
18:56:49.960 INFO  - Process project properties 
18:56:50.209 INFO  - Load project repositories 
18:56:50.290 INFO  - Load project repositories (done) | time=81ms 
18:56:50.298 INFO  - Apply project exclusions 
18:56:50.369 INFO  - Load quality profiles 
18:56:50.401 INFO  - Load quality profiles (done) | time=32ms 
18:56:50.403 INFO  - Load active rules 
18:56:50.478 INFO  - Load active rules (done) | time=75ms 
18:56:50.498 WARN  - SCM provider autodetection failed. No SCM provider  claims to support this project. Please use sonar.scm.provider to define SCM of your project. 
18:56:50.499 INFO  - Publish mode 
18:56:50.500 INFO  - -------------  Scan TestSonarCustomRules 
18:56:50.582 INFO  - Load server rules 
18:56:50.630 INFO  - Load server rules (done) | time=48ms 
18:56:50.683 INFO  - Base dir: E:\Sonar Example\sonar-examples-master\plugins\java-custom-rules\src\test\files 
18:56:50.683 INFO  - Working dir: E:\Sonar Example\sonar-examples-master\plugins\java-custom-rules\src\test\files\.sonar 
18:56:50.685 INFO  - Source paths: . 
18:56:50.685 INFO  - Source encoding: windows-1252, default locale: en_US 
18:56:50.686 INFO  - Index files 
18:56:50.758 INFO  - 7 files indexed 
18:56:50.760 INFO  - Quality profile for java: Kapil Test Profile 
18:56:50.786 INFO  - Sensor JavaSquidSensor 
18:56:50.925 INFO  - Configured Java source version: none 
18:56:50.954 INFO  - JavaClasspath initialization... 
18:56:50.954 INFO  - JavaClasspath initialization done: 0 ms 
18:56:50.954 INFO  - JavaTestClasspath initialization... 
18:56:50.954 INFO  - JavaTestClasspath initialization done: 0 ms 
18:56:51.232 INFO  - Java Main Files AST scan... 
18:56:51.234 INFO  - 7 source files to be analyzed 
18:56:51.631 INFO  - 7/7 source files have been analyzed 
18:56:51.632 INFO  - Java Main Files AST scan done: 400 ms 
18:56:51.632 WARN  - Java bytecode has not been made available to the analyzer. The org.sonar.java.bytecode.visitor.DependenciesVisitor@3a5c2626 are disabled. 
18:56:51.632 INFO  - Java Test Files AST scan... 
18:56:51.632 INFO  - 0 source files to be analyzed 
18:56:51.632 INFO  - Java Test Files AST scan done: 0 ms 
18:56:51.632 INFO  - 0/0 source files have been analyzed 
18:56:51.632 INFO  - Sensor JavaSquidSensor (done) | time=846ms 
18:56:51.633 INFO  - Sensor Lines Sensor 
18:56:51.635 INFO  - Sensor Lines Sensor (done) | time=2ms 
18:56:51.635 INFO  - Sensor QProfileSensor 
18:56:51.640 INFO  - Sensor QProfileSensor (done) | time=5ms 
18:56:51.640 INFO  - Sensor SurefireSensor 
18:56:51.641 INFO  - parsing E:\Sonar Example\sonar-examples-master\plugins\java-custom-rules\src\test\files\target\surefire-reports 
18:56:51.641 ERROR - Reports path not found or is not a directory: E:\Sonar Example\sonar-examples-master\plugins\java-custom-rules\src\test\files\target\surefire-reports 
18:56:51.641 INFO  - Sensor SurefireSensor (done) | time=1ms 
18:56:51.641 INFO  - Sensor SCM Sensor 
18:56:51.641 INFO  - No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it. 
18:56:51.641 INFO  - Sensor SCM Sensor (done) | time=0ms 
18:56:51.641 INFO  - Sensor Code Colorizer Sensor 
18:56:51.642 INFO  - Sensor Code Colorizer Sensor (done) | time=1ms 
18:56:51.642 INFO  - Sensor CPD Sensor 
18:56:51.642 INFO  - JavaCpdEngine is used for java 
18:56:51.682 INFO  - Sensor CPD Sensor (done) | time=40ms 
18:56:51.752 INFO  - Analysis reports generated in 68ms, dir size=9 KB 
18:56:51.873 INFO  - Analysis reports compressed in 121ms, zip size=11 KB
18:56:51.912 INFO  - Analysis reports sent to server in 38ms 
18:56:51.913 INFO  - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/TestSonarCustomRules 
18:56:51.913 INFO  - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report. 
18:56:51.913 INFO  - More about the report processing at http://localhost:9000/api/ce/task?id=AVGl0nT8XJ_fdu5L48WL 
INFO: ------------------------------------------------------------------------ 
INFO: EXECUTION SUCCESS INFO:
------------------------------------------------------------------------ 
Total time: 3.290s Final Memory: 14M/325M INFO:
------------------------------------------------------------------------

声纳、访问和包装日志都很干净。

以下图片来自SonarQube web,显示了AvoidBrandInMETEDNamesChecks的问题,其中所有默认问题都被锁定,但针对自定义规则的问题没有被锁定:AvoidBrandInMETEDNamesChecks的问题

任何帮助都将不胜感激。

共有2个答案

潘文乐
2023-03-14

终于奏效了。我用了错误的例子。我的pom.xml文件java-Custate-规则没有以下内容:

<dependency>
  <groupId>org.sonarsource.java</groupId>
  <artifactId>java-squid</artifactId>
  <version>${java.plugin.version}</version>
</dependency>

注意:获取示例的最新版本。

孟英锐
2023-03-14

在日志级别为verbose/Debug的情况下完成分析时,未执行自定义插件代码中的调试语句。

使用SonarQube 5.1/5.2/5.3对默认嵌入式H2/PostgreSQL 9.5数据库进行分析时,行为相同

 类似资料:
  • 授人以鱼,不如授人以渔。Dism++的能力是有限的,无法覆盖的所有用户的需求。因此给程序添加了自定义规则功能,方便高级用户打造自己的专属工具。 创建一个空白的自定义规则文件 我们只需要在Config目录新建一个 Custom*.xml 这样形式的xml文件即可(*表示任何字符串,比如Custom1.xml或者Custom我爱我的家.xml,另外文件以UTF8或者Unicode编码保存)。初始文件内

  • 我们在中基于BaseTreeVisitor实现了一个自定义规则https://github.com/SonarSource/sonar-java/tree/master/java-checks/src/main/java/org/sonar/java/checks如中所述http://docs.sonarqube.org/display/SONAR/Extending编码规则。我们能够部署它,它看

  • 自定义中间有突起的UITabBar,demo中高仿了gogobot app底部不规则的TabBar。 [Code4App.com]

  • 我正在使用一个名为verify.js的新插件来验证表单字段,在我开始尝试创建自己的自定义验证规则之前,所有的工作都很顺利。 这里是他们文档的链接,其中解释了如何创建自定义验证:http://verifyjs.com/#custom-rules 更有帮助的是插件作者发布在JSfiddle上的这个示例:http://jsfidle.net/jpillora/r4t84/1/I几乎精确地复制了这里的代码

  • 我正在使用Sonarqube5.4来分析我自己的C#代码,分析工作与我预期的一样。现在我已经编写了一些自定义规则,一个使用StyleCop,另一个使用FxCop在我的代码上运行,但我没有找到如何在Sonarqube中导入自定义规则。我强调我使用Sonarqube5.4和C#插件5.1。在我的安装中,文件夹“规则”不存在。相反,我可以找到: 有人能帮我在SonarQube安装中导入我的自定义规则吗?

  • 我花了一天的时间将所有PMD和Checkstyle规则迁移到新的Squid规则,因为PMD/Checkstyle规则被标记为不推荐使用。 规则:BadConstantName_S00115_Check/S00115 我们所有的枚举都是用camelCase而不是CONSTANT_NAME实现的,例如: 比: 规则:MethodCyclomatic复杂性 迁移后,该规则报告所有equals和hashc