diff --git a/README.md b/README.md index e6f1b38..628547f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Quarkus QE Flaky Run Reporter -This is Maven extensions that accepts build reporter generated by the https://github.com/quarkusio/build-reporter and SureFire / FailSafe reports and creates flaky run reports. +This is Maven extensions that accepts SureFire / FailSafe reports and creates flaky run reports. ## Generate flaky run report Add Maven extension to your POM file: @@ -7,11 +7,6 @@ Add Maven extension to your POM file: ```xml - - io.quarkus.bot - build-reporter-maven-extension - ${build-reporter-maven-extension.version} - io.quarkus.qe flaky-run-reporter diff --git a/pom.xml b/pom.xml index 3ba4a45..6e49010 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,6 @@ 17 17 UTF-8 - 3.4.4 3.9.6 3.2.5 2.2.0 @@ -24,11 +23,6 @@ - - io.quarkus.bot - build-reporter-maven-extension-model - ${build-reporter-maven-extension.version} - org.apache.maven maven-core diff --git a/src/main/java/io/quarkus/qe/reporter/flakyrun/mavenextension/FlakyRunReportingMavenExtension.java b/src/main/java/io/quarkus/qe/reporter/flakyrun/mavenextension/FlakyRunReportingMavenExtension.java index a6fc0fe..b9d5a31 100644 --- a/src/main/java/io/quarkus/qe/reporter/flakyrun/mavenextension/FlakyRunReportingMavenExtension.java +++ b/src/main/java/io/quarkus/qe/reporter/flakyrun/mavenextension/FlakyRunReportingMavenExtension.java @@ -1,12 +1,16 @@ package io.quarkus.qe.reporter.flakyrun.mavenextension; import io.quarkus.qe.reporter.flakyrun.reporter.FlakyRunReporter; +import io.quarkus.qe.reporter.flakyrun.reporter.Project; import org.apache.maven.AbstractMavenLifecycleParticipant; import org.apache.maven.execution.MavenSession; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; +import java.nio.file.Path; +import java.util.List; + @Component(role = AbstractMavenLifecycleParticipant.class, hint = "quarkus-qe-flaky-run-reporter") public class FlakyRunReportingMavenExtension extends AbstractMavenLifecycleParticipant { @@ -15,6 +19,16 @@ public class FlakyRunReportingMavenExtension extends AbstractMavenLifecycleParti @Override public void afterSessionEnd(MavenSession session) { - new FlakyRunReporter(logger).createFlakyRunReport(); + var projects = getProjectsFromMvnSession(session); + if (!projects.isEmpty()) { + new FlakyRunReporter(logger).createReport(projects); + } + } + + private static List getProjectsFromMvnSession(MavenSession session) { + final Path rootPath = Path.of("").toAbsolutePath(); + return session.getResult().getTopologicallySortedProjects().stream() + .map(p -> new Project(p.getName(), rootPath.relativize(p.getBasedir().toPath()))) + .filter(p -> !p.baseDir().toString().isEmpty()).toList(); } } diff --git a/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/FlakyRunReporter.java b/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/FlakyRunReporter.java index 56fc6e1..883d771 100644 --- a/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/FlakyRunReporter.java +++ b/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/FlakyRunReporter.java @@ -3,8 +3,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import io.quarkus.bot.build.reporting.model.BuildReport; -import io.quarkus.bot.build.reporting.model.ProjectReport; import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger; import org.apache.maven.plugins.surefire.report.ReportTestCase; import org.apache.maven.plugins.surefire.report.ReportTestSuite; @@ -23,7 +21,6 @@ public class FlakyRunReporter { public static final String FLAKY_RUN_REPORT = "flaky-run-report.json"; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); - private static final String BUILD_REPORT_JSON_FILENAME = "build-report.json"; private static final String TARGET_DIR = "target"; private static final Path MAVEN_SUREFIRE_REPORTS_PATH = Path.of(TARGET_DIR, "surefire-reports"); private static final Path MAVEN_FAILSAFE_REPORTS_PATH = Path.of(TARGET_DIR, "failsafe-reports"); @@ -45,13 +42,12 @@ public static List parseFlakyTestsReport(Path reportPath) { } } - public void createFlakyRunReport() { - createFlakyRunReport(buildReportToFlakyTests(getBuildReporter())); + public void createReport(List projects) { + createFlakyRunReport(projectsToFlakyTests(projects)); } - private static List buildReportToFlakyTests(BuildReport buildReport) { - return buildReport.getProjectReports().stream() - .flatMap(projectReport -> testDirsToFlakyTests(toTestDirs(projectReport), projectReport)).toList(); + private static List projectsToFlakyTests(List projects) { + return projects.stream().flatMap(project -> testDirsToFlakyTests(toTestDirs(project), project)).toList(); } private void createFlakyRunReport(List flakyTests) { @@ -64,36 +60,18 @@ private void createFlakyRunReport(List flakyTests) { } } - private static BuildReport getBuildReporter() { - var buildReportPath = Path.of(TARGET_DIR).resolve(BUILD_REPORT_JSON_FILENAME); - if (Files.exists(buildReportPath)) { - try { - return OBJECT_MAPPER.readValue(buildReportPath.toFile(), BuildReport.class); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return new BuildReport(); - } - - private static List toTestDirs(ProjectReport projectReport) { - return Stream - .of(Path.of(normalizeModuleName(projectReport.getBasedir()))).flatMap(baseDir -> Stream - .of(baseDir.resolve(MAVEN_FAILSAFE_REPORTS_PATH), baseDir.resolve(MAVEN_SUREFIRE_REPORTS_PATH))) - .filter(Files::exists).map(Path::toFile).toList(); + private static List toTestDirs(Project project) { + return Stream.of(project.baseDir()).flatMap(baseDir -> Stream.of(baseDir.resolve(MAVEN_FAILSAFE_REPORTS_PATH), + baseDir.resolve(MAVEN_SUREFIRE_REPORTS_PATH))).filter(Files::exists).map(Path::toFile).toList(); } - private static Stream testDirsToFlakyTests(List testDirs, ProjectReport projectReport) { + private static Stream testDirsToFlakyTests(List testDirs, Project project) { if (testDirs.isEmpty()) { return Stream.empty(); } return new SurefireReportParser(testDirs, new NullConsoleLogger()).parseXMLReportFiles().stream() .filter(r -> r.getNumberOfFlakes() > 0).map(ReportTestSuite::getTestCases).flatMap(Collection::stream) .filter(ReportTestCase::hasFlakes) - .flatMap(reportTestCase -> FlakyTest.newInstances(reportTestCase, projectReport)); - } - - private static String normalizeModuleName(String moduleName) { - return moduleName.replace('\\', '/'); + .flatMap(reportTestCase -> FlakyTest.newInstances(reportTestCase, project)); } } diff --git a/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/FlakyTest.java b/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/FlakyTest.java index 07a6f1d..0da876e 100644 --- a/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/FlakyTest.java +++ b/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/FlakyTest.java @@ -1,6 +1,5 @@ package io.quarkus.qe.reporter.flakyrun.reporter; -import io.quarkus.bot.build.reporting.model.ProjectReport; import org.apache.maven.plugins.surefire.report.ReportTestCase; import java.time.ZonedDateTime; @@ -9,18 +8,18 @@ public record FlakyTest(String projectName, String projectBaseDir, String fullTestName, String failureMessage, String failureType, String failureStackTrace, String dateTime) { - static Stream newInstances(ReportTestCase reportTestCase, ProjectReport projectReport) { + static Stream newInstances(ReportTestCase reportTestCase, Project project) { final String now = ZonedDateTime.now().toString(); Stream result = Stream.empty(); if (!reportTestCase.getFlakyFailures().isEmpty()) { result = reportTestCase.getFlakyFailures().stream() - .map(s -> new FlakyTest(projectReport.getName(), projectReport.getBasedir(), - reportTestCase.getFullName(), s.getMessage(), s.getType(), s.getStackTrace(), now)); + .map(s -> new FlakyTest(project.name(), project.baseDir().toString(), reportTestCase.getFullName(), + s.getMessage(), s.getType(), s.getStackTrace(), now)); } if (!reportTestCase.getFlakyErrors().isEmpty()) { result = Stream.concat(result, reportTestCase.getFlakyErrors().stream() - .map(s -> new FlakyTest(projectReport.getName(), projectReport.getBasedir(), + .map(s -> new FlakyTest(project.name(), project.baseDir().toString(), reportTestCase.getFullName(), s.getMessage(), s.getType(), s.getStackTrace(), now))); } diff --git a/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/Project.java b/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/Project.java new file mode 100644 index 0000000..9daa0f1 --- /dev/null +++ b/src/main/java/io/quarkus/qe/reporter/flakyrun/reporter/Project.java @@ -0,0 +1,6 @@ +package io.quarkus.qe.reporter.flakyrun.reporter; + +import java.nio.file.Path; + +public record Project(String name, Path baseDir) { +}