MCPcopy Index your code
hub / github.com/benfry/processing4 / discover

Method discover

app/src/processing/app/Library.java:559–620  ·  view source on GitHub ↗
(File folder)

Source from the content-addressed store, hash-verified

557
558
559 static public List<File> discover(File folder) {
560 List<File> libraries = new ArrayList<>();
561 String[] folderNames = folder.list(junkFolderFilter);
562
563 // if a bad folder or unreadable, folderNames might be null
564 if (folderNames != null) {
565 // alphabetize list, since it's not always alpha order
566 // replaced hella slow bubble sort with this feller for 0093
567 Arrays.sort(folderNames, String.CASE_INSENSITIVE_ORDER);
568
569 // TODO a little odd because ContributionType.LIBRARY.isCandidate()
570 // handles some, but not all, of this; and the rules of selection
571 // should probably be consolidated in a sensible way [fry 200116]
572 for (String potentialName : folderNames) {
573 File baseFolder = new File(folder, potentialName);
574 File libraryFolder = new File(baseFolder, "library");
575 File libraryJar = new File(libraryFolder, potentialName + ".jar");
576 // If a .jar file of the same prefix as the folder exists
577 // inside the 'library' subfolder of the sketch
578 if (libraryJar.exists()) {
579 String sanityCheck = Sketch.sanitizeName(potentialName);
580 if (!sanityCheck.equals(potentialName)) {
581 final String mess =
582 "The library \"" + potentialName + "\" cannot be used.\n" +
583 "Library names must contain only basic letters and numbers.\n" +
584 "(ASCII only and no spaces, and it cannot start with a number)";
585 Messages.showMessage("Ignoring bad library name", mess);
586
587 } else {
588 String pkg = findCollision(libraryFolder);
589 if (pkg != null) {
590 final String mess =
591 "The library \"" + potentialName + "\" cannot be used\n" +
592 "because it contains the " + pkg + " libraries.\n" +
593 "Please contact the library author for an update.";
594 Messages.showMessage("Ignoring bad library", mess);
595
596 // Move the folder out of the way
597 File badFolder = new File(baseFolder.getParentFile(), "disabled");
598 boolean success = true;
599 if (!badFolder.exists()) {
600 success = badFolder.mkdirs();
601 }
602 if (success) {
603 File hideFolder = new File(badFolder, baseFolder.getName());
604 success = baseFolder.renameTo(hideFolder);
605 if (success) {
606 System.out.println("Moved " + baseFolder + " to " + hideFolder);
607 } else {
608 System.err.println("Could not move " + baseFolder + " to " + hideFolder);
609 }
610 }
611
612 } else {
613 libraries.add(baseFolder);
614 }
615 }
616 }

Callers 1

listMethod · 0.95

Calls 10

sanitizeNameMethod · 0.95
showMessageMethod · 0.95
findCollisionMethod · 0.95
renameToMethod · 0.80
listMethod · 0.45
sortMethod · 0.45
equalsMethod · 0.45
getNameMethod · 0.45
printlnMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected