Skip to content

Commit bc6e670

Browse files
authored
Merge pull request #50662 from gsmet/fix-cli-version
Fix version resolution in CLI
2 parents eb1b8dd + 03f14d9 commit bc6e670

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-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.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
}

devtools/cli/src/test/java/io/quarkus/cli/CliVersionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public void testCommandVersion() throws Exception {
1818
"Version output for command aliases should be the same.");
1919

2020
CliDriver.Result result2 = CliDriver.execute(workspaceRoot, "--version");
21+
result2.echoSystemOut();
2122
Assertions.assertEquals(result.stdout, result2.stdout, "Version output for command aliases should be the same.");
2223
}
2324
}

0 commit comments

Comments
 (0)