mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Fixed NPE when unknown platform/board are selected in preference
This commit is contained in:
parent
69b31ba86f
commit
12ac3f3958
@ -970,6 +970,8 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, File> getIDELibs() {
|
public Map<String, File> getIDELibs() {
|
||||||
|
if (libraries == null)
|
||||||
|
return new HashMap<String, File>();
|
||||||
Map<String, File> ideLibs = new HashMap<String, File>(libraries);
|
Map<String, File> ideLibs = new HashMap<String, File>(libraries);
|
||||||
for (String lib : libraries.keySet()) {
|
for (String lib : libraries.keySet()) {
|
||||||
if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
|
if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
|
||||||
@ -979,6 +981,8 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, File> getUserLibs() {
|
public Map<String, File> getUserLibs() {
|
||||||
|
if (libraries == null)
|
||||||
|
return new HashMap<String, File>();
|
||||||
Map<String, File> userLibs = new HashMap<String, File>(libraries);
|
Map<String, File> userLibs = new HashMap<String, File>(libraries);
|
||||||
for (String lib : libraries.keySet()) {
|
for (String lib : libraries.keySet()) {
|
||||||
if (!FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
|
if (!FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
|
||||||
@ -1002,34 +1006,37 @@ public class Base {
|
|||||||
importMenu.add(addLibraryMenuItem);
|
importMenu.add(addLibraryMenuItem);
|
||||||
|
|
||||||
// Split between user supplied libraries and IDE libraries
|
// Split between user supplied libraries and IDE libraries
|
||||||
Map<String, File> ideLibs = getIDELibs();
|
TargetPlatform targetPlatform = getTargetPlatform();
|
||||||
Map<String, File> userLibs = getUserLibs();
|
if (targetPlatform != null) {
|
||||||
try {
|
Map<String, File> ideLibs = getIDELibs();
|
||||||
// Find the current target. Get the platform, and then select the
|
Map<String, File> userLibs = getUserLibs();
|
||||||
// correct name and core path.
|
try {
|
||||||
PreferencesMap prefs = getTargetPlatform().getPreferences();
|
// Find the current target. Get the platform, and then select the
|
||||||
String targetname = prefs.get("name");
|
// correct name and core path.
|
||||||
|
PreferencesMap prefs = targetPlatform.getPreferences();
|
||||||
|
String targetname = prefs.get("name");
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
// Hack to extract these words by gettext tool.
|
// Hack to extract these words by gettext tool.
|
||||||
// These phrases are actually defined in the "platform.txt".
|
// These phrases are actually defined in the "platform.txt".
|
||||||
String notused = _("Arduino AVR Boards");
|
String notused = _("Arduino AVR Boards");
|
||||||
notused = _("Arduino ARM (32-bits) Boards");
|
notused = _("Arduino ARM (32-bits) Boards");
|
||||||
}
|
}
|
||||||
|
|
||||||
JMenuItem platformItem = new JMenuItem(_(targetname));
|
JMenuItem platformItem = new JMenuItem(_(targetname));
|
||||||
platformItem.setEnabled(false);
|
platformItem.setEnabled(false);
|
||||||
importMenu.add(platformItem);
|
importMenu.add(platformItem);
|
||||||
if (ideLibs.size()>0) {
|
if (ideLibs.size() > 0) {
|
||||||
importMenu.addSeparator();
|
importMenu.addSeparator();
|
||||||
addLibraries(importMenu, ideLibs);
|
addLibraries(importMenu, ideLibs);
|
||||||
|
}
|
||||||
|
if (userLibs.size() > 0) {
|
||||||
|
importMenu.addSeparator();
|
||||||
|
addLibraries(importMenu, userLibs);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (userLibs.size()>0) {
|
|
||||||
importMenu.addSeparator();
|
|
||||||
addLibraries(importMenu, userLibs);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1132,11 +1139,15 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onBoardOrPortChange() {
|
public void onBoardOrPortChange() {
|
||||||
|
TargetPlatform targetPlatform = getTargetPlatform();
|
||||||
|
if (targetPlatform == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// Calculate paths for libraries and examples
|
// Calculate paths for libraries and examples
|
||||||
examplesFolder = getContentFile("examples");
|
examplesFolder = getContentFile("examples");
|
||||||
toolsFolder = getContentFile("tools");
|
toolsFolder = getContentFile("tools");
|
||||||
|
|
||||||
File platformFolder = getTargetPlatform().getFolder();
|
File platformFolder = targetPlatform.getFolder();
|
||||||
librariesFolders = new ArrayList<File>();
|
librariesFolders = new ArrayList<File>();
|
||||||
librariesFolders.add(getContentFile("libraries"));
|
librariesFolders.add(getContentFile("libraries"));
|
||||||
librariesFolders.add(new File(platformFolder, "libraries"));
|
librariesFolders.add(new File(platformFolder, "libraries"));
|
||||||
@ -1400,6 +1411,9 @@ public class Base {
|
|||||||
*/
|
*/
|
||||||
protected boolean addSketches(JMenu menu, File folder,
|
protected boolean addSketches(JMenu menu, File folder,
|
||||||
final boolean replaceExisting) throws IOException {
|
final boolean replaceExisting) throws IOException {
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
// skip .DS_Store files, etc (this shouldn't actually be necessary)
|
// skip .DS_Store files, etc (this shouldn't actually be necessary)
|
||||||
if (!folder.isDirectory()) return false;
|
if (!folder.isDirectory()) return false;
|
||||||
|
|
||||||
@ -1846,7 +1860,10 @@ public class Base {
|
|||||||
*/
|
*/
|
||||||
static public TargetPlatform getTargetPlatform(String packageName,
|
static public TargetPlatform getTargetPlatform(String packageName,
|
||||||
String platformName) {
|
String platformName) {
|
||||||
return packages.get(packageName).get(platformName);
|
TargetPackage p = packages.get(packageName);
|
||||||
|
if (p == null)
|
||||||
|
return null;
|
||||||
|
return p.get(platformName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
|
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
|
||||||
|
@ -727,7 +727,10 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
|
|
||||||
protected void addTools(JMenu menu, File sourceFolder) {
|
protected void addTools(JMenu menu, File sourceFolder) {
|
||||||
HashMap<String, JMenuItem> toolItems = new HashMap<String, JMenuItem>();
|
if (sourceFolder == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Map<String, JMenuItem> toolItems = new HashMap<String, JMenuItem>();
|
||||||
|
|
||||||
File[] folders = sourceFolder.listFiles(new FileFilter() {
|
File[] folders = sourceFolder.listFiles(new FileFilter() {
|
||||||
public boolean accept(File folder) {
|
public boolean accept(File folder) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user