From 093d20d4c32af7254002aaf52121f9f228f31f39 Mon Sep 17 00:00:00 2001 From: Vasili Gulevich Date: Tue, 19 May 2026 23:05:01 +0400 Subject: [PATCH] Save screenshot to build output directory eclipse-platform/eclipse.platform.swt#3303 As screenshots are effectively a build artifact, save them in build output directory (target/ by default). SWT does not use Platform, so existing heuristics have not worked in GitHub Actions, abandoning screenshots in /tmp without archiving into artifacts. The change breaks existing Gerrit jobs by removing public method `Screenshots.isRunByGerritHudsonJob()`, but as Gerrit is no longer used, this should be fine. --- .github/workflows/mavenBuild.yml | 2 +- eclipse-platform-parent/pom.xml | 9 ++++ .../src/org/eclipse/test/Screenshots.java | 53 +++++++++---------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.github/workflows/mavenBuild.yml b/.github/workflows/mavenBuild.yml index 23946e6b41b..0fd5e9bd4e2 100644 --- a/.github/workflows/mavenBuild.yml +++ b/.github/workflows/mavenBuild.yml @@ -94,4 +94,4 @@ jobs: if-no-files-found: warn path: | ${{ github.workspace }}/**/target/surefire-reports/*.xml - ${{ github.workspace }}/**/results/**/*.png + ${{ github.workspace }}/**/target/screenshots/*.png diff --git a/eclipse-platform-parent/pom.xml b/eclipse-platform-parent/pom.xml index 2f9c91174d0..1ae1240c86d 100644 --- a/eclipse-platform-parent/pom.xml +++ b/eclipse-platform-parent/pom.xml @@ -131,6 +131,7 @@ 1200 + ${project.build.directory}/screenshots 17 false false @@ -343,6 +344,11 @@ org.apache.maven.plugins maven-surefire-plugin ${surefire.version} + + + ${surefire.screenshot_directory} + + org.apache.maven.plugins @@ -434,6 +440,9 @@ true ${surefire.testArgLine} ${surefire.platformSystemProperties} ${surefire.systemProperties} ${surefire.moduleProperties} true + + ${surefire.screenshot_directory} + diff --git a/eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/Screenshots.java b/eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/Screenshots.java index 864d54df626..ee774c50737 100644 --- a/eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/Screenshots.java +++ b/eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/Screenshots.java @@ -103,27 +103,34 @@ public static String takeScreenshot(Class testClass, String name) { return filename; } - /** - * @return unspecified - * @noreference This method is not intended to be referenced by clients. - */ - public static File getResultsDirectory() { - File resultsDir = getJunitReportOutput(); // ends up in testresults/linux.gtk.x86_6.0/..png + /** + * @return unspecified + * @noreference This method is not intended to be referenced by clients. + */ + public static File getResultsDirectory() { + File resultsDir = discoverResultsDirectory(); + resultsDir.mkdirs(); + return resultsDir; + } - if (resultsDir == null) { - File eclipseDir = new File("").getAbsoluteFile(); - if (isRunByGerritHudsonJob()) { - resultsDir = new File(eclipseDir, "/../").getAbsoluteFile(); // ends up in the workspace root - } else { - resultsDir = new File(System.getProperty("java.io.tmpdir")); - } - } + private static File discoverResultsDirectory() { + File resultsDir = getJunitReportOutput(); // ends up in testresults/linux.gtk.x86_6.0/..png + if (resultsDir != null) { + return resultsDir; + } + // Set from "surefire.screenshot_directory" Maven property by + // eclipse-platform-parent/pom.xml + String propertyPath = System.getProperty("eclipse.test.screenshot_directory"); + if (propertyPath != null) { + return new File(propertyPath); + } - resultsDir.mkdirs(); - return resultsDir; - } + return new File(System.getProperty("java.io.tmpdir")); + } - private static File getJunitReportOutput() { + private static File getJunitReportOutput() { + // Current implementation only interfaces with Ant test launcher. + // Maven tests do not use "-junitReportOutput" argument. boolean platformAvailable = false; try { Class.forName("org.eclipse.core.runtime.Platform", false, Screenshots.class.getClassLoader()); @@ -140,14 +147,6 @@ private static File getJunitReportOutput() { } } return null; - } - - /** - * @return unspecified - * @noreference This method is not intended to be referenced by clients. - */ - public static boolean isRunByGerritHudsonJob() { - return System.getProperty("user.dir").matches(".*/(?:eclipse|rt\\.equinox)\\.[^/]+-Gerrit/.*"); - } + } }