/** * Merge all reports in reportOverall. * @param reportOverall destination file of merge. * @param reports files to be merged. */ public static void mergeReports(File reportOverall, File... reports) { ExecutionDataVisitor edv = new ExecutionDataVisitor(); loadSourceFiles(edv, reports); try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(reportOverall))) { Object visitor = new ExecutionDataWriter(outputStream); for (Map.Entry<String, ExecutionDataStore> entry : edv.getSessions().entrySet()) { SessionInfo sessionInfo = new SessionInfo(entry.getKey(), 0, 0); ((ISessionInfoVisitor) visitor).visitSessionInfo(sessionInfo); entry.getValue().accept((IExecutionDataVisitor) visitor); } } catch (IOException e) { throw new AnalysisException(String.format("Unable to write overall coverage report %s", reportOverall.getAbsolutePath()), e); } }
@Override public void execute(SensorContext context) { if (context.config().hasKey(REPORT_MISSING_FORCE_ZERO)) { LOG.warn("Property '{}' is deprecated and its value will be ignored.", REPORT_MISSING_FORCE_ZERO); } Set<File> reportPaths = getReportPaths(context); if (reportPaths.isEmpty()) { return; } // Merge JaCoCo reports File reportMerged; if(reportPaths.size() == 1) { reportMerged = reportPaths.iterator().next(); } else { reportMerged = new File(context.fileSystem().workDir(), JACOCO_MERGED_FILENAME); reportMerged.getParentFile().mkdirs(); JaCoCoReportMerger.mergeReports(reportMerged, reportPaths.toArray(new File[0])); } new UnitTestAnalyzer(reportMerged, perspectives, javaResourceLocator, javaClasspath).analyse(context); }