11package io .quarkus .cli .common ;
22
3- import java .io .InputStream ;
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
45import java .net .URL ;
56import java .nio .file .Files ;
6- import java .nio .file .Paths ;
77import java .util .Properties ;
88
9+ import io .quarkus .runtime .util .ClassPathUtils ;
10+
911/**
1012 * Helper class to get client version without circular dependencies
1113 */
@@ -20,24 +22,31 @@ public static String clientVersion() {
2022 final Properties props = new Properties ();
2123 final URL quarkusPropertiesUrl = Thread .currentThread ().getContextClassLoader ().getResource ("quarkus.properties" );
2224 if (quarkusPropertiesUrl == null ) {
23- return "999-SNAPSHOT" ; // fallback version
25+ throw new RuntimeException ( "Failed to locate quarkus.properties on the classpath" );
2426 }
2527
26- try {
27- // Handle file and jar URLs differently to avoid file locks on Windows
28- if (quarkusPropertiesUrl .getProtocol ().equals ("file" )) {
29- try (InputStream is = Files .newInputStream (Paths .get (quarkusPropertiesUrl .toURI ()))) {
30- props .load (is );
31- }
32- } else {
33- try (InputStream is = quarkusPropertiesUrl .openStream ()) {
34- props .load (is );
28+ // we have a special case for file and jar as using getResourceAsStream() on Windows might cause file locks
29+ if ("file" .equals (quarkusPropertiesUrl .getProtocol ()) || "jar" .equals (quarkusPropertiesUrl .getProtocol ())) {
30+ ClassPathUtils .consumeAsPath (quarkusPropertiesUrl , p -> {
31+ try (BufferedReader reader = Files .newBufferedReader (p )) {
32+ props .load (reader );
33+ } catch (IOException e ) {
34+ throw new RuntimeException ("Failed to load quarkus.properties" , e );
3535 }
36+ });
37+ } else {
38+ try {
39+ props .load (Thread .currentThread ().getContextClassLoader ().getResourceAsStream ("quarkus.properties" ));
40+ } catch (IOException e ) {
41+ throw new IllegalStateException ("Failed to load quarkus.properties" , e );
3642 }
37- version = props .getProperty ("quarkus-core-version" , "999-SNAPSHOT" );
38- } catch (Exception e ) {
39- version = "999-SNAPSHOT" ; // fallback version
4043 }
44+
45+ version = props .getProperty ("quarkus-core-version" );
46+ if (version == null ) {
47+ throw new RuntimeException ("Failed to locate quarkus-core-version property in the bundled quarkus.properties" );
48+ }
49+
4150 return version ;
4251 }
4352}
0 commit comments