|
34 | 34 | import java.io.PrintWriter;
|
35 | 35 | import java.util.ArrayList;
|
36 | 36 | import java.util.Arrays;
|
| 37 | +import java.util.LinkedList; |
37 | 38 | import java.util.List;
|
38 | 39 | import java.util.Map;
|
39 | 40 | import java.util.SortedSet;
|
40 | 41 | import java.util.TreeSet;
|
41 | 42 |
|
| 43 | +import cc.arduino.packages.BoardPort; |
| 44 | +import cc.arduino.packages.Uploader; |
| 45 | +import cc.arduino.packages.UploaderFactory; |
| 46 | + |
42 | 47 | import processing.app.BaseNoGui;
|
43 | 48 | import processing.app.I18n;
|
44 | 49 | import processing.app.PreferencesData;
|
@@ -117,6 +122,52 @@ static public String build(SketchData data, String buildPath, File tempBuildFold
|
117 | 122 | return null;
|
118 | 123 | }
|
119 | 124 |
|
| 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 | + |
120 | 171 | /**
|
121 | 172 | * Create a new Compiler
|
122 | 173 | * @param _sketch Sketch object to be compiled.
|
|
0 commit comments