Skip to content

Commit 8dacb1e

Browse files
author
Federico Fissore
committed
see #1160
1 parent 15a7ebe commit 8dacb1e

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

app/src/processing/app/Base.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,14 @@ public void onBoardOrPortChange() {
11531153
// Populate importToLibraryTable
11541154
importToLibraryTable = new HashMap<String, File>();
11551155
for (File subfolder : libraries.values()) {
1156-
String packages[] = headerListFromIncludePath(subfolder);
1157-
for (String pkg : packages)
1158-
importToLibraryTable.put(pkg, subfolder);
1156+
try {
1157+
String packages[] = headerListFromIncludePath(subfolder);
1158+
for (String pkg : packages) {
1159+
importToLibraryTable.put(pkg, subfolder);
1160+
}
1161+
} catch (IOException e) {
1162+
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e);
1163+
}
11591164
}
11601165

11611166
// Update editors status bar
@@ -1501,8 +1506,13 @@ protected void addLibraries(JMenu menu, Map<String, File> libs) throws IOExcepti
15011506
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
15021507

15031508
ActionListener listener = new ActionListener() {
1504-
public void actionPerformed(ActionEvent e) {
1505-
activeEditor.getSketch().importLibrary(e.getActionCommand());
1509+
public void actionPerformed(ActionEvent event) {
1510+
String jarPath = event.getActionCommand();
1511+
try {
1512+
activeEditor.getSketch().importLibrary(jarPath);
1513+
} catch (IOException e) {
1514+
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e);
1515+
}
15061516
}
15071517
};
15081518

@@ -1524,8 +1534,12 @@ public void actionPerformed(ActionEvent e) {
15241534
* the header files in its sub-folders, as those should be included from
15251535
* within the header files at the top-level).
15261536
*/
1527-
static public String[] headerListFromIncludePath(File path) {
1528-
return path.list(new OnlyFilesWithExtension(".h"));
1537+
static public String[] headerListFromIncludePath(File path) throws IOException {
1538+
String[] list = path.list(new OnlyFilesWithExtension(".h"));
1539+
if (list == null) {
1540+
throw new IOException();
1541+
}
1542+
return list;
15291543
}
15301544

15311545
protected void loadHardware(File folder) {

app/src/processing/app/Sketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ public boolean addFile(File sourceFile) {
11241124
* Add import statements to the current tab for all of packages inside
11251125
* the specified jar file.
11261126
*/
1127-
public void importLibrary(String jarPath) {
1127+
public void importLibrary(String jarPath) throws IOException {
11281128
// make sure the user didn't hide the sketch folder
11291129
ensureExistence();
11301130

0 commit comments

Comments
 (0)