Skip to content

Commit 443f7a7

Browse files
bitroncmaglie
authored andcommitted
Moved some parameter processing methods from Base to BaseNoGui.
1 parent abe6ff5 commit 443f7a7

File tree

2 files changed

+92
-66
lines changed

2 files changed

+92
-66
lines changed

app/src/processing/app/Base.java

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -463,59 +463,11 @@ public Base(String[] args) throws Exception {
463463
}
464464

465465
protected void processBoardArgument(String selectBoard) {
466-
// No board selected? Nothing to do
467-
if (selectBoard == null)
468-
return;
469-
470-
String[] split = selectBoard.split(":", 4);
471-
472-
if (split.length < 3) {
473-
showError(null, I18n.format(_("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), 3);
474-
}
475-
476-
TargetPackage targetPackage = getTargetPackage(split[0]);
477-
if (targetPackage == null) {
478-
showError(null, I18n.format(_("{0}: Unknown package"), split[0]), 3);
479-
}
480-
481-
TargetPlatform targetPlatform = targetPackage.get(split[1]);
482-
if (targetPlatform == null) {
483-
showError(null, I18n.format(_("{0}: Unknown architecture"), split[1]), 3);
484-
}
485-
486-
TargetBoard targetBoard = targetPlatform.getBoard(split[2]);
487-
if (targetBoard == null) {
488-
showError(null, I18n.format(_("{0}: Unknown board"), split[2]), 3);
489-
}
490-
491-
selectBoard(targetBoard);
492-
493-
if (split.length > 3) {
494-
String[] options = split[3].split(",");
495-
for (String option : options) {
496-
String[] keyValue = option.split("=", 2);
497-
498-
if (keyValue.length != 2)
499-
showError(null, I18n.format(_("{0}: Invalid option, should be of the form \"name=value\""), option, targetBoard.getId()), 3);
500-
String key = keyValue[0].trim();
501-
String value = keyValue[1].trim();
502-
503-
if (!targetBoard.hasMenu(key))
504-
showError(null, I18n.format(_("{0}: Invalid option for board \"{1}\""), key, targetBoard.getId()), 3);
505-
if (targetBoard.getMenuLabel(key, value) == null)
506-
showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), 3);
507-
508-
Preferences.set("custom_" + key, targetBoard.getId() + "_" + value);
509-
}
510-
}
466+
BaseNoGui.processBoardArgument(selectBoard);
511467
}
512468

513469
protected void processPrefArgument(String arg) {
514-
String[] split = arg.split("=", 2);
515-
if (split.length != 2 || split[0].isEmpty())
516-
showError(null, I18n.format(_("{0}: Invalid argument to --pref, should be of the form \"pref=value\""), arg), 3);
517-
518-
Preferences.set(split[0], split[1]);
470+
BaseNoGui.processPrefArgument(arg);
519471
}
520472

521473
/**
@@ -1483,24 +1435,11 @@ private static JMenuItem selectFirstEnabledMenuItem(JMenu menu) {
14831435

14841436

14851437
private void selectBoard(TargetBoard targetBoard) {
1486-
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
1487-
TargetPackage targetPackage = targetPlatform.getContainerPackage();
1488-
1489-
Preferences.set("target_package", targetPackage.getId());
1490-
Preferences.set("target_platform", targetPlatform.getId());
1491-
Preferences.set("board", targetBoard.getId());
1492-
1493-
File platformFolder = targetPlatform.getFolder();
1494-
Preferences.set("runtime.platform.path", platformFolder.getAbsolutePath());
1495-
Preferences.set("runtime.hardware.path", platformFolder.getParentFile().getAbsolutePath());
1438+
BaseNoGui.selectBoard(targetBoard);
14961439
}
14971440

14981441
public static void selectSerialPort(String port) {
1499-
Preferences.set("serial.port", port);
1500-
if (port.startsWith("/dev/"))
1501-
Preferences.set("serial.port.file", port.substring(5));
1502-
else
1503-
Preferences.set("serial.port.file", port);
1442+
BaseNoGui.selectSerialPort(port);
15041443
}
15051444

15061445
public void rebuildProgrammerMenu(JMenu menu) {
@@ -1903,7 +1842,7 @@ static public String getAvrBasePath() {
19031842
* @return
19041843
*/
19051844
static public TargetPackage getTargetPackage(String packageName) {
1906-
return BaseNoGui.packages.get(packageName);
1845+
return BaseNoGui.getTargetPackage(packageName);
19071846
}
19081847

19091848
/**

app/src/processing/app/BaseNoGui.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ public static TargetBoard getTargetBoard() {
259259
return getTargetPlatform().getBoard(boardId);
260260
}
261261

262+
/**
263+
* Returns a specific TargetPackage
264+
*
265+
* @param packageName
266+
* @return
267+
*/
268+
static public TargetPackage getTargetPackage(String packageName) {
269+
return packages.get(packageName);
270+
}
271+
262272
/**
263273
* Returns the currently selected TargetPlatform.
264274
*
@@ -499,6 +509,62 @@ static public void prescanParameters(String args[]) {
499509
PreferencesData.init(absoluteFile(preferencesFile));
500510
}
501511

512+
static protected void processBoardArgument(String selectBoard) {
513+
// No board selected? Nothing to do
514+
if (selectBoard == null)
515+
return;
516+
517+
String[] split = selectBoard.split(":", 4);
518+
519+
if (split.length < 3) {
520+
showError(null, I18n.format(_("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), 3);
521+
}
522+
523+
TargetPackage targetPackage = getTargetPackage(split[0]);
524+
if (targetPackage == null) {
525+
showError(null, I18n.format(_("{0}: Unknown package"), split[0]), 3);
526+
}
527+
528+
TargetPlatform targetPlatform = targetPackage.get(split[1]);
529+
if (targetPlatform == null) {
530+
showError(null, I18n.format(_("{0}: Unknown architecture"), split[1]), 3);
531+
}
532+
533+
TargetBoard targetBoard = targetPlatform.getBoard(split[2]);
534+
if (targetBoard == null) {
535+
showError(null, I18n.format(_("{0}: Unknown board"), split[2]), 3);
536+
}
537+
538+
selectBoard(targetBoard);
539+
540+
if (split.length > 3) {
541+
String[] options = split[3].split(",");
542+
for (String option : options) {
543+
String[] keyValue = option.split("=", 2);
544+
545+
if (keyValue.length != 2)
546+
showError(null, I18n.format(_("{0}: Invalid option, should be of the form \"name=value\""), option, targetBoard.getId()), 3);
547+
String key = keyValue[0].trim();
548+
String value = keyValue[1].trim();
549+
550+
if (!targetBoard.hasMenu(key))
551+
showError(null, I18n.format(_("{0}: Invalid option for board \"{1}\""), key, targetBoard.getId()), 3);
552+
if (targetBoard.getMenuLabel(key, value) == null)
553+
showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), 3);
554+
555+
Preferences.set("custom_" + key, targetBoard.getId() + "_" + value);
556+
}
557+
}
558+
}
559+
560+
static protected void processPrefArgument(String arg) {
561+
String[] split = arg.split("=", 2);
562+
if (split.length != 2 || split[0].isEmpty())
563+
showError(null, I18n.format(_("{0}: Invalid argument to --pref, should be of the form \"pref=value\""), arg), 3);
564+
565+
PreferencesData.set(split[0], split[1]);
566+
}
567+
502568
/**
503569
* Recursively remove all files within a directory,
504570
* used with removeDir(), or when the contents of a dir
@@ -649,6 +715,27 @@ static public LibraryList scanLibraries(File folder) throws IOException {
649715
return res;
650716
}
651717

718+
static protected void selectBoard(TargetBoard targetBoard) {
719+
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
720+
TargetPackage targetPackage = targetPlatform.getContainerPackage();
721+
722+
PreferencesData.set("target_package", targetPackage.getId());
723+
PreferencesData.set("target_platform", targetPlatform.getId());
724+
PreferencesData.set("board", targetBoard.getId());
725+
726+
File platformFolder = targetPlatform.getFolder();
727+
PreferencesData.set("runtime.platform.path", platformFolder.getAbsolutePath());
728+
PreferencesData.set("runtime.hardware.path", platformFolder.getParentFile().getAbsolutePath());
729+
}
730+
731+
public static void selectSerialPort(String port) {
732+
PreferencesData.set("serial.port", port);
733+
if (port.startsWith("/dev/"))
734+
PreferencesData.set("serial.port.file", port.substring(5));
735+
else
736+
PreferencesData.set("serial.port.file", port);
737+
}
738+
652739
static public void showError(String title, String message, int exit_code) {
653740
showError(title, message, null, exit_code);
654741
}

0 commit comments

Comments
 (0)