mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-14 08:54:26 +01:00
Use Optional<> for getting selected Board/Platform
Optionals should make explicit the possibility to get empty results from BaseNoGui.getTargetBoard/Platform methods.
This commit is contained in:
parent
bbb81671d6
commit
ab9ba6ad4b
@ -285,9 +285,7 @@ public class Base {
|
|||||||
rebuildBoardsMenu();
|
rebuildBoardsMenu();
|
||||||
rebuildProgrammerMenu();
|
rebuildProgrammerMenu();
|
||||||
} else {
|
} else {
|
||||||
TargetBoard lastSelectedBoard = BaseNoGui.getTargetBoard();
|
BaseNoGui.getTargetBoard().ifPresent(board -> BaseNoGui.selectBoard(board));
|
||||||
if (lastSelectedBoard != null)
|
|
||||||
BaseNoGui.selectBoard(lastSelectedBoard);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup board-dependent variables.
|
// Setup board-dependent variables.
|
||||||
@ -1132,9 +1130,7 @@ public class Base {
|
|||||||
importMenu.addSeparator();
|
importMenu.addSeparator();
|
||||||
|
|
||||||
// Split between user supplied libraries and IDE libraries
|
// Split between user supplied libraries and IDE libraries
|
||||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
if (BaseNoGui.getTargetPlatform().isPresent()) {
|
||||||
|
|
||||||
if (targetPlatform != null) {
|
|
||||||
LibraryList libs = getSortedLibraries();
|
LibraryList libs = getSortedLibraries();
|
||||||
String lastLibType = null;
|
String lastLibType = null;
|
||||||
for (UserLibrary lib : libs) {
|
for (UserLibrary lib : libs) {
|
||||||
@ -1189,17 +1185,20 @@ public class Base {
|
|||||||
String boardId = null;
|
String boardId = null;
|
||||||
String referencedPlatformName = null;
|
String referencedPlatformName = null;
|
||||||
String myArch = null;
|
String myArch = null;
|
||||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
Optional<TargetPlatform> targetPlatform = BaseNoGui.getTargetPlatform();
|
||||||
if (targetPlatform != null) {
|
if (targetPlatform.isPresent()) {
|
||||||
myArch = targetPlatform.getId();
|
myArch = targetPlatform.get().getId();
|
||||||
boardId = BaseNoGui.getTargetBoard().getName();
|
Optional<TargetBoard> board = BaseNoGui.getTargetBoard();
|
||||||
|
if (board.isPresent()) {
|
||||||
|
boardId = board.get().getName();
|
||||||
|
}
|
||||||
String core = BaseNoGui.getBoardPreferences().get("build.core", "arduino");
|
String core = BaseNoGui.getBoardPreferences().get("build.core", "arduino");
|
||||||
if (core.contains(":")) {
|
if (core.contains(":")) {
|
||||||
String refcore = core.split(":")[0];
|
String refcore = core.split(":")[0];
|
||||||
TargetPlatform referencedPlatform = BaseNoGui.getTargetPlatform(refcore, myArch);
|
Optional<TargetPlatform> referencedPlatform = BaseNoGui.getTargetPlatform(refcore, myArch);
|
||||||
if (referencedPlatform != null) {
|
if (referencedPlatform.isPresent()) {
|
||||||
referencedPlatformName = referencedPlatform.getPreferences().get("name");
|
referencedPlatformName = referencedPlatform.get().getPreferences().get("name");
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1346,9 +1345,9 @@ public class Base {
|
|||||||
BaseNoGui.onBoardOrPortChange();
|
BaseNoGui.onBoardOrPortChange();
|
||||||
|
|
||||||
// reload keywords when package/platform changes
|
// reload keywords when package/platform changes
|
||||||
TargetPlatform tp = BaseNoGui.getTargetPlatform();
|
Optional<TargetPlatform> tp = BaseNoGui.getTargetPlatform();
|
||||||
if (tp != null) {
|
if (tp.isPresent()) {
|
||||||
String platformFolder = tp.getFolder().getAbsolutePath();
|
String platformFolder = tp.get().getFolder().getAbsolutePath();
|
||||||
if (priorPlatformFolder == null || !priorPlatformFolder.equals(platformFolder) || newLibraryImported) {
|
if (priorPlatformFolder == null || !priorPlatformFolder.equals(platformFolder) || newLibraryImported) {
|
||||||
pdeKeywords = new PdeKeywords();
|
pdeKeywords = new PdeKeywords();
|
||||||
pdeKeywords.reload();
|
pdeKeywords.reload();
|
||||||
@ -1701,9 +1700,11 @@ public class Base {
|
|||||||
programmerMenus = new LinkedList<>();
|
programmerMenus = new LinkedList<>();
|
||||||
ButtonGroup group = new ButtonGroup();
|
ButtonGroup group = new ButtonGroup();
|
||||||
|
|
||||||
TargetBoard board = BaseNoGui.getTargetBoard();
|
Optional<TargetBoard> mayBoard = BaseNoGui.getTargetBoard();
|
||||||
|
if (!mayBoard.isPresent()) return;
|
||||||
|
TargetBoard board = mayBoard.get();
|
||||||
TargetPlatform boardPlatform = board.getContainerPlatform();
|
TargetPlatform boardPlatform = board.getContainerPlatform();
|
||||||
TargetPlatform corePlatform = null;
|
Optional<TargetPlatform> corePlatform = Optional.empty();
|
||||||
|
|
||||||
String core = board.getPreferences().get("build.core");
|
String core = board.getPreferences().get("build.core");
|
||||||
if (core != null && core.contains(":")) {
|
if (core != null && core.contains(":")) {
|
||||||
@ -1712,8 +1713,9 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addProgrammersForPlatform(boardPlatform, programmerMenus, group);
|
addProgrammersForPlatform(boardPlatform, programmerMenus, group);
|
||||||
if (corePlatform != null)
|
if (corePlatform.isPresent()) {
|
||||||
addProgrammersForPlatform(corePlatform, programmerMenus, group);
|
addProgrammersForPlatform(corePlatform.get(), programmerMenus, group);
|
||||||
|
}
|
||||||
|
|
||||||
if (programmerMenus.isEmpty()) {
|
if (programmerMenus.isEmpty()) {
|
||||||
JMenuItem item = new JMenuItem(tr("No programmers available for this board"));
|
JMenuItem item = new JMenuItem(tr("No programmers available for this board"));
|
||||||
|
@ -57,6 +57,7 @@ import java.util.HashMap;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
@ -2587,9 +2588,9 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||||
|
|
||||||
protected void onBoardOrPortChange() {
|
protected void onBoardOrPortChange() {
|
||||||
TargetBoard board = BaseNoGui.getTargetBoard();
|
Optional<TargetBoard> board = BaseNoGui.getTargetBoard();
|
||||||
if (board != null)
|
if (board.isPresent())
|
||||||
lineStatus.setBoardName(board.getName());
|
lineStatus.setBoardName(board.get().getName());
|
||||||
else
|
else
|
||||||
lineStatus.setBoardName("-");
|
lineStatus.setBoardName("-");
|
||||||
lineStatus.setPort(PreferencesData.get("serial.port"));
|
lineStatus.setPort(PreferencesData.get("serial.port"));
|
||||||
|
@ -38,6 +38,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
@ -84,9 +85,9 @@ public class PdeKeywords {
|
|||||||
public void reload() {
|
public void reload() {
|
||||||
try {
|
try {
|
||||||
parseKeywordsTxt(new File(BaseNoGui.getContentFile("lib"), "keywords.txt"));
|
parseKeywordsTxt(new File(BaseNoGui.getContentFile("lib"), "keywords.txt"));
|
||||||
TargetPlatform tp = BaseNoGui.getTargetPlatform();
|
Optional<TargetPlatform> tp = BaseNoGui.getTargetPlatform();
|
||||||
if (tp != null) {
|
if (tp.isPresent()) {
|
||||||
File platformKeywords = new File(tp.getFolder(), "keywords.txt");
|
File platformKeywords = new File(tp.get().getFolder(), "keywords.txt");
|
||||||
if (platformKeywords.exists()) parseKeywordsTxt(platformKeywords);
|
if (platformKeywords.exists()) parseKeywordsTxt(platformKeywords);
|
||||||
}
|
}
|
||||||
for (UserLibrary lib : BaseNoGui.librariesIndexer.getInstalledLibraries()) {
|
for (UserLibrary lib : BaseNoGui.librariesIndexer.getInstalledLibraries()) {
|
||||||
|
@ -35,7 +35,12 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import processing.app.debug.TargetBoard;
|
import processing.app.debug.TargetBoard;
|
||||||
|
import processing.app.debug.TargetPlatform;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class DefaultTargetTest extends AbstractWithPreferencesTest {
|
public class DefaultTargetTest extends AbstractWithPreferencesTest {
|
||||||
|
|
||||||
@ -60,9 +65,11 @@ public class DefaultTargetTest extends AbstractWithPreferencesTest {
|
|||||||
createBase();
|
createBase();
|
||||||
|
|
||||||
// skip test if no target platforms are available
|
// skip test if no target platforms are available
|
||||||
Assume.assumeNotNull(BaseNoGui.getTargetPlatform());
|
Optional<TargetPlatform> targetPlatform = BaseNoGui.getTargetPlatform();
|
||||||
|
Assume.assumeTrue(targetPlatform.isPresent());
|
||||||
|
|
||||||
TargetBoard targetBoard = BaseNoGui.getTargetBoard();
|
Optional<TargetBoard> targetBoard = BaseNoGui.getTargetBoard();
|
||||||
assertNotEquals("unreal_board", targetBoard.getId());
|
assertTrue(targetBoard.isPresent());
|
||||||
|
assertNotEquals("unreal_board", targetBoard.get().getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,6 @@ package processing.app.debug;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import cc.arduino.packages.BoardPort;
|
import cc.arduino.packages.BoardPort;
|
||||||
|
@ -53,6 +53,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -163,11 +164,12 @@ public class Compiler implements MessageConsumer {
|
|||||||
this.buildPath = sketch.getBuildPath().getAbsolutePath();
|
this.buildPath = sketch.getBuildPath().getAbsolutePath();
|
||||||
this.buildCache = BaseNoGui.getCachePath();
|
this.buildCache = BaseNoGui.getCachePath();
|
||||||
|
|
||||||
TargetBoard board = BaseNoGui.getTargetBoard();
|
Optional<TargetBoard> mayBoard = BaseNoGui.getTargetBoard();
|
||||||
if (board == null) {
|
if (!mayBoard.isPresent()) {
|
||||||
throw new RunnerException("Board is not selected");
|
throw new RunnerException("Board is not selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TargetBoard board = mayBoard.get();
|
||||||
TargetPlatform platform = board.getContainerPlatform();
|
TargetPlatform platform = board.getContainerPlatform();
|
||||||
TargetPackage aPackage = platform.getContainerPackage();
|
TargetPackage aPackage = platform.getContainerPackage();
|
||||||
String vidpid = VIDPID();
|
String vidpid = VIDPID();
|
||||||
|
@ -37,6 +37,10 @@ import processing.app.helpers.StringReplacer;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static processing.app.I18n.format;
|
||||||
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class GenericNetworkUploader extends Uploader {
|
public class GenericNetworkUploader extends Uploader {
|
||||||
|
|
||||||
@ -58,19 +62,26 @@ public class GenericNetworkUploader extends Uploader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
|
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
|
||||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
|
||||||
PreferencesMap prefs = PreferencesData.getMap();
|
PreferencesMap prefs = PreferencesData.getMap();
|
||||||
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
||||||
if (boardPreferences != null) {
|
if (boardPreferences != null) {
|
||||||
prefs.putAll(boardPreferences);
|
prefs.putAll(boardPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<TargetPlatform> targetPlatform = BaseNoGui.getTargetPlatform();
|
||||||
String tool = prefs.getOrExcept("upload.tool");
|
String tool = prefs.getOrExcept("upload.tool");
|
||||||
if (tool.contains(":")) {
|
if (tool.contains(":")) {
|
||||||
String[] split = tool.split(":", 2);
|
String[] split = tool.split(":", 2);
|
||||||
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||||
|
if (!targetPlatform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0} from package {1}"), tool, split[0]));
|
||||||
|
}
|
||||||
tool = split[1];
|
tool = split[1];
|
||||||
}
|
}
|
||||||
prefs.putAll(targetPlatform.getTool(tool));
|
if (!targetPlatform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0}"), tool));
|
||||||
|
}
|
||||||
|
prefs.putAll(targetPlatform.get().getTool(tool));
|
||||||
|
|
||||||
String password = "";
|
String password = "";
|
||||||
if(requiresAuthorization()){
|
if(requiresAuthorization()){
|
||||||
|
@ -42,7 +42,6 @@ import processing.app.PreferencesData;
|
|||||||
import processing.app.debug.RunnerException;
|
import processing.app.debug.RunnerException;
|
||||||
import processing.app.debug.TargetPlatform;
|
import processing.app.debug.TargetPlatform;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
import processing.app.helpers.PreferencesMapException;
|
|
||||||
import processing.app.helpers.StringReplacer;
|
import processing.app.helpers.StringReplacer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -51,10 +50,12 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import static processing.app.I18n.format;
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class SSHUploader extends Uploader {
|
public class SSHUploader extends Uploader {
|
||||||
@ -79,31 +80,38 @@ public class SSHUploader extends Uploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws RunnerException, PreferencesMapException {
|
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
|
||||||
if (usingProgrammer) {
|
if (usingProgrammer) {
|
||||||
throw new RunnerException(tr("Network upload using programmer not supported"));
|
throw new RunnerException(tr("Network upload using programmer not supported"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
|
||||||
PreferencesMap prefs = PreferencesData.getMap();
|
PreferencesMap prefs = PreferencesData.getMap();
|
||||||
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
||||||
if (boardPreferences != null) {
|
if (boardPreferences != null) {
|
||||||
prefs.putAll(boardPreferences);
|
prefs.putAll(boardPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<TargetPlatform> targetPlatform = BaseNoGui.getTargetPlatform();
|
||||||
String tool = prefs.getOrExcept("upload.tool");
|
String tool = prefs.getOrExcept("upload.tool");
|
||||||
if (tool.contains(":")) {
|
if (tool.contains(":")) {
|
||||||
String[] split = tool.split(":", 2);
|
String[] split = tool.split(":", 2);
|
||||||
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||||
|
if (!targetPlatform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0} from package {1}"), tool, split[0]));
|
||||||
|
}
|
||||||
tool = split[1];
|
tool = split[1];
|
||||||
}
|
}
|
||||||
prefs.putAll(targetPlatform.getTool(tool));
|
if (!targetPlatform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0}"), tool));
|
||||||
|
}
|
||||||
|
prefs.putAll(targetPlatform.get().getTool(tool));
|
||||||
|
|
||||||
boolean coreMissesRemoteUploadTool = targetPlatform.getTool(tool + "_remote").isEmpty();
|
boolean coreMissesRemoteUploadTool = targetPlatform.get().getTool(tool + "_remote").isEmpty();
|
||||||
|
|
||||||
if (coreMissesRemoteUploadTool) {
|
if (coreMissesRemoteUploadTool) {
|
||||||
prefs.put("upload.pattern", "/usr/bin/run-avrdude /tmp/sketch.hex");
|
prefs.put("upload.pattern", "/usr/bin/run-avrdude /tmp/sketch.hex");
|
||||||
} else {
|
} else {
|
||||||
prefs.putAll(targetPlatform.getTool(tool + "_remote"));
|
prefs.putAll(targetPlatform.get().getTool(tool + "_remote"));
|
||||||
}
|
}
|
||||||
|
|
||||||
prefs.put("build.path", buildPath);
|
prefs.put("build.path", buildPath);
|
||||||
|
@ -47,7 +47,9 @@ import processing.app.helpers.StringReplacer;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static processing.app.I18n.format;
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class SerialUploader extends Uploader {
|
public class SerialUploader extends Uploader {
|
||||||
@ -65,19 +67,26 @@ public class SerialUploader extends Uploader {
|
|||||||
@Override
|
@Override
|
||||||
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
|
public boolean uploadUsingPreferences(File sourcePath, String buildPath, String className, boolean usingProgrammer, List<String> warningsAccumulator) throws Exception {
|
||||||
// FIXME: Preferences should be reorganized
|
// FIXME: Preferences should be reorganized
|
||||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
|
||||||
PreferencesMap prefs = PreferencesData.getMap();
|
PreferencesMap prefs = PreferencesData.getMap();
|
||||||
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
||||||
if (boardPreferences != null) {
|
if (boardPreferences != null) {
|
||||||
prefs.putAll(boardPreferences);
|
prefs.putAll(boardPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<TargetPlatform> targetPlatform = BaseNoGui.getTargetPlatform();
|
||||||
String tool = prefs.getOrExcept("upload.tool");
|
String tool = prefs.getOrExcept("upload.tool");
|
||||||
if (tool.contains(":")) {
|
if (tool.contains(":")) {
|
||||||
String[] split = tool.split(":", 2);
|
String[] split = tool.split(":", 2);
|
||||||
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||||
|
if (!targetPlatform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0} from package {1}"), tool, split[0]));
|
||||||
|
}
|
||||||
tool = split[1];
|
tool = split[1];
|
||||||
}
|
}
|
||||||
prefs.putAll(targetPlatform.getTool(tool));
|
if (!targetPlatform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0}"), tool));
|
||||||
|
}
|
||||||
|
prefs.putAll(targetPlatform.get().getTool(tool));
|
||||||
|
|
||||||
if (programmerPid != null && programmerPid.isAlive()) {
|
if (programmerPid != null && programmerPid.isAlive()) {
|
||||||
// kill the previous programmer
|
// kill the previous programmer
|
||||||
@ -279,24 +288,30 @@ public class SerialUploader extends Uploader {
|
|||||||
|
|
||||||
private boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {
|
private boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {
|
||||||
|
|
||||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
Optional<TargetPlatform> targetPlatform = BaseNoGui.getTargetPlatform();
|
||||||
String programmer = PreferencesData.get("programmer");
|
String programmer = PreferencesData.get("programmer");
|
||||||
if (programmer.contains(":")) {
|
if (programmer.contains(":")) {
|
||||||
String[] split = programmer.split(":", 2);
|
String[] split = programmer.split(":", 2);
|
||||||
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||||
|
if (!targetPlatform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0} from package {1}"), programmer, split[0]));
|
||||||
|
}
|
||||||
programmer = split[1];
|
programmer = split[1];
|
||||||
}
|
}
|
||||||
|
if (!targetPlatform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0}"), programmer));
|
||||||
|
}
|
||||||
|
|
||||||
PreferencesMap prefs = PreferencesData.getMap();
|
PreferencesMap prefs = PreferencesData.getMap();
|
||||||
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
||||||
if (boardPreferences != null) {
|
if (boardPreferences != null) {
|
||||||
prefs.putAll(boardPreferences);
|
prefs.putAll(boardPreferences);
|
||||||
}
|
}
|
||||||
PreferencesMap programmerPrefs = targetPlatform.getProgrammer(programmer);
|
PreferencesMap programmerPrefs = targetPlatform.get().getProgrammer(programmer);
|
||||||
if (programmerPrefs == null)
|
if (programmerPrefs == null)
|
||||||
throw new RunnerException(
|
throw new RunnerException(
|
||||||
tr("Please select a programmer from Tools->Programmer menu"));
|
tr("Please select a programmer from Tools->Programmer menu"));
|
||||||
prefs.putAll(targetPlatform.getTool(programmerPrefs.getOrExcept("program.tool")));
|
prefs.putAll(targetPlatform.get().getTool(programmerPrefs.getOrExcept("program.tool")));
|
||||||
prefs.putAll(programmerPrefs);
|
prefs.putAll(programmerPrefs);
|
||||||
|
|
||||||
prefs.put("build.path", buildPath);
|
prefs.put("build.path", buildPath);
|
||||||
@ -317,22 +332,26 @@ public class SerialUploader extends Uploader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean burnBootloader() throws Exception {
|
public boolean burnBootloader() throws Exception {
|
||||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform()
|
||||||
|
.orElseThrow(() -> new RunnerException(tr("Please select a programmer from Tools->Programmer menu")));
|
||||||
|
|
||||||
// Find preferences for the selected programmer
|
// Find preferences for the selected programmer
|
||||||
PreferencesMap programmerPrefs;
|
PreferencesMap programmerPrefs = null;
|
||||||
String programmer = PreferencesData.get("programmer");
|
String programmer = PreferencesData.get("programmer");
|
||||||
if (programmer.contains(":")) {
|
if (programmer.contains(":")) {
|
||||||
String[] split = programmer.split(":", 2);
|
String[] split = programmer.split(":", 2);
|
||||||
TargetPlatform platform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
Optional<TargetPlatform> platform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||||
|
if (!platform.isPresent()) {
|
||||||
|
throw new Exception(format(tr("Could not find tool {0} from package {1}"), programmer, split[0]));
|
||||||
|
}
|
||||||
programmer = split[1];
|
programmer = split[1];
|
||||||
programmerPrefs = platform.getProgrammer(programmer);
|
programmerPrefs = platform.get().getProgrammer(programmer);
|
||||||
} else {
|
} else {
|
||||||
programmerPrefs = targetPlatform.getProgrammer(programmer);
|
programmerPrefs = targetPlatform.getProgrammer(programmer);
|
||||||
}
|
}
|
||||||
if (programmerPrefs == null)
|
if (programmerPrefs == null) {
|
||||||
throw new RunnerException(
|
throw new RunnerException(tr("Please select a programmer from Tools->Programmer menu"));
|
||||||
tr("Please select a programmer from Tools->Programmer menu"));
|
}
|
||||||
|
|
||||||
// Build configuration for the current programmer
|
// Build configuration for the current programmer
|
||||||
PreferencesMap prefs = PreferencesData.getMap();
|
PreferencesMap prefs = PreferencesData.getMap();
|
||||||
@ -347,15 +366,19 @@ public class SerialUploader extends Uploader {
|
|||||||
String tool = prefs.getOrExcept("bootloader.tool");
|
String tool = prefs.getOrExcept("bootloader.tool");
|
||||||
if (tool.contains(":")) {
|
if (tool.contains(":")) {
|
||||||
String[] split = tool.split(":", 2);
|
String[] split = tool.split(":", 2);
|
||||||
TargetPlatform platform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
|
||||||
tool = split[1];
|
tool = split[1];
|
||||||
toolPrefs.putAll(platform.getTool(tool));
|
Optional<TargetPlatform> platform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||||
if (toolPrefs.size() == 0)
|
if (platform.isPresent()) {
|
||||||
|
toolPrefs.putAll(platform.get().getTool(tool));
|
||||||
|
}
|
||||||
|
if (toolPrefs.size() == 0) {
|
||||||
throw new RunnerException(I18n.format(tr("Could not find tool {0} from package {1}"), tool, split[0]));
|
throw new RunnerException(I18n.format(tr("Could not find tool {0} from package {1}"), tool, split[0]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
toolPrefs.putAll(targetPlatform.getTool(tool));
|
toolPrefs.putAll(targetPlatform.getTool(tool));
|
||||||
if (toolPrefs.size() == 0)
|
if (toolPrefs.size() == 0) {
|
||||||
throw new RunnerException(I18n.format(tr("Could not find tool {0}"), tool));
|
throw new RunnerException(I18n.format(tr("Could not find tool {0}"), tool));
|
||||||
|
}
|
||||||
|
|
||||||
// Merge tool with global configuration
|
// Merge tool with global configuration
|
||||||
prefs.putAll(toolPrefs);
|
prefs.putAll(toolPrefs);
|
||||||
|
@ -132,9 +132,10 @@ public class BaseNoGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public PreferencesMap getBoardPreferences() {
|
static public PreferencesMap getBoardPreferences() {
|
||||||
TargetBoard board = getTargetBoard();
|
Optional<TargetBoard> mayBoard = getTargetBoard();
|
||||||
if (board == null)
|
if (!mayBoard.isPresent())
|
||||||
return null;
|
return null;
|
||||||
|
TargetBoard board = mayBoard.get();
|
||||||
String boardId = board.getId();
|
String boardId = board.getId();
|
||||||
|
|
||||||
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
|
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
|
||||||
@ -161,19 +162,24 @@ public class BaseNoGui {
|
|||||||
List<ContributedTool> requiredTools = new ArrayList<>();
|
List<ContributedTool> requiredTools = new ArrayList<>();
|
||||||
|
|
||||||
// Add all tools dependencies specified in package index
|
// Add all tools dependencies specified in package index
|
||||||
ContributedPlatform p = indexer.getContributedPlaform(getTargetPlatform());
|
Optional<TargetPlatform> targetPlatform = getTargetPlatform();
|
||||||
if (p != null)
|
if (targetPlatform.isPresent()) {
|
||||||
|
ContributedPlatform p = indexer.getContributedPlaform(targetPlatform.get());
|
||||||
|
if (p != null) {
|
||||||
requiredTools.addAll(p.getResolvedTools());
|
requiredTools.addAll(p.getResolvedTools());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add all tools dependencies from the (possibily) referenced core
|
// Add all tools dependencies from the (possibily) referenced core
|
||||||
String core = prefs.get("build.core");
|
String core = prefs.get("build.core");
|
||||||
if (core != null && core.contains(":")) {
|
if (core != null && core.contains(":")) {
|
||||||
String split[] = core.split(":");
|
String split[] = core.split(":");
|
||||||
TargetPlatform referenced = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
Optional<TargetPlatform> referenced = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
|
||||||
if (referenced != null) {
|
if (referenced.isPresent()) {
|
||||||
ContributedPlatform referencedPlatform = indexer.getContributedPlaform(referenced);
|
ContributedPlatform referencedPlatform = indexer.getContributedPlaform(referenced.get());
|
||||||
if (referencedPlatform != null)
|
if (referencedPlatform != null) {
|
||||||
requiredTools.addAll(referencedPlatform.getResolvedTools());
|
requiredTools.addAll(referencedPlatform.getResolvedTools());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String msg = tr("The current selected board needs the core '{0}' that is not installed.");
|
String msg = tr("The current selected board needs the core '{0}' that is not installed.");
|
||||||
System.out.println(I18n.format(msg, core));
|
System.out.println(I18n.format(msg, core));
|
||||||
@ -204,7 +210,7 @@ public class BaseNoGui {
|
|||||||
return new File(installationFolder, name);
|
return new File(installationFolder, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
|
static public Optional<TargetPlatform> getCurrentTargetPlatformFromPackage(String pack) {
|
||||||
return getTargetPlatform(pack, PreferencesData.get("target_platform"));
|
return getTargetPlatform(pack, PreferencesData.get("target_platform"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,12 +377,13 @@ public class BaseNoGui {
|
|||||||
return sketchbookPath;
|
return sketchbookPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TargetBoard getTargetBoard() {
|
public static Optional<TargetBoard> getTargetBoard() {
|
||||||
TargetPlatform targetPlatform = getTargetPlatform();
|
Optional<TargetPlatform> targetPlatform = getTargetPlatform();
|
||||||
if (targetPlatform == null)
|
if (!targetPlatform.isPresent()) {
|
||||||
return null;
|
return Optional.empty();
|
||||||
|
}
|
||||||
String boardId = PreferencesData.get("board");
|
String boardId = PreferencesData.get("board");
|
||||||
return targetPlatform.getBoard(boardId);
|
return Optional.ofNullable(targetPlatform.get().getBoard(boardId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -385,8 +392,8 @@ public class BaseNoGui {
|
|||||||
* @param packageName
|
* @param packageName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static public TargetPackage getTargetPackage(String packageName) {
|
static public Optional<TargetPackage> getTargetPackage(String packageName) {
|
||||||
return packages.get(packageName);
|
return Optional.ofNullable(packages.get(packageName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,7 +401,7 @@ public class BaseNoGui {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static public TargetPlatform getTargetPlatform() {
|
static public Optional<TargetPlatform> getTargetPlatform() {
|
||||||
String packageName = PreferencesData.get("target_package");
|
String packageName = PreferencesData.get("target_package");
|
||||||
String platformName = PreferencesData.get("target_platform");
|
String platformName = PreferencesData.get("target_platform");
|
||||||
return getTargetPlatform(packageName, platformName);
|
return getTargetPlatform(packageName, platformName);
|
||||||
@ -407,12 +414,12 @@ public class BaseNoGui {
|
|||||||
* @param platformName
|
* @param platformName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static public TargetPlatform getTargetPlatform(String packageName,
|
static public Optional<TargetPlatform> getTargetPlatform(String packageName, String platformName) {
|
||||||
String platformName) {
|
Optional<TargetPackage> p = getTargetPackage(packageName);
|
||||||
TargetPackage p = packages.get(packageName);
|
if (!p.isPresent()) {
|
||||||
if (p == null)
|
return Optional.empty();
|
||||||
return null;
|
}
|
||||||
return p.get(platformName);
|
return Optional.ofNullable(p.get().get(platformName));
|
||||||
}
|
}
|
||||||
|
|
||||||
static public File getToolsFolder() {
|
static public File getToolsFolder() {
|
||||||
@ -649,20 +656,20 @@ public class BaseNoGui {
|
|||||||
// Add IDE libraries folder
|
// Add IDE libraries folder
|
||||||
librariesFolders.add(new UserLibraryFolder(getContentFile("libraries"), Location.IDE_BUILTIN));
|
librariesFolders.add(new UserLibraryFolder(getContentFile("libraries"), Location.IDE_BUILTIN));
|
||||||
|
|
||||||
TargetPlatform targetPlatform = getTargetPlatform();
|
Optional<TargetPlatform> targetPlatform = getTargetPlatform();
|
||||||
if (targetPlatform != null) {
|
if (targetPlatform.isPresent()) {
|
||||||
String core = getBoardPreferences().get("build.core", "arduino");
|
String core = getBoardPreferences().get("build.core", "arduino");
|
||||||
if (core.contains(":")) {
|
if (core.contains(":")) {
|
||||||
String referencedCore = core.split(":")[0];
|
String referencedCore = core.split(":")[0];
|
||||||
TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId());
|
Optional<TargetPlatform> referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.get().getId());
|
||||||
if (referencedPlatform != null) {
|
if (referencedPlatform.isPresent()) {
|
||||||
File referencedPlatformFolder = referencedPlatform.getFolder();
|
File referencedPlatformFolder = referencedPlatform.get().getFolder();
|
||||||
// Add libraries folder for the referenced platform
|
// Add libraries folder for the referenced platform
|
||||||
File folder = new File(referencedPlatformFolder, "libraries");
|
File folder = new File(referencedPlatformFolder, "libraries");
|
||||||
librariesFolders.add(new UserLibraryFolder(folder, Location.REFERENCED_CORE));
|
librariesFolders.add(new UserLibraryFolder(folder, Location.REFERENCED_CORE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File platformFolder = targetPlatform.getFolder();
|
File platformFolder = targetPlatform.get().getFolder();
|
||||||
// Add libraries folder for the selected platform
|
// Add libraries folder for the selected platform
|
||||||
File folder = new File(platformFolder, "libraries");
|
File folder = new File(platformFolder, "libraries");
|
||||||
librariesFolders.add(new UserLibraryFolder(folder, Location.CORE));
|
librariesFolders.add(new UserLibraryFolder(folder, Location.CORE));
|
||||||
@ -675,8 +682,8 @@ public class BaseNoGui {
|
|||||||
// Libraries located in the latest folders on the list can override
|
// Libraries located in the latest folders on the list can override
|
||||||
// other libraries with the same name.
|
// other libraries with the same name.
|
||||||
librariesIndexer.setLibrariesFolders(librariesFolders);
|
librariesIndexer.setLibrariesFolders(librariesFolders);
|
||||||
if (getTargetPlatform() != null) {
|
if (targetPlatform.isPresent()) {
|
||||||
librariesIndexer.setArchitecturePriority(getTargetPlatform().getId());
|
librariesIndexer.setArchitecturePriority(targetPlatform.get().getId());
|
||||||
}
|
}
|
||||||
librariesIndexer.rescanLibraries();
|
librariesIndexer.rescanLibraries();
|
||||||
|
|
||||||
|
@ -232,13 +232,13 @@ public class CommandlineParser {
|
|||||||
BaseNoGui.showError(null, I18n.format(tr("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), 3);
|
BaseNoGui.showError(null, I18n.format(tr("{0}: Invalid board name, it should be of the form \"package:arch:board\" or \"package:arch:board:options\""), selectBoard), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPackage targetPackage = BaseNoGui.getTargetPackage(split[0]);
|
Optional<TargetPackage> targetPackage = BaseNoGui.getTargetPackage(split[0]);
|
||||||
if (targetPackage == null) {
|
if (!targetPackage.isPresent()) {
|
||||||
BaseNoGui.showError(null, I18n.format(tr("{0}: Unknown package"), split[0]), 3);
|
BaseNoGui.showError(null, I18n.format(tr("{0}: Unknown package"), split[0]), 3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPlatform targetPlatform = targetPackage.get(split[1]);
|
TargetPlatform targetPlatform = targetPackage.get().get(split[1]);
|
||||||
if (targetPlatform == null) {
|
if (targetPlatform == null) {
|
||||||
BaseNoGui.showError(null, I18n.format(tr("{0}: Unknown architecture"), split[1]), 3);
|
BaseNoGui.showError(null, I18n.format(tr("{0}: Unknown architecture"), split[1]), 3);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user