コード例 #1
0
ファイル: FirefoxProfile.java プロジェクト: GruLab/webdriver
  public void installDevelopmentExtension(String home) throws IOException {
    if (!home.endsWith("extension"))
      throw new RuntimeException(
          "The given source directory does not look like a source "
              + "directory for the extension: "
              + home);

    if (!FileHandler.createDir(extensionsDir))
      throw new IOException(
          "Cannot create extensions directory: " + extensionsDir.getAbsolutePath());

    File writeTo = new File(extensionsDir, EXTENSION_NAME);
    if (writeTo.exists() && !FileHandler.delete(writeTo)) {
      throw new IOException(
          "Cannot delete existing extensions directory: " + extensionsDir.getAbsolutePath());
    }

    FileWriter writer = null;
    try {
      writer = new FileWriter(writeTo);
      writer.write(home);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      Cleanly.close(writer);
    }
  }
コード例 #2
0
ファイル: FirefoxProfile.java プロジェクト: santiycr/selenium
  /**
   * Attempt to add an extension to install into this instance.
   *
   * @param extensionToInstall
   * @throws IOException
   */
  public void addExtension(File extensionToInstall) throws IOException {
    if (!extensionToInstall.isDirectory()
        && !FileHandler.isZipped(extensionToInstall.getAbsolutePath())) {
      throw new IOException("Can only install from a zip file, an XPI or a directory");
    }

    File root = obtainRootDirectory(extensionToInstall);

    String id = readIdFromInstallRdf(root);

    File extensionDirectory = new File(extensionsDir, id);

    if (extensionDirectory.exists() && !FileHandler.delete(extensionDirectory)) {
      throw new IOException("Unable to delete existing extension directory: " + extensionDirectory);
    }

    FileHandler.createDir(extensionDirectory);
    FileHandler.makeWritable(extensionDirectory);
    FileHandler.copyDir(root, extensionDirectory);
  }
コード例 #3
0
ファイル: FirefoxProfile.java プロジェクト: santiycr/selenium
  protected void installDevelopmentExtension() throws IOException {
    if (!FileHandler.createDir(extensionsDir))
      throw new IOException(
          "Cannot create extensions directory: " + extensionsDir.getAbsolutePath());

    String home = findFirefoxExtensionRootInSourceCode();

    File writeTo = new File(extensionsDir, EXTENSION_NAME);
    if (writeTo.exists() && !FileHandler.delete(writeTo)) {
      throw new IOException(
          "Cannot delete existing extensions directory: " + extensionsDir.getAbsolutePath());
    }

    FileWriter writer = null;
    try {
      writer = new FileWriter(writeTo);
      writer.write(home);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      Cleanly.close(writer);
    }
  }