Skip to content

Commit

Permalink
Use System#lineSeparator to replace /n (#12889)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanwenjun authored Nov 15, 2022
1 parent 6d8befa commit 92a9b7e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -135,7 +134,6 @@ private void buildProcess(String commandFile) throws IOException {
}
}
command.add(commandInterpreter());
command.addAll(Collections.emptyList());
command.add(commandFile);

// setting commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,24 @@ protected void createCommandFileIfNotExists(String execCommand, String commandFi

StringBuilder sb = new StringBuilder();
if (SystemUtils.IS_OS_WINDOWS) {
sb.append("@echo off\n");
sb.append("cd /d %~dp0\n");
sb.append("@echo off").append(System.lineSeparator());
sb.append("cd /d %~dp0").append(System.lineSeparator());
if (StringUtils.isNotBlank(taskRequest.getEnvironmentConfig())) {
sb.append(taskRequest.getEnvironmentConfig()).append("\n");
sb.append(taskRequest.getEnvironmentConfig()).append(System.lineSeparator());
} else {
if (taskRequest.getEnvFile() != null) {
sb.append("call ").append(taskRequest.getEnvFile()).append("\n");
sb.append("call ").append(taskRequest.getEnvFile()).append(System.lineSeparator());
}
}
} else {
sb.append("#!/bin/bash\n");
sb.append("BASEDIR=$(cd `dirname $0`; pwd)\n");
sb.append("cd $BASEDIR\n");
sb.append("#!/bin/bash").append(System.lineSeparator());
sb.append("BASEDIR=$(cd `dirname $0`; pwd)").append(System.lineSeparator());
sb.append("cd $BASEDIR").append(System.lineSeparator());
if (StringUtils.isNotBlank(taskRequest.getEnvironmentConfig())) {
sb.append(taskRequest.getEnvironmentConfig()).append("\n");
sb.append(taskRequest.getEnvironmentConfig()).append(System.lineSeparator());
} else {
if (taskRequest.getEnvFile() != null) {
sb.append("source ").append(taskRequest.getEnvFile()).append("\n");
sb.append("source ").append(taskRequest.getEnvFile()).append(System.lineSeparator());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private String buildDataxJsonFile(Map<String, Property> paramsMap) throws Except
}

if (dataXParameters.getCustomConfig() == Flag.YES.ordinal()) {
json = dataXParameters.getJson().replaceAll("\\r\\n", "\n");
json = dataXParameters.getJson().replaceAll("\\r\\n", System.lineSeparator());
} else {
ObjectNode job = JSONUtils.createObjectNode();
job.putArray("content").addAll(buildDataxJobContentJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void init() {

@Override
public String getPreScript() {
String rawPythonScript = pythonParameters.getRawScript().replaceAll("\\r\\n", "\n");
String rawPythonScript = pythonParameters.getRawScript().replaceAll("\\r\\n", System.lineSeparator());
try {
rawPythonScript = convertPythonScriptPlaceholders(rawPythonScript);
} catch (StringIndexOutOfBoundsException e) {
Expand Down Expand Up @@ -182,9 +182,9 @@ protected void createPythonCommandFileIfNotExists(String pythonScript, String py
logger.info("generate python script file:{}", pythonScriptFile);

StringBuilder sb = new StringBuilder();
sb.append("#-*- encoding=utf8 -*-\n");
sb.append("#-*- encoding=utf8 -*-").append(System.lineSeparator());

sb.append("\n\n");
sb.append(System.lineSeparator());
sb.append(pythonScript);
logger.info(sb.toString());

Expand Down Expand Up @@ -212,7 +212,7 @@ protected String buildPythonCommandFilePath() {
*/
protected String buildPythonScriptContent() throws Exception {
logger.info("raw python script : {}", pythonParameters.getRawScript());
String rawPythonScript = pythonParameters.getRawScript().replaceAll("\\r\\n", "\n");
String rawPythonScript = pythonParameters.getRawScript().replaceAll("\\r\\n", System.lineSeparator());
Map<String, Property> paramsMap = mergeParamsWithContext(pythonParameters);
return ParameterUtils.convertParameterPlaceholders(rawPythonScript, ParamUtils.convert(paramsMap));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected String buildCustomConfigCommand() throws Exception {

private String buildCustomConfigContent() {
logger.info("raw custom config content : {}", seatunnelParameters.getRawScript());
String script = seatunnelParameters.getRawScript().replaceAll("\\r\\n", "\n");
String script = seatunnelParameters.getRawScript().replaceAll("\\r\\n", System.lineSeparator());
script = parseScript(script);
return script;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private String buildCommand() throws Exception {
return fileName;
}

String script = shellParameters.getRawScript().replaceAll("\\r\\n", "\n");
String script = shellParameters.getRawScript().replaceAll("\\r\\n", System.lineSeparator());
script = parseScript(script);
shellParameters.setRawScript(script);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private String generateScriptFile() {
}

private String replaceParam(String script) {
script = script.replaceAll("\\r\\n", "\n");
script = script.replaceAll("\\r\\n", System.lineSeparator());
// replace placeholder, and combining local and global parameters
Map<String, Property> paramsMap = taskExecutionContext.getPrepareParamsMap();
script = ParameterUtils.convertParameterPlaceholders(script, ParamUtils.convert(paramsMap));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public String generateSqoopJob(SqoopParameters sqoopParameters,
sourceGenerator.generate(sqoopParameters, sqoopTaskExecutionContext),
targetGenerator.generate(sqoopParameters, sqoopTaskExecutionContext));
} else if (SqoopJobType.CUSTOM.getDescp().equals(sqoopParameters.getJobType())) {
sqoopScripts = sqoopParameters.getCustomShell().replaceAll("\\r\\n", "\n");
sqoopScripts = sqoopParameters.getCustomShell().replaceAll("\\r\\n", System.lineSeparator());
}

return sqoopScripts;
Expand Down

0 comments on commit 92a9b7e

Please sign in to comment.