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); }
public void removePlugin(String name, Terminal terminal) throws IOException { if (name == null) { throw new IllegalArgumentException("plugin name must be supplied with remove [name]."); } PluginHandle pluginHandle = PluginHandle.parse(name); boolean removed = false; checkForForbiddenName(pluginHandle.name); Path pluginToDelete = pluginHandle.extractedDir(environment); if (Files.exists(pluginToDelete)) { terminal.println(VERBOSE, "Removing: %s", pluginToDelete); try { IOUtils.rm(pluginToDelete); } catch (IOException ex) { throw new IOException( "Unable to remove " + pluginHandle.name + ". Check file permissions on " + pluginToDelete.toString(), ex); } removed = true; } Path binLocation = pluginHandle.binDir(environment); if (Files.exists(binLocation)) { terminal.println(VERBOSE, "Removing: %s", binLocation); try { IOUtils.rm(binLocation); } catch (IOException ex) { throw new IOException( "Unable to remove " + pluginHandle.name + ". Check file permissions on " + binLocation.toString(), ex); } removed = true; } if (removed) { terminal.println("Removed %s", name); } else { terminal.println( "Plugin %s not found. Run \"plugin list\" to get list of installed plugins.", name); } }