Java Code Examples for org.sonar.api.batch.fs.FileSystem#inputFile()

The following examples show how to use org.sonar.api.batch.fs.FileSystem#inputFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloverageMetricParser.java    From sonar-clojure with MIT License 5 votes vote down vote up
private static Optional<FileAnalysis> findFileBySources(SensorContext context, String filename) {
    FileSystem fs = context.fileSystem();
    FilePredicate pattern = fs.predicates().matchesPathPattern("**/" + filename);
    InputFile potentialFile = fs.inputFile(pattern);

    if (potentialFile != null) {
        LOG.debug("Found file");
        FileAnalysis foundSource = new FileAnalysis();
        foundSource.setInputFile(potentialFile);
        return Optional.of(foundSource);
    }

    return Optional.empty();
}
 
Example 2
Source File: RubocopSensor.java    From sonar-ruby-plugin with MIT License 5 votes vote down vote up
private InputFile findMatchingFile(FileSystem fs, String filePath) {
    File matchingFile = fs.resolvePath(filePath);

    if (matchingFile != null) {
        try {
            return fs.inputFile(fs.predicates().is(matchingFile));
        }
        catch (IllegalArgumentException e) {
            LOG.error("Failed to resolve " + filePath + " to a single path", e);
        }
    }
    return null;
}
 
Example 3
Source File: CoberturaReportParser.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void collectFileMeasures(SensorContext context, SMInputCursor clazz) throws XMLStreamException {
  FileSystem fileSystem = context.fileSystem();
  FilePredicates predicates = fileSystem.predicates();
  Map<String, InputFile> inputFileByFilename = new HashMap<>();
  while (clazz.getNext() != null) {
    String fileName = clazz.getAttrValue("filename");

    InputFile inputFile;
    // mxml files are not supported by the plugin
    if (inputFileByFilename.containsKey(fileName)) {
      inputFile = inputFileByFilename.get(fileName);
    } else {
      String key = fileName.startsWith(File.separator) ? fileName : (File.separator + fileName);
      inputFile = fileSystem.inputFile(predicates.and(
        predicates.matchesPathPattern("file:**" + key.replace(File.separator, "/")),
        predicates.hasType(InputFile.Type.MAIN),
        predicates.hasLanguage(Lua.KEY)));
      inputFileByFilename.put(fileName, inputFile);
      if (inputFile == null && !fileName.endsWith(".mxml")) {
        LOG.warn("Cannot save coverage result for file: {}, because resource not found.", fileName);
      }
    }
    if (inputFile != null) {
      collectFileData(
        clazz,
        context.newCoverage()
          .onFile(inputFile)
          .ofType(CoverageType.UNIT)
      );
    } else {
      SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line");
      while (line.getNext() != null) {
        // advance
      }
    }
  }
}
 
Example 4
Source File: LuaSquidSensor.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void save(SensorContext context, Collection<SourceCode> squidSourceFiles) {
  FileSystem fileSystem = context.fileSystem();
  for (SourceCode squidSourceFile : squidSourceFiles) {
    SourceFile squidFile = (SourceFile) squidSourceFile;

    InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().hasPath(squidFile.getKey()));

    saveClassComplexity(context, inputFile, squidFile);
    saveMeasures(context, inputFile, squidFile);
    saveFunctionsComplexityDistribution(context, inputFile, squidFile);
    saveFilesComplexityDistribution(context, inputFile, squidFile);
    visitors.add(new LuaTokensVisitor(context, LuaLexer.create(configuration)));
    saveViolations(context, inputFile, squidFile);
  }
}