From f3dca6c7199938bd91efa1a5743396e456406c26 Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Tue, 12 Nov 2024 08:38:29 +0100 Subject: [PATCH] chore: Use single report output directory - Make sure to us single output directory for generated reports in particular when running Citrus via JBang --- .../citrusframework/report/TestReporterSettings.java | 7 ++++++- .../org/citrusframework/testng/TestNGEngine.java | 2 ++ .../java/org/citrusframework/jbang/commands/Run.java | 12 +++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/citrus-api/src/main/java/org/citrusframework/report/TestReporterSettings.java b/core/citrus-api/src/main/java/org/citrusframework/report/TestReporterSettings.java index 62de765d1b..1b5c08fd2a 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/report/TestReporterSettings.java +++ b/core/citrus-api/src/main/java/org/citrusframework/report/TestReporterSettings.java @@ -31,6 +31,7 @@ private TestReporterSettings() { private static final String REPORT_DIRECTORY_PROPERTY = "citrus.report.directory"; private static final String REPORT_DIRECTORY_ENV = "CITRUS_REPORT_DIRECTORY"; + private static final String REPORT_DIRECTORY_DEFAULT = "target/citrus-reports"; /** * Get setting if report should automatically clear all test results after finishing the test suite. Default value @@ -57,6 +58,10 @@ public static boolean isIgnoreErrors() { */ public static String getReportDirectory() { return System.getProperty(REPORT_DIRECTORY_PROPERTY, System.getenv(REPORT_DIRECTORY_ENV) != null ? - System.getenv(REPORT_DIRECTORY_ENV) : "target/citrus-reports"); + System.getenv(REPORT_DIRECTORY_ENV) : REPORT_DIRECTORY_DEFAULT); + } + + public static void setReportDirectory(String dir) { + System.setProperty(REPORT_DIRECTORY_PROPERTY, dir); } } diff --git a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java index 69bdca2e3d..90b7ba84b8 100644 --- a/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java +++ b/runtime/citrus-testng/src/main/java/org/citrusframework/testng/TestNGEngine.java @@ -32,6 +32,7 @@ import org.citrusframework.main.TestRunConfiguration; import org.citrusframework.main.scan.ClassPathTestScanner; import org.citrusframework.main.scan.JarFileTestScanner; +import org.citrusframework.report.TestReporterSettings; import org.citrusframework.testng.main.TestNGCitrusTest; import org.citrusframework.util.StringUtils; import org.slf4j.Logger; @@ -64,6 +65,7 @@ public TestNGEngine(TestRunConfiguration configuration) { public void run() { TestNG testng = new TestNG(); + testng.setOutputDirectory(TestReporterSettings.getReportDirectory() + "/" + TestNG.DEFAULT_OUTPUTDIR); for (ITestNGListener listener : listeners) { testng.addListener(listener); diff --git a/tools/jbang/src/main/java/org/citrusframework/jbang/commands/Run.java b/tools/jbang/src/main/java/org/citrusframework/jbang/commands/Run.java index 2768af977e..1c7d87c5af 100644 --- a/tools/jbang/src/main/java/org/citrusframework/jbang/commands/Run.java +++ b/tools/jbang/src/main/java/org/citrusframework/jbang/commands/Run.java @@ -39,6 +39,7 @@ import org.citrusframework.main.TestEngine; import org.citrusframework.main.TestRunConfiguration; import org.citrusframework.report.TestReporter; +import org.citrusframework.report.TestReporterSettings; import org.citrusframework.report.TestResults; import org.citrusframework.util.FileUtils; import picocli.CommandLine.Command; @@ -63,14 +64,14 @@ public class Run extends CitrusCommand { "^\\s*public class\\s+([a-zA-Z0-9]*)[\\s+|;].*$", Pattern.MULTILINE); @Option(names = { "--logging" }, defaultValue = "true", description = "Can be used to turn off logging") - private boolean logging = true; + private final boolean logging = true; @Option(names = { "--logging-level" }, completionCandidates = LoggingSupport.LoggingLevels.class, defaultValue = "info", description = "Logging level") private String loggingLevel; @Option(names = { "--logging-color" }, defaultValue = "true", description = "Use colored logging") - private boolean loggingColor = true; + private final boolean loggingColor = true; @Parameters(description = "The test file(s) to run. If no files specified then application.properties is used as source for which files to run.", arity = "0..9", paramLabel = "", parameterConsumer = FilesConsumer.class) @@ -89,6 +90,7 @@ public Integer call() throws Exception { private int run() throws Exception { File work = new File(WORK_DIR); + TestReporterSettings.setReportDirectory(WORK_DIR + "/citrus-reports"); removeDir(work); if (!work.mkdirs()) { System.err.println("Failed to create working directory " + WORK_DIR); @@ -207,11 +209,7 @@ private boolean skipFile(String name) { String on = FileUtils.getBaseName(name); on = on.toLowerCase(Locale.ROOT); - if (on.endsWith("readme")) { - return true; - } - - return false; + return on.endsWith("readme"); } private static void removeDir(File d) {