Skip to content

Commit 5ce00f3

Browse files
committed
CLDR-14409 make URL configurable, read from local file
1 parent 8455124 commit 5ce00f3

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<groupId>org.seleniumhq.selenium</groupId>
2929
<artifactId>selenium-java</artifactId>
3030
<version>4.16.1</version>
31-
</dependency>
31+
</dependency>
3232
<dependency>
3333
<groupId>org.apache.logging.log4j</groupId>
3434
<artifactId>log4j-api</artifactId>

src/test/java/org/unicode/cldr/surveydriver/SurveyDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class SurveyDriver {
6969
/*
7070
* Configure for Survey Tool server, which can be localhost, cldr-smoke, cldr-staging, ...
7171
*/
72-
static final String BASE_URL = "http://localhost:9080/cldr-apps/";
72+
static final String BASE_URL = SurveyDriverCredentials.getUrl() + "/cldr-apps/";
7373
// static final String BASE_URL = "https://cldr-smoke.unicode.org/cldr-apps/";
7474
// static final String BASE_URL = "https://cldr-staging.unicode.org/cldr-apps/";
7575

src/test/java/org/unicode/cldr/surveydriver/SurveyDriverCredentials.java

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.unicode.cldr.surveydriver;
22

3+
import java.io.FileInputStream;
34
import java.io.IOException;
45
import java.io.InputStream;
56
import 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

Comments
 (0)