rename scala post proessing env variable (#1143)

This commit is contained in:
William Cheng 2018-09-29 21:39:37 +08:00 committed by GitHub
parent 8b47984e3c
commit cbc84254c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,8 +114,8 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
public void processOpts() { public void processOpts() {
super.processOpts(); super.processOpts();
if (StringUtils.isEmpty(System.getenv("SCALAFMT_PATH"))) { if (StringUtils.isEmpty(System.getenv("SCALA_POST_PROCESS_FILE"))) {
LOGGER.info("Environment variable SCALAFMT_PATH not defined so the Scala code may not be properly formatted. To define it, try 'export SCALAFMT_PATH=/usr/local/bin/scalafmt' (Linux/Mac)"); LOGGER.info("Environment variable SCALA_POST_PROCESS_FILE not defined so the Scala code may not be properly formatted. To define it, try 'export SCALA_POST_PROCESS_FILE=/usr/local/bin/scalafmt' (Linux/Mac)");
} }
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) { if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
@ -309,21 +309,22 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
return; return;
} }
String scalafmtPath = System.getenv("SCALAFMT_PATH"); String scalaPostProcessFile = System.getenv("SCALA_POST_PROCESS_FILE");
if (StringUtils.isEmpty(scalafmtPath)) { if (StringUtils.isEmpty(scalaPostProcessFile)) {
return; // skip if SCALAFMT_PATH env variable is not defined return; // skip if SCALA_POST_PROCESS_FILE env variable is not defined
} }
// only process files with scala extension // only process files with scala extension
if ("scala".equals(FilenameUtils.getExtension(file.toString()))) { if ("scala".equals(FilenameUtils.getExtension(file.toString()))) {
String command = scalafmtPath + " " + file.toString(); String command = scalaPostProcessFile + " " + file.toString();
try { try {
Process p = Runtime.getRuntime().exec(command); Process p = Runtime.getRuntime().exec(command);
p.waitFor(); int exitValue = p.waitFor();
if (p.exitValue() != 0) { if (exitValue != 0) {
LOGGER.error("Error running the command ({}). Exit value: {}", command, p.exitValue()); LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue);
} } else {
LOGGER.info("Successfully executed: " + command); LOGGER.info("Successfully executed: " + command);
}
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage()); LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
} }