Skip to content

Fix unneeded "Select port on upload" message #8194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 14, 2018
2 changes: 2 additions & 0 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,8 @@ private void handleBurnBootloader() {
SwingUtilities.invokeLater(() -> statusError(tr("Error while burning bootloader.")));
// error message will already be visible
}
} catch (SerialNotFoundException e) {
SwingUtilities.invokeLater(() -> statusError(tr("Error while burning bootloader: please select a serial port.")));
} catch (PreferencesMapException e) {
SwingUtilities.invokeLater(() -> {
statusError(I18n.format(
Expand Down
4 changes: 0 additions & 4 deletions app/src/processing/app/SketchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,6 @@ private boolean upload(String suggestedClassName, boolean usingProgrammer) throw

UploaderUtils uploaderInstance = new UploaderUtils();
Uploader uploader = uploaderInstance.getUploaderByPreferences(false);
if (uploader == null) {
editor.statusError(tr("Please select a Port before Upload"));
return false;
}

EditorConsole.setCurrentEditorConsole(editor.console);

Expand Down
3 changes: 0 additions & 3 deletions arduino-core/src/cc/arduino/UploaderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public Uploader getUploaderByPreferences(boolean noUploadPort) {
BoardPort boardPort = null;
if (!noUploadPort) {
String port = PreferencesData.get("serial.port");
if (port == null || port.isEmpty()) {
return null;
}
boardPort = BaseNoGui.getDiscoveryManager().find(port);
}

Expand Down
57 changes: 26 additions & 31 deletions arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import processing.app.debug.RunnerException;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.PreferencesMapException;
import processing.app.helpers.StringReplacer;

import java.io.File;
Expand Down Expand Up @@ -105,17 +106,11 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
else
prefs.put("upload.verify", prefs.get("upload.params.noverify", ""));

boolean uploadResult;
try {
String pattern = prefs.getOrExcept("upload.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
uploadResult = executeUploadCommand(cmd);
} catch (Exception e) {
throw new RunnerException(e);
return runCommand("upload.pattern", prefs);
} finally {
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
}
return uploadResult;
}

// need to do a little dance for Leonardo and derivatives:
Expand All @@ -127,7 +122,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
boolean doTouch = prefs.getBoolean("upload.use_1200bps_touch");
boolean waitForUploadPort = prefs.getBoolean("upload.wait_for_upload_port");

String userSelectedUploadPort = prefs.getOrExcept("serial.port");
String userSelectedUploadPort = prefs.get("serial.port", "");
String actualUploadPort = null;

if (doTouch) {
Expand Down Expand Up @@ -177,7 +172,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
Thread.sleep(100);
}

BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port", ""));
try {
prefs.put("serial.port.iserial", boardPort.getPrefs().getOrExcept("iserial"));
} catch (Exception e) {
Expand All @@ -199,13 +194,7 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String

boolean uploadResult;
try {
String pattern = prefs.getOrExcept("upload.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
uploadResult = executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
} catch (Exception e) {
throw new RunnerException(e);
uploadResult = runCommand("upload.pattern", prefs);
} finally {
BaseNoGui.getDiscoveryManager().getSerialDiscoverer().pausePolling(false);
}
Expand Down Expand Up @@ -328,15 +317,7 @@ private boolean uploadUsingProgrammer(String buildPath, String className) throws
else
prefs.put("program.verify", prefs.get("program.params.noverify", ""));

try {
String pattern = prefs.getOrExcept("program.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
return executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
} catch (Exception e) {
throw new RunnerException(e);
}
return runCommand("program.pattern", prefs);
}

@Override
Expand Down Expand Up @@ -393,13 +374,27 @@ public boolean burnBootloader() throws Exception {

new LoadVIDPIDSpecificPreferences().load(prefs);

String pattern = prefs.getOrExcept("erase.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
if (!executeUploadCommand(cmd))
if (!runCommand("erase.pattern", prefs))
return false;

pattern = prefs.getOrExcept("bootloader.pattern");
cmd = StringReplacer.formatAndSplit(pattern, prefs);
return executeUploadCommand(cmd);
return runCommand("bootloader.pattern", prefs);
}

private boolean runCommand(String patternKey, PreferencesMap prefs) throws Exception, RunnerException {
try {
String pattern = prefs.getOrExcept(patternKey);
StringReplacer.checkIfRequiredKeyIsMissingOrExcept("serial.port", pattern, prefs);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only line that can throw a PreferencesMapException? If so, wouldn't it be better to have a smaller try block for that (or perhaps even let checkIfRequiredKeyIsMissingOrExcept return a boolean, if all it does is except or not except)?

Reading this, I wonder: Shouldn't StringReplacer.formatAndSplit (etc.) just throw when they find any unset variable? Or does that break for optional variables in some cases?

String[] cmd = StringReplacer.formatAndSplit(pattern, prefs);
return executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
} catch (PreferencesMapException e) {
if (e.getMessage().equals("serial.port")) {
throw new SerialNotFoundException(e);
}
throw e;
} catch (Exception e) {
throw new RunnerException(e);
}
}
}
4 changes: 2 additions & 2 deletions build/shared/lib/preferences.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ programmer = arduino:avrispmkii
upload.using = bootloader
upload.verify = true

#default port is empty to prevent running AVRDUDE before Port selected (issue #7943)
serial.port=
# default port is not defined to prevent running AVRDUDE before Port selected (issue #7943)
#serial.port=
serial.databits=8
serial.stopbits=1
serial.parity=N
Expand Down