MCPcopy Index your code
hub / github.com/processing/processing / rebuildContribModes

Method rebuildContribModes

app/src/processing/app/Base.java:465–526  ·  view source on GitHub ↗

Instantiates and adds new contributed modes to the contribModes list. Checks for duplicates so the same mode isn't instantiates twice. Does not remove modes because modes can't be removed once they are instantiated.

()

Source from the content-addressed store, hash-verified

463 * remove modes because modes can't be removed once they are instantiated.
464 */
465 void rebuildContribModes() {
466 if (modeContribs == null) {
467 modeContribs = new ArrayList<>();
468 }
469 File modesFolder = getSketchbookModesFolder();
470 List<ModeContribution> contribModes = getModeContribs();
471
472 Map<File, ModeContribution> known = new HashMap<>();
473 for (ModeContribution contrib : contribModes) {
474 known.put(contrib.getFolder(), contrib);
475 }
476 File[] potential = ContributionType.MODE.listCandidates(modesFolder);
477 // If modesFolder does not exist or is inaccessible (folks might like to
478 // mess with folders then report it as a bug) 'potential' will be null.
479 if (potential != null) {
480 for (File folder : potential) {
481 if (!known.containsKey(folder)) {
482 try {
483 contribModes.add(new ModeContribution(this, folder, null));
484 } catch (NoSuchMethodError nsme) {
485 System.err.println(folder.getName() + " is not compatible with this version of Processing");
486 if (DEBUG) nsme.printStackTrace();
487 } catch (NoClassDefFoundError ncdfe) {
488 System.err.println(folder.getName() + " is not compatible with this version of Processing");
489 if (DEBUG) ncdfe.printStackTrace();
490 } catch (InvocationTargetException ite) {
491 System.err.println(folder.getName() + " could not be loaded and may not compatible with this version of Processing");
492 if (DEBUG) ite.printStackTrace();
493 } catch (IgnorableException ig) {
494 Messages.log(ig.getMessage());
495 if (DEBUG) ig.printStackTrace();
496 } catch (Throwable e) {
497 System.err.println("Could not load Mode from " + folder);
498 e.printStackTrace();
499 }
500 } else {
501 known.remove(folder); // remove this item as already been seen
502 }
503 }
504 }
505
506 // This allows you to build and test your Mode code from Eclipse.
507 // -Dusemode=com.foo.FrobMode:/path/to/FrobMode
508 final String useMode = System.getProperty("usemode");
509 if (useMode != null) {
510 final String[] modeInfo = useMode.split(":", 2);
511 final String modeClass = modeInfo[0];
512 final String modeResourcePath = modeInfo[1];
513 System.out.println("Attempting to load " + modeClass + " with resources at " + modeResourcePath);
514 ModeContribution mc = ModeContribution.load(this, new File(modeResourcePath), modeClass);
515 contribModes.add(mc);
516 File key = getFileForContrib(mc, known);
517 if (key != null) {
518 known.remove(key);
519 }
520 }
521 if (known.size() != 0) {
522 for (ModeContribution mc : known.values()) {

Callers 2

BaseMethod · 0.95
refreshContribsMethod · 0.95

Calls 15

getModeContribsMethod · 0.95
logMethod · 0.95
loadMethod · 0.95
getFileForContribMethod · 0.95
listCandidatesMethod · 0.80
containsKeyMethod · 0.80
splitMethod · 0.80
getMessageMethod · 0.65
putMethod · 0.45
getFolderMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected