Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public static boolean setUserLogFile(String fileName) {
   if (fileName == null) {
     fileName = System.getProperty("sikuli.LogfileUser");
   }
   if (fileName != null) {
     if ("".equals(fileName)) {
       if (Settings.isMacApp) {
         fileName = "UserLog.txt";
       } else {
         fileName = FileManager.slashify(System.getProperty("user.dir"), true) + "UserLog.txt";
       }
     }
     try {
       if (printoutuser != null) {
         printoutuser.close();
       }
       printoutuser = new PrintStream(fileName);
       log(3, "Debug: setLogFile: " + fileName);
       return true;
     } catch (FileNotFoundException ex) {
       System.out.printf("[Error] User logfile %s not accessible - check given path", fileName);
       System.out.println();
       return false;
     }
   }
   return false;
 }
Esempio n. 3
0
 static {
   CodeSource codeSrc = SikuliX.class.getProtectionDomain().getCodeSource();
   if (codeSrc != null && codeSrc.getLocation() != null) {
     URL jarURL = codeSrc.getLocation();
     jarPath = FileManager.slashify(new File(jarURL.getPath()).getAbsolutePath(), false);
     jarParentPath = (new File(jarPath)).getParent();
     if (jarPath.endsWith(".jar")) {
       runningFromJar = true;
     } else {
       jarPath += "/";
     }
   }
 }