private static Optional<File> getReport(Configuration settings, FileSystem fs, String reportPathPropertyKey, String msg) { Optional<String> reportPathProp = settings.get(reportPathPropertyKey); if (reportPathProp.isPresent()) { warnUsageOfDeprecatedProperty(settings, reportPathPropertyKey); String reportPathProperty = reportPathProp.get(); File report = fs.resolvePath(reportPathProperty); if (!report.isFile()) { LOG.info(msg, reportPathProperty); } else { return Optional.of(report); } } return Optional.empty(); }
private static Set<File> getReportPaths(SensorContext context) { Set<File> reportPaths = new HashSet<>(); Configuration settings = context.config(); FileSystem fs = context.fileSystem(); for (String reportPath : settings.getStringArray(REPORT_PATHS_PROPERTY)) { File report = fs.resolvePath(reportPath); if (!report.isFile()) { if (settings.hasKey(REPORT_PATHS_PROPERTY)) { LOG.info("JaCoCo report not found: '{}'", reportPath); } } else { reportPaths.add(report); } } getReport(settings, fs, REPORT_PATH_PROPERTY, "JaCoCo UT report not found: '{}'").ifPresent(reportPaths::add); getReport(settings, fs, IT_REPORT_PATH_PROPERTY, "JaCoCo IT report not found: '{}'").ifPresent(reportPaths::add); return reportPaths; }
@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); }