rename JS environment variable (#1214)

This commit is contained in:
William Cheng 2018-10-12 17:03:50 +08:00 committed by GitHub
parent ccf9611ad7
commit 11b7fb4f7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -232,8 +232,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
} }
super.processOpts(); super.processOpts();
if (StringUtils.isEmpty(System.getenv("JS_BEAUTIFY_PATH"))) { if (StringUtils.isEmpty(System.getenv("JS_POST_PROCESS_FILE"))) {
LOGGER.info("Environment variable JS_BEAUTIFY_PATH not defined so the JS code may not be properly formatted. To define it, try 'export JS_BEAUTIFY_PATH=/usr/local/bin/js-beautify' (Linux/Mac)"); LOGGER.info("Environment variable JS_POST_PROCESS_FILE not defined so the JS code may not be properly formatted. To define it, try 'export JS_POST_PROCESS_FILE=\"/usr/local/bin/js-beautify -r -f\"' (Linux/Mac)");
} }
if (additionalProperties.containsKey(PROJECT_NAME)) { if (additionalProperties.containsKey(PROJECT_NAME)) {
@ -1167,19 +1167,20 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
return; return;
} }
String jsBeautifyPath = System.getenv("JS_BEAUTIFY_PATH"); String jsPostProcessFile = System.getenv("JS_POST_PROCESS_FILE");
if (StringUtils.isEmpty(jsBeautifyPath)) { if (StringUtils.isEmpty(jsPostProcessFile)) {
return; // skip if JS_BEAUTIFY_PATH env variable is not defined return; // skip if JS_POST_PROCESS_FILE env variable is not defined
} }
// only process files with js extension // only process files with js extension
if ("js".equals(FilenameUtils.getExtension(file.toString()))) { if ("js".equals(FilenameUtils.getExtension(file.toString()))) {
String command = jsBeautifyPath + " -r -f " + file.toString(); String command = jsPostProcessFile + " " + file.toString();
try { try {
Process p = Runtime.getRuntime().exec(command); Process p = Runtime.getRuntime().exec(command);
p.waitFor(); p.waitFor();
if (p.exitValue() != 0) { int exitValue = p.exitValue();
LOGGER.error("Error running the command ({}). Exit code: {}", command, p.exitValue()); if (exitValue != 0) {
LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue);
} }
LOGGER.info("Successfully executed: " + command); LOGGER.info("Successfully executed: " + command);
} catch (Exception e) { } catch (Exception e) {
@ -1187,5 +1188,4 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
} }
} }
} }
} }