移除commons-exec,采用原生方式实现;

2.1.2
xuxueli 5 years ago
parent 916b541cb1
commit 82b4d735ca

@ -1672,9 +1672,9 @@ public ReturnT<String> execute(String param) {
return ReturnT.SUCCESS;
}
```
- 2、调度中心dispatcher servlet加载顺序优化
- 2、移除commons-exec采用原生方式实现
- 3、执行器回调乱码问题修复
- 4、[迭代中]移除commons-exec采用原生方式实现
- 4、调度中心dispatcher servlet加载顺序优化
- 5、[迭代中]任务操作API服务调整为restful方式降低接入成本

@ -34,8 +34,6 @@
<slf4j-api.version>1.7.28</slf4j-api.version>
<junit.version>4.12</junit.version>
<commons-exec.version>1.3</commons-exec.version>
<groovy.version>2.5.8</groovy.version>
<maven-source-plugin.version>3.1.0</maven-source-plugin.version>

@ -29,13 +29,6 @@
<version>${groovy.version}</version>
</dependency>
<!-- commons-exec -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>${commons-exec.version}</version>
</dependency>
<!-- spring-context -->
<dependency>
<groupId>org.springframework</groupId>

@ -1,12 +1,13 @@
package com.xxl.job.core.util;
import com.xxl.job.core.log.XxlJobLogger;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
/**
* 1"PythonInterpreter"使java"Runtime.getRuntime().exec()"(shellpython)
@ -42,13 +43,143 @@ public class ScriptUtil {
}
/**
*
*
*
* @param command
* @param scriptFile
* @param logFile
* @param params
* @return
* @throws IOException
*/
public static int execToFileB(String command, String scriptFile, String logFile, String... params) throws IOException {
FileOutputStream fileOutputStream = null;
Thread inputThread = null;
Thread errThread = null;
try {
// file
fileOutputStream = new FileOutputStream(logFile, true);
// command
List<String> cmdarray = new ArrayList<>();
cmdarray.add(command);
cmdarray.add(scriptFile);
if (params!=null && params.length>0) {
for (String param:params) {
cmdarray.add(param);
}
}
String[] cmdarrayFinal = cmdarray.toArray(new String[cmdarray.size()]);
// process-exec
final Process process = Runtime.getRuntime().exec(cmdarrayFinal);
// log-thread
final FileOutputStream finalFileOutputStream = fileOutputStream;
inputThread = new Thread(new Runnable() {
@Override
public void run() {
try {
copy(process.getInputStream(), finalFileOutputStream, new byte[1024]);
} catch (IOException e) {
XxlJobLogger.log(e);
}
}
});
errThread = new Thread(new Runnable() {
@Override
public void run() {
try {
copy(process.getErrorStream(), finalFileOutputStream, new byte[1024]);
} catch (IOException e) {
XxlJobLogger.log(e);
}
}
});
inputThread.start();
errThread.start();
// process-wait
int exitValue = process.waitFor(); // exit code: 0=success, 1=error
// log-thread join
inputThread.join();
errThread.join();
return exitValue;
} catch (Exception e) {
XxlJobLogger.log(e);
return -1;
} finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
XxlJobLogger.log(e);
}
}
if (inputThread != null && inputThread.isAlive()) {
inputThread.interrupt();
}
if (errThread != null && errThread.isAlive()) {
errThread.interrupt();
}
}
}
/**
* CopyInputOutput
*
* @param inputStream
* @param outputStream
* @param buffer
* @return
* @throws IOException
*/
private static long copy(InputStream inputStream, OutputStream outputStream, byte[] buffer) throws IOException {
try {
long total = 0;
for (;;) {
int res = inputStream.read(buffer);
if (res == -1) {
break;
}
if (res > 0) {
total += res;
if (outputStream != null) {
outputStream.write(buffer, 0, res);
}
}
}
outputStream.flush();
//out = null;
inputStream.close();
inputStream = null;
return total;
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
/**
*
*
*
*
*
* Java
*
* <!-- commons-exec -->
* <dependency>
* <groupId>org.apache.commons</groupId>
* <artifactId>commons-exec</artifactId>
* <version>${commons-exec.version}</version>
* </dependency>
*
* @param command
* @param scriptFile
* @param logFile
@ -56,7 +187,7 @@ public class ScriptUtil {
* @return
* @throws IOException
*/
public static int execToFile(String command, String scriptFile, String logFile, String... params) throws IOException {
/*public static int execToFile(String command, String scriptFile, String logFile, String... params) throws IOException {
// 标准输出print null if watchdog timeout
// 错误输出logging + 异常 still exists if watchdog timeout
// 标准输入
@ -92,6 +223,6 @@ public class ScriptUtil {
}
}
}
}*/
}

Loading…
Cancel
Save