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

Method rebuildContribModes

app/src/processing/app/Base.java:773–829  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

771 * remove modes because modes can't be removed once they are instantiated.
772 */
773 void rebuildContribModes() {
774 if (contribModes == null) {
775 contribModes = new ArrayList<>();
776 }
777 File modesFolder = getSketchbookModesFolder();
778 Map<File, ModeContribution> known = new HashMap<>();
779 for (ModeContribution contrib : getContribModes()) {
780 known.put(contrib.getFolder(), contrib);
781 }
782 File[] potential = ContributionType.MODE.listCandidates(modesFolder);
783 // If modesFolder does not exist or is inaccessible (folks might like to
784 // mess with folders then report it as a bug) 'potential' will be null.
785 if (potential != null) {
786 for (File folder : potential) {
787 if (!known.containsKey(folder)) {
788 try {
789 contribModes.add(new ModeContribution(this, folder, null));
790 } catch (NoSuchMethodError | NoClassDefFoundError ne) {
791 System.err.println(folder.getName() + " is not compatible with this version of Processing");
792 if (DEBUG) ne.printStackTrace();
793 } catch (InvocationTargetException ite) {
794 System.err.println(folder.getName() + " could not be loaded and may not compatible with this version of Processing");
795 if (DEBUG) ite.printStackTrace();
796 } catch (IgnorableException ig) {
797 Messages.log(ig.getMessage());
798 if (DEBUG) ig.printStackTrace();
799 } catch (Throwable e) {
800 System.err.println("Could not load Mode from " + folder);
801 e.printStackTrace();
802 }
803 } else {
804 known.remove(folder); // remove this item as already been seen
805 }
806 }
807 }
808
809 // This allows you to build and test a Mode from Eclipse
810 // -Dusemode=com.foo.FrobMode:/path/to/FrobMode
811 final String useMode = System.getProperty("usemode");
812 if (useMode != null) {
813 final String[] modeInfo = useMode.split(":", 2);
814 final String modeClass = modeInfo[0];
815 final String modeResourcePath = modeInfo[1];
816 System.out.println("Attempting to load " + modeClass + " with resources at " + modeResourcePath);
817 ModeContribution mc = ModeContribution.load(this, new File(modeResourcePath), modeClass);
818 contribModes.add(mc);
819 File key = getModeContribFile(mc, known);
820 if (key != null) {
821 known.remove(key);
822 }
823 }
824 if (known.size() != 0) {
825 for (ModeContribution mc : known.values()) {
826 System.out.println("Extraneous Mode entry: " + mc.getName());
827 }
828 }
829 }
830

Callers 2

BaseMethod · 0.95
refreshContribsMethod · 0.95

Calls 15

getContribModesMethod · 0.95
logMethod · 0.95
loadMethod · 0.95
getModeContribFileMethod · 0.95
listCandidatesMethod · 0.80
splitMethod · 0.80
getMessageMethod · 0.65
putMethod · 0.45
getFolderMethod · 0.45
addMethod · 0.45
printlnMethod · 0.45

Tested by

no test coverage detected