Skip to content

Commit 03f14d9

Browse files
committed
Bring back the original implementation of getting version in CLI
I think the main issue that Ioannis tried to work around was an artifact missing. This should handle the problem properly.
1 parent abb793a commit 03f14d9

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

devtools/cli-common/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
1212

13-
<properties>
14-
<quarkus.package.jar.type>uber-jar</quarkus.package.jar.type>
15-
</properties>
16-
1713
<artifactId>quarkus-cli-common</artifactId>
18-
<name>Quarkus - Command Line Common Uitility Classes</name>
14+
<name>Quarkus - Command Line Interface - Common Utility Classes</name>
1915
<description>Quarkus command line common utility classes</description>
2016

2117
<dependencies>
@@ -35,6 +31,10 @@
3531
<groupId>io.quarkus</groupId>
3632
<artifactId>quarkus-devtools-registry-client</artifactId>
3733
</dependency>
34+
<dependency>
35+
<groupId>io.quarkus</groupId>
36+
<artifactId>quarkus-project-core-extension-codestarts</artifactId>
37+
</dependency>
3838
<dependency>
3939
<groupId>org.junit.jupiter</groupId>
4040
<artifactId>junit-jupiter</artifactId>
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package io.quarkus.cli.common;
22

3-
import java.io.InputStream;
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
45
import java.net.URL;
56
import java.nio.file.Files;
6-
import java.nio.file.Paths;
77
import 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

Comments
 (0)