From 66e09dc66ec3439b53edf9fd9142506b615bae35 Mon Sep 17 00:00:00 2001 From: Rick Cheng Date: Thu, 8 Jun 2023 08:59:53 +0800 Subject: [PATCH] [Improvement-14295][common] Remove the duplicate FileUtils (#14301) --- .../common/utils/FileUtils.java | 24 +++++++++ .../plugin/task/api/ShellCommandExecutor.java | 2 +- .../plugin/task/api/utils/FileUtils.java | 51 ------------------- .../task/remoteshell/RemoteShellTask.java | 2 +- .../plugin/task/shell/ShellTask.java | 2 +- 5 files changed, 27 insertions(+), 54 deletions(-) delete mode 100644 dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/FileUtils.java diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java index b2776bc7b9..463071a8b0 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java @@ -26,6 +26,7 @@ import static org.apache.dolphinscheduler.common.constants.Constants.UTF_8; import static org.apache.dolphinscheduler.common.constants.DateConstants.YYYYMMDDHHMMSS; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.SystemUtils; import java.io.ByteArrayOutputStream; import java.io.File; @@ -34,10 +35,17 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; import java.util.zip.CRC32; import java.util.zip.CheckedInputStream; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; /** @@ -52,6 +60,11 @@ public class FileUtils { public static final String KUBE_CONFIG_FILE = "config"; + private static final String RWXR_XR_X = "rwxr-xr-x"; + + private static final FileAttribute> PERMISSION_755 = + PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(RWXR_XR_X)); + private FileUtils() { throw new UnsupportedOperationException("Construct FileUtils"); } @@ -310,4 +323,15 @@ public class FileUtils { return crcString; } + /** + * Create a file with '755'. + */ + public static void createFileWith755(@NonNull Path path) throws IOException { + if (SystemUtils.IS_OS_WINDOWS) { + Files.createFile(path); + } else { + Files.createFile(path, PERMISSION_755); + } + } + } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/ShellCommandExecutor.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/ShellCommandExecutor.java index 1a30864a94..9bcc765bb3 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/ShellCommandExecutor.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/ShellCommandExecutor.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.task.api; -import org.apache.dolphinscheduler.plugin.task.api.utils.FileUtils; +import org.apache.dolphinscheduler.common.utils.FileUtils; import org.apache.dolphinscheduler.plugin.task.api.utils.ShellUtils; import org.apache.commons.collections4.CollectionUtils; diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/FileUtils.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/FileUtils.java deleted file mode 100644 index e415ee9669..0000000000 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/FileUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dolphinscheduler.plugin.task.api.utils; - -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.RWXR_XR_X; - -import org.apache.commons.lang3.SystemUtils; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.FileAttribute; -import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; -import java.util.Set; - -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class FileUtils { - - private static final FileAttribute> PERMISSION_755 = - PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(RWXR_XR_X)); - - /** - * Create a file with '755'. - */ - public static void createFileWith755(@NonNull Path path) throws IOException { - if (SystemUtils.IS_OS_WINDOWS) { - Files.createFile(path); - } else { - Files.createFile(path, PERMISSION_755); - } - } -} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteShellTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteShellTask.java index c6eb8084e6..c0af396499 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteShellTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteShellTask.java @@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.plugin.task.remoteshell; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_FAILURE; +import org.apache.dolphinscheduler.common.utils.FileUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils; import org.apache.dolphinscheduler.plugin.datasource.ssh.param.SSHConnectionParam; @@ -32,7 +33,6 @@ import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.DataSourceParameters; import org.apache.dolphinscheduler.plugin.task.api.parser.ParamUtils; import org.apache.dolphinscheduler.plugin.task.api.parser.ParameterUtils; -import org.apache.dolphinscheduler.plugin.task.api.utils.FileUtils; import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.commons.lang3.SystemUtils; diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java index dfae160da6..469c30bb12 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-shell/src/main/java/org/apache/dolphinscheduler/plugin/task/shell/ShellTask.java @@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.plugin.task.shell; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_FAILURE; +import org.apache.dolphinscheduler.common.utils.FileUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.plugin.task.api.AbstractTask; import org.apache.dolphinscheduler.plugin.task.api.ShellCommandExecutor; @@ -30,7 +31,6 @@ import org.apache.dolphinscheduler.plugin.task.api.model.TaskResponse; import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters; import org.apache.dolphinscheduler.plugin.task.api.parser.ParamUtils; import org.apache.dolphinscheduler.plugin.task.api.parser.ParameterUtils; -import org.apache.dolphinscheduler.plugin.task.api.utils.FileUtils; import org.apache.commons.lang3.SystemUtils;