From 5b14319cbc16fd1cf559425be6d543ec375daf47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=93=A0?= Date: Fri, 13 Nov 2020 18:25:16 +0800 Subject: [PATCH] code smell --- .../dolphinscheduler/plugin/alert/script/OSUtils.java | 2 +- .../plugin/alert/script/ProcessUtils.java | 8 +++++--- .../plugin/alert/script/ScriptSender.java | 6 +++--- .../plugin/alert/script/StreamGobbler.java | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java index d7e6d23a88..acf3e310cc 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java @@ -26,7 +26,7 @@ public class OSUtils { throw new UnsupportedOperationException("Construct OSUtils"); } - public static Boolean isWindows() { + static Boolean isWindows() { return System.getProperty("os.name").startsWith("Windows"); } } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java index 11fc869761..500c2724cc 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java @@ -30,21 +30,23 @@ public class ProcessUtils { private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); + private ProcessUtils() { + throw new IllegalStateException("Utility class"); + } + /** * executeScript * * @param cmd cmd params * @return exit code */ - public static Integer executeScript(String... cmd) { + static Integer executeScript(String... cmd) { int exitCode = -1; ProcessBuilder processBuilder = new ProcessBuilder(cmd); try { Process process = processBuilder.start(); - InputStream in = process.getErrorStream(); - StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream()); StreamGobbler errorStreamGobbler = new StreamGobbler(process.getErrorStream()); diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java index f7a89d8859..377c318b8e 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java @@ -37,13 +37,13 @@ public class ScriptSender { private String userParams; - public ScriptSender(Map config) { + ScriptSender(Map config) { scriptPath = config.get(ScriptParamsConstants.NAME_SCRIPT_PATH); scriptType = Integer.parseInt(config.get(ScriptParamsConstants.NAME_SCRIPT_TYPE)); userParams = config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS); } - public AlertResult sendScriptAlert(String msg) { + AlertResult sendScriptAlert(String msg) { AlertResult alertResult = new AlertResult(); if (ScriptType.of(scriptType).equals(ScriptType.SHELL)) { return executeShellScript(msg); @@ -54,7 +54,7 @@ public class ScriptSender { private AlertResult executeShellScript(String msg) { AlertResult alertResult = new AlertResult(); alertResult.setStatus("false"); - if (OSUtils.isWindows()) { + if (Boolean.TRUE.equals(OSUtils.isWindows())) { alertResult.setMessage("shell script not support windows os"); return alertResult; } diff --git a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java index cde0c7914d..2ec25280b4 100644 --- a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java +++ b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java @@ -32,7 +32,7 @@ public class StreamGobbler extends Thread { private static final Logger logger = LoggerFactory.getLogger(StreamGobbler.class); - InputStream inputStream; + private InputStream inputStream; StreamGobbler(InputStream inputStream) { this.inputStream = inputStream;