Browse Source

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

3.2.0-release
Wenjun Ruan 2 years ago committed by GitHub
parent
commit
92a9b7e243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
  2. 18
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/ShellCommandExecutor.java
  3. 2
      dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/main/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTask.java
  4. 8
      dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java
  5. 2
      dolphinscheduler-task-plugin/dolphinscheduler-task-seatunnel/src/main/java/org/apache/dolphinscheduler/plugin/task/seatunnel/SeatunnelTask.java
  6. 2
      dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java
  7. 2
      dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/main/java/org/apache/dolphinscheduler/plugin/task/spark/SparkTask.java
  8. 2
      dolphinscheduler-task-plugin/dolphinscheduler-task-sqoop/src/main/java/org/apache/dolphinscheduler/plugin/task/sqoop/generator/SqoopJobGenerator.java

2
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java

@ -33,7 +33,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -135,7 +134,6 @@ public abstract class AbstractCommandExecutor {
} }
} }
command.add(commandInterpreter()); command.add(commandInterpreter());
command.addAll(Collections.emptyList());
command.add(commandFile); command.add(commandFile);
// setting commands // setting commands

18
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/ShellCommandExecutor.java

@ -91,24 +91,24 @@ public class ShellCommandExecutor extends AbstractCommandExecutor {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (SystemUtils.IS_OS_WINDOWS) { if (SystemUtils.IS_OS_WINDOWS) {
sb.append("@echo off\n"); sb.append("@echo off").append(System.lineSeparator());
sb.append("cd /d %~dp0\n"); sb.append("cd /d %~dp0").append(System.lineSeparator());
if (StringUtils.isNotBlank(taskRequest.getEnvironmentConfig())) { if (StringUtils.isNotBlank(taskRequest.getEnvironmentConfig())) {
sb.append(taskRequest.getEnvironmentConfig()).append("\n"); sb.append(taskRequest.getEnvironmentConfig()).append(System.lineSeparator());
} else { } else {
if (taskRequest.getEnvFile() != null) { if (taskRequest.getEnvFile() != null) {
sb.append("call ").append(taskRequest.getEnvFile()).append("\n"); sb.append("call ").append(taskRequest.getEnvFile()).append(System.lineSeparator());
} }
} }
} else { } else {
sb.append("#!/bin/bash\n"); sb.append("#!/bin/bash").append(System.lineSeparator());
sb.append("BASEDIR=$(cd `dirname $0`; pwd)\n"); sb.append("BASEDIR=$(cd `dirname $0`; pwd)").append(System.lineSeparator());
sb.append("cd $BASEDIR\n"); sb.append("cd $BASEDIR").append(System.lineSeparator());
if (StringUtils.isNotBlank(taskRequest.getEnvironmentConfig())) { if (StringUtils.isNotBlank(taskRequest.getEnvironmentConfig())) {
sb.append(taskRequest.getEnvironmentConfig()).append("\n"); sb.append(taskRequest.getEnvironmentConfig()).append(System.lineSeparator());
} else { } else {
if (taskRequest.getEnvFile() != null) { if (taskRequest.getEnvFile() != null) {
sb.append("source ").append(taskRequest.getEnvFile()).append("\n"); sb.append("source ").append(taskRequest.getEnvFile()).append(System.lineSeparator());
} }
} }
} }

2
dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/main/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTask.java

@ -209,7 +209,7 @@ public class DataxTask extends AbstractTask {
} }
if (dataXParameters.getCustomConfig() == Flag.YES.ordinal()) { if (dataXParameters.getCustomConfig() == Flag.YES.ordinal()) {
json = dataXParameters.getJson().replaceAll("\\r\\n", "\n"); json = dataXParameters.getJson().replaceAll("\\r\\n", System.lineSeparator());
} else { } else {
ObjectNode job = JSONUtils.createObjectNode(); ObjectNode job = JSONUtils.createObjectNode();
job.putArray("content").addAll(buildDataxJobContentJson()); job.putArray("content").addAll(buildDataxJobContentJson());

8
dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java

@ -89,7 +89,7 @@ public class PythonTask extends AbstractTask {
@Override @Override
public String getPreScript() { public String getPreScript() {
String rawPythonScript = pythonParameters.getRawScript().replaceAll("\\r\\n", "\n"); String rawPythonScript = pythonParameters.getRawScript().replaceAll("\\r\\n", System.lineSeparator());
try { try {
rawPythonScript = convertPythonScriptPlaceholders(rawPythonScript); rawPythonScript = convertPythonScriptPlaceholders(rawPythonScript);
} catch (StringIndexOutOfBoundsException e) { } catch (StringIndexOutOfBoundsException e) {
@ -182,9 +182,9 @@ public class PythonTask extends AbstractTask {
logger.info("generate python script file:{}", pythonScriptFile); logger.info("generate python script file:{}", pythonScriptFile);
StringBuilder sb = new StringBuilder(); 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); sb.append(pythonScript);
logger.info(sb.toString()); logger.info(sb.toString());
@ -212,7 +212,7 @@ public class PythonTask extends AbstractTask {
*/ */
protected String buildPythonScriptContent() throws Exception { protected String buildPythonScriptContent() throws Exception {
logger.info("raw python script : {}", pythonParameters.getRawScript()); 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); Map<String, Property> paramsMap = mergeParamsWithContext(pythonParameters);
return ParameterUtils.convertParameterPlaceholders(rawPythonScript, ParamUtils.convert(paramsMap)); return ParameterUtils.convertParameterPlaceholders(rawPythonScript, ParamUtils.convert(paramsMap));
} }

2
dolphinscheduler-task-plugin/dolphinscheduler-task-seatunnel/src/main/java/org/apache/dolphinscheduler/plugin/task/seatunnel/SeatunnelTask.java

@ -172,7 +172,7 @@ public class SeatunnelTask extends AbstractRemoteTask {
private String buildCustomConfigContent() { private String buildCustomConfigContent() {
logger.info("raw custom config content : {}", seatunnelParameters.getRawScript()); 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); script = parseScript(script);
return script; return script;
} }

2
dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java

@ -137,7 +137,7 @@ public class ShellTask extends AbstractTask {
return fileName; return fileName;
} }
String script = shellParameters.getRawScript().replaceAll("\\r\\n", "\n"); String script = shellParameters.getRawScript().replaceAll("\\r\\n", System.lineSeparator());
script = parseScript(script); script = parseScript(script);
shellParameters.setRawScript(script); shellParameters.setRawScript(script);

2
dolphinscheduler-task-plugin/dolphinscheduler-task-spark/src/main/java/org/apache/dolphinscheduler/plugin/task/spark/SparkTask.java

@ -254,7 +254,7 @@ public class SparkTask extends AbstractYarnTask {
} }
private String replaceParam(String script) { 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 // replace placeholder, and combining local and global parameters
Map<String, Property> paramsMap = taskExecutionContext.getPrepareParamsMap(); Map<String, Property> paramsMap = taskExecutionContext.getPrepareParamsMap();
script = ParameterUtils.convertParameterPlaceholders(script, ParamUtils.convert(paramsMap)); script = ParameterUtils.convertParameterPlaceholders(script, ParamUtils.convert(paramsMap));

2
dolphinscheduler-task-plugin/dolphinscheduler-task-sqoop/src/main/java/org/apache/dolphinscheduler/plugin/task/sqoop/generator/SqoopJobGenerator.java

@ -80,7 +80,7 @@ public class SqoopJobGenerator {
sourceGenerator.generate(sqoopParameters, sqoopTaskExecutionContext), sourceGenerator.generate(sqoopParameters, sqoopTaskExecutionContext),
targetGenerator.generate(sqoopParameters, sqoopTaskExecutionContext)); targetGenerator.generate(sqoopParameters, sqoopTaskExecutionContext));
} else if (SqoopJobType.CUSTOM.getDescp().equals(sqoopParameters.getJobType())) { } 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; return sqoopScripts;

Loading…
Cancel
Save