30
30
package cc .arduino ;
31
31
32
32
import cc .arduino .i18n .I18NAwareMessageConsumer ;
33
+ import cc .arduino .packages .BoardPort ;
33
34
import org .apache .commons .exec .CommandLine ;
34
35
import org .apache .commons .exec .DefaultExecutor ;
35
36
import org .apache .commons .exec .PumpStreamHandler ;
37
+ import org .apache .commons .lang3 .StringUtils ;
36
38
import processing .app .*;
37
39
import processing .app .debug .*;
38
40
import processing .app .helpers .PreferencesMap ;
@@ -128,13 +130,14 @@ public String build(CompilerProgressListener progListener, boolean exportHex) th
128
130
129
131
TargetPlatform platform = board .getContainerPlatform ();
130
132
TargetPackage aPackage = platform .getContainerPackage ();
133
+ String vidpid = VIDPID ();
131
134
132
- PreferencesMap prefs = loadPreferences (board , platform , aPackage );
135
+ PreferencesMap prefs = loadPreferences (board , platform , aPackage , vidpid );
133
136
134
137
MessageConsumerOutputStream out = new MessageConsumerOutputStream (new ProgressAwareMessageConsumer (new I18NAwareMessageConsumer (System .out ), progListener ), "\n " );
135
138
MessageConsumerOutputStream err = new MessageConsumerOutputStream (new I18NAwareMessageConsumer (System .err , Compiler .this ), "\n " );
136
139
137
- callArduinoBuilder (board , platform , aPackage , BuilderAction .COMPILE , new PumpStreamHandler (out , err ));
140
+ callArduinoBuilder (board , platform , aPackage , vidpid , BuilderAction .COMPILE , new PumpStreamHandler (out , err ));
138
141
139
142
out .flush ();
140
143
err .flush ();
@@ -152,12 +155,27 @@ public String build(CompilerProgressListener progListener, boolean exportHex) th
152
155
return sketch .getName () + ".ino" ;
153
156
}
154
157
155
- private PreferencesMap loadPreferences (TargetBoard board , TargetPlatform platform , TargetPackage aPackage ) throws RunnerException , IOException {
158
+ private String VIDPID () {
159
+ BoardPort boardPort = BaseNoGui .getDiscoveryManager ().find (PreferencesData .get ("serial.port" ));
160
+ if (boardPort == null ) {
161
+ return "" ;
162
+ }
163
+
164
+ String vid = boardPort .getPrefs ().get ("vid" );
165
+ String pid = boardPort .getPrefs ().get ("pid" );
166
+ if (StringUtils .isEmpty (vid ) || StringUtils .isEmpty (pid )) {
167
+ return "" ;
168
+ }
169
+
170
+ return vid .toUpperCase () + "_" + pid .toUpperCase ();
171
+ }
172
+
173
+ private PreferencesMap loadPreferences (TargetBoard board , TargetPlatform platform , TargetPackage aPackage , String vidpid ) throws RunnerException , IOException {
156
174
ByteArrayOutputStream stdout = new ByteArrayOutputStream ();
157
175
ByteArrayOutputStream stderr = new ByteArrayOutputStream ();
158
176
MessageConsumerOutputStream err = new MessageConsumerOutputStream (new I18NAwareMessageConsumer (new PrintStream (stderr ), Compiler .this ), "\n " );
159
177
try {
160
- callArduinoBuilder (board , platform , aPackage , BuilderAction .DUMP_PREFS , new PumpStreamHandler (stdout , err ));
178
+ callArduinoBuilder (board , platform , aPackage , vidpid , BuilderAction .DUMP_PREFS , new PumpStreamHandler (stdout , err ));
161
179
} catch (RunnerException e ) {
162
180
System .err .println (new String (stderr .toByteArray ()));
163
181
throw e ;
@@ -167,7 +185,7 @@ private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platfor
167
185
return prefs ;
168
186
}
169
187
170
- private void callArduinoBuilder (TargetBoard board , TargetPlatform platform , TargetPackage aPackage , BuilderAction action , PumpStreamHandler streamHandler ) throws RunnerException {
188
+ private void callArduinoBuilder (TargetBoard board , TargetPlatform platform , TargetPackage aPackage , String vidpid , BuilderAction action , PumpStreamHandler streamHandler ) throws RunnerException {
171
189
File executable = BaseNoGui .getContentFile ("arduino-builder" );
172
190
CommandLine commandLine = new CommandLine (executable );
173
191
commandLine .addArgument (action .value , false );
@@ -197,6 +215,10 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
197
215
String fqbn = Stream .of (aPackage .getId (), platform .getId (), board .getId (), boardOptions (board )).filter (s -> !s .isEmpty ()).collect (Collectors .joining (":" ));
198
216
commandLine .addArgument ("-fqbn=" + fqbn , false );
199
217
218
+ if (!"" .equals (vidpid )) {
219
+ commandLine .addArgument ("-vid-pid=" + vidpid , false );
220
+ }
221
+
200
222
commandLine .addArgument ("-ide-version=" + BaseNoGui .REVISION , false );
201
223
commandLine .addArgument ("-build-path" , false );
202
224
commandLine .addArgument ("\" " + buildPath + "\" " , false );
0 commit comments