This is an automated email from the ASF dual-hosted git repository.

wenjun pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 6634ff98af  Add source env list in common.properties (#13317)
6634ff98af is described below

commit 6634ff98aff47887328447cb638536a5e2e47d60
Author: Wenjun Ruan <[email protected]>
AuthorDate: Wed Jan 4 20:53:52 2023 +0800

     Add source env list in common.properties (#13317)
---
 .../src/main/resources/common.properties           |  5 ++-
 .../plugin/task/api/ShellCommandExecutor.java      | 12 +++++++
 .../plugin/task/api/utils/ShellUtils.java          | 37 ++++++++++++++++++++++
 .../plugin/task/api/utils/ShellUtilsTest.java      | 32 +++++++++++++++++++
 .../src/test}/resources/common.properties          |  5 ++-
 5 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/dolphinscheduler-common/src/main/resources/common.properties 
b/dolphinscheduler-common/src/main/resources/common.properties
index 4a962043f0..0ea630f412 100644
--- a/dolphinscheduler-common/src/main/resources/common.properties
+++ b/dolphinscheduler-common/src/main/resources/common.properties
@@ -124,4 +124,7 @@ 
ml.mlflow.preset_repository=https://github.com/apache/dolphinscheduler-mlflow
 ml.mlflow.preset_repository_version="main"
 
 # way to collect applicationId: log(original regex match), aop
-appId.collect: log
\ No newline at end of file
+appId.collect=log
+
+# The default env list will be load by Shell task, e.g. 
/etc/profile,~/.bash_profile
+shell.env_source_list=
\ No newline at end of file
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 ec96122205..18799227b1 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
@@ -18,7 +18,9 @@
 package org.apache.dolphinscheduler.plugin.task.api;
 
 import org.apache.dolphinscheduler.plugin.task.api.utils.FileUtils;
+import org.apache.dolphinscheduler.plugin.task.api.utils.ShellUtils;
 
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.SystemUtils;
 
@@ -93,6 +95,11 @@ public class ShellCommandExecutor extends 
AbstractCommandExecutor {
         if (SystemUtils.IS_OS_WINDOWS) {
             sb.append("@echo off").append(System.lineSeparator());
             sb.append("cd /d %~dp0").append(System.lineSeparator());
+            if (CollectionUtils.isNotEmpty(ShellUtils.ENV_SOURCE_LIST)) {
+                for (String envSourceFile : ShellUtils.ENV_SOURCE_LIST) {
+                    sb.append("call ").append(envSourceFile).append("\n");
+                }
+            }
             if (StringUtils.isNotBlank(taskRequest.getEnvironmentConfig())) {
                 
sb.append(taskRequest.getEnvironmentConfig()).append(System.lineSeparator());
             }
@@ -100,6 +107,11 @@ public class ShellCommandExecutor extends 
AbstractCommandExecutor {
             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 (CollectionUtils.isNotEmpty(ShellUtils.ENV_SOURCE_LIST)) {
+                for (String envSourceFile : ShellUtils.ENV_SOURCE_LIST) {
+                    sb.append("source ").append(envSourceFile).append("\n");
+                }
+            }
             if (StringUtils.isNotBlank(taskRequest.getEnvironmentConfig())) {
                 
sb.append(taskRequest.getEnvironmentConfig()).append(System.lineSeparator());
             }
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ShellUtils.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ShellUtils.java
new file mode 100644
index 0000000000..7988bd0459
--- /dev/null
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ShellUtils.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.dolphinscheduler.common.utils.PropertyUtils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import lombok.experimental.UtilityClass;
+
+@UtilityClass
+public class ShellUtils {
+
+    public List<String> ENV_SOURCE_LIST = Arrays.stream(
+            
Optional.ofNullable(PropertyUtils.getString("shell.env_source_list"))
+                    .map(s -> s.split(",")).orElse(new String[0]))
+            .map(String::trim)
+            .collect(Collectors.toList());
+}
diff --git 
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ShellUtilsTest.java
 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ShellUtilsTest.java
new file mode 100644
index 0000000000..c437edd076
--- /dev/null
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ShellUtilsTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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 java.util.ArrayList;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ShellUtilsTest {
+
+    @Test
+    public void testGetEnvSourceList() {
+        Assertions.assertEquals(new ArrayList<>(), ShellUtils.ENV_SOURCE_LIST);
+    }
+
+}
diff --git a/dolphinscheduler-common/src/main/resources/common.properties 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/resources/common.properties
similarity index 97%
copy from dolphinscheduler-common/src/main/resources/common.properties
copy to 
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/resources/common.properties
index 4a962043f0..1f4d6779cf 100644
--- a/dolphinscheduler-common/src/main/resources/common.properties
+++ 
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/resources/common.properties
@@ -124,4 +124,7 @@ 
ml.mlflow.preset_repository=https://github.com/apache/dolphinscheduler-mlflow
 ml.mlflow.preset_repository_version="main"
 
 # way to collect applicationId: log(original regex match), aop
-appId.collect: log
\ No newline at end of file
+appId.collect=log
+
+# The default env list will be load by Shell task, e.g. 
/etc/profile,~/.bash_profile
+# shell.env_source_list=/etc/profile,~/.bash_profile
\ No newline at end of file

Reply via email to