protected static boolean addToClasspath(String jar) { Method method; URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = sysLoader.getURLs(); log0(lvl, "before adding to classpath: " + jar); for (int i = 0; i < urls.length; i++) { log0(lvl, "%d: %s", i, urls[i]); } Class sysclass = URLClassLoader.class; try { jar = FileManager.slashify(new File(jar).getAbsolutePath(), false); if (Settings.isWindows()) { jar = "/" + jar; } URL u = (new URI("file", jar, null)).toURL(); method = sysclass.getDeclaredMethod("addURL", new Class[] {URL.class}); method.setAccessible(true); method.invoke(sysLoader, new Object[] {u}); } catch (Exception ex) { log0(-1, ex.getMessage()); return false; } urls = sysLoader.getURLs(); log0(lvl, "after adding to classpath"); for (int i = 0; i < urls.length; i++) { log0(lvl, "%d: %s", i, urls[i]); } return true; }
public App focus(int num) { Debug.history("App.focus " + this.toString() + " #" + num); if (_pid != 0) { if (_osUtil.switchApp(_pid, num) == 0) { Debug.error("App.focus failed: " + _appName + "(" + _pid + ") not found"); return null; } } else { boolean failed = false; if (Settings.isWindows()) { _pid = _osUtil.switchApp(_appName, num); if (_pid == 0) { failed = true; } } else { if (_osUtil.switchApp(_appName, num) < 0) { failed = true; } } if (failed) { Debug.error("App.focus failed: " + _appName + " not found"); return null; } } return this; }
public App open() { if (Settings.isWindows() || Settings.isLinux()) { int pid = _osUtil.openApp(_appName); _pid = pid; Debug.history("App.open " + this.toString()); if (pid == 0) { Debug.error("App.open failed: " + _appName + " not found"); return null; } } else { Debug.history("App.open " + this.toString()); if (_osUtil.openApp(_appName) < 0) { Debug.error("App.open failed: " + _appName + " not found"); return null; } } return this; }
@Override public void releaseModifiers(int modifiers) { if ((modifiers & KeyModifier.SHIFT) != 0) { keyRelease(KeyEvent.VK_SHIFT); } if ((modifiers & KeyModifier.CTRL) != 0) { keyRelease(KeyEvent.VK_CONTROL); } if ((modifiers & KeyModifier.ALT) != 0) { keyRelease(KeyEvent.VK_ALT); } if ((modifiers & KeyModifier.META) != 0) { if (Settings.isWindows()) { keyRelease(KeyEvent.VK_WINDOWS); } else { keyRelease(KeyEvent.VK_META); } } }
private void checkMousePosition(Location p) { PointerInfo mp = MouseInfo.getPointerInfo(); Point pc; if (mp == null) { Debug.error( "RobotDesktop: checkMousePosition: MouseInfo.getPointerInfo invalid\nafter move to %s", p); } else { pc = mp.getLocation(); if (pc.x != p.x || pc.y != p.y) { Debug.error( "RobotDesktop: checkMousePosition: should be %s\nbut after move is %s" + "\nPossible cause: Mouse actions are blocked generally or by the frontmost application." + (Settings.isWindows() ? "\nYou might try to run the SikuliX stuff as admin." : ""), p, new Location(pc)); } } }