private int writeChangedLines(ScmProvider provider, ScannerReportWriter writer, String targetScmBranch) { Path rootBaseDir = project.getBaseDir(); Map<Path, DefaultInputFile> changedFiles = StreamSupport.stream(inputComponentStore.allChangedFilesToPublish().spliterator(), false) .collect(Collectors.toMap(DefaultInputFile::path, f -> f)); Map<Path, Set<Integer>> pathSetMap = provider.branchChangedLines(targetScmBranch, rootBaseDir, changedFiles.keySet()); int count = 0; if (pathSetMap == null) { // no information returned by the SCM, we write nothing in the report and // the compute engine will use SCM dates to estimate which lines are new return count; } for (Map.Entry<Path, DefaultInputFile> e : changedFiles.entrySet()) { Set<Integer> changedLines = pathSetMap.getOrDefault(e.getKey(), Collections.emptySet()); if (changedLines.isEmpty()) { LOG.warn("File '{}' was detected as changed but without having changed lines", e.getKey().toAbsolutePath()); } count++; writeChangedLines(writer, e.getValue().scannerId(), changedLines); } return count; }
@Override public void publish(ScannerReportWriter writer) { String targetScmBranch = branchConfiguration.targetScmBranch(); if (scmConfiguration.isDisabled() || !branchConfiguration.isShortOrPullRequest() || targetScmBranch == null) { return; } ScmProvider provider = scmConfiguration.provider(); if (provider == null) { return; } Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); int count = writeChangedLines(provider, writer, targetScmBranch); LOG.debug("SCM reported changed lines for {} {} in the branch", count, ScannerUtils.pluralize("file", count)); profiler.stopInfo(); }
private int writeChangedLines(ScmProvider provider, ScannerReportWriter writer, String targetScmBranch) { Path rootBaseDir = project.getBaseDir(); Map<Path, DefaultInputFile> changedFiles = StreamSupport.stream(inputComponentStore.allChangedFilesToPublish().spliterator(), false) .collect(Collectors.toMap(DefaultInputFile::path, f -> f)); Map<Path, Set<Integer>> pathSetMap = provider.branchChangedLines(targetScmBranch, rootBaseDir, changedFiles.keySet()); int count = 0; if (pathSetMap == null) { // no information returned by the SCM, we write nothing in the report and // the compute engine will use SCM dates to estimate which lines are new return count; } for (Map.Entry<Path, DefaultInputFile> e : changedFiles.entrySet()) { Set<Integer> changedLines = pathSetMap.getOrDefault(e.getKey(), Collections.emptySet()); if (changedLines.isEmpty()) { LOG.warn("File '{}' was detected as changed but without having changed lines", e.getKey().toAbsolutePath()); } count++; writeChangedLines(writer, e.getValue().scannerId(), changedLines); } return count; }
@Override public void publish(ScannerReportWriter writer) { String targetScmBranch = branchConfiguration.targetScmBranch(); if (scmConfiguration.isDisabled() || !branchConfiguration.isShortOrPullRequest() || targetScmBranch == null) { return; } ScmProvider provider = scmConfiguration.provider(); if (provider == null) { return; } Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); int count = writeChangedLines(provider, writer, targetScmBranch); LOG.debug("SCM reported changed lines for {} {} in the branch", count, ScannerUtils.pluralize("file", count)); profiler.stopInfo(); }