public void showUpdatesDialog(Map<String, PluginRegistry> downloadsProviders) { List<PluginInfo> selUpdates = PluginPanel.showDialog(downloadsProviders, null); if (selUpdates != null){ PluginInstaller installer = new PluginInstaller(selUpdates); installer.run(); // @@TODO remove the installed plugins from the updatesProvider } }
/** * Find a jar or a folder containing a plugin.xml file * @param startDir the directory to search in * @return the first jar or plugin folder found */ private static File getPluginDir(File startDir) { if (!startDir.isDirectory()) { if (startDir.getName().endsWith(".jar")){ return startDir; } return null; } for (File f : startDir.listFiles()) { File pluginDir = getPluginDir(f); if (pluginDir != null) { return pluginDir; } } return null; }
private static Optional<File> moveExistingPluginToBackupLocation(PluginInfo pluginInfo) { Optional<File> existingPluginFileName = getPluginFileName(pluginInfo); if(!existingPluginFileName.isPresent()) { return Optional.empty(); } File backupFileName = getPluginBackupFileName(existingPluginFileName.get()); if(existingPluginFileName.get().renameTo(backupFileName)) { return Optional.of(backupFileName); } else { return Optional.empty(); } }
private InstallerResult install(PluginInfo info) { BackgroundTask downloading = ProtegeApplication.getBackgroundTaskManager().startTask("downloading " + info.getLabel()); logger.info("Downloading " + info.getLabel()); try { File tempPluginFile = downloadPlugin(info); if (tempPluginFile == null) { logger.error("Could not download plugin"); return InstallerResult.ERROR; } File installedPluginFile = copyPluginToInstallLocation(tempPluginFile, info); if (installedPluginFile == null) { logger.error("Could not install plugin"); return InstallerResult.ERROR; } if (installPlugin(installedPluginFile, info)) { return InstallerResult.INSTALLED; } else { return InstallerResult.DOWNLOADED; } } catch (Throwable t) { logger.error("Exception caught installing plugins", t); return InstallerResult.ERROR; } finally{ ProtegeApplication.getBackgroundTaskManager().endTask(downloading); } }
private File downloadPlugin(PluginInfo info) throws IOException { URL downloadURL = info.getDownloadURL(); final String[] path = downloadURL.getFile().split("/"); String downloadFileName = path[path.length-1]; String tmpPath = System.getProperty("java.io.tmpdir"); File tempPluginFile = new File(tmpPath, downloadFileName); tempPluginFile.deleteOnExit(); URLConnection conn = downloadURL.openConnection(); BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempPluginFile)); while (true) { byte [] buffer = new byte [4068]; int read = bis.read(buffer); if (read == -1) { break; } bos.write(buffer, 0, read); } bis.close(); bos.flush(); bos.close(); // Extract if a zip file if (downloadURL.getFile().endsWith(".zip")){ tempPluginFile = extractPlugin(tempPluginFile, info); } return tempPluginFile; }
private static Optional<File> copyPluginToInstallLocation(File downloadedPlugin, PluginInfo info) throws URISyntaxException { final Optional<File> backupFileName = moveExistingPluginToBackupLocation(info); final File pluginsFolder = new File(System.getProperty(ProtegeApplication.BUNDLE_DIR_PROP)); final String destinationFileName = String.format("%s-%s.jar", info.getId(), info.getAvailableVersion()); final File downloadedPluginDestination = new File(pluginsFolder, destinationFileName); try { FileUtils.copyFile(downloadedPlugin, downloadedPluginDestination); logger.info("Copied the {} plugin to {} in the plugins directory", info.getLabel(), downloadedPluginDestination.getName()); deletePluginBackup(backupFileName); return Optional.of(downloadedPluginDestination); } catch (IOException e) { try { File userPluginDirectory = ProtegeDirectories.getUserPluginDirectory(); logger.info("Could not copy the plugin to Protege plugins directory: {}", e.getMessage()); File userDirectoryPluginFile = new File(userPluginDirectory, info.getId() + ".jar"); FileUtils.copyFileToDirectory(downloadedPlugin, userDirectoryPluginFile); logger.info("Copied the {} plugin to the user plugin directory at {}. " + "This plugin will only be use-able by the current user.", info.getLabel(), userPluginDirectory); deletePluginBackup(backupFileName); return Optional.of(userDirectoryPluginFile); } catch (IOException ioe) { logger.error("An error occurred whilst attempting to save the plugin: {}", ioe.getMessage(), ioe); return Optional.empty(); } } }
private InstallerResult install(PluginInfo info) { BackgroundTask downloading = ProtegeApplication.getBackgroundTaskManager().startTask("downloading " + info.getLabel()); logger.info("Downloading " + info.getLabel()); try { File tempPluginFile = downloadPlugin(info); if (tempPluginFile == null) { logger.error("Could not download plugin"); return InstallerResult.ERROR; } File installedPluginFile = copyPluginToInstallLocation(tempPluginFile, info); if (installedPluginFile == null) { logger.error("Could not install plugin"); return InstallerResult.ERROR; } if (installPlugin(installedPluginFile, info)) { return InstallerResult.INSTALLED; } else { return InstallerResult.DOWNLOADED; } } catch (Throwable t) { logger.error("Exception caught installing plugins", t); return InstallerResult.ERROR; } finally{ ProtegeApplication.getBackgroundTaskManager().endTask(downloading); } }
private File downloadPlugin(PluginInfo info) throws IOException { URL downloadURL = info.getDownloadURL(); final String[] path = downloadURL.getFile().split("/"); String downloadFileName = path[path.length-1]; String tmpPath = System.getProperty("java.io.tmpdir"); File tempPluginFile = new File(tmpPath, downloadFileName); tempPluginFile.deleteOnExit(); URLConnection conn = downloadURL.openConnection(); BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempPluginFile)); while (true) { byte [] buffer = new byte [4068]; int read = bis.read(buffer); if (read == -1) { break; } bos.write(buffer, 0, read); } bis.close(); bos.flush(); bos.close(); // Extract if a zip file if (downloadURL.getFile().endsWith(".zip")){ tempPluginFile = extractPlugin(tempPluginFile, info); } return tempPluginFile; }
private InstallerResult install(PluginInfo info) { logger.info(LogBanner.start("Downloading and Installing Plugin")); BackgroundTask downloading = ProtegeApplication.getBackgroundTaskManager().startTask("downloading " + info.getLabel()); logger.info("Downloading the {} plugin (Version {})", info.getLabel(), info.getAvailableVersion()); try { Optional<File> downloadedPlugin = downloadPlugin(info); if (!downloadedPlugin.isPresent()) { logger.error("An error occurred whilst downloading the {} plugin. The plugin has not been installed.", info.getLabel()); return InstallerResult.ERROR; } Optional<File> installedPluginFile = copyPluginToInstallLocation(downloadedPlugin.get(), info); if (!installedPluginFile.isPresent()) { logger.error("There was an error whilst trying to install the {} plugin. It has not been installed", info.getLabel()); return InstallerResult.ERROR; } if (installPlugin(installedPluginFile.get(), info)) { return InstallerResult.INSTALLED; } else { return InstallerResult.DOWNLOADED; } } catch (IOException | URISyntaxException t) { logger.error("An error occurred whilst downloading and installing the {} plugin: {}", info.getLabel(), t.getMessage(), t); return InstallerResult.ERROR; } finally { logger.info(LogBanner.end()); ProtegeApplication.getBackgroundTaskManager().endTask(downloading); } }
public void showUpdatesDialog(Map<String, PluginRegistry> downloadsProviders) { List<PluginInfo> selUpdates = PluginPanel.showDialog(downloadsProviders, null); if (selUpdates != null){ PluginInstaller installer = new PluginInstaller(selUpdates); installer.run(); // @@TODO remove the installed plugins from the updatesProvider } }
/** * Find a jar or a folder containing a plugin.xml file * @param startDir the directory to search in * @return the first jar or plugin folder found */ private static File getPluginDir(File startDir) { if (!startDir.isDirectory()) { if (startDir.getName().endsWith(".jar")){ return startDir; } return null; } for (File f : startDir.listFiles()) { File pluginDir = getPluginDir(f); if (pluginDir != null) { return pluginDir; } } return null; }
private Optional<File> downloadPlugin(PluginInfo info) throws IOException { URL downloadURL = info.getDownloadURL(); logger.info("Downloading the {} plugin from: {}", info.getLabel(), downloadURL); File tempPluginFile = File.createTempFile(info.getId(), ".jar"); tempPluginFile.deleteOnExit(); URLConnection conn = downloadURL.openConnection(); BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempPluginFile)); while (true) { byte[] buffer = new byte[4068]; int read = bis.read(buffer); if (read == -1) { break; } bos.write(buffer, 0, read); } bis.close(); bos.flush(); bos.close(); logger.info("The {} plugin has been downloaded to {}", info.getLabel(), tempPluginFile.getAbsolutePath()); // Extract if a zip file if (downloadURL.getFile().endsWith(".zip")) { return extractPlugin(tempPluginFile, info); } else { return Optional.of(tempPluginFile); } }
private void showPluginsDialog(List<PluginInfo> pluginInfoList) { SwingUtilities.invokeLater(() -> { List<PluginInfo> selUpdates = PluginPanel.showDialog(pluginInfoList, null); if (!selUpdates.isEmpty()) { PluginInstaller installer = new PluginInstaller(selUpdates); installer.run(); } }); }
/** * Find a jar or a folder containing a plugin.xml file * * @param startDir the directory to search in * @return the first jar or plugin folder found. Optional.empty() if nothing is found. */ private static Optional<File> getPluginDir(File startDir) { if (!startDir.isDirectory()) { if (startDir.getName().endsWith(".jar")) { return Optional.of(startDir); } return Optional.empty(); } File[] files = startDir.listFiles(); if (files == null) { return Optional.empty(); } for (File f : files) { Optional<File> pluginDir = getPluginDir(f); if (pluginDir.isPresent()) { return pluginDir; } } return Optional.empty(); }
return getPluginDir(tempDir);
return getPluginDir(tempDir);