@@ -30,12 +30,18 @@ record BuildConstantsRecord(
3030 */
3131 static Optional <BuildConstantsRecord > fromGeneratedClass (Class <?> buildConstantsClass ) {
3232 try {
33+ ZonedDateTime gitDate = extractZonedDateTime (buildConstantsClass , "GIT_DATE" );
34+ if (gitDate == null ) {
35+ return Optional .empty ();
36+ }
37+ ZonedDateTime buildDate = extractZonedDateTime (buildConstantsClass , "BUILD_DATE" );
38+ if (buildDate == null ) {
39+ return Optional .empty ();
40+ }
3341 String mavenName = (String ) buildConstantsClass .getDeclaredField ("MAVEN_NAME" ).get (null );
3442 int gitRevision = (int ) buildConstantsClass .getDeclaredField ("GIT_REVISION" ).get (null );
3543 String gitSha = (String ) buildConstantsClass .getDeclaredField ("GIT_SHA" ).get (null );
36- String gitDate = (String ) buildConstantsClass .getDeclaredField ("GIT_DATE" ).get (null );
3744 String gitBranch = (String ) buildConstantsClass .getDeclaredField ("GIT_BRANCH" ).get (null );
38- String buildDate = (String ) buildConstantsClass .getDeclaredField ("BUILD_DATE" ).get (null );
3945 long buildTimeMillis =
4046 (long ) buildConstantsClass .getDeclaredField ("BUILD_UNIX_TIME" ).get (null );
4147 int dirty = (int ) buildConstantsClass .getDeclaredField ("DIRTY" ).get (null );
@@ -46,11 +52,11 @@ static Optional<BuildConstantsRecord> fromGeneratedClass(Class<?> buildConstants
4652 gitRevision ,
4753 gitSha ,
4854 gitBranch ,
49- ZonedDateTime . parse ( gitDate , DATE_FORMATTER ) ,
50- ZonedDateTime . parse ( buildDate , DATE_FORMATTER ) ,
55+ gitDate ,
56+ buildDate ,
5157 buildTimeMillis ,
5258 dirty ));
53- } catch (NoSuchFieldException | IllegalAccessException | DateTimeParseException e ) {
59+ } catch (NoSuchFieldException | IllegalAccessException e ) {
5460 String message =
5561 "Could not extract build constants from "
5662 + buildConstantsClass .getSimpleName ()
@@ -68,4 +74,22 @@ String gitSubmitTimeString() {
6874 String buildTimeString () {
6975 return DATE_FORMATTER .format (buildTime );
7076 }
77+
78+ private static ZonedDateTime extractZonedDateTime (Class <?> buildConstantsClass , String fieldName )
79+ throws NoSuchFieldException , IllegalAccessException {
80+ String value = (String ) buildConstantsClass .getDeclaredField (fieldName ).get (null );
81+ try {
82+ return ZonedDateTime .parse (value , DATE_FORMATTER );
83+ } catch (DateTimeParseException e ) {
84+ String message =
85+ "Could not extract build constants from "
86+ + buildConstantsClass .getSimpleName ()
87+ + " due to unparsable date-time value for "
88+ + fieldName
89+ + ": "
90+ + e .getMessage ();
91+ DriverStation .reportWarning (message , e .getStackTrace ());
92+ return null ;
93+ }
94+ }
7195}
0 commit comments