[英]Java plugin - SonarQube Add Custom Rule
As mentioned in this Question ,I have followed all the steps and added a TestRule.java in /checks folder. 如本问题所述 ,我已经按照所有步骤操作,并在/ checks文件夹中添加了TestRule.java。
But when I compile this plugin code I get following error : 但是,当我编译此插件代码时,出现以下错误:
17:02:52.614 [main] INFO o.s.s.j.c.SecurityAnnotationMandatoryCheck - implements Interface : Second
Interface
17:02:52.614 [main] INFO o.s.s.j.c.SecurityAnnotationMandatoryCheck - Method Name MySecurityAnnotat
ion
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.073 sec - in org.sonar.samples.jav
a.checks.SecurityAnnotationMandatoryCheckTest
Running org.sonar.samples.java.checks.TestRuleTests
17:02:52.617 [Report about progress of Java AST analyzer] INFO org.sonar.squidbridge.ProgressReport
- 1/1 source files have been analyzed
Executing *****************************TestRULE...........17:02:52.673 [main] INFO org.sonar.squidb
ridge.ProgressReport - 1 source files to be analyzed
17:02:52.679 [main] DEBUG o.s.java.bytecode.ClassLoaderBuilder - ----- Classpath analyzed by Squid:
17:02:52.680 [main] DEBUG o.s.java.bytecode.ClassLoaderBuilder - C:\Users\dev\JavaPlugin\sonar-examples-master\sonar-examples-master\plugins\java-custom-rules\target\test-jars\commo
ns-collections4-4.0.jar
17:02:52.680 [main] DEBUG o.s.java.bytecode.ClassLoaderBuilder - C:\Users\dev\Jav
aPlugin\sonar-examples-master\sonar-examples-master\plugins\java-custom-rules\target\test-classes
17:02:52.680 [main] DEBUG o.s.java.bytecode.ClassLoaderBuilder - -----
17:02:52.688 [main] DEBUG o.s.java.resolve.BytecodeCompleter - Completing symbol : Object
17:02:52.691 [Report about progress of Java AST analyzer] INFO org.sonar.squidbridge.ProgressReport
- 1/1 source files have been analyzed
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.04 sec <<< FAILURE! - in org.sonar
.samples.java.checks.TestRuleTests
detected(org.sonar.samples.java.checks.TestRuleTests) Time elapsed: 0.033 sec <<< ERROR!
java.lang.IllegalStateException: At least one issue expected
at org.sonar.samples.java.checks.TestRuleTests.detected(TestRuleTests.java:19)
Results :
Tests in error:
TestRuleTests.detected:19 ╗ IllegalState At least one issue expected
Tests run: 8, Failures: 0, Errors: 1, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.750 s
[INFO] Finished at: 2015-12-04T17:02:53+05:30
[INFO] Final Memory: 28M/313M
[INFO] ------------------------------------------------------------------------
Code on org.sonar.samples.java.checks.TestRuleTests.detected(TestRuleTests.java:19) is given below : org.sonar.samples.java.checks.TestRuleTests.detected(TestRuleTests.java:19)上的代码如下:
import org.junit.Test;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import java.lang.System;
public class TestRuleTests {
TestRule check = new TestRule();
//check.max=100;
@Test
public void detected() {
// Verifies that the check will raise the adequate issues with the expected message.
// In the test file, lines which should raise an issue have been commented out
// by using the following syntax: "// Noncompliant {{EXPECTED_MESSAGE}}"
System.out.print("Executing *****************************TestRULE...........");
JavaCheckVerifier.verify("src/test/files/TestRule.java", check); //Line number 19,this line is indicated in error
System.out.print("After Executing *****************************TestRULE...........");
}
}
How can I add issue ? 如何添加问题?
If you read the error : an issue is expected in the file you are testing. 如果您读取错误:正在测试的文件中可能存在问题。
So in "src/test/files/TestRule.java" an issue should be raised by your rule and checked by using the comment : // Noncompliant as specified in the comment in your test class. 因此,在“ src / test / files / TestRule.java”中,您的规则应引发一个问题,并使用注释进行检查://不符合测试类的注释中指定的条件。
If you have absolutely no issue raised by your check then you should use the method verifyNoIssue
to avoid the error. 如果检查绝对没有问题,则应使用
verifyNoIssue
方法来避免错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.