14
14
import org .prebid .server .util .ResourceUtil ;
15
15
16
16
import java .io .IOException ;
17
+ import java .util .regex .Matcher ;
18
+ import java .util .regex .Pattern ;
17
19
18
20
/**
19
21
* Handles HTTP request for pbs project version.
@@ -22,7 +24,7 @@ public class VersionHandler implements Handler<RoutingContext> {
22
24
23
25
private static final Logger logger = LoggerFactory .getLogger (VersionHandler .class );
24
26
25
- private static final String NOT_SET = "not-set " ;
27
+ private static final String UNDEFINED = "undefined " ;
26
28
27
29
private final String revisionResponseBody ;
28
30
@@ -36,22 +38,29 @@ public static VersionHandler create(String revisionFilePath, JacksonMapper mappe
36
38
revision = mapper .mapper ().readValue (ResourceUtil .readFromClasspath (revisionFilePath ), Revision .class );
37
39
} catch (IllegalArgumentException | IOException e ) {
38
40
logger .error ("Was not able to read revision file {0}. Reason: {1}" , revisionFilePath , e .getMessage ());
39
- revision = Revision .of ( NOT_SET , NOT_SET ) ;
41
+ revision = Revision .EMPTY ;
40
42
}
41
43
return new VersionHandler (createRevisionResponseBody (revision , mapper ));
42
44
}
43
45
44
46
private static String createRevisionResponseBody (Revision revision , JacksonMapper mapper ) {
45
47
try {
46
48
return mapper .mapper ().writeValueAsString (RevisionResponse .of (
47
- revision .commitHash != null ? revision .commitHash : NOT_SET ,
48
- revision .pbsVersion != null ? revision .pbsVersion : NOT_SET ));
49
+ revision .commitHash != null ? revision .commitHash : UNDEFINED ,
50
+ revision .pbsVersion != null ? extractVersion ( revision .pbsVersion ) : UNDEFINED ));
49
51
} catch (JsonProcessingException e ) {
50
52
logger .error ("/version Critical error when trying to marshal revision response: %s" , e .getMessage ());
51
53
return null ;
52
54
}
53
55
}
54
56
57
+ private static String extractVersion (String buildVersion ) {
58
+ final Pattern versionPattern = Pattern .compile ("\\ d+\\ .\\ d+\\ .\\ d" );
59
+ final Matcher versionMatcher = versionPattern .matcher (buildVersion );
60
+
61
+ return versionMatcher .lookingAt () ? versionMatcher .group () : null ;
62
+ }
63
+
55
64
/**
56
65
* Responds with commit revision.
57
66
*/
@@ -68,6 +77,8 @@ public void handle(RoutingContext context) {
68
77
@ Value
69
78
private static class Revision {
70
79
80
+ private static final Revision EMPTY = Revision .of (null , null );
81
+
71
82
@ JsonProperty ("git.commit.id" )
72
83
String commitHash ;
73
84
0 commit comments