From 8dacb1eab05ca411945610e165842f1a5b04f573 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Wed, 12 Dec 2012 17:23:46 +0100 Subject: [PATCH] see #1160 --- app/src/processing/app/Base.java | 28 +++++++++++++++++++++------- app/src/processing/app/Sketch.java | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index a46b29204..0633c04cc 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1153,9 +1153,14 @@ public class Base { // Populate importToLibraryTable importToLibraryTable = new HashMap(); for (File subfolder : libraries.values()) { - String packages[] = headerListFromIncludePath(subfolder); - for (String pkg : packages) - importToLibraryTable.put(pkg, subfolder); + try { + String packages[] = headerListFromIncludePath(subfolder); + for (String pkg : packages) { + importToLibraryTable.put(pkg, subfolder); + } + } catch (IOException e) { + showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e); + } } // Update editors status bar @@ -1501,8 +1506,13 @@ public class Base { Collections.sort(list, String.CASE_INSENSITIVE_ORDER); ActionListener listener = new ActionListener() { - public void actionPerformed(ActionEvent e) { - activeEditor.getSketch().importLibrary(e.getActionCommand()); + public void actionPerformed(ActionEvent event) { + String jarPath = event.getActionCommand(); + try { + activeEditor.getSketch().importLibrary(jarPath); + } catch (IOException e) { + showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e); + } } }; @@ -1524,8 +1534,12 @@ public class Base { * the header files in its sub-folders, as those should be included from * within the header files at the top-level). */ - static public String[] headerListFromIncludePath(File path) { - return path.list(new OnlyFilesWithExtension(".h")); + static public String[] headerListFromIncludePath(File path) throws IOException { + String[] list = path.list(new OnlyFilesWithExtension(".h")); + if (list == null) { + throw new IOException(); + } + return list; } protected void loadHardware(File folder) { diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 0293b622f..8e0f327fa 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1124,7 +1124,7 @@ public class Sketch { * Add import statements to the current tab for all of packages inside * the specified jar file. */ - public void importLibrary(String jarPath) { + public void importLibrary(String jarPath) throws IOException { // make sure the user didn't hide the sketch folder ensureExistence();