11package org .unicode .cldr .surveydriver ;
22
3+ import java .io .FileInputStream ;
34import java .io .IOException ;
45import java .io .InputStream ;
56import java .util .Properties ;
@@ -20,6 +21,7 @@ public class SurveyDriverCredentials {
2021 private static final String PROPS_FILENAME = "surveydriver.properties" ;
2122
2223 private static final String PROPS_PASSWORD_KEY = "WEBDRIVER_PASSWORD" ;
24+ private static final String PROPS_URL_KEY = "SURVEYTOOL_URL" ;
2325 private static String webdriverPassword = null ;
2426
2527 private final String email ;
@@ -41,25 +43,63 @@ public String getEmail() {
4143 return email ;
4244 }
4345
46+ private static final class PropsHelper {
47+ public final Properties props = new java .util .Properties ();
48+
49+ PropsHelper () {
50+ if (!tryFromFile ()) {
51+ tryFromResource ();
52+ }
53+ }
54+
55+ boolean tryFromFile () {
56+ try (final InputStream stream = new FileInputStream (PROPS_FILENAME )) {
57+ props .load (stream );
58+ return true ;
59+ } catch (IOException e ) {
60+ System .err .println ("While reading " + PROPS_FILENAME + " " + e );
61+ e .printStackTrace ();
62+ return false ;
63+ }
64+ }
65+
66+ void tryFromResource () {
67+ final InputStream stream =
68+ SurveyDriverCredentials .class .getResourceAsStream (PROPS_FILENAME );
69+ if (stream == null ) {
70+ throw new RuntimeException ("File not found: " + PROPS_FILENAME );
71+ }
72+ try {
73+ props .load (stream );
74+ } catch (IOException e ) {
75+ throw new RuntimeException (e );
76+ }
77+ }
78+
79+ static final PropsHelper INSTANCE = new PropsHelper ();
80+ }
81+
82+ public static Properties getProperties () {
83+ return PropsHelper .INSTANCE .props ;
84+ }
85+
4486 public String getPassword () {
4587 if (webdriverPassword != null ) {
4688 return webdriverPassword ;
4789 }
48- final InputStream stream =
49- SurveyDriverCredentials .class .getResourceAsStream (PROPS_FILENAME );
50- if (stream == null ) {
51- throw new RuntimeException ("File not found: " + PROPS_FILENAME );
52- }
53- final Properties props = new java .util .Properties ();
54- try {
55- props .load (stream );
56- } catch (IOException e ) {
57- throw new RuntimeException (e );
58- }
59- webdriverPassword = (String ) props .get (PROPS_PASSWORD_KEY );
90+
91+ webdriverPassword = (String ) getProperties ().get (PROPS_PASSWORD_KEY );
6092 if (webdriverPassword == null || webdriverPassword .isBlank ()) {
6193 throw new RuntimeException ("WEBDRIVER_PASSWORD not found in " + PROPS_FILENAME );
6294 }
6395 return webdriverPassword ;
6496 }
97+
98+ public static String getUrl () {
99+ String host = getProperties ().get (PROPS_URL_KEY ).toString ();
100+ if (host == null || host .isEmpty ()) {
101+ host = "http://localhost:9080" ;
102+ }
103+ return host ;
104+ }
65105}
0 commit comments