protected void copyModel(File sourceDir, File profileDir) throws IOException {
    if (sourceDir == null || !sourceDir.exists()) {
      return;
    }

    FileHandler.copy(sourceDir, profileDir);
  }
Exemple #2
0
 // TODO(simon): Replace me
 public static void copyDirectory(File source, File dest) {
   try {
     FileHandler.copy(source, dest);
   } catch (IOException e) {
     throw Throwables.propagate(e);
   }
 }
Exemple #3
0
 /**
  * Copies all files matching the suffix to the destination directory.
  *
  * <p>If no files match, and the destination directory did not already exist, the destination
  * directory is still created, if possible.
  *
  * @param source the source directory
  * @param suffix the suffix for all files to be copied.
  * @param dest the destination directory
  */
 protected static boolean copyDirectory(File source, String suffix, File dest) {
   try {
     FileHandler.copy(source, dest, suffix);
     return true;
   } catch (IOException e) {
     return false;
   }
 }
  protected static void checkExecutable(File exe) {

    checkState(exe.exists(), "The driver executable does not exist: %s", exe.getAbsolutePath());
    checkState(
        !exe.isDirectory(), "The driver executable is a directory: %s", exe.getAbsolutePath());
    checkState(
        FileHandler.canExecute(exe), "The driver is not executable: %s", exe.getAbsolutePath());
  }
 @Test
 public void shouldInstallExtensionFromDirectory() throws IOException {
   FirefoxProfile profile = new FirefoxProfile();
   File extension = InProject.locate(FIREBUG_PATH);
   File unzippedExtension = FileHandler.unzip(new FileInputStream(extension));
   profile.addExtension(unzippedExtension);
   File profileDir = profile.layoutOnDisk();
   File extensionDir = new File(profileDir, "extensions/[email protected]");
   assertTrue(extensionDir.exists());
 }
  /**
   * Asserts whether given launcher exists, is a file and that it's executable.
   *
   * @param launcher the launcher to assert
   * @throws IOException if there is a problem with the provided launcher
   */
  public static void assertLauncherGood(File launcher) throws IOException {
    if (!launcher.exists()) {
      throw new IOException("Unknown file: " + launcher.getPath());
    }

    if (!launcher.isFile()) {
      throw new IOException("Not a real file: " + launcher.getPath());
    }

    if (!FileHandler.canExecute(launcher)) {
      throw new IOException("Not executable: " + launcher.getPath());
    }
  }
  /** change the network settings to enable use of our proxy */
  public void changeNetworkSettings() {
    if (networkService == null) {
      getCurrentNetworkSettings();
    }
    customProxyPACDir = LauncherUtils.createCustomProfileDir(sessionId);
    if (customProxyPACDir.exists()) {
      FileHandler.delete(customProxyPACDir);
    }
    customProxyPACDir.mkdir();
    log.info("Modifying OS X global network settings...");
    // TODO Disable proxy PAC URL (or, even better, use one!) SRC-364

    runNetworkSetup("-setwebproxy", networkService, "localhost", "" + port);

    runNetworkSetup("-setproxybypassdomains", networkService, "Empty");
  }
  @Test
  public void shouldConvertItselfIntoAMeaningfulRepresentation() throws IOException {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("i.like.cheese", true);

    String json = profile.toJson();

    assertNotNull(json);

    File dir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("webdriver", "duplicated");
    new Zip().unzip(json, dir);

    File prefs = new File(dir, "user.js");
    assertTrue(prefs.exists());

    assertTrue(FileHandler.readAsString(prefs).contains("i.like.cheese"));
  }
  protected String extractAndCheck(
      File profileDir, String noFocusSoName, String jarPath32Bit, String jarPath64Bit) {

    // 1. Extract x86/x_ignore_nofocus.so to profile.getLibsDir32bit
    // 2. Extract amd64/x_ignore_nofocus.so to profile.getLibsDir64bit
    // 3. Create a new LD_LIB_PATH string to contain:
    //   profile.getLibsDir32bit + ":" + profile.getLibsDir64bit

    Set<String> pathsSet = new HashSet<String>();
    pathsSet.add(jarPath32Bit);
    pathsSet.add(jarPath64Bit);

    StringBuilder builtPath = new StringBuilder();

    for (String path : pathsSet) {
      try {

        FileHandler.copyResource(profileDir, getClass(), path + File.separator + noFocusSoName);

      } catch (IOException e) {
        if (Boolean.getBoolean("webdriver.development")) {
          System.err.println(
              "Exception unpacking required library, but in development mode. Continuing");
        } else {
          throw new WebDriverException(e);
        }
      } // End catch.

      String outSoPath = profileDir.getAbsolutePath() + File.separator + path;

      File file = new File(outSoPath, noFocusSoName);
      if (!file.exists()) {
        throw new WebDriverException(
            "Could not locate " + path + ": " + "native events will not work.");
      }

      builtPath.append(outSoPath).append(":");
    }

    return builtPath.toString();
  }
Exemple #10
0
  // TODO(simon): Replace me
  public static void copySingleFileWithOverwrite(
      File sourceFile, File destFile, boolean overwrite) {
    // Ensure that the source is actually a file
    if (!sourceFile.exists()) {
      throw new RuntimeException("Source file does not exist: " + sourceFile);
    }

    if (!sourceFile.isFile()) {
      throw new RuntimeException("Source is not a single file: " + sourceFile);
    }

    if (!overwrite && destFile.exists()) {
      throw new RuntimeException("Destination file already exists: " + destFile);
    }

    try {
      FileHandler.copy(sourceFile, destFile);
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }
Exemple #11
0
 /** Delete a directory and all subdirectories */
 public static void recursivelyDeleteDir(File customProfileDir) {
   FileHandler.delete(customProfileDir);
 }