1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Moved the sketch uploading code from Sketch to Compiler.

This commit is contained in:
Claudio Indellicati 2014-08-25 13:10:53 +02:00 committed by Cristian Maglie
parent 998142d16d
commit 061d1f14b6
2 changed files with 53 additions and 10 deletions

View File

@ -23,13 +23,10 @@
package processing.app;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.UploaderFactory;
import cc.arduino.packages.Uploader;
import processing.app.debug.Compiler;
import processing.app.debug.Compiler.ProgressListener;
import processing.app.debug.RunnerException;
import processing.app.debug.TargetPlatform;
import processing.app.forms.PasswordAuthorizationDialog;
import processing.app.helpers.OSUtils;
import processing.app.packages.Library;
@ -1193,12 +1190,7 @@ public class Sketch {
protected boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
TargetPlatform target = Base.getTargetPlatform();
String board = Preferences.get("board");
BoardPort boardPort = Base.getDiscoveryManager().find(Preferences.get("serial.port"));
Uploader uploader = new UploaderFactory().newUploader(target.getBoards().get(board), boardPort);
Uploader uploader = Compiler.getUploaderByPreferences();
boolean success = false;
do {
@ -1217,7 +1209,7 @@ public class Sketch {
List<String> warningsAccumulator = new LinkedList<String>();
try {
success = uploader.uploadUsingPreferences(getFolder(), buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
} finally {
if (uploader.requiresAuthorization() && !success) {
Preferences.remove(uploader.getAuthorizationKey());

View File

@ -34,11 +34,16 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Uploader;
import cc.arduino.packages.UploaderFactory;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;
@ -117,6 +122,52 @@ public class Compiler implements MessageConsumer {
return null;
}
static public Uploader getUploaderByPreferences() {
TargetPlatform target = BaseNoGui.getTargetPlatform();
String board = PreferencesData.get("board");
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort);
}
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
if (uploader == null)
uploader = getUploaderByPreferences();
boolean success = false;
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) {
BaseNoGui.showError(_("Authorization required"),
_("No athorization data found"), null);
}
boolean useNewWarningsAccumulator = false;
if (warningsAccumulator == null) {
warningsAccumulator = new LinkedList<String>();
useNewWarningsAccumulator = true;
}
try {
success = uploader.uploadUsingPreferences(data.getFolder(), buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
} finally {
if (uploader.requiresAuthorization() && !success) {
PreferencesData.remove(uploader.getAuthorizationKey());
}
}
if (useNewWarningsAccumulator) {
for (String warning : warningsAccumulator) {
System.out.print(_("Warning"));
System.out.print(": ");
System.out.println(warning);
}
}
return success;
}
/**
* Create a new Compiler
* @param _sketch Sketch object to be compiled.