use of org.sonar.plugins.java.api.JavaCheck in project JavaForFun by gumartinm.
the class CustomRulesCheckRegistrarTest method whenCreatingCustomJavaCheckRegistrarThenGenerateClassWithSuccess.
@Test
public void whenCreatingCustomJavaCheckRegistrarThenGenerateClassWithSuccess() {
CustomRulesCheckRegistrar registrar = new CustomRulesCheckRegistrar();
RegistrarContext registrarContext = new CheckRegistrar.RegistrarContext();
registrar.register(registrarContext);
List<Class<? extends JavaCheck>> checkClasses = Lists.newArrayList(registrarContext.checkClasses());
List<Class<? extends JavaCheck>> testCheckClasses = Lists.newArrayList(registrarContext.testCheckClasses());
assertThat(checkClasses.size(), is(2));
assertThat(testCheckClasses.size(), is(0));
assertThat(registrarContext.repositoryKey(), is(CheckList.REPOSITORY_KEY));
}
use of org.sonar.plugins.java.api.JavaCheck in project sonar-java by SonarSource.
the class JavaSquidSensor method execute.
@Override
public void execute(SensorContext context) {
javaResourceLocator.setSensorContext(context);
sonarComponents.setSensorContext(context);
sonarComponents.setRuleRepositoryKey(CheckList.REPOSITORY_KEY);
List<Class<? extends JavaCheck>> checks = ImmutableList.<Class<? extends JavaCheck>>builder().addAll(CheckList.getJavaChecks()).addAll(CheckList.getDebugChecks()).build();
sonarComponents.registerCheckClasses(CheckList.REPOSITORY_KEY, checks);
sonarComponents.registerTestCheckClasses(CheckList.REPOSITORY_KEY, CheckList.getJavaTestChecks());
Measurer measurer = new Measurer(fs, context, noSonarFilter);
JavaSquid squid = new JavaSquid(getJavaVersion(), isXFileEnabled(), sonarComponents, measurer, javaResourceLocator, postAnalysisIssueFilter, sonarComponents.checkClasses());
squid.scan(getSourceFiles(), getTestFiles());
sonarComponents.saveAnalysisErrors();
}
use of org.sonar.plugins.java.api.JavaCheck in project sonar-java by SonarSource.
the class AnalyzerMessageTest method testAnalyzerMessageOnFile2.
@Test
public void testAnalyzerMessageOnFile2() {
JavaCheck javaCheck = mock(JavaCheck.class);
File file = new File("a");
String message = "analyzer message";
int cost = 3;
AnalyzerMessage analyzerMessage = new AnalyzerMessage(javaCheck, file, -5, message, cost);
assertThat(analyzerMessage.getCheck()).isEqualTo(javaCheck);
assertThat(analyzerMessage.getFile()).isEqualTo(file);
assertThat(analyzerMessage.getLine()).isEqualTo(null);
assertThat(analyzerMessage.getMessage()).isEqualTo(message);
assertThat(analyzerMessage.getCost()).isEqualTo(cost);
assertThat(analyzerMessage.primaryLocation()).isNull();
}
use of org.sonar.plugins.java.api.JavaCheck in project sonar-java by SonarSource.
the class AnalyzerMessageTest method testAnalyzerMessageWithoutCost.
@Test
public void testAnalyzerMessageWithoutCost() {
JavaCheck javaCheck = mock(JavaCheck.class);
File file = new File("a");
String message = "analyzer message";
int cost = 0;
AnalyzerMessage analyzerMessage = new AnalyzerMessage(javaCheck, file, null, message, cost);
assertThat(analyzerMessage.getCheck()).isEqualTo(javaCheck);
assertThat(analyzerMessage.getFile()).isEqualTo(file);
assertThat(analyzerMessage.getLine()).isEqualTo(null);
assertThat(analyzerMessage.getMessage()).isEqualTo(message);
assertThat(analyzerMessage.getCost()).isNull();
assertThat(analyzerMessage.primaryLocation()).isNull();
}
use of org.sonar.plugins.java.api.JavaCheck in project sonar-java by SonarSource.
the class AnalyzerMessageTest method testAnalyzerMessage.
@Test
public void testAnalyzerMessage() {
JavaCheck javaCheck = mock(JavaCheck.class);
File file = new File("a");
int line = 5;
String message = "analyzer message";
int cost = 3;
AnalyzerMessage analyzerMessage = new AnalyzerMessage(javaCheck, file, line, message, cost);
assertThat(analyzerMessage.getCheck()).isEqualTo(javaCheck);
assertThat(analyzerMessage.getFile()).isEqualTo(file);
assertThat(analyzerMessage.getLine()).isEqualTo(line);
assertThat(analyzerMessage.getMessage()).isEqualTo(message);
assertThat(analyzerMessage.getCost()).isEqualTo(cost);
AnalyzerMessage.TextSpan location = analyzerMessage.primaryLocation();
assertThat(location.startLine).isEqualTo(line);
assertThat(location.startCharacter).isEqualTo(-1);
assertThat(location.endLine).isEqualTo(line);
assertThat(location.endCharacter).isEqualTo(-1);
assertThat(location.isEmpty()).isTrue();
assertThat(location.toString()).isEqualTo("(5:-1)-(5:-1)");
}
Aggregations