public boolean isValid(Bundle bundle) throws UpdateException { if (info.getId() == null){ throw new UpdateException(info.getId(), updateFileLocation, "No plugin ID given"); } if (bundle != null){ final String pluginID = bundle.getSymbolicName(); if (!info.getId().equals(pluginID)){ throw new UpdateException(info.getId(), updateFileLocation, "ID does not match the plugin (" + pluginID + ")"); } } if (info.getAvailableVersion() == null){ throw new UpdateException(info.getId(), updateFileLocation, "Cannot find version"); } if (info.getDownloadURL() == null){ throw new UpdateException(info.getId(), updateFileLocation, "No download location given"); } return true; }
public boolean isValid(Bundle bundle) throws UpdateException { if (info.getId() == null){ throw new UpdateException(info.getId(), updateFileLocation, "No plugin ID given"); } if (bundle != null){ final String pluginID = bundle.getSymbolicName(); if (!info.getId().equals(pluginID)){ throw new UpdateException(info.getId(), updateFileLocation, "ID does not match the plugin (" + pluginID + ")"); } } if (info.getAvailableVersion() == null){ throw new UpdateException(info.getId(), updateFileLocation, "Cannot find version"); } if (info.getDownloadURL() == null){ throw new UpdateException(info.getId(), updateFileLocation, "No download location given"); } return true; }
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); } }
if (info != null) { if (logger.isDebugEnabled()) { logger.debug("Node " + node + "has valid Plugin Info: " + info.getId()); if (pluginType == PluginRegistryType.PLUGIN_DOWNLOAD_REGISTRY && !bundleByIds.containsKey(info.getId())) { plugins.add(info); if (logger.isDebugEnabled()) { Bundle bundle = bundleByIds.get(info.getId()); if (pluginType == PluginRegistryType.PLUGIN_UPDATE_REGISTRY && bundle != null && bundle.getVersion().compareTo(info.getAvailableVersion()) < 0 && !selfUpdatingBundleIds.contains(info.getId())) { info.setPluginDescriptor(bundle); plugins.add(info);
if (info != null) { if (logger.isDebugEnabled()) { logger.debug("Node " + node + "has valid Plugin Info: " + info.getId()); if (pluginType == PluginRegistryType.PLUGIN_DOWNLOAD_REGISTRY && !bundleByIds.containsKey(info.getId())) { plugins.add(info); if (logger.isDebugEnabled()) { Bundle bundle = bundleByIds.get(info.getId()); if (pluginType == PluginRegistryType.PLUGIN_UPDATE_REGISTRY && bundle != null && bundle.getVersion().compareTo(info.getAvailableVersion()) < 0 && !selfUpdatingBundleIds.contains(info.getId())) { info.setPluginDescriptor(bundle); plugins.add(info);
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(); } } }
newPluginFile = new File(pluginsFolder, info.getId() + ".jar");