@@ -360,63 +360,86 @@ static public boolean hasMultipleArch(int platform, ArrayList<Library> libraries
360360 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
361361
362362
363+ static protected FilenameFilter junkFolderFilter = new FilenameFilter () {
364+ public boolean accept (File dir , String name ) {
365+ // skip .DS_Store files, .svn folders, etc
366+ if (name .charAt (0 ) == '.' ) return false ;
367+ if (name .equals ("CVS" )) return false ;
368+ return (new File (dir , name ).isDirectory ());
369+ }
370+ };
371+
372+ static protected ArrayList <File > discover (File folder ) throws IOException {
373+ ArrayList <File > libraries = new ArrayList <File >();
374+ discover (folder , libraries );
375+ return libraries ;
376+ }
377+
378+ static protected void discover (File folder , ArrayList <File > libraries ) throws IOException {
379+ String [] list = folder .list (junkFolderFilter );
380+
381+ // if a bad folder or something like that, this might come back null
382+ if (list != null ) {
383+ // alphabetize list, since it's not always alpha order
384+ // replaced hella slow bubble sort with this feller for 0093
385+ Arrays .sort (list , String .CASE_INSENSITIVE_ORDER );
386+
387+ for (String potentialName : list ) {
388+ File baseFolder = new File (folder , potentialName );
389+ File libraryFolder = new File (baseFolder , "library" );
390+ File libraryJar = new File (libraryFolder , potentialName + ".jar" );
391+ // If a .jar file of the same prefix as the folder exists
392+ // inside the 'library' subfolder of the sketch
393+ if (libraryJar .exists ()) {
394+ String sanityCheck = Sketch .sanitizeName (potentialName );
395+ if (sanityCheck .equals (potentialName )) {
396+ libraries .add (baseFolder );
397+
398+ } else {
399+ String mess = "The library \" "
400+ + potentialName
401+ + "\" cannot be used.\n "
402+ + "Library names must contain only basic letters and numbers.\n "
403+ + "(ASCII only and no spaces, and it cannot start with a number)" ;
404+ Base .showMessage ("Ignoring bad library name" , mess );
405+ continue ;
406+ }
407+ }
408+ }
409+ }
410+ }
411+
363412 static protected ArrayList <Library > list (File folder ) throws IOException {
364413 ArrayList <Library > libraries = new ArrayList <Library >();
365414 list (folder , libraries );
366415 return libraries ;
367416 }
368417
369-
370418 static protected void list (File folder , ArrayList <Library > libraries ) throws IOException {
371- list (folder , libraries , null );
372- }
373-
374-
375- static protected void list (File folder , ArrayList <Library > libraries , String subfolder ) throws IOException {
376- if (folder .isDirectory ()) {
377- String [] list = folder .list (new FilenameFilter () {
378- public boolean accept (File dir , String name ) {
379- // skip .DS_Store files, .svn folders, etc
380- if (name .charAt (0 ) == '.' ) return false ;
381- if (name .equals ("CVS" )) return false ;
382- return (new File (dir , name ).isDirectory ());
383- }
384- });
385- // if a bad folder or something like that, this might come back null
386- if (list != null ) {
387- // alphabetize list, since it's not always alpha order
388- // replaced hella slow bubble sort with this feller for 0093
389- Arrays .sort (list , String .CASE_INSENSITIVE_ORDER );
390-
391- for (String potentialName : list ) {
392- File baseFolder = new File (folder , potentialName );
393- File libraryFolder = new File (baseFolder , "library" );
394- File libraryJar = new File (libraryFolder , potentialName + ".jar" );
395- // If a .jar file of the same prefix as the folder exists
396- // inside the 'library' subfolder of the sketch
397- if (libraryJar .exists ()) {
398- String sanityCheck = Sketch .sanitizeName (potentialName );
399- if (sanityCheck .equals (potentialName )) {
400- libraries .add (new Library (baseFolder , subfolder ));
401-
402- } else {
403- String mess =
404- "The library \" " + potentialName + "\" cannot be used.\n " +
405- "Library names must contain only basic letters and numbers.\n " +
406- "(ASCII only and no spaces, and it cannot start with a number)" ;
407- Base .showMessage ("Ignoring bad library name" , mess );
408- continue ;
409- }
410- } else if (subfolder == null ) { // no library jar, maybe a subfolder?
411- // Add the recursive library folders back for toxi
412- // http://code.google.com/p/processing/issues/detail?id=578
413- list (new File (folder , potentialName ), libraries , potentialName );
419+ ArrayList <File > librariesFolders = new ArrayList <File >();
420+ discover (folder , librariesFolders );
421+
422+ for (File baseFolder : librariesFolders ) {
423+ libraries .add (new Library (baseFolder , null ));
424+ }
425+
426+ String [] list = folder .list (junkFolderFilter );
427+ if (list != null ) {
428+ for (String subfolderName : list ) {
429+ File subfolder = new File (folder , subfolderName );
430+
431+ if (!libraries .contains (subfolder )) {
432+ ArrayList <File > discoveredLibFolders = new ArrayList <File >();
433+ discover (subfolder , discoveredLibFolders );
434+
435+ for (File discoveredFolder : discoveredLibFolders ) {
436+ libraries .add (new Library (discoveredFolder , subfolderName ));
414437 }
415438 }
416439 }
417440 }
418441 }
419-
442+
420443 public Type getType () {
421444 return Type .LIBRARY ;
422445 }
0 commit comments