/** * create a new PathEntry from the given absolute path name and add it to the * end of the current image path<br> * for usage with jars see; {@link #add(String, String)} * * @param mainPath relative or absolute path * @return true if successful otherwise false */ public static boolean add(String mainPath) { return add(mainPath, null); }
File fPath = new File(mainPath); if (!fPath.isAbsolute() && mainPath.contains(":")) { return addHTTP(mainPath); path = makePathURL(mainPath, altPath); if (path != null) { if (hasPath(path) < 0) { log(lvl, "add: %s", path); imagePaths.add(path); } else { log(lvl, "duplicate not added: %s", path); log(-1, "add: not valid: %s %s", mainPath, (altPath == null ? "" : " / " + altPath));
/** * empty path list and add given path as first entry * Image cache is cleared completely * * @param path absolute path * @return true on success, false otherwise */ public static boolean reset(String path) { if (bundleEquals(path)) { return true; } reset(); return setBundlePath(path); }
/** * print the list of path entries * * @param lvl debug level to use */ public static void dump(int lvl) { log(lvl, "ImagePath has %d entries (valid %d)", imagePaths.size(), getCount()); String bundle = "(taken as bundle path)"; for (PathEntry p : imagePaths) { if (p == null) { log(lvl, "Path: NULL %s", bundle); } else { log(lvl, "Path: given: %s\nis: %s", p.path, p.getPath()); } bundle = ""; } }
if (bPath == null) { path = makePathURL(FileManager.normalizeAbsolute(Settings.BundlePath, false), null); } else { path = makePathURL(FileManager.normalizeAbsolute(bPath, false), null); if (bundleEquals(path)) { return true; Settings.BundlePath = path.getPath(); bundlePath = path; log(lvl, "new BundlePath:\n%s", path); return true; if (getCount() ==0) { String wf = System.getProperty("user.dir"); log(-1, "setBundlePath: invalid BundlePath: %s \nusing working folder: %s", bPath, wf); if (!new File(wf).exists()) { log(-1, "setBundlePath: Fatal error: working folder does not exist --- terminating"); System.exit(1); return setBundlePath(wf);
int retval; if (fScript == null) { ImagePath.addHTTP(fpScript); retval = (Runner.pyRunner.exec(scriptName) ? 0 : -1); ImagePath.removeHTTP(fpScript); } else { if (null == ImagePath.getBundlePathSet()) ImagePath.setBundlePath(fScript.getParent()); else { ImagePath.add(fScript.getParent());
fURL = FileManager.makeURL(fname); } else { log(-1, "find: File does not exist: " + fname); setBundlePath(null); for (PathEntry path : getPaths()) { if (path == null) { continue; log(-1, "find: URL not supported: " + path.pathURL); return fURL; log(-1, "find: not on image path: " + fname); dump(lvl);
/** * forwarded to ImagePath.getBundlePath() * * @return the current bundlepath * @deprecated */ @Deprecated public static String getBundlePath() { return ImagePath.getBundlePath(); }
public static int runTest(String givenName, String[] args) { String savePath = ImagePath.getBundlePath(); int retVal = new RunBox(givenName, args, true).run(); ImagePath.setBundlePath(savePath); return retVal; }
public static int run(String givenName, String[] args) { String savePath = ImagePath.getBundlePathSet(); int retVal = new RunBox(givenName, args, false).run(); if (savePath != null) { ImagePath.setBundlePath(savePath); } lastReturnCode = retVal; return retVal; }
log(lvl, "open: " + fname); URL furl = find(fname); if (furl != null) { BufferedReader br = null; br = new BufferedReader(new InputStreamReader(furl.openStream())); } catch (IOException ex) { log(-1, "open: %s", ex.getMessage()); return null; return br; } catch (IOException ex) { log(-1, "open: %s", ex.getMessage()); try { br.close(); } catch (IOException ex1) { log(-1, "open: %s", ex1.getMessage()); return null;
File innerBundle = new File(fScript.getParentFile(), scriptName + ".sikuli"); if (innerBundle.exists()) { ImagePath.setBundlePath(innerBundle.getCanonicalPath()); } else { ImagePath.setBundlePath(fScript.getParent()); ImagePath.addHTTP(script.toExternalForm()); String sname = new File(script.toExternalForm()).getName(); ImagePath.addHTTP(script.toExternalForm() + "/" + sname + ".sikuli");
ImagePath.add(asImagePath); ImagePath.setBundlePath(fScript.getAbsolutePath()); List<String> args = new ArrayList<String>();
public static boolean isImageBundled(URL fURL) { if ("file".equals(fURL.getProtocol())) { return bundleEquals(new File(fURL.getPath()).getParent()); } return false; }
protected static void set(Image img) { URL fURL = null; File imgFile = new File(img.getName()); if (imgFile.isAbsolute()) { if (imgFile.exists()) { fURL = FileManager.makeURL(img.getName()); } } else { fURL = imageNames.get(img.getName()); if (fURL == null) { fURL = ImagePath.find(img.getName()); } } if (fURL != null) { img.init(img.getName(), fURL, true); } }
/** * forwarded to ImagePath.getImagePath() * * @return an array of the imagepaths as added * @deprecated */ @Deprecated public static String[] getImagePath() { return ImagePath.get(); }
public int runJar(String fpJarOrFolder, String imagePath) { SikulixForJython.get(); String fpJar = load(fpJarOrFolder, true); ImagePath.addJar(fpJar, imagePath); String scriptName = new File(fpJar).getName().replace("_sikuli.jar", ""); if(exec("try: reload(" + scriptName + ")\nexcept: import " + scriptName)) { return 0; } else { return -1; } }
ImagePath.dump(lvl); log(lvl, "ImageFiles entries: %d", imageFiles.size()); Iterator<Map.Entry<URL, Image>> it = imageFiles.entrySet().iterator();
public static String saveTimedImage(BufferedImage img) { return saveTimedImage(img, ImagePath.getBundlePath(), null); }
/** * remove entry with given URL<br> * bundlepath (entry 0) cannot be removed * loaded images are removed from cache * * @param pURL a valid URL (not checked) * @return true on success, false ozherwise */ private static boolean remove(URL pURL) { if (bundleEquals(pURL)) { Image.purge(pURL); bundlePath = null; Settings.BundlePath = null; imagePaths.set(0, null); } Iterator<PathEntry> it = imagePaths.subList(1, imagePaths.size()).iterator(); PathEntry p, p0; p0 = imagePaths.get(0); while (it.hasNext()) { p = it.next(); if (!p.equals(pURL)) { continue; } it.remove(); Image.purge(p.pathURL); } return true; }