1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

CollectStdOutExecutor and CollectStdOutStdErrExecutor were plain wrong, were losing data and were blocking compilation. Fixes #3124 and #3115

This commit is contained in:
Federico Fissore
2015-05-25 16:32:33 +02:00
parent 5faa1c9866
commit 8a1e6c8a9b
8 changed files with 105 additions and 135 deletions

View File

@ -35,14 +35,13 @@ import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import cc.arduino.MyStreamPumper;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Uploader;
import cc.arduino.packages.UploaderFactory;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteStreamHandler;
import org.apache.commons.exec.*;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;
@ -703,37 +702,13 @@ public class Compiler implements MessageConsumer {
}
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new ExecuteStreamHandler() {
@Override
public void setProcessInputStream(OutputStream os) throws IOException {
}
executor.setStreamHandler(new PumpStreamHandler() {
@Override
public void setProcessErrorStream(InputStream is) throws IOException {
forwardToMessage(is);
}
@Override
public void setProcessOutputStream(InputStream is) throws IOException {
forwardToMessage(is);
}
private void forwardToMessage(InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
message(line + "\n");
}
}
@Override
public void start() throws IOException {
}
@Override
public void stop() {
protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted) {
final Thread result = new Thread(new MyStreamPumper(is, Compiler.this));
result.setDaemon(true);
return result;
}
});

View File

@ -23,11 +23,12 @@
package processing.app.linux;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.Executor;
import org.apache.commons.exec.PumpStreamHandler;
import processing.app.PreferencesData;
import processing.app.debug.TargetPackage;
import processing.app.legacy.PConstants;
import processing.app.tools.CollectStdOutExecutor;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -124,7 +125,8 @@ public class Platform extends processing.app.Platform {
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
assert packages != null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Executor executor = new CollectStdOutExecutor(baos);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(baos, null));
try {
CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial);

View File

@ -25,12 +25,13 @@ package processing.app.macosx;
import cc.arduino.packages.BoardPort;
import com.apple.eio.FileManager;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.Executor;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.lang3.StringUtils;
import processing.app.debug.TargetPackage;
import processing.app.legacy.PApplet;
import processing.app.legacy.PConstants;
import processing.app.tools.CollectStdOutExecutor;
import java.awt.*;
import java.io.*;
@ -67,7 +68,8 @@ public class Platform extends processing.app.Platform {
private void discoverRealOsArch() throws IOException {
CommandLine uname = CommandLine.parse("uname -m");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CollectStdOutExecutor executor = new CollectStdOutExecutor(baos);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(baos, null));
executor.execute(uname);
osArch = StringUtils.trim(new String(baos.toByteArray()));
}
@ -214,7 +216,8 @@ public class Platform extends processing.app.Platform {
@Override
public String preListAllCandidateDevices() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Executor executor = new CollectStdOutExecutor(baos);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(baos, null));
try {
CommandLine toDevicePath = CommandLine.parse("/usr/sbin/system_profiler SPUSBDataType");

View File

@ -1,44 +0,0 @@
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 CollectStdOutExecutor extends DefaultExecutor {
public CollectStdOutExecutor(final OutputStream stdout) {
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) {
stdout.write(buf, 0, bytes);
}
}
@Override
public void start() throws IOException {
}
@Override
public void stop() {
}
});
}
}

View File

@ -1,49 +0,0 @@
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 and stderr into given OutputStreams
*/
public class CollectStdOutStdErrExecutor extends DefaultExecutor {
public CollectStdOutStdErrExecutor(final OutputStream stdout, final OutputStream stderr) {
this.setStreamHandler(new ExecuteStreamHandler() {
@Override
public void setProcessInputStream(OutputStream outputStream) throws IOException {
}
@Override
public void setProcessErrorStream(InputStream inputStream) throws IOException {
byte[] buf = new byte[4096];
int bytes = -1;
while ((bytes = inputStream.read(buf)) != -1) {
stderr.write(buf, 0, bytes);
}
}
@Override
public void setProcessOutputStream(InputStream inputStream) throws IOException {
byte[] buf = new byte[4096];
int bytes = -1;
while ((bytes = inputStream.read(buf)) != -1) {
stdout.write(buf, 0, bytes);
}
}
@Override
public void start() throws IOException {
}
@Override
public void stop() {
}
});
}
}

View File

@ -23,11 +23,12 @@
package processing.app.windows;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.Executor;
import org.apache.commons.exec.PumpStreamHandler;
import processing.app.debug.TargetPackage;
import processing.app.legacy.PApplet;
import processing.app.legacy.PConstants;
import processing.app.tools.CollectStdOutExecutor;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -62,7 +63,8 @@ public class Platform extends processing.app.Platform {
private String getFolderPathFromRegistry(String folderType) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Executor executor = new CollectStdOutExecutor(baos);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(baos, null));
CommandLine toDevicePath = CommandLine.parse("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v \"" + folderType + "\"");
executor.execute(toDevicePath);
@ -193,7 +195,8 @@ public class Platform extends processing.app.Platform {
@Override
public String preListAllCandidateDevices() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Executor executor = new CollectStdOutExecutor(baos);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(baos, null));
try {
String listComPorts = new File(System.getProperty("user.dir"), "hardware/tools/listComPorts.exe").getCanonicalPath();