mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
refactored DefaultExecutor to ExternalProcessExecutor
This commit is contained in:
@ -23,11 +23,10 @@
|
|||||||
package processing.app.linux;
|
package processing.app.linux;
|
||||||
|
|
||||||
import org.apache.commons.exec.CommandLine;
|
import org.apache.commons.exec.CommandLine;
|
||||||
import org.apache.commons.exec.DefaultExecutor;
|
|
||||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
|
||||||
import org.apache.commons.exec.Executor;
|
import org.apache.commons.exec.Executor;
|
||||||
import processing.app.Preferences;
|
import processing.app.Preferences;
|
||||||
import processing.app.debug.TargetPackage;
|
import processing.app.debug.TargetPackage;
|
||||||
|
import processing.app.tools.ExternalProcessExecutor;
|
||||||
import processing.core.PConstants;
|
import processing.core.PConstants;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -131,35 +130,8 @@ public class Platform extends processing.app.Platform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
|
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
|
||||||
Executor executor = new DefaultExecutor();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
Executor executor = new ExternalProcessExecutor(baos);
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
executor.setStreamHandler(new ExecuteStreamHandler() {
|
|
||||||
@Override
|
|
||||||
public void setProcessInputStream(OutputStream outputStream) throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setProcessErrorStream(InputStream inputStream) throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setProcessOutputStream(InputStream inputStream) throws IOException {
|
|
||||||
byte[] buf = new byte[4096];
|
|
||||||
int bytes = -1;
|
|
||||||
while ((bytes = inputStream.read(buf)) != -1) {
|
|
||||||
baos.write(buf, 0, bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start() throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial);
|
CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial);
|
||||||
|
@ -24,11 +24,10 @@ package processing.app.macosx;
|
|||||||
|
|
||||||
import com.apple.eio.FileManager;
|
import com.apple.eio.FileManager;
|
||||||
import org.apache.commons.exec.CommandLine;
|
import org.apache.commons.exec.CommandLine;
|
||||||
import org.apache.commons.exec.DefaultExecutor;
|
|
||||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
|
||||||
import org.apache.commons.exec.Executor;
|
import org.apache.commons.exec.Executor;
|
||||||
import processing.app.Base;
|
import processing.app.Base;
|
||||||
import processing.app.debug.TargetPackage;
|
import processing.app.debug.TargetPackage;
|
||||||
|
import processing.app.tools.ExternalProcessExecutor;
|
||||||
import processing.core.PApplet;
|
import processing.core.PApplet;
|
||||||
import processing.core.PConstants;
|
import processing.core.PConstants;
|
||||||
|
|
||||||
@ -207,35 +206,8 @@ public class Platform extends processing.app.Platform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
|
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
|
||||||
Executor executor = new DefaultExecutor();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
Executor executor = new ExternalProcessExecutor(baos);
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
executor.setStreamHandler(new ExecuteStreamHandler() {
|
|
||||||
@Override
|
|
||||||
public void setProcessInputStream(OutputStream outputStream) throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setProcessErrorStream(InputStream inputStream) throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setProcessOutputStream(InputStream inputStream) throws IOException {
|
|
||||||
byte[] buf = new byte[4096];
|
|
||||||
int bytes = -1;
|
|
||||||
while ((bytes = inputStream.read(buf)) != -1) {
|
|
||||||
baos.write(buf, 0, bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start() throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommandLine toDevicePath = CommandLine.parse("/usr/sbin/system_profiler SPUSBDataType");
|
CommandLine toDevicePath = CommandLine.parse("/usr/sbin/system_profiler SPUSBDataType");
|
||||||
|
44
app/src/processing/app/tools/ExternalProcessExecutor.java
Normal file
44
app/src/processing/app/tools/ExternalProcessExecutor.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package processing.app.tools;
|
||||||
|
|
||||||
|
import org.apache.commons.exec.DefaultExecutor;
|
||||||
|
import org.apache.commons.exec.ExecuteStreamHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handy process executor, collecting stdout into a given OutputStream
|
||||||
|
*/
|
||||||
|
public class ExternalProcessExecutor extends DefaultExecutor {
|
||||||
|
|
||||||
|
public ExternalProcessExecutor(final OutputStream os) {
|
||||||
|
this.setStreamHandler(new ExecuteStreamHandler() {
|
||||||
|
@Override
|
||||||
|
public void setProcessInputStream(OutputStream outputStream) throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProcessErrorStream(InputStream inputStream) throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProcessOutputStream(InputStream inputStream) throws IOException {
|
||||||
|
byte[] buf = new byte[4096];
|
||||||
|
int bytes = -1;
|
||||||
|
while ((bytes = inputStream.read(buf)) != -1) {
|
||||||
|
os.write(buf, 0, bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user