mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Moved the sketch uploading code from Sketch to Compiler.
This commit is contained in:
parent
998142d16d
commit
061d1f14b6
@ -23,13 +23,10 @@
|
|||||||
|
|
||||||
package processing.app;
|
package processing.app;
|
||||||
|
|
||||||
import cc.arduino.packages.BoardPort;
|
|
||||||
import cc.arduino.packages.UploaderFactory;
|
|
||||||
import cc.arduino.packages.Uploader;
|
import cc.arduino.packages.Uploader;
|
||||||
import processing.app.debug.Compiler;
|
import processing.app.debug.Compiler;
|
||||||
import processing.app.debug.Compiler.ProgressListener;
|
import processing.app.debug.Compiler.ProgressListener;
|
||||||
import processing.app.debug.RunnerException;
|
import processing.app.debug.RunnerException;
|
||||||
import processing.app.debug.TargetPlatform;
|
|
||||||
import processing.app.forms.PasswordAuthorizationDialog;
|
import processing.app.forms.PasswordAuthorizationDialog;
|
||||||
import processing.app.helpers.OSUtils;
|
import processing.app.helpers.OSUtils;
|
||||||
import processing.app.packages.Library;
|
import processing.app.packages.Library;
|
||||||
@ -1193,12 +1190,7 @@ public class Sketch {
|
|||||||
|
|
||||||
protected boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
|
protected boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
|
||||||
|
|
||||||
TargetPlatform target = Base.getTargetPlatform();
|
Uploader uploader = Compiler.getUploaderByPreferences();
|
||||||
String board = Preferences.get("board");
|
|
||||||
|
|
||||||
BoardPort boardPort = Base.getDiscoveryManager().find(Preferences.get("serial.port"));
|
|
||||||
|
|
||||||
Uploader uploader = new UploaderFactory().newUploader(target.getBoards().get(board), boardPort);
|
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
do {
|
do {
|
||||||
@ -1217,7 +1209,7 @@ public class Sketch {
|
|||||||
|
|
||||||
List<String> warningsAccumulator = new LinkedList<String>();
|
List<String> warningsAccumulator = new LinkedList<String>();
|
||||||
try {
|
try {
|
||||||
success = uploader.uploadUsingPreferences(getFolder(), buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
|
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
|
||||||
} finally {
|
} finally {
|
||||||
if (uploader.requiresAuthorization() && !success) {
|
if (uploader.requiresAuthorization() && !success) {
|
||||||
Preferences.remove(uploader.getAuthorizationKey());
|
Preferences.remove(uploader.getAuthorizationKey());
|
||||||
|
@ -34,11 +34,16 @@ import java.io.IOException;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
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.BaseNoGui;
|
||||||
import processing.app.I18n;
|
import processing.app.I18n;
|
||||||
import processing.app.PreferencesData;
|
import processing.app.PreferencesData;
|
||||||
@ -117,6 +122,52 @@ public class Compiler implements MessageConsumer {
|
|||||||
return null;
|
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
|
* Create a new Compiler
|
||||||
* @param _sketch Sketch object to be compiled.
|
* @param _sketch Sketch object to be compiled.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user