better error handling on uploading

This commit is contained in:
Federico Fissore 2013-05-28 17:46:15 +02:00
parent c174737584
commit 556c6ea5c1
2 changed files with 42 additions and 36 deletions

View File

@ -89,7 +89,7 @@ public class Sketch {
private String classPath;
/**
* List of library folders.
* List of library folders.
*/
private LibraryList importedLibraries;
@ -397,7 +397,7 @@ public class Sketch {
return;
}
}
// 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
// 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."));
return;
}
if (renamingCode && currentIndex == 0) {
for (int i = 1; i < codeCount; i++) {
if (sanitaryName.equalsIgnoreCase(code[i].getPrettyName()) &&
@ -726,7 +726,7 @@ public class Sketch {
return name.toLowerCase().endsWith(".pde");
}
});
if (pdeFiles != null && pdeFiles.length > 0) {
if (Preferences.get("editor.update_extension") == null) {
Object[] options = { _("OK"), _("Cancel") };
@ -744,12 +744,12 @@ public class Sketch {
null,
options,
options[0]);
if (result != JOptionPane.OK_OPTION) return false; // save cancelled
Preferences.setBoolean("editor.update_extension", true);
}
if (Preferences.getBoolean("editor.update_extension")) {
// Do rename of all .pde files to new .ino extension
for (File pdeFile : pdeFiles)
@ -759,14 +759,14 @@ public class Sketch {
}
for (int i = 0; i < codeCount; i++) {
if (code[i].isModified())
if (code[i].isModified())
code[i].save();
}
calcModified();
return true;
}
protected boolean renameCodeToInoExtension(File pdeFile) {
for (SketchCode c : code) {
if (!c.getFile().equals(pdeFile))
@ -778,7 +778,7 @@ public class Sketch {
}
return false;
}
/**
* Handles 'Save As' for a sketch.
@ -1118,7 +1118,7 @@ public class Sketch {
public void importLibrary(Library lib) throws IOException {
importLibrary(lib.getSrcFolder());
}
/**
* Add import statements to the current tab for all of packages inside
* the specified jar file.
@ -1211,13 +1211,13 @@ public class Sketch {
// need to be recompiled, or if the board does not
// use setting build.dependency
//Base.removeDir(tempBuildFolder);
// note that we can't remove the builddir itself, otherwise
// 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
// will ignore the fact that that dir is in the CLASSPATH in run.sh
Base.removeDescendants(tempBuildFolder);
deleteFilesOnNextBuild = false;
} else {
// 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)
//tempBuildFolder.mkdirs();
}
@ -1277,8 +1277,8 @@ public class Sketch {
private static boolean deleteFilesOnNextBuild = true;
/**
* When running from the editor, take care of preparations before running
* the build.
* When running from the editor, take care of preparations before running
* the build.
*/
public void prepare() {
// make sure the user didn't hide the sketch folder
@ -1398,7 +1398,7 @@ public class Sketch {
FileOutputStream outputStream = new FileOutputStream(streamFile);
preprocessor.write(outputStream);
outputStream.close();
// store this for the compiler and the runtime
primaryClassName = name + ".cpp";
@ -1461,7 +1461,7 @@ public class Sketch {
return importedLibraries;
}
/**
* Map an error from a set of processed .java files back to its location
* in the actual sketch.
@ -1510,7 +1510,7 @@ public class Sketch {
// }
// return null;
// }
/**
* 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
* possible to place the exception to the sketch code.
*/
public RunnerException placeException(String message,
String dotJavaFilename,
public RunnerException placeException(String message,
String dotJavaFilename,
int dotJavaLine) {
// Placing errors is simple, because we inserted #line directives
// into the preprocessed source. The compiler gives us correct
@ -1569,8 +1569,8 @@ public class Sketch {
return primaryClassName;
}
return null;
}
}
protected boolean exportApplet(boolean usingProgrammer) throws Exception {
return exportApplet(tempBuildFolder.getAbsolutePath(), usingProgrammer);
}
@ -1583,7 +1583,7 @@ public class Sketch {
throws RunnerException, IOException, SerialException {
prepare();
// build the sketch
editor.status.progressNotice(_("Compiling sketch..."));
String foundName = build(appletPath, false);
@ -1605,7 +1605,7 @@ public class Sketch {
return success;
}
public void setCompilingProgress(int percent) {
editor.status.progressUpdate(percent);
}
@ -1629,7 +1629,7 @@ public class Sketch {
e.getMessage()));
return;
}
long textSize = sizes[0];
long dataSize = sizes[1];
System.out.println(I18n
@ -1680,11 +1680,14 @@ public class Sketch {
Preferences.set(uploader.getAuthorizationKey(), DigestUtils.sha256Hex(dialog.getPassword()));
}
success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
if (uploader.requiresAuthorization() && !success) {
Preferences.remove(uploader.getAuthorizationKey());
try {
success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
} finally {
if (uploader.requiresAuthorization() && !success) {
Preferences.remove(uploader.getAuthorizationKey());
}
}
} while (uploader.requiresAuthorization() && !success);
return success;
@ -1695,9 +1698,9 @@ public class Sketch {
return false;
}
/**
* Export to application via GUI.
* Export to application via GUI.
*/
protected boolean exportApplication() throws IOException, RunnerException {
return false;
@ -1763,7 +1766,7 @@ public class Sketch {
// canWrite() doesn't work on directories
// } else if (!folder.canWrite()) {
// check to see if each modified code file can be written to
for (int i = 0; i < codeCount; i++) {
if (code[i].isModified() && code[i].fileReadOnly() &&
@ -1831,7 +1834,7 @@ public class Sketch {
public List<String> getHiddenExtensions() {
return hiddenExtensions;
}
/**
* Returns a String[] array of proper extensions.
*/

View File

@ -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");
get.setRequestHeader("Authorization", "Basic " + auth);
try {
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;
} catch (IOException e) {
e.printStackTrace();
return true;
}
}