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(); } } }