88import java .io .FileInputStream ;
99import java .io .FileWriter ;
1010import java .io .IOException ;
11+ import java .io .InputStream ;
1112import java .io .InputStreamReader ;
13+ import java .util .Properties ;
1214import java .net .Authenticator ;
1315import java .net .ServerSocket ;
1416import java .util .HashMap ;
2527import ssh .TunnelPoller ;
2628
2729public 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