public PluginInfoDocument(URL updateFileLocation) throws IOException { this.updateFileLocation = updateFileLocation; Properties properties = new Properties(); properties.load(new BufferedInputStream(updateFileLocation.openStream())); String id = properties.getProperty(ID_PROPERTY_NAME); String versionString = properties.getProperty(VERSION_PROPERTY_NAME); Version version = null; if (versionString != null){ version = new Version(versionString); } final String downloadURLStr = properties.getProperty(DOWNLOAD_PROPERTY_NAME); URL downloadURL = null; if (downloadURLStr != null){ downloadURL = new URL(downloadURLStr); } info = new PluginInfo(id, version, downloadURL); final String readmeStr = properties.getProperty(DOC_PROPERTY_NAME); if (readmeStr != null){ info.setReadmeURI(new URL(readmeStr)); } info.setLicense(properties.getProperty(LICENSE_PROPERTY_NAME)); info.setAuthor(properties.getProperty(AUTHOR_PROPERTY_NAME)); info.setLabel(properties.getProperty(LABEL_PROPERTY_NAME)); }
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); } }
private boolean installPlugin(File pluginLocation, PluginInfo info) throws BundleException { if (info.getPluginDescriptor() == null) { // download not an update... logger.info("Loading " + info.getLabel()); Bundle b = ProtegeApplication.getContext().installBundle("file:" + pluginLocation.getPath()); b.start(); return true; } else { logger.info("Plugin " + info.getLabel() + " will be loaded when Protege is restarted"); return false; } } }
UpdateChecker checker = new UpdateChecker(url, bundle); PluginInfo info = checker.run(); if (info != null && info.getAvailableVersion().compareTo(bundle.getVersion()) > 0) { info.setPluginDescriptor(bundle); plugins.add(info); selfUpdatingBundleIds.add(info.getId()); if (logger.isDebugEnabled()) { logger.debug("Found self updating bundle " + info.getId());
final PluginInfo info = plugins.get(rowIndex); if (columnIndex == 1) { if (info.getPluginDescriptor() != null){ return info.getPluginDescriptor().getHeaders().get("Bundle-Name"); return info.getLabel(); Bundle bundle = info.getPluginDescriptor(); StringBuilder versionString = new StringBuilder(); if (bundle != null){ return info.getAvailableVersion();
private static File copyPluginToInstallLocation(File pluginFile, PluginInfo info) throws URISyntaxException { logger.info("Copying " + info.getLabel()); boolean doCopy = true; File pluginsFolder = new File(System.getProperty(BundleManager.BUNDLE_DIR_PROP)); File newPluginFile = null; if (info.getPluginDescriptor() != null) { String location = info.getPluginDescriptor().getLocation(); location = location.substring(location.indexOf(":")+1, location.length()); File existingPlugin = new File(location); newPluginFile = new File(pluginsFolder, info.getId() + ".jar");
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 void updateInfoPanel(final PluginInfo info) { updateDocPanel(new ContentMimePair("", ""), readmePane, readmeScroller); if (info != null){ authorLabel.setText(info.getAuthor().orElse("")); licenseLabel.setText(info.getLicense().orElse("")); ContentMimePair readme = updateInfoReadmeMap.get(info); if (readme != null){ updateDocPanel(readme, readmePane, readmeScroller); } else{ if (info.getReadmeURI().isPresent()) { Runnable loadContent = () -> { final ContentMimePair readme1 = getContent(info.getReadmeURI().get()); updateInfoReadmeMap.put(info, readme1); SwingUtilities.invokeLater(() -> { updateDocPanel(readme1, readmePane, readmeScroller); }); }; Thread t = new Thread(loadContent, "Load plugin info"); t.setPriority(Thread.MIN_PRIORITY); t.start(); } } } else{ authorLabel.setText(""); licenseLabel.setText(""); } }
public Optional<PluginInfo> run() throws PluginDocumentParseException { final PluginInfoDocumentParser pluginInfoDocumentParser = new PluginInfoDocumentParser(url); PluginInfo info = pluginInfoDocumentParser.parseDocument(b); if(!b.isPresent()) { info.setPluginDescriptor(null); return Optional.of(info); } if (info.getAvailableVersion().compareTo(PluginUtilities.getBundleVersion(b.get())) > 0) { // New version available! info.setPluginDescriptor(b.get()); return Optional.of(info); } return Optional.empty(); } }
private void updateInfoPanel(final PluginInfo info) { updateDocPanel(new ContentMimePair("", ""), readmePane, readmeScroller); if (info != null){ authorLabel.setText(info.getAuthor()); licenseLabel.setText(info.getLicense());
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 run() { final ContentMimePair readme = getContent(info.getReadmeURI()); updateInfoReadmeMap.put(info, readme); SwingUtilities.invokeLater(new Runnable(){ public void run() { updateDocPanel(readme, readmePane, readmeScroller); } }); } };
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> getPluginFileName(PluginInfo info) { Bundle pluginDescriptor = info.getPluginDescriptor(); if (pluginDescriptor == null) { return Optional.empty(); } final String locationURL = pluginDescriptor.getLocation(); File existingPluginLocation = new File(locationURL.substring(locationURL.indexOf(":") + 1, locationURL.length())); return Optional.of(existingPluginLocation); } //
UpdateChecker checker = new UpdateChecker(url, bundle); PluginInfo info = checker.run(); if (info != null && info.getAvailableVersion().compareTo(bundle.getVersion()) > 0) { info.setPluginDescriptor(bundle); plugins.add(info); selfUpdatingBundleIds.add(info.getId()); if (logger.isDebugEnabled()) { logger.debug("Found self updating bundle " + info.getId());
final PluginInfo info = getUpdateInfoList().get(rowIndex); if (columnIndex == 1) { if (info.getPluginDescriptor() != null){ return info.getPluginDescriptor().getHeaders().get("Bundle-Name"); return info.getLabel(); Bundle bundle = info.getPluginDescriptor(); StringBuilder versionString = new StringBuilder(); if (bundle != null){ return info.getAvailableVersion();
private static File copyPluginToInstallLocation(File pluginFile, PluginInfo info) throws URISyntaxException { logger.info("Copying " + info.getLabel()); File pluginsFolder = new File(System.getProperty(ProtegeApplication.BUNDLE_DIR_PROP)); File oldPluginFile = null; File newPluginFile = null; if (info.getPluginDescriptor() != null) { String location = info.getPluginDescriptor().getLocation(); location = location.substring(location.indexOf(":")+1, location.length()); File existingPlugin = new File(location); newPluginFile = new File(pluginsFolder, info.getId() + ".jar"); newPluginFile = new File(CommonProtegeProperties.getUserPluginDirectory(), info.getId() + ".jar"); try { FileUtils.copyFileToDirectory(pluginFile, newPluginFile);
public PluginInfo run() throws IOException, UpdateException { final PluginInfoDocument pluginInfoDocument = new PluginInfoDocument(url); if (pluginInfoDocument.isValid(b)) { PluginInfo info = pluginInfoDocument.getPluginInfo(); if (b == null || info.getAvailableVersion().compareTo(PluginUtilities.getBundleVersion(b)) > 0) { // New version available! info.setPluginDescriptor(b); return info; } } return null; } }