1717package org .springframework .cloud .kubernetes .integration .tests .commons ;
1818
1919import java .io .File ;
20- import java .io .IOException ;
2120import java .io .InputStream ;
2221import java .nio .charset .StandardCharsets ;
2322import java .nio .file .Files ;
4140import org .testcontainers .k3s .K3sContainer ;
4241
4342import org .springframework .core .io .ClassPathResource ;
44- import org .springframework .util .ReflectionUtils ;
4543import org .springframework .util .StreamUtils ;
4644import org .springframework .util .StringUtils ;
4745
@@ -61,21 +59,6 @@ public final class Commons {
6159
6260 private static String POM_VERSION ;
6361
64- static {
65- try (InputStream in = new ClassPathResource (KUBERNETES_VERSION_FILE ).getInputStream ()) {
66- String version = StreamUtils .copyToString (in , StandardCharsets .UTF_8 );
67- if (StringUtils .hasText (version )) {
68- version = version .trim ();
69- }
70- POM_VERSION = version ;
71- }
72- catch (IOException e ) {
73- ReflectionUtils .rethrowRuntimeException (e );
74- }
75- // not reachable since exception rethrown at runtime
76- POM_VERSION = null ;
77- }
78-
7962 private static final Log LOG = LogFactory .getLog (Commons .class );
8063
8164 private Commons () {
@@ -224,6 +207,18 @@ public static void pullImage(String image, String tag, K3sContainer container) t
224207 }
225208
226209 public static String pomVersion () {
210+ if (POM_VERSION == null ) {
211+ try (InputStream in = new ClassPathResource (KUBERNETES_VERSION_FILE ).getInputStream ()) {
212+ String version = StreamUtils .copyToString (in , StandardCharsets .UTF_8 );
213+ if (StringUtils .hasText (version )) {
214+ POM_VERSION = version .trim ();
215+ }
216+ }
217+ catch (Exception e ) {
218+ throw new RuntimeException (e );
219+ }
220+ }
221+
227222 return POM_VERSION ;
228223 }
229224
0 commit comments