mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
Added new command line options.
--buildpath --nouploadport --useprogrammer
This commit is contained in:
parent
b2a88ecdd2
commit
1974d77abe
@ -64,11 +64,22 @@ public abstract class Uploader implements MessageConsumer {
|
||||
|
||||
private String error;
|
||||
protected boolean notFoundError;
|
||||
protected boolean noUploadPort;
|
||||
|
||||
protected Uploader() {
|
||||
this.error = null;
|
||||
this.verbose = PreferencesData.getBoolean("upload.verbose");
|
||||
init(false);
|
||||
}
|
||||
|
||||
protected Uploader(boolean nup) {
|
||||
this.verbose = PreferencesData.getBoolean("upload.verbose");
|
||||
init(nup);
|
||||
}
|
||||
|
||||
private void init(boolean nup) {
|
||||
this.error = null;
|
||||
this.notFoundError = false;
|
||||
this.noUploadPort = nup;
|
||||
}
|
||||
|
||||
public abstract boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception;
|
||||
|
@ -35,7 +35,10 @@ import processing.app.debug.TargetBoard;
|
||||
|
||||
public class UploaderFactory {
|
||||
|
||||
public Uploader newUploader(TargetBoard board, BoardPort port) {
|
||||
public Uploader newUploader(TargetBoard board, BoardPort port, boolean noUploadPort) {
|
||||
if (noUploadPort)
|
||||
return new SerialUploader(noUploadPort);
|
||||
|
||||
if ("true".equals(board.getPreferences().get("upload.via_ssh")) && port != null && "network".equals(port.getProtocol())) {
|
||||
return new SSHUploader(port);
|
||||
}
|
||||
|
@ -46,6 +46,16 @@ import cc.arduino.packages.Uploader;
|
||||
|
||||
public class SerialUploader extends Uploader {
|
||||
|
||||
public SerialUploader()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public SerialUploader(boolean noUploadPort)
|
||||
{
|
||||
super(noUploadPort);
|
||||
}
|
||||
|
||||
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
|
||||
// FIXME: Preferences should be reorganized
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
@ -65,6 +75,26 @@ public class SerialUploader extends Uploader {
|
||||
return uploadUsingProgrammer(buildPath, className);
|
||||
}
|
||||
|
||||
if (noUploadPort)
|
||||
{
|
||||
prefs.put("build.path", buildPath);
|
||||
prefs.put("build.project_name", className);
|
||||
if (verbose)
|
||||
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.verbose"));
|
||||
else
|
||||
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.quiet"));
|
||||
|
||||
boolean uploadResult;
|
||||
try {
|
||||
String pattern = prefs.getOrExcept("upload.pattern");
|
||||
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
uploadResult = executeUploadCommand(cmd);
|
||||
} catch (Exception e) {
|
||||
throw new RunnerException(e);
|
||||
}
|
||||
return uploadResult;
|
||||
}
|
||||
|
||||
// need to do a little dance for Leonardo and derivatives:
|
||||
// open then close the port at the magic baudrate (usually 1200 bps) first
|
||||
// to signal to the sketch that it should reset into bootloader. after doing
|
||||
|
@ -477,7 +477,7 @@ public class BaseNoGui {
|
||||
|
||||
if (parser.getFilenames().size() != 1)
|
||||
{
|
||||
showError(_("Multiple files not supported"), _("Only one file at time suported with --upload option"), null);
|
||||
showError(_("Multiple files not supported"), _("The --upload option supports only one file at a time"), null);
|
||||
}
|
||||
|
||||
List<String> warningsAccumulator = new LinkedList<String>();
|
||||
@ -498,14 +498,16 @@ public class BaseNoGui {
|
||||
// - chiama Sketch.build(verbose=false) che chiama Sketch.ensureExistence(), imposta il progressListener e chiama Compiler.build()
|
||||
// - chiama Sketch.upload() (cfr. dopo...)
|
||||
if (!data.getFolder().exists()) showError(_("No sketch"), _("Can't find the sketch in the specified path"), null);
|
||||
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, false);
|
||||
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, parser.isDoVerboseBuild());
|
||||
if (suggestedClassName == null) showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), null);
|
||||
showMessage(_("Done compiling"), _("Done compiling"));
|
||||
|
||||
// - chiama Sketch.upload() ... to be continued ...
|
||||
Uploader uploader = Compiler.getUploaderByPreferences();
|
||||
Uploader uploader = Compiler.getUploaderByPreferences(parser.isNoUploadPort());
|
||||
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) showError(_("..."), _("..."), null);
|
||||
try {
|
||||
success = Compiler.upload(data, uploader, tempBuildFolder.getAbsolutePath(), suggestedClassName, false, warningsAccumulator);
|
||||
success = Compiler.upload(data, uploader, tempBuildFolder.getAbsolutePath(), suggestedClassName, parser.isDoUseProgrammer(), parser.isNoUploadPort(), warningsAccumulator);
|
||||
showMessage(_("Done uploading"), _("Done uploading"));
|
||||
} finally {
|
||||
if (uploader.requiresAuthorization() && !success) {
|
||||
PreferencesData.remove(uploader.getAuthorizationKey());
|
||||
@ -543,6 +545,7 @@ public class BaseNoGui {
|
||||
if (!data.getFolder().exists()) showError(_("No sketch"), _("Can't find the sketch in the specified path"), null);
|
||||
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, parser.isDoVerboseBuild());
|
||||
if (suggestedClassName == null) showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), null);
|
||||
showMessage(_("Done compiling"), _("Done compiling"));
|
||||
} catch (Exception e) {
|
||||
showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), e);
|
||||
}
|
||||
@ -667,6 +670,9 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static public void main(String args[]) throws Exception {
|
||||
if (args.length == 0)
|
||||
showError(_("No parameters"), _("No command line parameters found"), null);
|
||||
|
||||
initPlatform();
|
||||
|
||||
initPortableFolder();
|
||||
@ -934,6 +940,10 @@ public class BaseNoGui {
|
||||
PreferencesData.set("serial.port.file", port);
|
||||
}
|
||||
|
||||
public static void setBuildFolder(File newBuildFolder) {
|
||||
buildFolder = newBuildFolder;
|
||||
}
|
||||
|
||||
static public void showError(String title, String message, int exit_code) {
|
||||
showError(title, message, null, exit_code);
|
||||
}
|
||||
|
@ -1195,7 +1195,7 @@ public class Sketch {
|
||||
|
||||
protected boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
|
||||
|
||||
Uploader uploader = Compiler.getUploaderByPreferences();
|
||||
Uploader uploader = Compiler.getUploaderByPreferences(false);
|
||||
|
||||
boolean success = false;
|
||||
do {
|
||||
@ -1214,7 +1214,7 @@ public class Sketch {
|
||||
|
||||
List<String> warningsAccumulator = new LinkedList<String>();
|
||||
try {
|
||||
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
|
||||
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
|
||||
} finally {
|
||||
if (uploader.requiresAuthorization() && !success) {
|
||||
Preferences.remove(uploader.getAuthorizationKey());
|
||||
|
@ -122,19 +122,25 @@ public class Compiler implements MessageConsumer {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public Uploader getUploaderByPreferences() {
|
||||
static public Uploader getUploaderByPreferences(boolean noUploadPort) {
|
||||
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);
|
||||
if (noUploadPort)
|
||||
{
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), null, noUploadPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort, noUploadPort);
|
||||
}
|
||||
}
|
||||
|
||||
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
|
||||
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, boolean noUploadPort, List<String> warningsAccumulator) throws Exception {
|
||||
|
||||
if (uploader == null)
|
||||
uploader = getUploaderByPreferences();
|
||||
uploader = getUploaderByPreferences(noUploadPort);
|
||||
|
||||
boolean success = false;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package processing.app.helpers;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -22,6 +23,8 @@ public class CommandlineParser {
|
||||
private ACTION action = ACTION.GUI;
|
||||
private boolean doVerboseBuild = false;
|
||||
private boolean doVerboseUpload = false;
|
||||
private boolean doUseProgrammer = false;
|
||||
private boolean noUploadPort = false;
|
||||
private boolean forceSavePrefs = false;
|
||||
private String getPref = null;
|
||||
private List<String> filenames = new LinkedList<String>();
|
||||
@ -79,6 +82,18 @@ public class CommandlineParser {
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--useprogrammer")) {
|
||||
doUseProgrammer = true;
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--nouploadport")) {
|
||||
noUploadPort = true;
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--board")) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
@ -104,6 +119,21 @@ public class CommandlineParser {
|
||||
// Argument should be already processed by Base.main(...)
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--buildpath")) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
BaseNoGui.showError(null, "Argument required for --buildpath", 3);
|
||||
}
|
||||
File buildFolder = new File(args[i]);
|
||||
if (!buildFolder.exists()) {
|
||||
BaseNoGui.showError(null, "The build path doesn't exist", 3);
|
||||
}
|
||||
if (!buildFolder.isDirectory()) {
|
||||
BaseNoGui.showError(null, "The build path is not a folder", 3);
|
||||
}
|
||||
BaseNoGui.setBuildFolder(buildFolder);
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--pref")) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
@ -242,4 +272,12 @@ public class CommandlineParser {
|
||||
return isVerifyMode() || isUploadMode();
|
||||
}
|
||||
|
||||
public boolean isDoUseProgrammer() {
|
||||
return doUseProgrammer;
|
||||
}
|
||||
|
||||
public boolean isNoUploadPort() {
|
||||
return noUploadPort;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
||||
boardPort.setBoardName("yun");
|
||||
boardPort.setAddress("192.168.0.1");
|
||||
boardPort.setProtocol("network");
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort);
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
|
||||
|
||||
assertTrue(uploader instanceof SSHUploader);
|
||||
}
|
||||
@ -41,7 +41,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
||||
boardPort.setBoardName("myyun");
|
||||
boardPort.setAddress("192.168.0.1");
|
||||
boardPort.setProtocol("network");
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort);
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
|
||||
|
||||
assertTrue(uploader instanceof SerialUploader);
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
||||
boardPort.setBoardName("Arduino Leonardo");
|
||||
boardPort.setAddress("/dev/ttyACM0");
|
||||
boardPort.setProtocol("serial");
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort);
|
||||
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
|
||||
|
||||
assertTrue(uploader instanceof SerialUploader);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user