Skip to content

Commit

Permalink
Inline format strings in DevServerHelper
Browse files Browse the repository at this point in the history
Summary: Having format strings and values to interpolate separated makes reading the respective calls difficult. It has also led to situations where format strings were reused with slightly different values, instead of creating a parameterized method.

Reviewed By: pakoito

Differential Revision: D6900905

fbshipit-source-id: 68b56af6a86c0b46bc8cf9c44fbe0fb93ee151ac
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Feb 7, 2018
1 parent d3db764 commit 06d8f96
Showing 1 changed file with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,6 @@
public class DevServerHelper {
public static final String RELOAD_APP_EXTRA_JS_PROXY = "jsproxy";

private static final String BUNDLE_URL_FORMAT =
"http://%s/%s.%s?platform=android&dev=%s&minify=%s";
private static final String RESOURCE_URL_FORMAT = "http://%s/%s";
private static final String LAUNCH_JS_DEVTOOLS_COMMAND_URL_FORMAT =
"http://%s/launch-js-devtools";
private static final String ONCHANGE_ENDPOINT_URL_FORMAT =
"http://%s/onchange";
private static final String WEBSOCKET_PROXY_URL_FORMAT = "ws://%s/debugger-proxy?role=client";
private static final String PACKAGER_STATUS_URL_FORMAT = "http://%s/status";
private static final String INSPECTOR_DEVICE_URL_FORMAT = "http://%s/inspector/device?name=%s&app=%s";
private static final String INSPECTOR_ATTACH_URL_FORMAT = "http://%s/nuclide/attach-debugger-nuclide?title=%s&app=%s&device=%s";
private static final String SYMBOLICATE_URL_FORMAT = "http://%s/symbolicate";
private static final String OPEN_STACK_FRAME_URL_FORMAT = "http://%s/open-stack-frame";

private static final String PACKAGER_OK_STATUS = "packager-status:running";

private static final int LONG_POLL_KEEP_ALIVE_DURATION_MS = 2 * 60 * 1000; // 2 mins
Expand Down Expand Up @@ -365,14 +351,14 @@ public void onResponse(Call call, final Response response) throws IOException {
public String getWebsocketProxyURL() {
return String.format(
Locale.US,
WEBSOCKET_PROXY_URL_FORMAT,
"ws://%s/debugger-proxy?role=client",
mSettings.getPackagerConnectionSettings().getDebugServerHost());
}

private String getInspectorDeviceUrl() {
return String.format(
Locale.US,
INSPECTOR_DEVICE_URL_FORMAT,
"http://%s/inspector/device?name=%s&app=%s",
mSettings.getPackagerConnectionSettings().getInspectorServerHost(),
AndroidInfoHelpers.getFriendlyDeviceName(),
mPackageName);
Expand All @@ -381,7 +367,7 @@ private String getInspectorDeviceUrl() {
private String getInspectorAttachUrl(String title) {
return String.format(
Locale.US,
INSPECTOR_ATTACH_URL_FORMAT,
"http://%s/nuclide/attach-debugger-nuclide?title=%s&app=%s&device=%s",
AndroidInfoHelpers.getServerHost(),
title,
mPackageName,
Expand Down Expand Up @@ -426,7 +412,7 @@ private boolean getJSMinifyMode() {
private String createBundleURL(String mainModuleID, BundleType type, String host) {
return String.format(
Locale.US,
BUNDLE_URL_FORMAT,
"http://%s/%s.%s?platform=android&dev=%s&minify=%s",
host,
mainModuleID,
type.typeID(),
Expand All @@ -440,15 +426,15 @@ private String createBundleURL(String mainModuleID, BundleType type) {
}

private static String createResourceURL(String host, String resourcePath) {
return String.format(Locale.US, RESOURCE_URL_FORMAT, host, resourcePath);
return String.format(Locale.US, "http://%s/%s", host, resourcePath);
}

private static String createSymbolicateURL(String host) {
return String.format(Locale.US, SYMBOLICATE_URL_FORMAT, host);
return String.format(Locale.US, "http://%s/symbolicate", host);
}

private static String createOpenStackFrameURL(String host) {
return String.format(Locale.US, OPEN_STACK_FRAME_URL_FORMAT, host);
return String.format(Locale.US, "http://%s/open-stack-frame", host);
}

public String getDevServerBundleURL(final String jsModulePath) {
Expand Down Expand Up @@ -508,7 +494,7 @@ public void onResponse(Call call, Response response) throws IOException {
}

private static String createPackagerStatusURL(String host) {
return String.format(Locale.US, PACKAGER_STATUS_URL_FORMAT, host);
return String.format(Locale.US, "http://%s/status", host);
}

public void stopPollingOnChangeEndpoint() {
Expand Down Expand Up @@ -583,14 +569,14 @@ public void onResponse(Call call, Response response) throws IOException {
private String createOnChangeEndpointUrl() {
return String.format(
Locale.US,
ONCHANGE_ENDPOINT_URL_FORMAT,
"http://%s/onchange",
mSettings.getPackagerConnectionSettings().getDebugServerHost());
}

private String createLaunchJSDevtoolsCommandUrl() {
return String.format(
Locale.US,
LAUNCH_JS_DEVTOOLS_COMMAND_URL_FORMAT,
"http://%s/launch-js-devtools",
mSettings.getPackagerConnectionSettings().getDebugServerHost());
}

Expand Down

0 comments on commit 06d8f96

Please sign in to comment.