Skip to content

Commit e27b0ad

Browse files
parse version from pom.xml
1 parent 6fd5a37 commit e27b0ad

File tree

1 file changed

+21
-1
lines changed
  • src/main/java/com/testingbot/tunnel

1 file changed

+21
-1
lines changed

src/main/java/com/testingbot/tunnel/App.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import java.io.FileInputStream;
99
import java.io.FileWriter;
1010
import java.io.IOException;
11+
import java.io.InputStream;
1112
import java.io.InputStreamReader;
13+
import java.util.Properties;
1214
import java.net.Authenticator;
1315
import java.net.ServerSocket;
1416
import java.util.HashMap;
@@ -25,7 +27,7 @@
2527
import ssh.TunnelPoller;
2628

2729
public class App {
28-
public static final Float VERSION = 4.1f;
30+
public static final Float VERSION = getVersionFromProperties();
2931
private Api api;
3032
private String clientKey;
3133
private String clientSecret;
@@ -51,6 +53,24 @@ public class App {
5153
private int metricsPort = 8003;
5254
private int sshPort = 0;
5355

56+
private static Float getVersionFromProperties() {
57+
try (InputStream input = App.class.getClassLoader().getResourceAsStream("version.properties")) {
58+
if (input == null) {
59+
return 0.0f;
60+
}
61+
Properties prop = new Properties();
62+
prop.load(input);
63+
String version = prop.getProperty("version");
64+
if (version != null) {
65+
String numericVersion = version.replaceAll("-SNAPSHOT", "").replaceAll("[^0-9.]", "");
66+
return Float.parseFloat(numericVersion);
67+
}
68+
} catch (IOException | NumberFormatException ex) {
69+
Logger.getLogger(App.class.getName()).log(Level.WARNING, "Could not read version from properties, using fallback", ex);
70+
}
71+
return 0.0f;
72+
}
73+
5474
public static void main(String... args) throws Exception {
5575

5676
final CommandLineParser cmdLinePosixParser = new PosixParser();

0 commit comments

Comments
 (0)