mirror of https://github.com/noisymime/Arduino.git
better error handling on uploading
This commit is contained in:
parent
c174737584
commit
556c6ea5c1
|
@ -89,7 +89,7 @@ public class Sketch {
|
||||||
private String classPath;
|
private String classPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of library folders.
|
* List of library folders.
|
||||||
*/
|
*/
|
||||||
private LibraryList importedLibraries;
|
private LibraryList importedLibraries;
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ public class Sketch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In Arduino, don't allow a .cpp file with the same name as the sketch,
|
// In Arduino, don't allow a .cpp file with the same name as the sketch,
|
||||||
// because the sketch is concatenated into a file with that name as part
|
// because the sketch is concatenated into a file with that name as part
|
||||||
// of the build process.
|
// of the build process.
|
||||||
|
@ -406,7 +406,7 @@ public class Sketch {
|
||||||
_("You can't have a .cpp file with the same name as the sketch."));
|
_("You can't have a .cpp file with the same name as the sketch."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renamingCode && currentIndex == 0) {
|
if (renamingCode && currentIndex == 0) {
|
||||||
for (int i = 1; i < codeCount; i++) {
|
for (int i = 1; i < codeCount; i++) {
|
||||||
if (sanitaryName.equalsIgnoreCase(code[i].getPrettyName()) &&
|
if (sanitaryName.equalsIgnoreCase(code[i].getPrettyName()) &&
|
||||||
|
@ -726,7 +726,7 @@ public class Sketch {
|
||||||
return name.toLowerCase().endsWith(".pde");
|
return name.toLowerCase().endsWith(".pde");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (pdeFiles != null && pdeFiles.length > 0) {
|
if (pdeFiles != null && pdeFiles.length > 0) {
|
||||||
if (Preferences.get("editor.update_extension") == null) {
|
if (Preferences.get("editor.update_extension") == null) {
|
||||||
Object[] options = { _("OK"), _("Cancel") };
|
Object[] options = { _("OK"), _("Cancel") };
|
||||||
|
@ -744,12 +744,12 @@ public class Sketch {
|
||||||
null,
|
null,
|
||||||
options,
|
options,
|
||||||
options[0]);
|
options[0]);
|
||||||
|
|
||||||
if (result != JOptionPane.OK_OPTION) return false; // save cancelled
|
if (result != JOptionPane.OK_OPTION) return false; // save cancelled
|
||||||
|
|
||||||
Preferences.setBoolean("editor.update_extension", true);
|
Preferences.setBoolean("editor.update_extension", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Preferences.getBoolean("editor.update_extension")) {
|
if (Preferences.getBoolean("editor.update_extension")) {
|
||||||
// Do rename of all .pde files to new .ino extension
|
// Do rename of all .pde files to new .ino extension
|
||||||
for (File pdeFile : pdeFiles)
|
for (File pdeFile : pdeFiles)
|
||||||
|
@ -759,14 +759,14 @@ public class Sketch {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < codeCount; i++) {
|
for (int i = 0; i < codeCount; i++) {
|
||||||
if (code[i].isModified())
|
if (code[i].isModified())
|
||||||
code[i].save();
|
code[i].save();
|
||||||
}
|
}
|
||||||
calcModified();
|
calcModified();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected boolean renameCodeToInoExtension(File pdeFile) {
|
protected boolean renameCodeToInoExtension(File pdeFile) {
|
||||||
for (SketchCode c : code) {
|
for (SketchCode c : code) {
|
||||||
if (!c.getFile().equals(pdeFile))
|
if (!c.getFile().equals(pdeFile))
|
||||||
|
@ -778,7 +778,7 @@ public class Sketch {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles 'Save As' for a sketch.
|
* Handles 'Save As' for a sketch.
|
||||||
|
@ -1118,7 +1118,7 @@ public class Sketch {
|
||||||
public void importLibrary(Library lib) throws IOException {
|
public void importLibrary(Library lib) throws IOException {
|
||||||
importLibrary(lib.getSrcFolder());
|
importLibrary(lib.getSrcFolder());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add import statements to the current tab for all of packages inside
|
* Add import statements to the current tab for all of packages inside
|
||||||
* the specified jar file.
|
* the specified jar file.
|
||||||
|
@ -1211,13 +1211,13 @@ public class Sketch {
|
||||||
// need to be recompiled, or if the board does not
|
// need to be recompiled, or if the board does not
|
||||||
// use setting build.dependency
|
// use setting build.dependency
|
||||||
//Base.removeDir(tempBuildFolder);
|
//Base.removeDir(tempBuildFolder);
|
||||||
|
|
||||||
// note that we can't remove the builddir itself, otherwise
|
// note that we can't remove the builddir itself, otherwise
|
||||||
// the next time we start up, internal runs using Runner won't
|
// the next time we start up, internal runs using Runner won't
|
||||||
// work because the build dir won't exist at startup, so the classloader
|
// work because the build dir won't exist at startup, so the classloader
|
||||||
// will ignore the fact that that dir is in the CLASSPATH in run.sh
|
// will ignore the fact that that dir is in the CLASSPATH in run.sh
|
||||||
Base.removeDescendants(tempBuildFolder);
|
Base.removeDescendants(tempBuildFolder);
|
||||||
|
|
||||||
deleteFilesOnNextBuild = false;
|
deleteFilesOnNextBuild = false;
|
||||||
} else {
|
} else {
|
||||||
// delete only stale source files, from the previously
|
// delete only stale source files, from the previously
|
||||||
|
@ -1235,7 +1235,7 @@ public class Sketch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a fresh applet folder (needed before preproc is run below)
|
// Create a fresh applet folder (needed before preproc is run below)
|
||||||
//tempBuildFolder.mkdirs();
|
//tempBuildFolder.mkdirs();
|
||||||
}
|
}
|
||||||
|
@ -1277,8 +1277,8 @@ public class Sketch {
|
||||||
private static boolean deleteFilesOnNextBuild = true;
|
private static boolean deleteFilesOnNextBuild = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When running from the editor, take care of preparations before running
|
* When running from the editor, take care of preparations before running
|
||||||
* the build.
|
* the build.
|
||||||
*/
|
*/
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
// make sure the user didn't hide the sketch folder
|
// make sure the user didn't hide the sketch folder
|
||||||
|
@ -1398,7 +1398,7 @@ public class Sketch {
|
||||||
FileOutputStream outputStream = new FileOutputStream(streamFile);
|
FileOutputStream outputStream = new FileOutputStream(streamFile);
|
||||||
preprocessor.write(outputStream);
|
preprocessor.write(outputStream);
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
|
|
||||||
// store this for the compiler and the runtime
|
// store this for the compiler and the runtime
|
||||||
primaryClassName = name + ".cpp";
|
primaryClassName = name + ".cpp";
|
||||||
|
|
||||||
|
@ -1461,7 +1461,7 @@ public class Sketch {
|
||||||
return importedLibraries;
|
return importedLibraries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map an error from a set of processed .java files back to its location
|
* Map an error from a set of processed .java files back to its location
|
||||||
* in the actual sketch.
|
* in the actual sketch.
|
||||||
|
@ -1510,7 +1510,7 @@ public class Sketch {
|
||||||
// }
|
// }
|
||||||
// return null;
|
// return null;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map an error from a set of processed .java files back to its location
|
* Map an error from a set of processed .java files back to its location
|
||||||
|
@ -1521,8 +1521,8 @@ public class Sketch {
|
||||||
* @return A RunnerException to be sent to the editor, or null if it wasn't
|
* @return A RunnerException to be sent to the editor, or null if it wasn't
|
||||||
* possible to place the exception to the sketch code.
|
* possible to place the exception to the sketch code.
|
||||||
*/
|
*/
|
||||||
public RunnerException placeException(String message,
|
public RunnerException placeException(String message,
|
||||||
String dotJavaFilename,
|
String dotJavaFilename,
|
||||||
int dotJavaLine) {
|
int dotJavaLine) {
|
||||||
// Placing errors is simple, because we inserted #line directives
|
// Placing errors is simple, because we inserted #line directives
|
||||||
// into the preprocessed source. The compiler gives us correct
|
// into the preprocessed source. The compiler gives us correct
|
||||||
|
@ -1569,8 +1569,8 @@ public class Sketch {
|
||||||
return primaryClassName;
|
return primaryClassName;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean exportApplet(boolean usingProgrammer) throws Exception {
|
protected boolean exportApplet(boolean usingProgrammer) throws Exception {
|
||||||
return exportApplet(tempBuildFolder.getAbsolutePath(), usingProgrammer);
|
return exportApplet(tempBuildFolder.getAbsolutePath(), usingProgrammer);
|
||||||
}
|
}
|
||||||
|
@ -1583,7 +1583,7 @@ public class Sketch {
|
||||||
throws RunnerException, IOException, SerialException {
|
throws RunnerException, IOException, SerialException {
|
||||||
|
|
||||||
prepare();
|
prepare();
|
||||||
|
|
||||||
// build the sketch
|
// build the sketch
|
||||||
editor.status.progressNotice(_("Compiling sketch..."));
|
editor.status.progressNotice(_("Compiling sketch..."));
|
||||||
String foundName = build(appletPath, false);
|
String foundName = build(appletPath, false);
|
||||||
|
@ -1605,7 +1605,7 @@ public class Sketch {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setCompilingProgress(int percent) {
|
public void setCompilingProgress(int percent) {
|
||||||
editor.status.progressUpdate(percent);
|
editor.status.progressUpdate(percent);
|
||||||
}
|
}
|
||||||
|
@ -1629,7 +1629,7 @@ public class Sketch {
|
||||||
e.getMessage()));
|
e.getMessage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long textSize = sizes[0];
|
long textSize = sizes[0];
|
||||||
long dataSize = sizes[1];
|
long dataSize = sizes[1];
|
||||||
System.out.println(I18n
|
System.out.println(I18n
|
||||||
|
@ -1680,11 +1680,14 @@ public class Sketch {
|
||||||
Preferences.set(uploader.getAuthorizationKey(), DigestUtils.sha256Hex(dialog.getPassword()));
|
Preferences.set(uploader.getAuthorizationKey(), DigestUtils.sha256Hex(dialog.getPassword()));
|
||||||
}
|
}
|
||||||
|
|
||||||
success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
|
try {
|
||||||
|
success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
|
||||||
if (uploader.requiresAuthorization() && !success) {
|
} finally {
|
||||||
Preferences.remove(uploader.getAuthorizationKey());
|
if (uploader.requiresAuthorization() && !success) {
|
||||||
|
Preferences.remove(uploader.getAuthorizationKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (uploader.requiresAuthorization() && !success);
|
} while (uploader.requiresAuthorization() && !success);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -1695,9 +1698,9 @@ public class Sketch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export to application via GUI.
|
* Export to application via GUI.
|
||||||
*/
|
*/
|
||||||
protected boolean exportApplication() throws IOException, RunnerException {
|
protected boolean exportApplication() throws IOException, RunnerException {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1763,7 +1766,7 @@ public class Sketch {
|
||||||
|
|
||||||
// canWrite() doesn't work on directories
|
// canWrite() doesn't work on directories
|
||||||
// } else if (!folder.canWrite()) {
|
// } else if (!folder.canWrite()) {
|
||||||
|
|
||||||
// check to see if each modified code file can be written to
|
// check to see if each modified code file can be written to
|
||||||
for (int i = 0; i < codeCount; i++) {
|
for (int i = 0; i < codeCount; i++) {
|
||||||
if (code[i].isModified() && code[i].fileReadOnly() &&
|
if (code[i].isModified() && code[i].fileReadOnly() &&
|
||||||
|
@ -1831,7 +1834,7 @@ public class Sketch {
|
||||||
public List<String> getHiddenExtensions() {
|
public List<String> getHiddenExtensions() {
|
||||||
return hiddenExtensions;
|
return hiddenExtensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a String[] array of proper extensions.
|
* Returns a String[] array of proper extensions.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -155,14 +155,17 @@ public class HttpUploader extends Uploader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean boardNotReady(String auth) {
|
protected boolean boardNotReady(String auth) throws RunnerException {
|
||||||
GetMethod get = new GetMethod(baseUrl + "/ready");
|
GetMethod get = new GetMethod(baseUrl + "/ready");
|
||||||
get.setRequestHeader("Authorization", "Basic " + auth);
|
get.setRequestHeader("Authorization", "Basic " + auth);
|
||||||
try {
|
try {
|
||||||
int httpStatus = client.executeMethod(get);
|
int httpStatus = client.executeMethod(get);
|
||||||
|
if (httpStatus % HttpStatus.SC_BAD_REQUEST < 100 || httpStatus % HttpStatus.SC_INTERNAL_SERVER_ERROR < 100) {
|
||||||
|
System.err.println(get.getResponseBodyAsString());
|
||||||
|
throw new RunnerException("Problem knowing if the board was ready");
|
||||||
|
}
|
||||||
return httpStatus != HttpStatus.SC_OK;
|
return httpStatus != HttpStatus.SC_OK;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue