@CheckForNull private static InputFile findFile(SensorContext context, String filePath) { return context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath)); }
Iterator<String> splitCoveredBlock = Splitter.on(",").split(coveredBlockStr).iterator(); String componentPath = splitCoveredBlock.next(); InputFile coveredFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(componentPath)); MutableTestable testable = perspectives.as(MutableTestable.class, coveredFile); List<Integer> coveredLines = new ArrayList<>();
@Test public void has_path() throws Exception { // is relative path assertThat(predicates.hasPath("src/main/java/struts/Action.java").apply(javaFile)).isTrue(); assertThat(predicates.hasPath("src/main/java/struts/Other.java").apply(javaFile)).isFalse(); // is absolute path String path = javaFile.file().getAbsolutePath(); assertThat(predicates.hasAbsolutePath(path).apply(javaFile)).isTrue(); assertThat(predicates.hasPath(temp.newFile().getAbsolutePath()).apply(javaFile)).isFalse(); }
@Override public void execute(SensorContext context) { File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS)); FileSystem fs = context.fileSystem(); FilePredicates p = fs.predicates(); try { for (String path : FileUtils.readLines(f)) { createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context); } } catch (IOException e) { throw new IllegalStateException(e); } }
private void parseFiles(SMInputCursor fileCursor, SensorContext context) throws XMLStreamException { while (fileCursor.getNext() != null) { checkElementName(fileCursor, "file"); String filePath = mandatoryAttribute(fileCursor, "path"); InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath)); if (inputFile == null) { numberOfUnknownFiles++; if (numberOfUnknownFiles <= MAX_STORED_UNKNOWN_FILE_PATHS) { firstUnknownFiles.add(filePath); } continue; } Preconditions.checkState( inputFile.language() != null, "Line %s of report refers to a file with an unknown language: %s", fileCursor.getCursorLocation().getLineNumber(), filePath); Preconditions.checkState( inputFile.type() != InputFile.Type.MAIN, "Line %s of report refers to a file which is not configured as a test file: %s", fileCursor.getCursorLocation().getLineNumber(), filePath); matchedFileKeys.add(inputFile.absolutePath()); MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, inputFile); SMInputCursor testCaseCursor = fileCursor.childElementCursor(); while (testCaseCursor.getNext() != null) { parseTestCase(testCaseCursor, testPlan); } } }
private void parseFiles(SMInputCursor fileCursor, SensorContext context) throws XMLStreamException { while (fileCursor.getNext() != null) { checkElementName(fileCursor, "file"); String filePath = mandatoryAttribute(fileCursor, "path"); InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath)); if (inputFile == null) { numberOfUnknownFiles++; if (numberOfUnknownFiles <= MAX_STORED_UNKNOWN_FILE_PATHS) { firstUnknownFiles.add(filePath); } continue; } Preconditions.checkState( inputFile.language() != null, "Line %s of report refers to a file with an unknown language: %s", fileCursor.getCursorLocation().getLineNumber(), filePath); matchedFileKeys.add(inputFile.key()); NewCoverage newCoverage = context.newCoverage().onFile(inputFile); SMInputCursor lineToCoverCursor = fileCursor.childElementCursor(); while (lineToCoverCursor.getNext() != null) { parseLineToCover(lineToCoverCursor, newCoverage); } newCoverage.save(); } }
private static InputFile findInputFile(SensorContext context, List<String> sourceDirs, String relativeLinuxPath) { FilePredicates predicates = context.fileSystem().predicates(); InputFile inputFile = null; for (String sourceDir : sourceDirs) { File sourceFile = new File(sourceDir, relativeLinuxPath); inputFile = context.fileSystem().inputFile(predicates.hasPath(sourceFile.toString())); if (inputFile != null) { break; } } return inputFile; }
private static InputFile findInputFile(SensorContext context, List<String> sourceDirs, String relativeLinuxPath) { FilePredicates predicates = context.fileSystem().predicates(); InputFile inputFile = null; for (String sourceDir : sourceDirs) { File sourceFile = new File(sourceDir, relativeLinuxPath); inputFile = context.fileSystem().inputFile(predicates.hasPath(sourceFile.toString())); if (inputFile != null) { break; } } return inputFile; }
public static InputFile getByPath(final SensorContext context, final String filePath) { final FileSystem fileSystem = context.fileSystem(); final FilePredicates predicates = fileSystem.predicates(); return fileSystem.inputFile(predicates.hasPath(filePath)); }
private void onFileElement(StartElement element) { String filePath = getAttributeValue(element, NAME); if (filePath.isEmpty()) { inputFile = null; return; } FilePredicates predicates = context.fileSystem().predicates(); inputFile = context.fileSystem().inputFile(predicates.hasPath(filePath)); if (inputFile == null) { LOG.warn("No input file found for '{}'. No checkstyle issues will be imported on this file.", filePath); } }
private InputFile getFile(String filePath) { FilePredicate fp = context.fileSystem().predicates().hasPath(filePath); if(context.fileSystem().hasFiles(fp)) return context.fileSystem().inputFile(fp); LOGGER.warn("Can't find file {}",filePath); return null; }
@Override public void execute(SensorContext context) { File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS)); FileSystem fs = context.fileSystem(); FilePredicates p = fs.predicates(); try { for (String path : FileUtils.readLines(f)) { createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context); } } catch (IOException e) { throw new IllegalStateException(e); } }
private void onFileElement(StartElement element) { String filePath = getAttributeValue(element, NAME); if (filePath.isEmpty()) { inputFile = null; return; } FilePredicates predicates = context.fileSystem().predicates(); inputFile = context.fileSystem().inputFile(predicates.hasPath(filePath)); if (inputFile == null) { LOG.warn("No input file found for '{}'. No checkstyle issues will be imported on this file.", filePath); } }
@Override public void execute(SensorContext context) { File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS)); FileSystem fs = context.fileSystem(); FilePredicates p = fs.predicates(); try { for (String path : FileUtils.readLines(f)) { createIssues(fs.inputFile(p.and(p.hasPath(path), p.hasType(Type.MAIN), p.hasLanguage(Xoo.KEY))), context); } } catch (IOException e) { throw new IllegalStateException(e); } }
private InputFile getUnitTestInputFile(FileSystem fileSystem) { FilePredicates predicates = fileSystem.predicates(); return fileSystem.inputFile(predicates.and( predicates.hasPath(file), predicates.hasType(InputFile.Type.TEST), predicates.hasLanguage(Php.KEY))); }
private InputFile getUnitTestInputFile(FileSystem fileSystem) { FilePredicates predicates = fileSystem.predicates(); return fileSystem.inputFile(predicates.and( predicates.hasPath(file), predicates.hasType(InputFile.Type.TEST), predicates.hasLanguage(Php.KEY))); }
private static InputFile getInputFile(SensorContext context, String fileName) { FilePredicates predicates = context.fileSystem().predicates(); InputFile inputFile = context.fileSystem().inputFile(predicates.hasPath(fileName)); if (inputFile == null) { LOG.warn("No input file found for {}. No {} issues will be imported on this file.", fileName, LINER_NAME); return null; } return inputFile; }
/** * Gets the file pointed by the report. * * @param filePath the unit test report */ private InputFile getUnitTestInputFile(String filePath) { return fileSystem.inputFile(fileSystem.predicates().and( filePredicates.hasPath(filePath), filePredicates.hasType(InputFile.Type.TEST), filePredicates.hasLanguage(PerlLanguage.KEY))); } }
private static void saveIssues(List<Issue> issues, SensorContext context) { FileSystem fileSystem = context.fileSystem(); for (Issue pylintIssue : issues) { String filepath = pylintIssue.getFilename(); InputFile pyfile = fileSystem.inputFile(fileSystem.predicates().hasPath(filepath)); if (pyfile != null) { ActiveRule rule = context.activeRules().find(RuleKey.of(PylintRuleRepository.REPOSITORY_KEY, pylintIssue.getRuleId())); processRule(pylintIssue, pyfile, rule, context); } else { LOG.warn("Cannot find the file '{}' in SonarQube, ignoring violation", filepath); } } }
private void getResourceAndSaveIssue(final GoError error) { FilePredicates predicates = fileSystem.predicates(); InputFile inputFile = fileSystem.inputFile( predicates.and(predicates.hasPath(error.getFilePath()), predicates.hasType(InputFile.Type.MAIN))); GoKeyRule.init(); if (inputFile != null) { saveIssue(inputFile, error.getLine(), GoKeyRule.getKeyFromError(error), error.getMessage()); } else { LOGGER.error("Not able to find an InputFile from " + error.getFilePath()); } }