Use System#lineSeparator to replace /n (#12889)

This commit is contained in:
Wenjun Ruan 2022-11-15 13:57:45 +08:00 committed by GitHub
parent 6d8befa075
commit 92a9b7e243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 20 deletions

View File

@ -33,7 +33,6 @@ import java.io.File;
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;
@ -135,7 +134,6 @@ public abstract class AbstractCommandExecutor {
}
}
command.add(commandInterpreter());
command.addAll(Collections.emptyList());
command.add(commandFile);
// setting commands

View File

@ -91,24 +91,24 @@ public class ShellCommandExecutor extends AbstractCommandExecutor {
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());
}
}
}

View File

@ -209,7 +209,7 @@ public class DataxTask extends AbstractTask {
}
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());

View File

@ -89,7 +89,7 @@ public class PythonTask extends AbstractTask {
@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) {
@ -182,9 +182,9 @@ public class PythonTask extends AbstractTask {
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());
@ -212,7 +212,7 @@ public class PythonTask extends AbstractTask {
*/
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));
}

View File

@ -172,7 +172,7 @@ public class SeatunnelTask extends AbstractRemoteTask {
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;
}

View File

@ -137,7 +137,7 @@ public class ShellTask extends AbstractTask {
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);

View File

@ -254,7 +254,7 @@ public class SparkTask extends AbstractYarnTask {
}
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));

View File

@ -80,7 +80,7 @@ public class SqoopJobGenerator {
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;