1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-15 12:29:26 +01:00

Local (user installed) libraries have priority over system libraries

See #1853
This commit is contained in:
Cristian Maglie 2014-02-17 14:15:17 +01:00
parent 1d060cafe0
commit 57bee97d7b

View File

@ -1211,7 +1211,7 @@ public class Base {
boolean ifound = false; boolean ifound = false;
for (String potentialName : list) { for (String potentialName : list) {
File subfolder = new File(folder, potentialName); File libFolder = new File(folder, potentialName);
// File libraryFolder = new File(subfolder, "library"); // File libraryFolder = new File(subfolder, "library");
// File libraryJar = new File(libraryFolder, potentialName + ".jar"); // File libraryJar = new File(libraryFolder, potentialName + ".jar");
// // If a .jar file of the same prefix as the folder exists // // 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 // // need to associate each import with a library folder
// String packages[] = // String packages[] =
// Compiler.packageListFromClassPath(libraryClassPath); // Compiler.packageListFromClassPath(libraryClassPath);
libraries.add(subfolder); libraries.add(libFolder);
String libFolderPath = libFolder.getAbsolutePath();
try { try {
String packages[] = String headers[] = Compiler.headerListFromIncludePath(libFolderPath);
Compiler.headerListFromIncludePath(subfolder.getAbsolutePath()); for (String header : headers) {
for (String pkg : packages) { // Extract file name (without extension ".h")
File old = importToLibraryTable.get(pkg); String name = header.substring(0, header.length() - 2);
if (old != null) {
// If a library was already found with this header, keep it if // If the header name equals to the current library folder use it
// the library's directory name matches the header name. if (libFolderPath.endsWith(name)) {
String name = pkg.substring(0, pkg.length() - 2); importToLibraryTable.put(header, libFolder);
if (old.getPath().endsWith(name)) continue; 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) { } 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); JMenuItem item = new JMenuItem(libraryName);
item.addActionListener(listener); item.addActionListener(listener);
item.setActionCommand(subfolder.getAbsolutePath()); item.setActionCommand(libFolderPath);
menu.add(item); menu.add(item);
ifound = true; ifound = true;