Skip to content

Commit c897f17

Browse files
committed
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.
1 parent 9c51d36 commit c897f17

3 files changed

Lines changed: 36 additions & 28 deletions

File tree

.github/workflows/mavenBuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ jobs:
9494
if-no-files-found: warn
9595
path: |
9696
${{ github.workspace }}/**/target/surefire-reports/*.xml
97-
${{ github.workspace }}/**/results/**/*.png
97+
${{ github.workspace }}/**/target/screenshots/*.png

eclipse-platform-parent/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<!-- system specific JVM args; if needed provided by system properties to the build command -->
132132
<surefire.systemProperties></surefire.systemProperties>
133133
<surefire.timeout>1200</surefire.timeout>
134+
<surefire.screenshot_directory>${project.build.directory}/screenshots</surefire.screenshot_directory>
134135
<java.version>17</java.version>
135136
<printApiMessages>false</printApiMessages>
136137
<failOnJavadocErrors>false</failOnJavadocErrors>
@@ -343,6 +344,11 @@
343344
<groupId>org.apache.maven.plugins</groupId>
344345
<artifactId>maven-surefire-plugin</artifactId>
345346
<version>${surefire.version}</version>
347+
<configuration>
348+
<systemPropertyVariables>
349+
<eclipse.screenshot_directory>${surefire.screenshot_directory}</eclipse.screenshot_directory>
350+
</systemPropertyVariables>
351+
</configuration>
346352
</plugin>
347353
<plugin>
348354
<groupId>org.apache.maven.plugins</groupId>
@@ -434,6 +440,9 @@
434440
<enableAssertions>true</enableAssertions>
435441
<argLine>${surefire.testArgLine} ${surefire.platformSystemProperties} ${surefire.systemProperties} ${surefire.moduleProperties}</argLine>
436442
<quiet>true</quiet>
443+
<systemProperties>
444+
<eclipse.screenshot_directory>${surefire.screenshot_directory}</eclipse.screenshot_directory>
445+
</systemProperties>
437446
</configuration>
438447
</plugin>
439448
<plugin>

eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/Screenshots.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,34 @@ public static String takeScreenshot(Class<?> testClass, String name) {
103103
return filename;
104104
}
105105

106-
/**
107-
* @return unspecified
108-
* @noreference This method is not intended to be referenced by clients.
109-
*/
110-
public static File getResultsDirectory() {
111-
File resultsDir = getJunitReportOutput(); // ends up in testresults/linux.gtk.x86_6.0/<class>.<test>.png
106+
/**
107+
* @return unspecified
108+
* @noreference This method is not intended to be referenced by clients.
109+
*/
110+
public static File getResultsDirectory() {
111+
File resultsDir = discoverResultsDirectory();
112+
resultsDir.mkdirs();
113+
return resultsDir;
114+
}
112115

113-
if (resultsDir == null) {
114-
File eclipseDir = new File("").getAbsoluteFile();
115-
if (isRunByGerritHudsonJob()) {
116-
resultsDir = new File(eclipseDir, "/../").getAbsoluteFile(); // ends up in the workspace root
117-
} else {
118-
resultsDir = new File(System.getProperty("java.io.tmpdir"));
119-
}
120-
}
116+
private static File discoverResultsDirectory() {
117+
File resultsDir = getJunitReportOutput(); // ends up in testresults/linux.gtk.x86_6.0/<class>.<test>.png
118+
if (resultsDir != null) {
119+
return resultsDir;
120+
}
121+
// Set from "surefire.screenshot_directory" Maven property by
122+
// eclipse-platform-parent/pom.xml
123+
String propertyPath = System.getProperty("eclipse.screenshot_directory");
124+
if (propertyPath != null) {
125+
return new File(propertyPath);
126+
}
121127

122-
resultsDir.mkdirs();
123-
return resultsDir;
124-
}
128+
return new File(System.getProperty("java.io.tmpdir"));
129+
}
125130

126-
private static File getJunitReportOutput() {
131+
private static File getJunitReportOutput() {
132+
// Current implementation only interfaces with Ant test launcher.
133+
// Maven tests do not use "-junitReportOutput" argument.
127134
boolean platformAvailable = false;
128135
try {
129136
Class.forName("org.eclipse.core.runtime.Platform", false, Screenshots.class.getClassLoader());
@@ -140,14 +147,6 @@ private static File getJunitReportOutput() {
140147
}
141148
}
142149
return null;
143-
}
144-
145-
/**
146-
* @return unspecified
147-
* @noreference This method is not intended to be referenced by clients.
148-
*/
149-
public static boolean isRunByGerritHudsonJob() {
150-
return System.getProperty("user.dir").matches(".*/(?:eclipse|rt\\.equinox)\\.[^/]+-Gerrit/.*");
151-
}
150+
}
152151

153152
}

0 commit comments

Comments
 (0)