Skip to content

Commit 1974d77

Browse files
bitroncmaglie
authored andcommitted
Added new command line options.
--buildpath --nouploadport --useprogrammer
1 parent b2a88ec commit 1974d77

File tree

8 files changed

+116
-18
lines changed

8 files changed

+116
-18
lines changed

app/src/cc/arduino/packages/Uploader.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,22 @@ public abstract class Uploader implements MessageConsumer {
6464

6565
private String error;
6666
protected boolean notFoundError;
67+
protected boolean noUploadPort;
6768

6869
protected Uploader() {
69-
this.error = null;
7070
this.verbose = PreferencesData.getBoolean("upload.verbose");
71+
init(false);
72+
}
73+
74+
protected Uploader(boolean nup) {
75+
this.verbose = PreferencesData.getBoolean("upload.verbose");
76+
init(nup);
77+
}
78+
79+
private void init(boolean nup) {
80+
this.error = null;
7181
this.notFoundError = false;
82+
this.noUploadPort = nup;
7283
}
7384

7485
public abstract boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception;

app/src/cc/arduino/packages/UploaderFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535

3636
public class UploaderFactory {
3737

38-
public Uploader newUploader(TargetBoard board, BoardPort port) {
38+
public Uploader newUploader(TargetBoard board, BoardPort port, boolean noUploadPort) {
39+
if (noUploadPort)
40+
return new SerialUploader(noUploadPort);
41+
3942
if ("true".equals(board.getPreferences().get("upload.via_ssh")) && port != null && "network".equals(port.getProtocol())) {
4043
return new SSHUploader(port);
4144
}

app/src/cc/arduino/packages/uploaders/SerialUploader.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646

4747
public class SerialUploader extends Uploader {
4848

49+
public SerialUploader()
50+
{
51+
super();
52+
}
53+
54+
public SerialUploader(boolean noUploadPort)
55+
{
56+
super(noUploadPort);
57+
}
58+
4959
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
5060
// FIXME: Preferences should be reorganized
5161
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
@@ -65,6 +75,26 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
6575
return uploadUsingProgrammer(buildPath, className);
6676
}
6777

78+
if (noUploadPort)
79+
{
80+
prefs.put("build.path", buildPath);
81+
prefs.put("build.project_name", className);
82+
if (verbose)
83+
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.verbose"));
84+
else
85+
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.quiet"));
86+
87+
boolean uploadResult;
88+
try {
89+
String pattern = prefs.getOrExcept("upload.pattern");
90+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
91+
uploadResult = executeUploadCommand(cmd);
92+
} catch (Exception e) {
93+
throw new RunnerException(e);
94+
}
95+
return uploadResult;
96+
}
97+
6898
// need to do a little dance for Leonardo and derivatives:
6999
// open then close the port at the magic baudrate (usually 1200 bps) first
70100
// to signal to the sketch that it should reset into bootloader. after doing

app/src/processing/app/BaseNoGui.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static public void init(String[] args) {
477477

478478
if (parser.getFilenames().size() != 1)
479479
{
480-
showError(_("Multiple files not supported"), _("Only one file at time suported with --upload option"), null);
480+
showError(_("Multiple files not supported"), _("The --upload option supports only one file at a time"), null);
481481
}
482482

483483
List<String> warningsAccumulator = new LinkedList<String>();
@@ -498,14 +498,16 @@ static public void init(String[] args) {
498498
// - chiama Sketch.build(verbose=false) che chiama Sketch.ensureExistence(), imposta il progressListener e chiama Compiler.build()
499499
// - chiama Sketch.upload() (cfr. dopo...)
500500
if (!data.getFolder().exists()) showError(_("No sketch"), _("Can't find the sketch in the specified path"), null);
501-
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, false);
501+
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, parser.isDoVerboseBuild());
502502
if (suggestedClassName == null) showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), null);
503-
503+
showMessage(_("Done compiling"), _("Done compiling"));
504+
504505
// - chiama Sketch.upload() ... to be continued ...
505-
Uploader uploader = Compiler.getUploaderByPreferences();
506+
Uploader uploader = Compiler.getUploaderByPreferences(parser.isNoUploadPort());
506507
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) showError(_("..."), _("..."), null);
507508
try {
508-
success = Compiler.upload(data, uploader, tempBuildFolder.getAbsolutePath(), suggestedClassName, false, warningsAccumulator);
509+
success = Compiler.upload(data, uploader, tempBuildFolder.getAbsolutePath(), suggestedClassName, parser.isDoUseProgrammer(), parser.isNoUploadPort(), warningsAccumulator);
510+
showMessage(_("Done uploading"), _("Done uploading"));
509511
} finally {
510512
if (uploader.requiresAuthorization() && !success) {
511513
PreferencesData.remove(uploader.getAuthorizationKey());
@@ -543,6 +545,7 @@ static public void init(String[] args) {
543545
if (!data.getFolder().exists()) showError(_("No sketch"), _("Can't find the sketch in the specified path"), null);
544546
String suggestedClassName = Compiler.build(data, tempBuildFolder.getAbsolutePath(), tempBuildFolder, null, parser.isDoVerboseBuild());
545547
if (suggestedClassName == null) showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), null);
548+
showMessage(_("Done compiling"), _("Done compiling"));
546549
} catch (Exception e) {
547550
showError(_("Error while verifying"), _("An error occurred while verifying the sketch"), e);
548551
}
@@ -667,6 +670,9 @@ static public String loadFile(File file) throws IOException {
667670
}
668671

669672
static public void main(String args[]) throws Exception {
673+
if (args.length == 0)
674+
showError(_("No parameters"), _("No command line parameters found"), null);
675+
670676
initPlatform();
671677

672678
initPortableFolder();
@@ -934,6 +940,10 @@ public static void selectSerialPort(String port) {
934940
PreferencesData.set("serial.port.file", port);
935941
}
936942

943+
public static void setBuildFolder(File newBuildFolder) {
944+
buildFolder = newBuildFolder;
945+
}
946+
937947
static public void showError(String title, String message, int exit_code) {
938948
showError(title, message, null, exit_code);
939949
}

app/src/processing/app/Sketch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ public boolean exportApplet(String appletPath, boolean usingProgrammer)
11951195

11961196
protected boolean upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws Exception {
11971197

1198-
Uploader uploader = Compiler.getUploaderByPreferences();
1198+
Uploader uploader = Compiler.getUploaderByPreferences(false);
11991199

12001200
boolean success = false;
12011201
do {
@@ -1214,7 +1214,7 @@ protected boolean upload(String buildPath, String suggestedClassName, boolean us
12141214

12151215
List<String> warningsAccumulator = new LinkedList<String>();
12161216
try {
1217-
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, warningsAccumulator);
1217+
success = Compiler.upload(data, uploader, buildPath, suggestedClassName, usingProgrammer, false, warningsAccumulator);
12181218
} finally {
12191219
if (uploader.requiresAuthorization() && !success) {
12201220
Preferences.remove(uploader.getAuthorizationKey());

app/src/processing/app/debug/Compiler.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,25 @@ static public String build(SketchData data, String buildPath, File tempBuildFold
122122
return null;
123123
}
124124

125-
static public Uploader getUploaderByPreferences() {
125+
static public Uploader getUploaderByPreferences(boolean noUploadPort) {
126126
TargetPlatform target = BaseNoGui.getTargetPlatform();
127127
String board = PreferencesData.get("board");
128128

129-
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
130-
131-
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort);
129+
if (noUploadPort)
130+
{
131+
return new UploaderFactory().newUploader(target.getBoards().get(board), null, noUploadPort);
132+
}
133+
else
134+
{
135+
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
136+
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort, noUploadPort);
137+
}
132138
}
133139

134-
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
140+
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, boolean noUploadPort, List<String> warningsAccumulator) throws Exception {
135141

136142
if (uploader == null)
137-
uploader = getUploaderByPreferences();
143+
uploader = getUploaderByPreferences(noUploadPort);
138144

139145
boolean success = false;
140146

app/src/processing/app/helpers/CommandlineParser.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static processing.app.I18n._;
44

5+
import java.io.File;
56
import java.util.HashMap;
67
import java.util.LinkedList;
78
import java.util.List;
@@ -22,6 +23,8 @@ protected static enum ACTION { GUI, NOOP, VERIFY, UPLOAD, GET_PREF };
2223
private ACTION action = ACTION.GUI;
2324
private boolean doVerboseBuild = false;
2425
private boolean doVerboseUpload = false;
26+
private boolean doUseProgrammer = false;
27+
private boolean noUploadPort = false;
2528
private boolean forceSavePrefs = false;
2629
private String getPref = null;
2730
private List<String> filenames = new LinkedList<String>();
@@ -79,6 +82,18 @@ private void parseArguments(String[] args) {
7982
action = ACTION.NOOP;
8083
continue;
8184
}
85+
if (args[i].equals("--useprogrammer")) {
86+
doUseProgrammer = true;
87+
if (action == ACTION.GUI)
88+
action = ACTION.NOOP;
89+
continue;
90+
}
91+
if (args[i].equals("--nouploadport")) {
92+
noUploadPort = true;
93+
if (action == ACTION.GUI)
94+
action = ACTION.NOOP;
95+
continue;
96+
}
8297
if (args[i].equals("--board")) {
8398
i++;
8499
if (i >= args.length)
@@ -104,6 +119,21 @@ private void parseArguments(String[] args) {
104119
// Argument should be already processed by Base.main(...)
105120
continue;
106121
}
122+
if (args[i].equals("--buildpath")) {
123+
i++;
124+
if (i >= args.length) {
125+
BaseNoGui.showError(null, "Argument required for --buildpath", 3);
126+
}
127+
File buildFolder = new File(args[i]);
128+
if (!buildFolder.exists()) {
129+
BaseNoGui.showError(null, "The build path doesn't exist", 3);
130+
}
131+
if (!buildFolder.isDirectory()) {
132+
BaseNoGui.showError(null, "The build path is not a folder", 3);
133+
}
134+
BaseNoGui.setBuildFolder(buildFolder);
135+
continue;
136+
}
107137
if (args[i].equals("--pref")) {
108138
i++;
109139
if (i >= args.length)
@@ -242,4 +272,12 @@ public boolean isVerifyOrUploadMode() {
242272
return isVerifyMode() || isUploadMode();
243273
}
244274

275+
public boolean isDoUseProgrammer() {
276+
return doUseProgrammer;
277+
}
278+
279+
public boolean isNoUploadPort() {
280+
return noUploadPort;
281+
}
282+
245283
}

app/test/processing/app/debug/UploaderFactoryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void shouldCreateAnInstanceOfSSHUploader() throws Exception {
2929
boardPort.setBoardName("yun");
3030
boardPort.setAddress("192.168.0.1");
3131
boardPort.setProtocol("network");
32-
Uploader uploader = new UploaderFactory().newUploader(board, boardPort);
32+
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
3333

3434
assertTrue(uploader instanceof SSHUploader);
3535
}
@@ -41,7 +41,7 @@ public void shouldCreateAnInstanceOfBasicUploaderWhenSSHIsUnsupported() throws E
4141
boardPort.setBoardName("myyun");
4242
boardPort.setAddress("192.168.0.1");
4343
boardPort.setProtocol("network");
44-
Uploader uploader = new UploaderFactory().newUploader(board, boardPort);
44+
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
4545

4646
assertTrue(uploader instanceof SerialUploader);
4747
}
@@ -53,7 +53,7 @@ public void shouldCreateAnInstanceOfBasicUploaderWhenPortIsSerial() throws Excep
5353
boardPort.setBoardName("Arduino Leonardo");
5454
boardPort.setAddress("/dev/ttyACM0");
5555
boardPort.setProtocol("serial");
56-
Uploader uploader = new UploaderFactory().newUploader(board, boardPort);
56+
Uploader uploader = new UploaderFactory().newUploader(board, boardPort, false);
5757

5858
assertTrue(uploader instanceof SerialUploader);
5959
}

0 commit comments

Comments
 (0)