24
24
import java .nio .file .Path ;
25
25
import java .nio .file .SimpleFileVisitor ;
26
26
import java .nio .file .attribute .BasicFileAttributes ;
27
+ import java .time .Instant ;
28
+ import java .time .LocalDateTime ;
29
+ import java .time .OffsetDateTime ;
30
+ import java .time .ZonedDateTime ;
31
+ import java .time .format .DateTimeFormatter ;
32
+ import java .time .temporal .ChronoUnit ;
33
+ import java .time .temporal .TemporalAccessor ;
27
34
import java .util .ArrayList ;
28
35
import java .util .Collections ;
29
36
import java .util .HashMap ;
@@ -64,6 +71,7 @@ private static Document parse(Path testReport) {
64
71
}
65
72
}
66
73
74
+ @ SuppressWarnings ("JavaTimeDefaultTimeZone" )
67
75
private void scanTestFile (Path testReport ) {
68
76
Document doc = parse (testReport );
69
77
doc .getDocumentElement ().normalize ();
@@ -80,6 +88,29 @@ private void scanTestFile(Path testReport) {
80
88
return ;
81
89
}
82
90
91
+ // google sheets don't automatically recognize dates with time zone, here we reformat the date
92
+ // so that it wouldn't have the time zone
93
+ TemporalAccessor ta =
94
+ DateTimeFormatter .ISO_DATE_TIME .parseBest (
95
+ timestamp , ZonedDateTime ::from , LocalDateTime ::from );
96
+ timestamp = DateTimeFormatter .ISO_LOCAL_DATE_TIME .format (ta );
97
+
98
+ // when test result file was modified more than 20 minutes after the time in the results file
99
+ // then the test results were restored from gradle cache and the test wasn't actually executed
100
+ Instant reportModified = Instant .ofEpochMilli (testReport .toFile ().lastModified ());
101
+ reportModified = reportModified .minus (20 , ChronoUnit .MINUTES );
102
+ Instant testExecuted = null ;
103
+ if (ta instanceof ZonedDateTime ) {
104
+ testExecuted = ((ZonedDateTime ) ta ).toInstant ();
105
+ } else if (ta instanceof LocalDateTime ) {
106
+ testExecuted = ((LocalDateTime ) ta ).toInstant (OffsetDateTime .now ().getOffset ());
107
+ }
108
+ if (testExecuted != null && reportModified .isAfter (testExecuted )) {
109
+ System .err .println (
110
+ "Ignoring " + testReport + " since it appears to be restored from gradle build cache" );
111
+ return ;
112
+ }
113
+
83
114
class TestCase {
84
115
final String className ;
85
116
final String name ;
0 commit comments