From 57bee97d7be07023bc94460cde54c96e4ef3de1d Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 17 Feb 2014 14:15:17 +0100 Subject: [PATCH 1/2] Local (user installed) libraries have priority over system libraries See #1853 --- app/src/processing/app/Base.java | 38 ++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 29540399b..7e87b76a8 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1211,7 +1211,7 @@ public class Base { boolean ifound = false; for (String potentialName : list) { - File subfolder = new File(folder, potentialName); + File libFolder = new File(folder, potentialName); // File libraryFolder = new File(subfolder, "library"); // File libraryJar = new File(libraryFolder, potentialName + ".jar"); // // If a .jar file of the same prefix as the folder exists @@ -1240,27 +1240,37 @@ public class Base { // // need to associate each import with a library folder // String packages[] = // Compiler.packageListFromClassPath(libraryClassPath); - libraries.add(subfolder); + libraries.add(libFolder); + String libFolderPath = libFolder.getAbsolutePath(); try { - String packages[] = - Compiler.headerListFromIncludePath(subfolder.getAbsolutePath()); - for (String pkg : packages) { - File old = importToLibraryTable.get(pkg); - if (old != null) { - // If a library was already found with this header, keep it if - // the library's directory name matches the header name. - String name = pkg.substring(0, pkg.length() - 2); - if (old.getPath().endsWith(name)) continue; + String headers[] = Compiler.headerListFromIncludePath(libFolderPath); + for (String header : headers) { + // Extract file name (without extension ".h") + String name = header.substring(0, header.length() - 2); + + // If the header name equals to the current library folder use it + if (libFolderPath.endsWith(name)) { + importToLibraryTable.put(header, libFolder); + continue; } - importToLibraryTable.put(pkg, subfolder); + + // If a library was already found with this header, keep it if + // the library's directory name matches the header name. + File old = importToLibraryTable.get(header); + if (old != null) { + if (old.getPath().endsWith(name)) + continue; + } + importToLibraryTable.put(header, libFolder); } } catch (IOException e) { - showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e); + showWarning(_("Error"), I18n.format( + "Unable to list header files in {0}", libFolder), e); } JMenuItem item = new JMenuItem(libraryName); item.addActionListener(listener); - item.setActionCommand(subfolder.getAbsolutePath()); + item.setActionCommand(libFolderPath); menu.add(item); ifound = true; From 3a72c02480e5b85a59a08b6739ed7b45d81d390a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 17 Feb 2014 14:17:19 +0100 Subject: [PATCH 2/2] Removed unused code, fixed indentation. --- app/src/processing/app/Base.java | 58 +++++++++----------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 7e87b76a8..5d784facf 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1212,34 +1212,17 @@ public class Base { for (String potentialName : list) { File libFolder = new File(folder, potentialName); -// File libraryFolder = new File(subfolder, "library"); -// File libraryJar = new File(libraryFolder, potentialName + ".jar"); -// // If a .jar file of the same prefix as the folder exists -// // inside the 'library' subfolder of the sketch -// if (libraryJar.exists()) { - String sanityCheck = Sketch.sanitizeName(potentialName); - if (!sanityCheck.equals(potentialName)) { - String mess = I18n.format( - _("The library \"{0}\" cannot be used.\n" + - "Library names must contain only basic letters and numbers.\n" + - "(ASCII only and no spaces, and it cannot start with a number)"), - potentialName - ); - Base.showMessage(_("Ignoring bad library name"), mess); - continue; - } + String sanityCheck = Sketch.sanitizeName(potentialName); + if (!sanityCheck.equals(potentialName)) { + String mess = I18n.format(_("The library \"{0}\" cannot be used.\n" + + "Library names must contain only basic letters and numbers.\n" + + "(ASCII only and no spaces, and it cannot start with a number)"), + potentialName); + Base.showMessage(_("Ignoring bad library name"), mess); + continue; + } - String libraryName = potentialName; -// // get the path for all .jar files in this code folder -// String libraryClassPath = -// Compiler.contentsToClassPath(libraryFolder); -// // grab all jars and classes from this folder, -// // and append them to the library classpath -// librariesClassPath += -// File.pathSeparatorChar + libraryClassPath; -// // need to associate each import with a library folder -// String packages[] = -// Compiler.packageListFromClassPath(libraryClassPath); + String libraryName = potentialName; libraries.add(libFolder); String libFolderPath = libFolder.getAbsolutePath(); try { @@ -1268,22 +1251,11 @@ public class Base { "Unable to list header files in {0}", libFolder), e); } - JMenuItem item = new JMenuItem(libraryName); - item.addActionListener(listener); - item.setActionCommand(libFolderPath); - menu.add(item); - ifound = true; - -// XXX: DAM: should recurse here so that library folders can be nested -// } else { // not a library, but is still a folder, so recurse -// JMenu submenu = new JMenu(libraryName); -// // needs to be separate var, otherwise would set ifound to false -// boolean found = addLibraries(submenu, subfolder); -// if (found) { -// menu.add(submenu); -// ifound = true; -// } -// } + JMenuItem item = new JMenuItem(libraryName); + item.addActionListener(listener); + item.setActionCommand(libFolderPath); + menu.add(item); + ifound = true; } return ifound; }