private static String fileContent(InputFile file) { try { return file.contents(); } catch (IOException e) { throw new IllegalStateException(e); } } }
private static String fileContent(InputFile file) { try { return file.contents(); } catch (IOException e) { throw new IllegalStateException(e); } } }
@Override public String content() { try { return inputFile.contents(); } catch (IOException e) { throw new IllegalStateException("Could not read content of input file " + inputFile, e); } }
@Override public void enterFile(InputFile inputFile) throws IOException { String[] lines = inputFile.contents().split("\\r?\\n"); for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line.length() > maximum) { String message = String.format(MESSAGE, line.length(), maximum); reportIssueOnLine(i + 1, message); } } }
@Override public String contents() { try { return wrapped.contents(); } catch (IOException e) { throw new InputFileIOException(e); } }
@Override public String contents() { try { return wrapped.contents(); } catch (IOException e) { throw new InputFileIOException(e); } }
private static List<String> readLines(InputFile file) { try { return CharStreams.readLines(new StringReader(file.contents())); } catch (IOException e) { throw new IllegalStateException("Unable to read " + file, e); } }
@Nullable InputFile findTestFile(FileSystem fileSystem, TestInfo testInfo) throws IOException { List<InputFile> testInputFilesInPackage = testFilesByPackage.computeIfAbsent( testInfo.Package, goPackage -> getTestFilesForPackage(fileSystem, goPackage)); Pattern pattern = Pattern.compile("^func\\s+" + testInfo.Test + "\\s*\\(", Pattern.MULTILINE); for (InputFile testFile : testInputFilesInPackage) { if (pattern.matcher(testFile.contents()).find()) { return testFile; } } return null; }
ContextualAnalysisRequest(InputFile inputFile, TypeScriptRules typeScriptRules, String projectRoot, @Nullable String tsconfigPath) throws IOException { Path path = Paths.get(inputFile.uri()); this.file = path.toString(); this.content = inputFile.contents(); this.rules = SensorContextUtils.convertToRulesToExecute(typeScriptRules); this.projectRoot = projectRoot; if (tsconfigPath != null) { this.tsconfigPath = new File(projectRoot, tsconfigPath).getAbsolutePath(); } else { this.tsconfigPath = null; } } }
@Override public void enterFile(InputFile inputFile) throws IOException { String contents = inputFile.contents(); if (!isRegularExpression) { contents = normalizeEOL(contents); } Matcher matcher = headerPattern.matcher(contents); if (!matcher.lookingAt()) { reportIssueOnFile("Add or update the header of this file."); } }
@Override public String content() { try { return inputFile().contents(); } catch (IOException e) { throw new IllegalStateException("Could not read content of input file " + inputFile(), e); } }
@Override public String content() { try { return inputFile().contents(); } catch (IOException e) { throw new IllegalStateException("Could not read content of input file " + inputFile(), e); } }
@Override public String content() { try { return inputFile().contents(); } catch (IOException e) { throw new IllegalStateException("Could not read content of input file " + inputFile(), e); } }
public String fileContent(File file) { try { return inputFromIOFile(file).contents(); } catch (IOException e) { throw new AnalysisException("Unable to read file "+file, e); } }
public String fileContent(File file) { try { return inputFromIOFile(file).contents(); } catch (IOException e) { throw new AnalysisException("Unable to read file "+file, e); } }
private static JavaScriptVisitorContext createContext(InputFile file, ActionParser<Tree> parser) { try { ScriptTree scriptTree = (ScriptTree) parser.parse(file.contents()); return new JavaScriptVisitorContext(scriptTree, file, config()); } catch (IOException e) { throw Throwables.propagate(e); } }
private static void saveFileCoverage(SensorContext sensorContext, String filePath, List<CoverageStat> coverageStats) throws IOException { FileSystem fileSystem = sensorContext.fileSystem(); InputFile inputFile = findInputFile(filePath, fileSystem); if (inputFile != null) { LOG.debug("Saving coverage measures for file '{}'", filePath); List<String> lines = Arrays.asList(inputFile.contents().split("\\r?\\n")); NewCoverage newCoverage = sensorContext.newCoverage().onFile(inputFile); FileCoverage fileCoverage = new FileCoverage(coverageStats, lines); for (Map.Entry<Integer, LineCoverage> entry : fileCoverage.lineMap.entrySet()) { newCoverage.lineHits(entry.getKey(), entry.getValue().hits); } newCoverage.save(); } else { LOG.warn("File '{}' is not included in the project, ignoring coverage", filePath); } }
@Override void scanFile(SensorContext sensorContext, InputFile inputFile) throws IOException { final HtlScanner scanner = setupScanner(); HtmlSourceCode sourceCode = new HtmlSourceCode(inputFile); try (Reader reader = new StringReader(inputFile.contents())) { List<Node> nodeList = lexer.parse(reader); scanner.scan(nodeList, sourceCode); MetricsSaver.saveIssues(sensorContext, sourceCode); MetricsSaver.saveMeasures(sensorContext, sourceCode); MetricsSaver.saveLineLevelMeasures(inputFile, sourceCode, fileLinesContextFactory); } }
@Test public void test() throws Exception { when(inputFile.contents()).thenReturn("Input file content"); when(inputFile.filename()).thenReturn("file.php"); when(inputFile.toString()).thenReturn("to string"); when(inputFile.relativePath()).thenReturn("path/to/file.php"); PhpFile phpFile = new PhpFileImpl(inputFile); assertThat(phpFile).isExactlyInstanceOf(PhpFileImpl.class); assertThat(phpFile.contents()).isEqualTo("Input file content"); assertThat(phpFile.filename()).isEqualTo("file.php"); assertThat(phpFile.relativePath()).isEqualTo(Paths.get("path/to/file.php")); assertThat(phpFile.toString()).isEqualTo("to string"); } }
private void analyse(SensorContext sensorContext, InputFile inputFile, ProductDependentExecutor executor, List<TreeVisitor> visitors) { ActionParser<Tree> currentParser = this.parser; if (inputFile.filename().endsWith(".vue")) { currentParser = this.vueParser; } ScriptTree scriptTree; try { scriptTree = (ScriptTree) currentParser.parse(inputFile.contents()); scanFile(sensorContext, inputFile, executor, visitors, scriptTree); } catch (RecognitionException e) { checkInterrupted(e); LOG.error("Unable to parse file: " + inputFile.uri()); LOG.error(e.getMessage()); processRecognitionException(e, sensorContext, inputFile); } catch (Exception e) { checkInterrupted(e); processException(e, sensorContext, inputFile); LOG.error("Unable to analyse file: " + inputFile.uri(), e); } }