use of org.sonar.api.batch.sensor.SensorContext in project sonar-java by SonarSource.
the class SurefireJavaParserTest method should_store_zero_tests_when_directory_is_null_or_non_existing_or_a_file.
@Test
public void should_store_zero_tests_when_directory_is_null_or_non_existing_or_a_file() throws Exception {
SensorContext context = mock(SensorContext.class);
context = mock(SensorContext.class);
parser.collect(context, getDirs("nonExistingReportsDirectory"), false);
verify(context, never()).newMeasure();
context = mock(SensorContext.class);
parser.collect(context, getDirs("file.txt"), true);
verify(context, never()).newMeasure();
}
use of org.sonar.api.batch.sensor.SensorContext in project sonar-java by SonarSource.
the class SurefireJavaParserTest method shouldNotInsertZeroOnFiles.
@Test
public void shouldNotInsertZeroOnFiles() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
parser.collect(context, getDirs("noTests"), true);
verify(context, never()).newMeasure();
}
use of org.sonar.api.batch.sensor.SensorContext in project sonarqube by SonarSource.
the class OneIssuePerDirectorySensor method analyse.
private static void analyse(SensorContext context) {
FileSystem fs = context.fileSystem();
FilePredicates p = fs.predicates();
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
StreamSupport.stream(fs.inputFiles(p.hasType(Type.MAIN)).spliterator(), false).map(file -> fs.inputDir(file.file().getParentFile())).filter(Objects::nonNull).distinct().forEach(inputDir -> {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputDir).message("This issue is generated for any non-empty directory")).save();
});
}
use of org.sonar.api.batch.sensor.SensorContext in project sonar-java by SonarSource.
the class SurefireJavaParserTest method shouldInsertZeroWhenNoReports.
/**
* See http://jira.codehaus.org/browse/SONAR-2371
*/
@Test
public void shouldInsertZeroWhenNoReports() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
parser.collect(context, getDirs("noReports"), true);
verify(context, never()).newMeasure();
}
use of org.sonar.api.batch.sensor.SensorContext in project sonarqube by SonarSource.
the class JavaCpdBlockIndexerSensor method execute.
@Override
public void execute(SensorContext context) {
FilePredicates p = context.fileSystem().predicates();
List<InputFile> sourceFiles = StreamSupport.stream(context.fileSystem().inputFiles(p.and(p.hasType(InputFile.Type.MAIN), p.hasLanguage("java"))).spliterator(), false).filter(f -> !((DefaultInputFile) f).isExcludedForDuplication()).collect(Collectors.toList());
if (sourceFiles.isEmpty()) {
return;
}
createIndex(sourceFiles);
}
Aggregations