Ejemplo n.º 1
0
  protected static DefaultFontMapper getMapper() {
    if (mapper == null) {
      //      long t = System.currentTimeMillis();
      mapper = new DefaultFontMapper();

      if (PApplet.platform == PApplet.MACOSX) {
        try {
          String homeLibraryFonts = System.getProperty("user.home") + "/Library/Fonts";
          mapper.insertDirectory(homeLibraryFonts);
        } catch (Exception e) {
          // might be a security issue with getProperty() and user.home
          // if this sketch is running from the web
        }
        // add the system font paths
        mapper.insertDirectory("/System/Library/Fonts");
        mapper.insertDirectory("/Library/Fonts");

      } else if (PApplet.platform == PApplet.WINDOWS) {
        // how to get the windows fonts directory?
        // could be c:\winnt\fonts or c:\windows\fonts or not even c:
        // maybe do a Runtime.exec() on echo %WINDIR% ?
        // Runtime.exec solution might be a mess on systems where the
        // the backslash/colon characters not really used (i.e. JP)

        // find the windows fonts folder
        File roots[] = File.listRoots();
        for (int i = 0; i < roots.length; i++) {
          if (roots[i].toString().startsWith("A:")) {
            // Seems to be a problem with some machines that the A:
            // drive is returned as an actual root, even if not available.
            // This won't fix the issue if the same thing happens with
            // other removable drive devices, but should fix the
            // initial/problem as cited by the bug report:
            // http://dev.processing.org/bugs/show_bug.cgi?id=478
            // If not, will need to use the other fileExists() code below.
            continue;
          }

          File folder = new File(roots[i], "WINDOWS/Fonts");
          if (folder.exists()) {
            mapper.insertDirectory(folder.getAbsolutePath());
            break;
          }
          folder = new File(roots[i], "WINNT/Fonts");
          if (folder.exists()) {
            mapper.insertDirectory(folder.getAbsolutePath());
            break;
          }
        }
      }
      //      System.out.println("mapping " + (System.currentTimeMillis() - t));
    }
    return mapper;
  }
Ejemplo n.º 2
0
 /** List who's inside a windows64, macosx, linux32, etc folder. */
 static String[] listPlatformEntries(File libraryFolder, String folderName, String[] baseList) {
   File folder = new File(libraryFolder, folderName);
   if (folder.exists()) {
     String[] entries = folder.list(standardFilter);
     if (entries != null) {
       String[] outgoing = new String[entries.length + baseList.length];
       for (int i = 0; i < entries.length; i++) {
         outgoing[i] = folderName + "/" + entries[i];
       }
       // Copy the base libraries in there as well
       System.arraycopy(baseList, 0, outgoing, entries.length, baseList.length);
       return outgoing;
     }
   }
   return null;
 }
Ejemplo n.º 3
0
  public static List<File> discover(File folder) {
    List<File> libraries = new ArrayList<File>();
    String[] folderNames = folder.list(junkFolderFilter);

    // if a bad folder or something like that, this might come back null
    if (folderNames != null) {
      // alphabetize list, since it's not always alpha order
      // replaced hella slow bubble sort with this feller for 0093
      Arrays.sort(folderNames, String.CASE_INSENSITIVE_ORDER);

      for (String potentialName : folderNames) {
        File baseFolder = new File(folder, potentialName);
        File libraryFolder = new File(baseFolder, "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)) {
            libraries.add(baseFolder);

          } else {
            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)";
            Messages.showMessage("Ignoring bad library name", mess);
            continue;
          }
        }
      }
    }
    return libraries;
  }
Ejemplo n.º 4
0
 /**
  * Tests whether the reference's index file indicated by referenceFile exists.
  *
  * @return true if and only if the file denoted by referenceFile exists; false otherwise.
  */
 public boolean hasReference() {
   return referenceFile.exists();
 }
Ejemplo n.º 5
0
 public boolean hasExamples() {
   return examplesFolder.exists();
 }
Ejemplo n.º 6
0
  private Library(File folder, String groupName) {
    super(folder);
    this.group = groupName;

    libraryFolder = new File(folder, "library");
    examplesFolder = new File(folder, "examples");
    referenceFile = new File(folder, "reference/index.html");

    File exportSettings = new File(libraryFolder, "export.txt");
    StringDict exportTable =
        exportSettings.exists() ? Util.readSettings(exportSettings) : new StringDict();

    exportList = new HashMap<String, String[]>();

    // get the list of files just in the library root
    String[] baseList = libraryFolder.list(standardFilter);
    //    System.out.println("Loading " + name + "...");
    //    PApplet.println(baseList);

    String appletExportStr = exportTable.get("applet");
    if (appletExportStr != null) {
      appletExportList = PApplet.splitTokens(appletExportStr, ", ");
    } else {
      appletExportList = baseList;
    }

    String androidExportStr = exportTable.get("android");
    if (androidExportStr != null) {
      androidExportList = PApplet.splitTokens(androidExportStr, ", ");
    } else {
      androidExportList = baseList;
    }

    // for the host platform, need to figure out what's available
    File nativeLibraryFolder = libraryFolder;
    String hostPlatform = Platform.getName();
    //    System.out.println("1 native lib folder now " + nativeLibraryFolder);
    // see if there's a 'windows', 'macosx', or 'linux' folder
    File hostLibrary = new File(libraryFolder, hostPlatform);
    if (hostLibrary.exists()) {
      nativeLibraryFolder = hostLibrary;
    }
    //    System.out.println("2 native lib folder now " + nativeLibraryFolder);
    // check for bit-specific version, e.g. on windows, check if there
    // is a window32 or windows64 folder (on windows)
    hostLibrary = new File(libraryFolder, hostPlatform + Platform.getNativeBits());
    if (hostLibrary.exists()) {
      nativeLibraryFolder = hostLibrary;
    }
    //    System.out.println("3 native lib folder now " + nativeLibraryFolder);

    if (hostPlatform.equals("linux") && System.getProperty("os.arch").equals("arm")) {
      hostLibrary = new File(libraryFolder, "linux-armv6hf");
      if (hostLibrary.exists()) {
        nativeLibraryFolder = hostLibrary;
      }
    }

    // save that folder for later use
    nativeLibraryPath = nativeLibraryFolder.getAbsolutePath();

    // for each individual platform that this library supports, figure out what's around
    for (int i = 1; i < platformNames.length; i++) {
      String platformName = platformNames[i];
      String platformName32 = platformName + "32";
      String platformName64 = platformName + "64";
      String platformNameArmv6hh = platformName + "-armv6hf";

      // First check for things like 'application.macosx=' or 'application.windows32' in the
      // export.txt file.
      // These will override anything in the platform-specific subfolders.
      String platformAll = exportTable.get("application." + platformName);
      String[] platformList = platformAll == null ? null : PApplet.splitTokens(platformAll, ", ");
      String platform32 = exportTable.get("application." + platformName + "32");
      String[] platformList32 = platform32 == null ? null : PApplet.splitTokens(platform32, ", ");
      String platform64 = exportTable.get("application." + platformName + "64");
      String[] platformList64 = platform64 == null ? null : PApplet.splitTokens(platform64, ", ");
      String platformArmv6hf = exportTable.get("application." + platformName + "-armv6hf");
      String[] platformListArmv6hf =
          platformArmv6hf == null ? null : PApplet.splitTokens(platformArmv6hf, ", ");

      // If nothing specified in the export.txt entries, look for the platform-specific folders.
      if (platformAll == null) {
        platformList = listPlatformEntries(libraryFolder, platformName, baseList);
      }
      if (platform32 == null) {
        platformList32 = listPlatformEntries(libraryFolder, platformName32, baseList);
      }
      if (platform64 == null) {
        platformList64 = listPlatformEntries(libraryFolder, platformName64, baseList);
      }
      if (platformListArmv6hf == null) {
        platformListArmv6hf = listPlatformEntries(libraryFolder, platformNameArmv6hh, baseList);
      }

      if (platformList32 != null || platformList64 != null || platformListArmv6hf != null) {
        multipleArch[i] = true;
      }

      // if there aren't any relevant imports specified or in their own folders,
      // then use the baseList (root of the library folder) as the default.
      if (platformList == null
          && platformList32 == null
          && platformList64 == null
          && platformListArmv6hf == null) {
        exportList.put(platformName, baseList);

      } else {
        // once we've figured out which side our bread is buttered on, save it.
        // (also concatenate the list of files in the root folder as well
        if (platformList != null) {
          exportList.put(platformName, platformList);
        }
        if (platformList32 != null) {
          exportList.put(platformName32, platformList32);
        }
        if (platformList64 != null) {
          exportList.put(platformName64, platformList64);
        }
        if (platformListArmv6hf != null) {
          exportList.put(platformNameArmv6hh, platformListArmv6hf);
        }
      }
    }
    //    for (String p : exportList.keySet()) {
    //      System.out.println(p + " -> ");
    //      PApplet.println(exportList.get(p));
    //    }

    // get the path for all .jar files in this code folder
    packageList = Util.packageListFromClassPath(getClassPath());
  }
Ejemplo n.º 7
0
 private boolean is_already_compiled(File src, File obj, File dep, Map<String, String> prefs) {
   boolean ret=true;
   try {
     //System.out.println("\n  is_already_compiled: begin checks: " + obj.getPath());
     if (!obj.exists()) return false;  // object file (.o) does not exist
     if (!dep.exists()) return false;  // dep file (.d) does not exist
     long src_modified = src.lastModified();
     long obj_modified = obj.lastModified();
     if (src_modified >= obj_modified) return false;  // source modified since object compiled
     if (src_modified >= dep.lastModified()) return false;  // src modified since dep compiled
     BufferedReader reader = new BufferedReader(new FileReader(dep.getPath()));
     String line;
     boolean need_obj_parse = true;
     while ((line = reader.readLine()) != null) {
       if (line.endsWith("\\")) {
         line = line.substring(0, line.length() - 1);
       }
       line = line.trim();
       if (line.length() == 0) continue; // ignore blank lines
       if (need_obj_parse) {
         // line is supposed to be the object file - make sure it really is!
         if (line.endsWith(":")) {
           line = line.substring(0, line.length() - 1);
           String objpath = obj.getCanonicalPath();
           File linefile = new File(line);
           String linepath = linefile.getCanonicalPath();
           //System.out.println("  is_already_compiled: obj =  " + objpath);
           //System.out.println("  is_already_compiled: line = " + linepath);
           if (objpath.compareTo(linepath) == 0) {
             need_obj_parse = false;
             continue;
           } else {
             ret = false;  // object named inside .d file is not the correct file!
             break;
           }
         } else {
           ret = false;  // object file supposed to end with ':', but didn't
           break;
         }
       } else {
         // line is a prerequisite file
         File prereq = new File(line);
         if (!prereq.exists()) {
           ret = false;  // prerequisite file did not exist
           break;
         }
         if (prereq.lastModified() >= obj_modified) {
           ret = false;  // prerequisite modified since object was compiled
           break;
         }
         //System.out.println("  is_already_compiled:  prerequisite ok");
       }
     }
     reader.close();
   } catch (Exception e) {
     return false;  // any error reading dep file = recompile it
   }
   if (ret && (verbose || Preferences.getBoolean("build.verbose"))) {
     System.out.println("  Using previously compiled: " + obj.getPath());
   }
   return ret;
 }
Ejemplo n.º 8
0
 public boolean fileExists(String filename) {
   File file = new File(sketchPath(filename));
   return file.exists();
 }