diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 689c13719..50462befe 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1182,8 +1182,13 @@ public class Base { Arrays.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); + } } }; @@ -1220,11 +1225,15 @@ public class Base { // String packages[] = // Compiler.packageListFromClassPath(libraryClassPath); libraries.add(subfolder); + try { String packages[] = Compiler.headerListFromIncludePath(subfolder.getAbsolutePath()); for (String pkg : packages) { importToLibraryTable.put(pkg, subfolder); } + } catch (IOException e) { + showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e); + } JMenuItem item = new JMenuItem(libraryName); item.addActionListener(listener); diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 5f8a09b5d..dd3bcb2b8 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1128,7 +1128,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(); diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index cf5980610..a715d59a4 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -644,14 +644,18 @@ public class Compiler implements MessageConsumer { * not 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(String path) { + static public String[] headerListFromIncludePath(String path) throws IOException { FilenameFilter onlyHFiles = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".h"); } }; - - return (new File(path)).list(onlyHFiles); + + String[] list = (new File(path)).list(onlyHFiles); + if (list == null) { + throw new IOException(); + } + return list; } static public ArrayList findFilesInPath(String path, String extension,