3737import processing .app .helpers .PreferencesMap ;
3838import processing .app .helpers .filefilters .OnlyDirs ;
3939import processing .app .helpers .filefilters .OnlyFilesWithExtension ;
40- import processing .app .javax .swing .filechooser .FileNameExtensionFilter ;import processing .app .tools .MapWithSubkeys ;
40+ import processing .app .javax .swing .filechooser .FileNameExtensionFilter ;import processing .app .packages .Library ;
41+ import processing .app .packages .LibraryList ;
42+ import processing .app .tools .MapWithSubkeys ;
4143import processing .app .tools .ZipDeflater ;
4244import processing .core .*;
4345import static processing .app .I18n ._ ;
@@ -89,10 +91,10 @@ public class Base {
8991 static private List <File > librariesFolders ;
9092
9193 // maps library name to their library folder
92- static private Map < String , File > libraries ;
94+ static private LibraryList libraries ;
9395
9496 // maps #included files to their library folder
95- static Map <String , File > importToLibraryTable ;
97+ static Map <String , Library > importToLibraryTable ;
9698
9799 // classpath for all known libraries for p5
98100 // (both those in the p5/libs folder and those with lib subfolders
@@ -1038,26 +1040,26 @@ protected void rebuildSketchbookMenu(JMenu menu) {
10381040 }
10391041 }
10401042
1041- public Map <String , File > getIDELibs () {
1043+ public LibraryList getIDELibs () {
1044+ LibraryList libs = new LibraryList ();
10421045 if (libraries == null )
1043- return new HashMap <String , File >();
1044- Map <String , File > ideLibs = new HashMap <String , File >(libraries );
1045- for (String lib : libraries .keySet ()) {
1046- if (FileUtils .isSubDirectory (getSketchbookFolder (), libraries .get (lib )))
1047- ideLibs .remove (lib );
1046+ return libs ;
1047+ for (Library lib : libraries ) {
1048+ if (!FileUtils .isSubDirectory (getSketchbookFolder (), lib .getRootFolder ()))
1049+ libs .add (lib );
10481050 }
1049- return ideLibs ;
1051+ return libs ;
10501052 }
10511053
1052- public Map <String , File > getUserLibs () {
1054+ public LibraryList getUserLibs () {
1055+ LibraryList libs = new LibraryList ();
10531056 if (libraries == null )
1054- return new HashMap <String , File >();
1055- Map <String , File > userLibs = new HashMap <String , File >(libraries );
1056- for (String lib : libraries .keySet ()) {
1057- if (!FileUtils .isSubDirectory (getSketchbookFolder (), libraries .get (lib )))
1058- userLibs .remove (lib );
1057+ return libs ;
1058+ for (Library lib : libraries ) {
1059+ if (FileUtils .isSubDirectory (getSketchbookFolder (), lib .getRootFolder ()))
1060+ libs .add (lib );
10591061 }
1060- return userLibs ;
1062+ return libs ;
10611063 }
10621064
10631065 public void rebuildImportMenu (JMenu importMenu , final Editor editor ) {
@@ -1077,8 +1079,8 @@ public void actionPerformed(ActionEvent e) {
10771079 // Split between user supplied libraries and IDE libraries
10781080 TargetPlatform targetPlatform = getTargetPlatform ();
10791081 if (targetPlatform != null ) {
1080- Map < String , File > ideLibs = getIDELibs ();
1081- Map < String , File > userLibs = getUserLibs ();
1082+ LibraryList ideLibs = getIDELibs ();
1083+ LibraryList userLibs = getUserLibs ();
10821084 try {
10831085 // Find the current target. Get the platform, and then select the
10841086 // correct name and core path.
@@ -1118,24 +1120,24 @@ public void rebuildExamplesMenu(JMenu menu) {
11181120 if (found ) menu .addSeparator ();
11191121
11201122 // Add examples from libraries
1121- Map < String , File > ideLibs = getIDELibs ();
1122- List < String > names = new ArrayList < String > (ideLibs . keySet () );
1123- Collections . sort ( names , String . CASE_INSENSITIVE_ORDER );
1124- for ( String name : names ) {
1125- File folder = ideLibs . get ( name );
1123+ LibraryList ideLibs = getIDELibs ();
1124+ Collections . sort (ideLibs , Library . CASE_INSENSITIVE_ORDER );
1125+ for ( Library lib : ideLibs ) {
1126+ File folder = lib . getRootFolder ();
1127+ String name = lib . getName ( );
11261128 addSketchesSubmenu (menu , name , folder , false );
11271129 // Allows "fat" libraries to have examples in the root folder
11281130 if (folder .getName ().equals (Base .getTargetPlatform ().getName ()))
11291131 addSketchesSubmenu (menu , name , folder .getParentFile (), false );
11301132 }
11311133
1132- Map < String , File > userLibs = getUserLibs ();
1134+ LibraryList userLibs = getUserLibs ();
11331135 if (userLibs .size ()>0 ) {
11341136 menu .addSeparator ();
1135- names = new ArrayList < String > (userLibs . keySet () );
1136- Collections . sort ( names , String . CASE_INSENSITIVE_ORDER );
1137- for ( String name : names ) {
1138- File folder = userLibs . get ( name );
1137+ Collections . sort (userLibs , Library . CASE_INSENSITIVE_ORDER );
1138+ for ( Library lib : userLibs ) {
1139+ File folder = lib . getRootFolder ();
1140+ String name = lib . getName ( );
11391141 addSketchesSubmenu (menu , name , folder , false );
11401142 // Allows "fat" libraries to have examples in the root folder
11411143 if (folder .getName ().equals (Base .getTargetPlatform ().getName ()))
@@ -1147,15 +1149,16 @@ public void rebuildExamplesMenu(JMenu menu) {
11471149 }
11481150 }
11491151
1150- public Map < String , File > scanLibraries (List <File > folders ) {
1151- Map < String , File > res = new HashMap < String , File > ();
1152+ public LibraryList scanLibraries (List <File > folders ) {
1153+ LibraryList res = new LibraryList ();
11521154 for (File folder : folders )
1153- res .putAll (scanLibraries (folder ));
1155+ res .addAll (scanLibraries (folder ));
11541156 return res ;
11551157 }
11561158
1157- public Map <String , File > scanLibraries (File folder ) {
1158- Map <String , File > res = new HashMap <String , File >();
1159+ public LibraryList scanLibraries (File folder ) {
1160+ LibraryList res = new LibraryList ();
1161+
11591162 String list [] = folder .list (new OnlyDirs ());
11601163 // if a bad folder or something like that, this might come back null
11611164 if (list == null )
@@ -1172,41 +1175,15 @@ public Map<String, File> scanLibraries(File folder) {
11721175 continue ;
11731176 }
11741177
1175- subfolder = scanFatLibrary (subfolder );
1178+ Library lib = Library . fromFolder (subfolder , Base . getTargetPlatform (). getName () );
11761179
11771180 // (also replace previously found libs with the same name)
1178- if (subfolder != null )
1179- res .put ( libName , subfolder );
1181+ if (lib != null )
1182+ res .addOrReplace ( lib );
11801183 }
11811184 return res ;
11821185 }
11831186
1184- /**
1185- * Scans inside a "FAT" (multi-platform) library folder to see if it contains
1186- * a version suitable for the actual selected architecture. If a suitable
1187- * version is found the folder containing that version is returned, otherwise
1188- * <b>null</b> is returned.<br />
1189- * <br />
1190- * If a non-"FAT" library is detected, we assume that the library is suitable
1191- * for the current architecture and the libFolder parameter is returned.<br />
1192- *
1193- * @param libFolder
1194- * @return
1195- */
1196- public File scanFatLibrary (File libFolder ) {
1197- // A library is considered "fat" if it contains a file called
1198- // "library.properties"
1199- File libraryPropFile = new File (libFolder , "library.properties" );
1200- if (!libraryPropFile .exists () || !libraryPropFile .isFile ())
1201- return libFolder ;
1202-
1203- // Search for a subfolder for actual architecture, return null if not found
1204- File archSubfolder = new File (libFolder , Base .getTargetPlatform ().getName ());
1205- if (!archSubfolder .exists () || !archSubfolder .isDirectory ())
1206- return null ;
1207- return archSubfolder ;
1208- }
1209-
12101187 public void onBoardOrPortChange () {
12111188 TargetPlatform targetPlatform = getTargetPlatform ();
12121189 if (targetPlatform == null )
@@ -1228,15 +1205,16 @@ public void onBoardOrPortChange() {
12281205 libraries = scanLibraries (librariesFolders );
12291206
12301207 // Populate importToLibraryTable
1231- importToLibraryTable = new HashMap <String , File >();
1232- for (File subfolder : libraries . values () ) {
1208+ importToLibraryTable = new HashMap <String , Library >();
1209+ for (Library lib : libraries ) {
12331210 try {
1234- String packages [] = headerListFromIncludePath (subfolder );
1235- for (String pkg : packages ) {
1236- importToLibraryTable .put (pkg , subfolder );
1211+ String headers [] = headerListFromIncludePath (lib . getRootFolder () );
1212+ for (String header : headers ) {
1213+ importToLibraryTable .put (header , lib );
12371214 }
12381215 } catch (IOException e ) {
1239- showWarning (_ ("Error" ), I18n .format ("Unable to list header files in {0}" , subfolder ), e );
1216+ showWarning (_ ("Error" ), I18n
1217+ .format ("Unable to list header files in {0}" , lib .getRootFolder ()), e );
12401218 }
12411219 }
12421220
@@ -1580,10 +1558,10 @@ public void actionPerformed(ActionEvent e) {
15801558 return found ;
15811559 }
15821560
1583- protected void addLibraries (JMenu menu , Map < String , File > libs ) throws IOException {
1561+ protected void addLibraries (JMenu menu , LibraryList libs ) throws IOException {
15841562
1585- List < String > list = new ArrayList < String > (libs . keySet () );
1586- Collections .sort (list , String .CASE_INSENSITIVE_ORDER );
1563+ LibraryList list = new LibraryList (libs );
1564+ Collections .sort (list , Library .CASE_INSENSITIVE_ORDER );
15871565
15881566 ActionListener listener = new ActionListener () {
15891567 public void actionPerformed (ActionEvent event ) {
@@ -1596,11 +1574,11 @@ public void actionPerformed(ActionEvent event) {
15961574 }
15971575 };
15981576
1599- for (String name : list ) {
1600- File folder = libs . get ( name );
1577+ for (Library lib : list ) {
1578+ File folder = lib . getRootFolder ( );
16011579
16021580 // Add new element at the bottom
1603- JMenuItem item = new JMenuItem (name );
1581+ JMenuItem item = new JMenuItem (lib . getName () );
16041582 item .addActionListener (listener );
16051583 item .setActionCommand (folder .getAbsolutePath ());
16061584 menu .add (item );
@@ -1874,7 +1852,7 @@ static public File createTempFolder(String name) {
18741852 }
18751853
18761854
1877- static public Map < String , File > getLibraries () {
1855+ static public LibraryList getLibraries () {
18781856 return libraries ;
18791857 }
18801858
0 commit comments