MCPcopy
hub / github.com/arduino/Arduino / addTools

Method addTools

app/src/processing/app/Editor.java:807–907  ·  view source on GitHub ↗
(JMenu menu, File sourceFolder)

Source from the content-addressed store, hash-verified

805
806
807 private void addTools(JMenu menu, File sourceFolder) {
808 if (sourceFolder == null)
809 return;
810
811 Map<String, JMenuItem> toolItems = new HashMap<>();
812
813 File[] folders = sourceFolder.listFiles(new FileFilter() {
814 public boolean accept(File folder) {
815 if (folder.isDirectory()) {
816 //System.out.println("checking " + folder);
817 File subfolder = new File(folder, "tool");
818 return subfolder.exists();
819 }
820 return false;
821 }
822 });
823
824 if (folders == null || folders.length == 0) {
825 return;
826 }
827
828 for (File folder : folders) {
829 File toolDirectory = new File(folder, "tool");
830
831 try {
832 // add dir to classpath for .classes
833 //urlList.add(toolDirectory.toURL());
834
835 // add .jar files to classpath
836 File[] archives = toolDirectory.listFiles(new FilenameFilter() {
837 public boolean accept(File dir, String name) {
838 return (name.toLowerCase().endsWith(".jar") ||
839 name.toLowerCase().endsWith(".zip"));
840 }
841 });
842
843 URL[] urlList = new URL[archives.length];
844 for (int j = 0; j < urlList.length; j++) {
845 urlList[j] = archives[j].toURI().toURL();
846 }
847 URLClassLoader loader = new URLClassLoader(urlList);
848
849 String className = null;
850 for (File archive : archives) {
851 className = findClassInZipFile(folder.getName(), archive);
852 if (className != null) break;
853 }
854
855 /*
856 // Alternatively, could use manifest files with special attributes:
857 // http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html
858 // Example code for loading from a manifest file:
859 // http://forums.sun.com/thread.jspa?messageID=3791501
860 File infoFile = new File(toolDirectory, "tool.txt");
861 if (!infoFile.exists()) continue;
862
863 String[] info = PApplet.loadStrings(infoFile);
864 //Main-Class: org.poo.shoe.AwesomerTool

Callers 1

buildToolsMenuMethod · 0.95

Calls 11

findClassInZipFileMethod · 0.95
initMethod · 0.95
getMenuTitleMethod · 0.95
listFilesMethod · 0.80
putMethod · 0.80
printStackTraceMethod · 0.80
sizeMethod · 0.80
sortMethod · 0.80
getNameMethod · 0.65
getMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected