3030package cc .arduino ;
3131
3232import cc .arduino .i18n .I18NAwareMessageConsumer ;
33+ import cc .arduino .packages .BoardPort ;
3334import org .apache .commons .exec .CommandLine ;
3435import org .apache .commons .exec .DefaultExecutor ;
3536import org .apache .commons .exec .PumpStreamHandler ;
37+ import org .apache .commons .lang3 .StringUtils ;
3638import processing .app .*;
3739import processing .app .debug .*;
3840import processing .app .helpers .PreferencesMap ;
@@ -128,13 +130,14 @@ public String build(CompilerProgressListener progListener, boolean exportHex) th
128130
129131 TargetPlatform platform = board .getContainerPlatform ();
130132 TargetPackage aPackage = platform .getContainerPackage ();
133+ String vidpid = VIDPID ();
131134
132- PreferencesMap prefs = loadPreferences (board , platform , aPackage );
135+ PreferencesMap prefs = loadPreferences (board , platform , aPackage , vidpid );
133136
134137 MessageConsumerOutputStream out = new MessageConsumerOutputStream (new ProgressAwareMessageConsumer (new I18NAwareMessageConsumer (System .out ), progListener ), "\n " );
135138 MessageConsumerOutputStream err = new MessageConsumerOutputStream (new I18NAwareMessageConsumer (System .err , Compiler .this ), "\n " );
136139
137- callArduinoBuilder (board , platform , aPackage , BuilderAction .COMPILE , new PumpStreamHandler (out , err ));
140+ callArduinoBuilder (board , platform , aPackage , vidpid , BuilderAction .COMPILE , new PumpStreamHandler (out , err ));
138141
139142 out .flush ();
140143 err .flush ();
@@ -152,12 +155,27 @@ public String build(CompilerProgressListener progListener, boolean exportHex) th
152155 return sketch .getName () + ".ino" ;
153156 }
154157
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 {
156174 ByteArrayOutputStream stdout = new ByteArrayOutputStream ();
157175 ByteArrayOutputStream stderr = new ByteArrayOutputStream ();
158176 MessageConsumerOutputStream err = new MessageConsumerOutputStream (new I18NAwareMessageConsumer (new PrintStream (stderr ), Compiler .this ), "\n " );
159177 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 ));
161179 } catch (RunnerException e ) {
162180 System .err .println (new String (stderr .toByteArray ()));
163181 throw e ;
@@ -167,7 +185,7 @@ private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platfor
167185 return prefs ;
168186 }
169187
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 {
171189 File executable = BaseNoGui .getContentFile ("arduino-builder" );
172190 CommandLine commandLine = new CommandLine (executable );
173191 commandLine .addArgument (action .value , false );
@@ -197,6 +215,10 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
197215 String fqbn = Stream .of (aPackage .getId (), platform .getId (), board .getId (), boardOptions (board )).filter (s -> !s .isEmpty ()).collect (Collectors .joining (":" ));
198216 commandLine .addArgument ("-fqbn=" + fqbn , false );
199217
218+ if (!"" .equals (vidpid )) {
219+ commandLine .addArgument ("-vid-pid=" + vidpid , false );
220+ }
221+
200222 commandLine .addArgument ("-ide-version=" + BaseNoGui .REVISION , false );
201223 commandLine .addArgument ("-build-path" , false );
202224 commandLine .addArgument ("\" " + buildPath + "\" " , false );
0 commit comments