mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
refactored DefaultExecutor to ExternalProcessExecutor
This commit is contained in:
parent
284c5bd173
commit
66a811eeee
@ -23,11 +23,10 @@
|
||||
package processing.app.linux;
|
||||
|
||||
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 processing.app.Preferences;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.tools.ExternalProcessExecutor;
|
||||
import processing.core.PConstants;
|
||||
|
||||
import java.io.*;
|
||||
@ -131,35 +130,8 @@ public class Platform extends processing.app.Platform {
|
||||
|
||||
@Override
|
||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
|
||||
Executor executor = new DefaultExecutor();
|
||||
|
||||
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() {
|
||||
}
|
||||
});
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new ExternalProcessExecutor(baos);
|
||||
|
||||
try {
|
||||
CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial);
|
||||
|
@ -24,11 +24,10 @@ package processing.app.macosx;
|
||||
|
||||
import com.apple.eio.FileManager;
|
||||
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 processing.app.Base;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.tools.ExternalProcessExecutor;
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PConstants;
|
||||
|
||||
@ -207,35 +206,8 @@ public class Platform extends processing.app.Platform {
|
||||
|
||||
@Override
|
||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
|
||||
Executor executor = new DefaultExecutor();
|
||||
|
||||
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() {
|
||||
}
|
||||
});
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new ExternalProcessExecutor(baos);
|
||||
|
||||
try {
|
||||
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() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user