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