25
25
26
26
import static processing .app .I18n ._ ;
27
27
28
- import java .io .BufferedReader ;
29
- import java .io .File ;
30
- import java .io .FileNotFoundException ;
31
- import java .io .FileOutputStream ;
32
- import java .io .FileReader ;
33
- import java .io .IOException ;
34
- import java .io .PrintWriter ;
28
+ import java .io .*;
35
29
import java .util .ArrayList ;
36
30
import java .util .Arrays ;
37
31
import java .util .Collections ;
45
39
import cc .arduino .packages .Uploader ;
46
40
import cc .arduino .packages .UploaderFactory ;
47
41
42
+ import org .apache .commons .exec .CommandLine ;
43
+ import org .apache .commons .exec .DefaultExecutor ;
44
+ import org .apache .commons .exec .ExecuteStreamHandler ;
48
45
import processing .app .BaseNoGui ;
49
46
import processing .app .I18n ;
50
47
import processing .app .PreferencesData ;
@@ -696,38 +693,64 @@ private void execAsynchronously(String[] command) throws RunnerException {
696
693
command = stringList .toArray (new String [stringList .size ()]);
697
694
if (command .length == 0 )
698
695
return ;
699
- int result = 0 ;
700
696
701
697
if (verbose ) {
702
698
for (String c : command )
703
699
System .out .print (c + " " );
704
700
System .out .println ();
705
701
}
706
702
707
- Process process ;
703
+ DefaultExecutor executor = new DefaultExecutor ();
704
+ executor .setStreamHandler (new ExecuteStreamHandler () {
705
+ @ Override
706
+ public void setProcessInputStream (OutputStream os ) throws IOException {
707
+
708
+ }
709
+
710
+ @ Override
711
+ public void setProcessErrorStream (InputStream is ) throws IOException {
712
+ forwardToMessage (is );
713
+ }
714
+
715
+ @ Override
716
+ public void setProcessOutputStream (InputStream is ) throws IOException {
717
+ forwardToMessage (is );
718
+ }
719
+
720
+ private void forwardToMessage (InputStream is ) throws IOException {
721
+ BufferedReader reader = new BufferedReader (new InputStreamReader (is ));
722
+ String line ;
723
+ while ((line = reader .readLine ()) != null ) {
724
+ message (line + "\n " );
725
+ }
726
+ }
727
+
728
+ @ Override
729
+ public void start () throws IOException {
730
+
731
+ }
732
+
733
+ @ Override
734
+ public void stop () {
735
+
736
+ }
737
+ });
738
+
739
+ CommandLine commandLine = new CommandLine (command [0 ]);
740
+ for (int i = 1 ; i < command .length ; i ++) {
741
+ commandLine .addArgument (command [i ]);
742
+ }
743
+
744
+ int result ;
745
+ executor .setExitValues (null );
708
746
try {
709
- process = ProcessUtils . exec ( command );
747
+ result = executor . execute ( commandLine );
710
748
} catch (IOException e ) {
711
749
RunnerException re = new RunnerException (e .getMessage ());
712
750
re .hideStackTrace ();
713
751
throw re ;
714
752
}
715
-
716
- MessageSiphon in = new MessageSiphon (process .getInputStream (), this );
717
- MessageSiphon err = new MessageSiphon (process .getErrorStream (), this );
718
-
719
- // wait for the process to finish. if interrupted
720
- // before waitFor returns, continue waiting
721
- boolean compiling = true ;
722
- while (compiling ) {
723
- try {
724
- in .join ();
725
- err .join ();
726
- result = process .waitFor ();
727
- //System.out.println("result is " + result);
728
- compiling = false ;
729
- } catch (InterruptedException ignored ) { }
730
- }
753
+ executor .setExitValues (new int [0 ]);
731
754
732
755
// an error was queued up by message(), barf this back to compile(),
733
756
// which will barf it back to Editor. if you're having trouble
@@ -769,10 +792,10 @@ public void message(String s) {
769
792
s = s .substring (0 , i ) + s .substring (i + (buildPath + File .separator ).length ());
770
793
}
771
794
}
772
-
795
+
773
796
// look for error line, which contains file name, line number,
774
797
// and at least the first line of the error message
775
- String errorFormat = "([ \\ w \\ d_]+ .\\ w+):(\\ d+):\\ s*error:\\ s*(.*)\\ s*" ;
798
+ String errorFormat = "(.+ \\ .\\ w+):(\\ d+)(: \\ d+)* :\\ s*error:\\ s*(.*)\\ s*" ;
776
799
String [] pieces = PApplet .match (s , errorFormat );
777
800
778
801
// if (pieces != null && exception == null) {
@@ -781,56 +804,56 @@ public void message(String s) {
781
804
// }
782
805
783
806
if (pieces != null ) {
784
- String error = pieces [3 ], msg = "" ;
807
+ String error = pieces [pieces . length - 1 ], msg = "" ;
785
808
786
- if (pieces [ 3 ] .trim ().equals ("SPI.h: No such file or directory" )) {
809
+ if (error .trim ().equals ("SPI.h: No such file or directory" )) {
787
810
error = _ ("Please import the SPI library from the Sketch > Import Library menu." );
788
811
msg = _ ("\n As of Arduino 0019, the Ethernet library depends on the SPI library." +
789
812
"\n You appear to be using it or another library that depends on the SPI library.\n \n " );
790
813
}
791
814
792
- if (pieces [ 3 ] .trim ().equals ("'BYTE' was not declared in this scope" )) {
815
+ if (error .trim ().equals ("'BYTE' was not declared in this scope" )) {
793
816
error = _ ("The 'BYTE' keyword is no longer supported." );
794
817
msg = _ ("\n As of Arduino 1.0, the 'BYTE' keyword is no longer supported." +
795
818
"\n Please use Serial.write() instead.\n \n " );
796
819
}
797
820
798
- if (pieces [ 3 ] .trim ().equals ("no matching function for call to 'Server::Server(int)'" )) {
821
+ if (error .trim ().equals ("no matching function for call to 'Server::Server(int)'" )) {
799
822
error = _ ("The Server class has been renamed EthernetServer." );
800
823
msg = _ ("\n As of Arduino 1.0, the Server class in the Ethernet library " +
801
824
"has been renamed to EthernetServer.\n \n " );
802
825
}
803
826
804
- if (pieces [ 3 ] .trim ().equals ("no matching function for call to 'Client::Client(byte [4], int)'" )) {
827
+ if (error .trim ().equals ("no matching function for call to 'Client::Client(byte [4], int)'" )) {
805
828
error = _ ("The Client class has been renamed EthernetClient." );
806
829
msg = _ ("\n As of Arduino 1.0, the Client class in the Ethernet library " +
807
830
"has been renamed to EthernetClient.\n \n " );
808
831
}
809
832
810
- if (pieces [ 3 ] .trim ().equals ("'Udp' was not declared in this scope" )) {
833
+ if (error .trim ().equals ("'Udp' was not declared in this scope" )) {
811
834
error = _ ("The Udp class has been renamed EthernetUdp." );
812
835
msg = _ ("\n As of Arduino 1.0, the Udp class in the Ethernet library " +
813
836
"has been renamed to EthernetUdp.\n \n " );
814
837
}
815
838
816
- if (pieces [ 3 ] .trim ().equals ("'class TwoWire' has no member named 'send'" )) {
839
+ if (error .trim ().equals ("'class TwoWire' has no member named 'send'" )) {
817
840
error = _ ("Wire.send() has been renamed Wire.write()." );
818
841
msg = _ ("\n As of Arduino 1.0, the Wire.send() function was renamed " +
819
842
"to Wire.write() for consistency with other libraries.\n \n " );
820
843
}
821
844
822
- if (pieces [ 3 ] .trim ().equals ("'class TwoWire' has no member named 'receive'" )) {
845
+ if (error .trim ().equals ("'class TwoWire' has no member named 'receive'" )) {
823
846
error = _ ("Wire.receive() has been renamed Wire.read()." );
824
847
msg = _ ("\n As of Arduino 1.0, the Wire.receive() function was renamed " +
825
848
"to Wire.read() for consistency with other libraries.\n \n " );
826
849
}
827
850
828
- if (pieces [ 3 ] .trim ().equals ("'Mouse' was not declared in this scope" )) {
851
+ if (error .trim ().equals ("'Mouse' was not declared in this scope" )) {
829
852
error = _ ("'Mouse' only supported on the Arduino Leonardo" );
830
853
//msg = _("\nThe 'Mouse' class is only supported on the Arduino Leonardo.\n\n");
831
854
}
832
855
833
- if (pieces [ 3 ] .trim ().equals ("'Keyboard' was not declared in this scope" )) {
856
+ if (error .trim ().equals ("'Keyboard' was not declared in this scope" )) {
834
857
error = _ ("'Keyboard' only supported on the Arduino Leonardo" );
835
858
//msg = _("\nThe 'Keyboard' class is only supported on the Arduino Leonardo.\n\n");
836
859
}
@@ -848,13 +871,15 @@ public void message(String s) {
848
871
SketchCode code = sketch .getCode (e .getCodeIndex ());
849
872
String fileName = (code .isExtension ("ino" ) || code .isExtension ("pde" )) ? code .getPrettyName () : code .getFileName ();
850
873
int lineNum = e .getCodeLine () + 1 ;
851
- s = fileName + ":" + lineNum + ": error: " + pieces [3 ] + msg ;
874
+ s = fileName + ":" + lineNum + ": error: " + error + msg ;
875
+ }
876
+
877
+ if (e != null ) {
878
+ if (exception == null || exception .getMessage ().equals (e .getMessage ())) {
879
+ exception = e ;
880
+ exception .hideStackTrace ();
881
+ }
852
882
}
853
-
854
- if (exception == null && e != null ) {
855
- exception = e ;
856
- exception .hideStackTrace ();
857
- }
858
883
}
859
884
860
885
if (s .contains ("undefined reference to `SPIClass::begin()'" ) &&
0 commit comments