private void processFile(InputFile inputFile) { try { Set<Integer> noSonarLines = new HashSet<>(); int[] lineCounter = {1}; try (Stream<String> stream = Files.lines(inputFile.path(), inputFile.charset())) { stream.forEachOrdered(lineStr -> { if (lineStr.contains("//NOSONAR")) { noSonarLines.add(lineCounter[0]); } lineCounter[0]++; }); } noSonarFilter.noSonarInFile(inputFile, noSonarLines); } catch (IOException e) { throw new IllegalStateException("Fail to process " + inputFile, e); } } }
@Override public boolean apply(InputFile f) { return pattern.match(f.path(), Paths.get(f.relativePath())); }
private static void parseIssues(InputFile file, SensorContext context, Map<Integer, TextPointer> startPositions, Map<Integer, TextPointer> endPositions) { int currentLine = 0; try { for (String lineStr : Files.readAllLines(file.path(), file.charset())) { currentLine++; Matcher m = START_ISSUE_PATTERN.matcher(lineStr); while (m.find()) { Integer issueId = Integer.parseInt(m.group(1)); TextPointer newPointer = file.newPointer(currentLine, m.end()); startPositions.put(issueId, newPointer); } m = END_ISSUE_PATTERN.matcher(lineStr); while (m.find()) { Integer issueId = Integer.parseInt(m.group(1)); TextPointer newPointer = file.newPointer(currentLine, m.start()); endPositions.put(issueId, newPointer); } } } catch (IOException e) { throw new IllegalStateException("Unable to read file", e); } }
int currentLine = 0; try { for (String lineStr : Files.readAllLines(file.path(), file.charset())) { currentLine++;
private void processSignificantCodeFile(InputFile inputFile, SensorContext context) { Path ioFile = inputFile.path(); Path significantCodeFile = ioFile.resolveSibling(ioFile.getFileName() + FILE_EXTENSION).toAbsolutePath(); if (Files.exists(significantCodeFile) && Files.isRegularFile(significantCodeFile)) { LOG.debug("Processing " + significantCodeFile.toString()); try { List<String> lines = Files.readAllLines(significantCodeFile, context.fileSystem().encoding()); NewSignificantCode significantCode = context.newSignificantCode() .onFile(inputFile); for (String line : lines) { if (StringUtils.isBlank(line) || line.startsWith("#")) { continue; } processLine(line, inputFile, significantCode); } significantCode.save(); } catch (IOException e) { throw new IllegalStateException(e); } } }
@Override public String fileName() { return inputFile.path().getFileName().toString(); }
@Override public String fileName() { return inputFile.path().getFileName().toString(); }
synchronized void markAsIndexed(InputFile inputFile) { if (indexed.contains(inputFile.path())) { throw MessageException.of("File " + inputFile + " can't be indexed twice. Please check that inclusion/exclusion patterns produce " + "disjoint sets for main and test files"); } indexed.add(inputFile.path()); progressReport.message(indexed.size() + " files indexed... (last one was " + inputFile.relativePath() + ")"); }
synchronized void markAsIndexed(InputFile inputFile) { if (indexed.contains(inputFile.path())) { throw MessageException.of("File " + inputFile + " can't be indexed twice. Please check that inclusion/exclusion patterns produce " + "disjoint sets for main and test files"); } indexed.add(inputFile.path()); progressReport.message(indexed.size() + " files indexed... (last one was " + inputFile.relativePath() + ")"); }
@Override public boolean apply(InputFile f) { return pattern.match(f.path(), Paths.get(f.relativePath())); }
private void processFile(InputFile inputFile) { try { Set<Integer> noSonarLines = new HashSet<>(); int[] lineCounter = {1}; try (Stream<String> stream = Files.lines(inputFile.path(), inputFile.charset())) { stream.forEachOrdered(lineStr -> { if (lineStr.contains("//NOSONAR")) { noSonarLines.add(lineCounter[0]); } lineCounter[0]++; }); } noSonarFilter.noSonarInFile(inputFile, noSonarLines); } catch (IOException e) { throw new IllegalStateException("Fail to process " + inputFile, e); } } }
private static void parseIssues(InputFile file, SensorContext context, Map<Integer, TextPointer> startPositions, Map<Integer, TextPointer> endPositions) { int currentLine = 0; try { for (String lineStr : Files.readAllLines(file.path(), file.charset())) { currentLine++; Matcher m = START_ISSUE_PATTERN.matcher(lineStr); while (m.find()) { Integer issueId = Integer.parseInt(m.group(1)); TextPointer newPointer = file.newPointer(currentLine, m.end()); startPositions.put(issueId, newPointer); } m = END_ISSUE_PATTERN.matcher(lineStr); while (m.find()) { Integer issueId = Integer.parseInt(m.group(1)); TextPointer newPointer = file.newPointer(currentLine, m.start()); endPositions.put(issueId, newPointer); } } } catch (IOException e) { throw new IllegalStateException("Unable to read file", e); } }
int currentLine = 0; try { for (String lineStr : Files.readAllLines(file.path(), file.charset())) { currentLine++;
@Override public String getIssuePath(PostJobIssue issue) { InputComponent ip = issue.inputComponent(); if (ip == null || !ip.isFile()) { return null; } InputFile inputFile = (InputFile) ip; Path baseDir = config .getRepositoryRoot() .orElse(projectBaseDir).toPath(); return new PathResolver().relativePath(baseDir, inputFile.path()); } }
private void processSignificantCodeFile(InputFile inputFile, SensorContext context) { Path ioFile = inputFile.path(); Path significantCodeFile = ioFile.resolveSibling(ioFile.getFileName() + FILE_EXTENSION).toAbsolutePath(); if (Files.exists(significantCodeFile) && Files.isRegularFile(significantCodeFile)) { LOG.debug("Processing " + significantCodeFile.toString()); try { List<String> lines = Files.readAllLines(significantCodeFile, context.fileSystem().encoding()); NewSignificantCode significantCode = context.newSignificantCode() .onFile(inputFile); for (String line : lines) { if (StringUtils.isBlank(line) || line.startsWith("#")) { continue; } processLine(line, inputFile, significantCode); } significantCode.save(); } catch (IOException e) { throw new IllegalStateException(e); } } }
public void saveForAllLine(final SensorContext context, final InputFile i) { final NewCoverage coverage = context.newCoverage().onFile(i); try (Stream<String> fileLine = Files.lines(i.path())) { FactoryLine.init(); LinePredicate.init(); fileLine.map(FactoryLine::create).filter(LinePredicate::filterLine) .forEach(l -> coverage.lineHits(l.getLineNumber(), l.getHits())); coverage.ofType(CoverageType.UNIT); coverage.save(); } catch (IOException e) { LOGGER.warn("IO Exception" + e); } }