Index: app/src/processing/app/Commander.java =================================================================== --- app/src/processing/app/Commander.java (revision 6185) +++ app/src/processing/app/Commander.java (working copy) @@ -146,7 +146,10 @@ } else if (arg.startsWith(outputArg)) { outputPath = arg.substring(outputArg.length()); - + + } else if (arg.startsWith(preferencesArg)) { + preferencesPath = arg.substring(preferencesArg.length()); + } else { complainAndQuit("I don't know anything about " + arg + "."); } @@ -191,6 +194,10 @@ //Sketch sketch = null; boolean success = false; + // now that we have the sketchbook folder from the preferences file + // we may harvest the libraries for the preprocessor to be ready + Base.initLibrariesFolder(); + try { sketch = new Sketch(null, pdePath); if (mode == PREPROCESS) { Index: app/src/processing/app/Base.java =================================================================== --- app/src/processing/app/Base.java (revision 6185) +++ app/src/processing/app/Base.java (working copy) @@ -207,8 +207,30 @@ "An unknown error occurred while trying to load\n" + "platform-specific code for your machine.", e); } + } + static protected void initLibrariesFolder() { + librariesFolder = getContentFile("libraries"); + // reset the table mapping imports to libraries + importToLibraryTable = new HashMap(); + + // Add from the "libraries" subfolder in the Processing directory + try { + addLibraries(librariesFolder); + } catch (IOException e) { + e.printStackTrace(); + } + // Add libraries found in the sketchbook folder + try { + File sketchbookLibraries = getSketchbookLibrariesFolder(); + boolean found = addLibraries(sketchbookLibraries); + + } catch (IOException e) { + e.printStackTrace(); + } + + } static protected void initRequirements() { try { @@ -1053,7 +1075,85 @@ return ifound; // actually ignored, but.. } + static protected boolean addLibraries(File folder) throws IOException { + if (!folder.isDirectory()) return false; + String list[] = folder.list(new FilenameFilter() { + public boolean accept(File dir, String name) { + // skip .DS_Store files, .svn folders, etc + if (name.charAt(0) == '.') return false; + if (name.equals("CVS")) return false; + return (new File(dir, name).isDirectory()); + } + }); + // if a bad folder or something like that, this might come back null + if (list == null) return false; + + // alphabetize list, since it's not always alpha order + // replaced hella slow bubble sort with this feller for 0093 + Arrays.sort(list, String.CASE_INSENSITIVE_ORDER); + + boolean ifound = false; + + for (String potentialName : list) { + File subfolder = new File(folder, potentialName); + File libraryFolder = new File(subfolder, "library"); + File libraryJar = new File(libraryFolder, potentialName + ".jar"); + // If a .jar file of the same prefix as the folder exists + // inside the 'library' subfolder of the sketch + if (libraryJar.exists()) { + String sanityCheck = Sketch.sanitizeName(potentialName); + if (!sanityCheck.equals(potentialName)) { + String mess = + "The library \"" + potentialName + "\" cannot be used.\n" + + "Library names must contain only basic letters and numbers.\n" + + "(ASCII only and no spaces, and it cannot start with a number)"; + Base.showMessage("Ignoring bad library name", mess); + continue; + } + + String libraryName = potentialName; + File exportFile = new File(libraryFolder, "export.txt"); +// System.out.println(exportFile.getAbsolutePath()); + if (exportFile.exists()) { + String[] exportLines = PApplet.loadStrings(exportFile); + for (String line : exportLines) { + String[] pieces = PApplet.trim(PApplet.split(line, '=')); +// System.out.println(pieces); + if (pieces[0].equals("name")) { + libraryName = pieces[1].trim(); + } + } + } + + // get the path for all .jar files in this code folder + String libraryClassPath = + Compiler.contentsToClassPath(libraryFolder); + // grab all jars and classes from this folder, + // and append them to the library classpath + librariesClassPath += + File.pathSeparatorChar + libraryClassPath; + // need to associate each import with a library folder + String packages[] = + Compiler.packageListFromClassPath(libraryClassPath); + for (String pkg : packages) { + importToLibraryTable.put(pkg, libraryFolder); + } + + ifound = true; + + } else { // not a library, but is still a folder, so recurse + // needs to be separate var, otherwise would set ifound to false + boolean found = addLibraries(subfolder); + if (found) { + ifound = true; + } + } + } + return ifound; + } + + protected boolean addLibraries(JMenu menu, File folder) throws IOException { if (!folder.isDirectory()) return false;