Search in sources :

Example 1 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.

the class DefaultCpdBlockIndexer method index.

@Override
public void index(String languageKey) {
    CpdMapping mapping = mappings.getMapping(languageKey);
    if (mapping == null) {
        LOG.debug("No CpdMapping for language {}", languageKey);
        return;
    }
    String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
    logExclusions(cpdExclusions);
    FilePredicates p = fs.predicates();
    List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and(p.hasType(InputFile.Type.MAIN), p.hasLanguage(languageKey), p.doesNotMatchPathPatterns(cpdExclusions))));
    if (sourceFiles.isEmpty()) {
        return;
    }
    // Create index
    populateIndex(languageKey, sourceFiles, mapping);
}
Also used : CpdMapping(org.sonar.api.batch.CpdMapping) FilePredicates(org.sonar.api.batch.fs.FilePredicates) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 2 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.

the class JavaCpdBlockIndexer method index.

@Override
public void index(String languageKey) {
    String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
    logExclusions(cpdExclusions);
    FilePredicates p = fs.predicates();
    List<InputFile> sourceFiles = Lists.newArrayList(fs.inputFiles(p.and(p.hasType(InputFile.Type.MAIN), p.hasLanguage(languageKey), p.doesNotMatchPathPatterns(cpdExclusions))));
    if (sourceFiles.isEmpty()) {
        return;
    }
    createIndex(sourceFiles);
}
Also used : FilePredicates(org.sonar.api.batch.fs.FilePredicates) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 3 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.

the class MultilineIssuesSensor method execute.

@Override
public void execute(SensorContext context) {
    FileSystem fs = context.fileSystem();
    FilePredicates p = fs.predicates();
    for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) {
        createIssues(file, context);
    }
}
Also used : FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) InputFile(org.sonar.api.batch.fs.InputFile)

Example 4 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates 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();
    });
}
Also used : Objects(java.util.Objects) RuleKey(org.sonar.api.rule.RuleKey) FileSystem(org.sonar.api.batch.fs.FileSystem) Type(org.sonar.api.batch.fs.InputFile.Type) StreamSupport(java.util.stream.StreamSupport) Sensor(org.sonar.api.batch.sensor.Sensor) SensorContext(org.sonar.api.batch.sensor.SensorContext) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) FilePredicates(org.sonar.api.batch.fs.FilePredicates) SensorDescriptor(org.sonar.api.batch.sensor.SensorDescriptor) RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) Objects(java.util.Objects)

Example 5 with FilePredicates

use of org.sonar.api.batch.fs.FilePredicates in project sonarqube by SonarSource.

the class OneIssuePerLineSensor method analyse.

private void analyse(SensorContext context, String language, String repo) {
    FileSystem fs = context.fileSystem();
    FilePredicates p = fs.predicates();
    for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(language), p.hasType(Type.MAIN)))) {
        createIssues(file, context, repo);
    }
}
Also used : FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

FilePredicates (org.sonar.api.batch.fs.FilePredicates)21 InputFile (org.sonar.api.batch.fs.InputFile)20 FileSystem (org.sonar.api.batch.fs.FileSystem)16 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)3 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 StreamSupport (java.util.stream.StreamSupport)2 SensorContext (org.sonar.api.batch.sensor.SensorContext)2 SensorDescriptor (org.sonar.api.batch.sensor.SensorDescriptor)2 RuleKey (org.sonar.api.rule.RuleKey)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1