/** * Helper method for downloading a plugin with a verbode progress bar * * @param name the plugin name * @param url the URL * @return true is plugin zip could be downloaded and unpacked */ public boolean downloadAndUnpackPlugin(String name, URL url) throws IOException { final String pluginGroupId = settings.get("apps.plugingroup", PluginApp.GROUP_ID); String version = "0"; // dummy version PluginApp app = new PluginApp(pluginGroupId, name, version, url); File appFile = app.getInstallPath(environment); if (appFile.exists()) { return false; } else { appFile.mkdirs(); // only zip supported File zipFile = new File(environment.pluginsFile(), name + ".zip"); downloadHelper.download(url, zipFile, new HttpDownloadHelper.VerboseProgress(System.out)); // extract zip unzip(environment, new ZipFile(zipFile), app.getInstallPath(environment), app.getPathName()); zipFile.delete(); return true; } }
/** * Helper method for refreshing all plugin apps * * @return a map of plugin apps that are present after refreshing */ private Map<String, PluginApp> refreshPluginApps() { final Map<String, PluginApp> loadedApps = newHashMap(); final String pluginGroupId = settings.get("apps.plugingroup", PluginApp.GROUP_ID); final Map<String, Settings> pluginSettings = settings.getGroups("apps.plugins"); // download all declared plugins if not already present for (Map.Entry<String, Settings> entry : pluginSettings.entrySet()) { try { String name = entry.getKey(); boolean enabled = entry.getValue().getAsBoolean("enabled", Boolean.TRUE); if (enabled) { URL url = new URL(entry.getValue().get("url")); String version = entry.getValue().get("version", "0"); PluginApp app = new PluginApp(pluginGroupId, name, version, url); File appFile = app.getInstallPath(environment); if (appFile.exists()) { loadedApps.put(app.getCanonicalForm(), app); } else { appFile.mkdirs(); logger.info("retrieving plugin from URL {}", url); // only zip supported File zipFile = new File(environment.pluginsFile(), name + ".zip"); downloadHelper.download(url, zipFile, null); // extract zip unzip( environment, new ZipFile(zipFile), app.getInstallPath(environment), app.getPathName()); zipFile.delete(); } } } catch (IOException e) { logger.error(e.getMessage(), e); } } return loadPlugins(environment.pluginsFile()); }