我想在Java中編寫我自己的聲納規則。我們需要在SonarQube中增加一些安全規則。在嘗試之前,我必須先嚐試編碼基本規則。要做到這一點,我遵循以下鏈接: https://github.com/SonarSource/sonar-java/tree/master/java-checks/srcJava中的編碼聲納規則
我嘗試添加聲納實例中提到的樣品規則,這些規則對我來說工作得很好。
現在我嘗試在github 中添加已存在的規則,方法是在同一個文件夾中創建新的java文件。
這裏我添加了, https://github.com/SonarSource/sonar-java/blob/master/java-checks/src/main/java/org/sonar/java/checks/DuplicateConditionIfElseIfCheck.java 代碼在我的主文件夾中。我也在測試文件夾中添加了各自的java文件。
但我得到當我編譯使用下面的錯誤 - > MVN編譯
C:\Sonar\sonar-examples-master\plugins\java-custom-rules>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Java Custom Rules 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sonar-packaging-maven-plugin:1.12.1:check-dependencies (default-check
-dependencies) @ java-custom-rules ---
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ java-custo
m-rules ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Sonar\sonar-examples-master\plugin
s\java-custom-rules\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ java-custom-rul
es ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 9 source files to C:\Sonar\sonar-examples-master\plugins\java-c
ustom-rules\target\classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] /C:/Sonar/sonar-examples-master/plugins/java-custom-rules/src/main/jav
a/org/sonar/samples/java/MyJavaFileCheckRegistrar.java: C:\Sonar\sonar-examples-
master\plugins\java-custom-rules\src\main\java\org\sonar\samples\java\MyJavaFile
CheckRegistrar.java uses unchecked or unsafe operations.
[WARNING] /C:/Sonar/sonar-examples-master/plugins/java-custom-rules/src/main/jav
a/org/sonar/samples/java/MyJavaFileCheckRegistrar.java: Recompile with -Xlint:un
checked for details.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Sonar/sonar-examples-master/plugins/java-custom-rules/src/main/java/
org/sonar/samples/java/DuplicateConditionIfElseIfCheck.java:[50,54] cannot find
symbol
symbol: class Location
location: interface org.sonar.plugins.java.api.JavaFileScannerContext
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.667 s
[INFO] Finished at: 2015-10-06T09:55:20+03:00
[INFO] Final Memory: 15M/37M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
1:compile (default-compile) on project java-custom-rules: Compilation failure
[ERROR] /C:/Sonar/sonar-examples-master/plugins/java-custom-rules/src/main/java/
org/sonar/samples/java/DuplicateConditionIfElseIfCheck.java:[50,54] cannot find
symbol
[ERROR] symbol: class Location
[ERROR] location: interface org.sonar.plugins.java.api.JavaFileScannerContext
我是否需要添加任何其他jar文件? 請幫幫我。
由於提前, Shruthi
看看我SonarQube插件請遵循自定義規則插件的示例:https://github.com/SonarSource/sonar-examples/tree/master/plugins/java-custom-rules – benzonico
我已經有這些例子,它對我來說工作得很好。現在我試圖添加https://github.com/SonarSource/sonar-java/tree/master/java-checks/src/main/java/org/sonar/java中的任何規則 –
如果我嘗試添加相同的代碼,我得到了上述錯誤 –