public void setup() { size(1000, 700); File dir = new File("/Users/quoctrungbui/Desktop/work/img/crop/"); // load path and count files images = dir.list(); filecount = images.length; for (int i = 1; i < filecount; i++) { img[i] = loadImage("/Users/quoctrungbui/Desktop/work/img/crop/" + images[i]); // load files } frameRate(2); }
/** * Gives the same basic functionality of File.exists but can be used to look for removable media * without showing a system dialog if the media is not present. Workaround pulled from the <A * HREF="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4089199"> bug report</A> on * bugs.sun.com. This bug was fixed in Java 6, and we can remove the workaround when we start * requiring Java 6. */ protected static boolean fileExists(File file) { try { Process process = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", "dir", file.getAbsolutePath()}); // We need to consume all available output or the process will block. boolean haveExitCode = false; int exitCode = -1; InputStream out = process.getInputStream(); InputStream err = process.getErrorStream(); while (!haveExitCode) { while (out.read() >= 0) {} while (err.read() >= 0) {} try { exitCode = process.exitValue(); haveExitCode = true; } catch (IllegalThreadStateException e) { // Not yet complete. Thread.sleep(100); } } // int exitCode = process.waitFor(); return exitCode == 0; } catch (IOException e) { System.out.println("Unable to check for file: " + file + " : " + e); return false; } catch (InterruptedException e) { System.out.println("Unable to check for file. Interrupted: " + file + " : " + e); return false; } }
public static List<Library> list(File folder) { List<Library> libraries = new ArrayList<Library>(); List<File> librariesFolders = new ArrayList<File>(); librariesFolders.addAll(discover(folder)); for (File baseFolder : librariesFolders) { libraries.add(new Library(baseFolder)); } // Support libraries inside of one level of subfolders? I believe this was // the compromise for supporting library groups, but probably a bad idea // because it's not compatible with the Manager. String[] folderNames = folder.list(junkFolderFilter); if (folderNames != null) { for (String subfolderName : folderNames) { File subfolder = new File(folder, subfolderName); if (!librariesFolders.contains(subfolder)) { List<File> discoveredLibFolders = discover(subfolder); for (File discoveredFolder : discoveredLibFolders) { libraries.add(new Library(discoveredFolder, subfolderName)); } } } } return libraries; }
/** 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; }
public void setPath(String path) { this.path = path; if (path != null) { file = new File(path); if (!file.isAbsolute()) file = null; } if (file == null) { throw new RuntimeException( "PGraphicsPDF requires an absolute path " + "for the location of the output file."); } }
private List<File> compileFiles(String avrBasePath, String buildPath, List<File> includePaths, List<File> sSources, List<File> cSources, List<File> cppSources, Map<String, String> boardPreferences) throws RunnerException { List<File> objectPaths = new ArrayList<File>(); for (File file : sSources) { String objectPath = buildPath + File.separator + file.getName() + ".o"; objectPaths.add(new File(objectPath)); execAsynchronously(getCommandCompilerS(avrBasePath, includePaths, file.getAbsolutePath(), objectPath, boardPreferences)); } for (File file : cSources) { String objectPath = buildPath + File.separator + file.getName() + ".o"; String dependPath = buildPath + File.separator + file.getName() + ".d"; File objectFile = new File(objectPath); File dependFile = new File(dependPath); objectPaths.add(objectFile); if (is_already_compiled(file, objectFile, dependFile, boardPreferences)) continue; execAsynchronously(getCommandCompilerC(avrBasePath, includePaths, file.getAbsolutePath(), objectPath, boardPreferences)); } for (File file : cppSources) { String objectPath = buildPath + File.separator + file.getName() + ".o"; String dependPath = buildPath + File.separator + file.getName() + ".d"; File objectFile = new File(objectPath); File dependFile = new File(dependPath); objectPaths.add(objectFile); if (is_already_compiled(file, objectFile, dependFile, boardPreferences)) continue; execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths, file.getAbsolutePath(), objectPath, boardPreferences)); } return objectPaths; }
// this prepends a colon so that it can be appended to other paths safely public String getClassPath() { StringBuilder cp = new StringBuilder(); // PApplet.println(libraryFolder.getAbsolutePath()); // PApplet.println(libraryFolder.list()); String[] jarHeads = libraryFolder.list(jarFilter); for (String jar : jarHeads) { cp.append(File.pathSeparatorChar); cp.append(new File(libraryFolder, jar).getAbsolutePath()); } File nativeLibraryFolder = new File(nativeLibraryPath); if (!libraryFolder.equals(nativeLibraryFolder)) { jarHeads = new File(nativeLibraryPath).list(jarFilter); for (String jar : jarHeads) { cp.append(File.pathSeparatorChar); cp.append(new File(nativeLibraryPath, jar).getAbsolutePath()); } } // cp.setLength(cp.length() - 1); // remove the last separator return cp.toString(); }
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; if (name.equals("export.txt")) return false; File file = new File(dir, name); // return (!file.isDirectory()); if (file.isDirectory()) { if (name.equals("macosx")) return false; if (name.equals("macosx32")) return false; if (name.equals("macosx64")) return false; if (name.equals("windows")) return false; if (name.equals("windows32")) return false; if (name.equals("windows64")) return false; if (name.equals("linux")) return false; if (name.equals("linux32")) return false; if (name.equals("linux64")) return false; if (name.equals("linux-armv6hf")) return false; if (name.equals("android")) return false; } return true; }
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; }
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; }
static public ArrayList<File> findFilesInFolder(File folder, String extension, boolean recurse) { ArrayList<File> files = new ArrayList<File>(); if (folder.listFiles() == null) return files; for (File file : folder.listFiles()) { if (file.getName().startsWith(".")) continue; // skip hidden files if (file.getName().endsWith("." + extension)) files.add(file); if (recurse && file.isDirectory()) { files.addAll(findFilesInFolder(file, extension, true)); } } return files; }
public boolean fileExists(String filename) { File file = new File(sketchPath(filename)); return file.exists(); }
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; }
/** * 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(); }
/** * Compile with avr-gcc. * * @param sketch Sketch object to be compiled. * @param buildPath Where the temporary files live and will be built from. * @param primaryClassName the name of the combined sketch file w/ extension * @return true if successful. * @throws RunnerException Only if there's a problem. Only then. * * [ROBOTIS]Changed prototype to support ARM Cortex-M3 based CM-900 Pandora project * 2012-09-26 [email protected] * */ public boolean compile(Sketch sketch, //change return type[ROBOTIS] String buildPath, String primaryClassName, boolean verbose, List<String> ignored) throws RunnerException { this.sketch = sketch; this.buildPath = buildPath; this.primaryClassName = primaryClassName; //예를 들면 cpp파일로 변환된 AnalogReadSerial.cpp this.verbose = verbose; this.sketchIsCompiled = false; System.out.println("Compiler.compile() sketch ="+sketch.getName()+"buildpath ="+buildPath+"primaryClassName ="+primaryClassName); // the pms object isn't used for anything but storage MessageStream pms = new MessageStream(this); String avrBasePath = Base.getAvrBasePath(); System.out.println("[ROBOTIS]avrBasePath ="+avrBasePath); Map<String, String> boardPreferences = Base.getBoardPreferences(); String core = boardPreferences.get("build.core"); System.out.println("[ROBOTIS]build.core ="+core); if (core == null) { RunnerException re = new RunnerException(_("No board selected; please choose a board from the Tools > Board menu.")); re.hideStackTrace(); throw re; } String corePath; if (core.indexOf(':') == -1) { Target t = Base.getTarget(); File coreFolder = new File(new File(t.getFolder(), "cores"), core); corePath = coreFolder.getAbsolutePath(); } else { Target t = Base.targetsTable.get(core.substring(0, core.indexOf(':'))); File coreFolder = new File(t.getFolder(), "cores"); coreFolder = new File(coreFolder, core.substring(core.indexOf(':') + 1)); corePath = coreFolder.getAbsolutePath(); } System.out.println("[ROBOTIS]corePath ="+corePath); String variant = boardPreferences.get("build.variant"); String variantPath = null; if (variant != null) { if (variant.indexOf(':') == -1) { Target t = Base.getTarget(); File variantFolder = new File(new File(t.getFolder(), "variants"), variant); variantPath = variantFolder.getAbsolutePath(); } else { Target t = Base.targetsTable.get(variant.substring(0, variant.indexOf(':'))); File variantFolder = new File(t.getFolder(), "variants"); variantFolder = new File(variantFolder, variant.substring(variant.indexOf(':') + 1)); variantPath = variantFolder.getAbsolutePath(); } } List<File> objectFiles = new ArrayList<File>(); // 0. include paths for core + all libraries sketch.setCompilingProgress(20); List includePaths = new ArrayList(); includePaths.add(corePath); if (variantPath != null) includePaths.add(variantPath); for (File file : sketch.getImportedLibraries()) { includePaths.add(file.getPath()); } // 1. compile the sketch (already in the buildPath) sketch.setCompilingProgress(30); objectFiles.addAll( compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(buildPath, "S", false), findFilesInPath(buildPath, "c", false), findFilesInPath(buildPath, "cpp", false), boardPreferences)); sketchIsCompiled = true; // 2. compile the libraries, outputting .o files to: <buildPath>/<library>/ sketch.setCompilingProgress(40); for (File libraryFolder : sketch.getImportedLibraries()) { File outputFolder = new File(buildPath, libraryFolder.getName()); File utilityFolder = new File(libraryFolder, "utility"); createFolder(outputFolder); // this library can use includes in its utility/ folder includePaths.add(utilityFolder.getAbsolutePath()); objectFiles.addAll( compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, findFilesInFolder(libraryFolder, "S", false), findFilesInFolder(libraryFolder, "c", false), findFilesInFolder(libraryFolder, "cpp", false), boardPreferences)); outputFolder = new File(outputFolder, "utility"); createFolder(outputFolder); objectFiles.addAll( compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, findFilesInFolder(utilityFolder, "S", false), findFilesInFolder(utilityFolder, "c", false), findFilesInFolder(utilityFolder, "cpp", false), boardPreferences)); // other libraries should not see this library's utility/ folder includePaths.remove(includePaths.size() - 1); } // 3. compile the core, outputting .o files to <buildPath> and then // collecting them into the core.a library file. sketch.setCompilingProgress(50); includePaths.clear(); includePaths.add(corePath); // include path for core only if (variantPath != null) includePaths.add(variantPath); List<File> coreObjectFiles = compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(corePath, "S", true), findFilesInPath(corePath, "c", true), findFilesInPath(corePath, "cpp", true), boardPreferences); String runtimeLibraryName = buildPath + File.separator + "core.a"; List baseCommandAR = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-ar", "rcs", runtimeLibraryName })); for(File file : coreObjectFiles) { List commandAR = new ArrayList(baseCommandAR); commandAR.add(file.getAbsolutePath()); execAsynchronously(commandAR); } // 4. link it all together into the .elf file // For atmega2560, need --relax linker option to link larger // programs correctly. String optRelax = ""; String atmega2560 = new String ("atmega2560"); if ( atmega2560.equals(boardPreferences.get("build.mcu")) ) { optRelax = new String(",--relax"); } sketch.setCompilingProgress(60); List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-Os", "-Wl,--gc-sections"+optRelax, "-mmcu=" + boardPreferences.get("build.mcu"), "-o", buildPath + File.separator + primaryClassName + ".elf" })); for (File file : objectFiles) { baseCommandLinker.add(file.getAbsolutePath()); } baseCommandLinker.add(runtimeLibraryName); baseCommandLinker.add("-L" + buildPath); baseCommandLinker.add("-lm"); execAsynchronously(baseCommandLinker); List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-objcopy", "-O", "-R", })); List commandObjcopy; // 5. extract EEPROM data (from EEMEM directive) to .eep file. sketch.setCompilingProgress(70); commandObjcopy = new ArrayList(baseCommandObjcopy); commandObjcopy.add(2, "ihex"); commandObjcopy.set(3, "-j"); commandObjcopy.add(".eeprom"); commandObjcopy.add("--set-section-flags=.eeprom=alloc,load"); commandObjcopy.add("--no-change-warnings"); commandObjcopy.add("--change-section-lma"); commandObjcopy.add(".eeprom=0"); commandObjcopy.add(buildPath + File.separator + primaryClassName + ".elf"); commandObjcopy.add(buildPath + File.separator + primaryClassName + ".eep"); execAsynchronously(commandObjcopy); // 6. build the .hex file sketch.setCompilingProgress(80); commandObjcopy = new ArrayList(baseCommandObjcopy); commandObjcopy.add(2, "ihex"); commandObjcopy.add(".eeprom"); // remove eeprom data commandObjcopy.add(buildPath + File.separator + primaryClassName + ".elf"); commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex"); execAsynchronously(commandObjcopy); sketch.setCompilingProgress(90); return true; }
static protected void createFolder(File folder) throws RunnerException { if (folder.isDirectory()) return; if (!folder.mkdir()) throw new RunnerException("Couldn't create: " + folder); }
public String getLibraryPath() { return libraryFolder.getAbsolutePath(); }
public boolean hasExamples() { return examplesFolder.exists(); }
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()); }