コード例 #1
0
ファイル: PluginManager.java プロジェクト: vroyer/elassandra
  public void downloadAndExtract(String name, Terminal terminal) throws IOException {
    if (name == null && url == null) {
      throw new IllegalArgumentException("plugin name or url must be supplied with install.");
    }

    if (!Files.exists(environment.pluginsFile())) {
      terminal.println(
          "Plugins directory [%s] does not exist. Creating...", environment.pluginsFile());
      Files.createDirectory(environment.pluginsFile());
    }

    if (!Environment.isWritable(environment.pluginsFile())) {
      throw new IOException("plugin directory " + environment.pluginsFile() + " is read only");
    }

    PluginHandle pluginHandle;
    if (name != null) {
      pluginHandle = PluginHandle.parse(name);
      checkForForbiddenName(pluginHandle.name);
    } else {
      // if we have no name but url, use temporary name that will be overwritten later
      pluginHandle = new PluginHandle("temp_name" + new Random().nextInt(), null, null);
    }

    Path pluginFile = download(pluginHandle, terminal);
    extract(pluginHandle, terminal, pluginFile);
  }