Skip to content

Commit 061d1f1

Browse files
bitroncmaglie
authored andcommitted
Moved the sketch uploading code from Sketch to Compiler.
1 parent 998142d commit 061d1f1

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

app/src/processing/app/Sketch.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@
2323

2424
package processing.app;
2525

26-
import cc.arduino.packages.BoardPort;
27-
import cc.arduino.packages.UploaderFactory;
2826
import cc.arduino.packages.Uploader;
2927
import processing.app.debug.Compiler;
3028
import processing.app.debug.Compiler.ProgressListener;
3129
import processing.app.debug.RunnerException;
32-
import processing.app.debug.TargetPlatform;
3330
import processing.app.forms.PasswordAuthorizationDialog;
3431
import processing.app.helpers.OSUtils;
3532
import processing.app.packages.Library;
@@ -1193,12 +1190,7 @@ public boolean exportApplet(String appletPath, boolean usingProgrammer)
11931190

11941191
protected boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
11951192

1196-
TargetPlatform target = Base.getTargetPlatform();
1197-
String board = Preferences.get("board");
1198-
1199-
BoardPort boardPort = Base.getDiscoveryManager().find(Preferences.get("serial.port"));
1200-
1201-
Uploader uploader = new UploaderFactory().newUploader(target.getBoards().get(board), boardPort);
1193+
Uploader uploader = Compiler.getUploaderByPreferences();
12021194

12031195
boolean success = false;
12041196
do {
@@ -1217,7 +1209,7 @@ protected boolean upload(String buildPath, String suggestedClassName, boolean us
12171209

12181210
List<String> warningsAccumulator = new LinkedList<String>();
12191211
try {
1220-
success = uploader.uploadUsingPreferences(getFolder(), buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
1212+
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
12211213
} finally {
12221214
if (uploader.requiresAuthorization() && !success) {
12231215
Preferences.remove(uploader.getAuthorizationKey());

app/src/processing/app/debug/Compiler.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@
3434
import java.io.PrintWriter;
3535
import java.util.ArrayList;
3636
import java.util.Arrays;
37+
import java.util.LinkedList;
3738
import java.util.List;
3839
import java.util.Map;
3940
import java.util.SortedSet;
4041
import java.util.TreeSet;
4142

43+
import cc.arduino.packages.BoardPort;
44+
import cc.arduino.packages.Uploader;
45+
import cc.arduino.packages.UploaderFactory;
46+
4247
import processing.app.BaseNoGui;
4348
import processing.app.I18n;
4449
import processing.app.PreferencesData;
@@ -117,6 +122,52 @@ static public String build(SketchData data, String buildPath, File tempBuildFold
117122
return null;
118123
}
119124

125+
static public Uploader getUploaderByPreferences() {
126+
TargetPlatform target = BaseNoGui.getTargetPlatform();
127+
String board = PreferencesData.get("board");
128+
129+
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
130+
131+
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort);
132+
}
133+
134+
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
135+
136+
if (uploader == null)
137+
uploader = getUploaderByPreferences();
138+
139+
boolean success = false;
140+
141+
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) {
142+
BaseNoGui.showError(_("Authorization required"),
143+
_("No athorization data found"), null);
144+
}
145+
146+
boolean useNewWarningsAccumulator = false;
147+
if (warningsAccumulator == null) {
148+
warningsAccumulator = new LinkedList<String>();
149+
useNewWarningsAccumulator = true;
150+
}
151+
152+
try {
153+
success = uploader.uploadUsingPreferences(data.getFolder(), buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
154+
} finally {
155+
if (uploader.requiresAuthorization() && !success) {
156+
PreferencesData.remove(uploader.getAuthorizationKey());
157+
}
158+
}
159+
160+
if (useNewWarningsAccumulator) {
161+
for (String warning : warningsAccumulator) {
162+
System.out.print(_("Warning"));
163+
System.out.print(": ");
164+
System.out.println(warning);
165+
}
166+
}
167+
168+
return success;
169+
}
170+
120171
/**
121172
* Create a new Compiler
122173
* @param _sketch Sketch object to be compiled.

0 commit comments

Comments
 (0)