/** * called when the jar loadingin hook has failed to find the jar this is never called in a GUI * thread. */ @Override public void update(Observable o, Object arg) { if (arg != null && arg instanceof JarMissingEvent) { final JarMissingEvent jarMissingEvent = (JarMissingEvent) arg; // only show message box once par plugin, meaning that if user ignored it once, the bundle // will not load // properly anyway. if (!bundlesAlreadyHandled.contains(jarMissingEvent.getBundleId())) { bundlesAlreadyHandled.add(jarMissingEvent.getBundleId()); showMissingModuleDialog(jarMissingEvent); } // else already handled so ignors it. } else { // notification is not expected so log it IllegalArgumentException illegalArgumentException = new IllegalArgumentException( "was expecting a type :" + JarMissingEvent.class.getCanonicalName()); // $NON-NLS-1$ illegalArgumentException.fillInStackTrace(); log.error( "Could not find the proper JarMissing values", illegalArgumentException); // $NON-NLS-1$ } }
/** * look for all the required modules for a given bundle, and let the user decide to download it. * this method is blocked until the dialog box is closed. * * @param jarMissingEvent, must never be null */ protected void showMissingModuleDialog(final JarMissingEvent jarMissingEvent) { if (allModulesNeededExtensionsForPlugin == null) { this.allModulesNeededExtensionsForPlugin = ModulesNeededProvider.getAllModulesNeededExtensionsForPlugin(); } List<ModuleNeeded> requiredModulesForBundle = ModulesNeededProvider.filterRequiredModulesForBundle( jarMissingEvent.getBundleSymbolicName(), allModulesNeededExtensionsForPlugin); final List<String> requiredJars = new ArrayList<String>(requiredModulesForBundle.size()); // filter the jar that are already installed for (ModuleNeeded module : requiredModulesForBundle) { String moduleName = module.getModuleName(); // if jar does not exist at expected folder then check if it is registered in the Studio if (!new File(jarMissingEvent.getExpectedLibFolder(), moduleName).exists()) { // check that library is already available and registered but not deployed to lib/java. try { if (librariesService != null && (librariesService.getLibraryStatus(moduleName) == ELibraryInstallStatus.INSTALLED)) { // lib exist so deploy it List<ModuleNeeded> allModuleNeeded = ModulesNeededProvider.getModulesNeededForName(moduleName); for (ModuleNeeded sameModule : allModuleNeeded) { String moduleLocation = sameModule.getModuleLocaion(); if (sameModule.getStatus() == ELibraryInstallStatus.INSTALLED && moduleLocation != null && !moduleLocation.isEmpty()) { URI uri = new URI(moduleLocation); URL url = FileLocator.toFileURL(uri.toURL()); if ("file".equals(url.getProtocol())) { // $NON-NLS-1$ libraryManagerService.deploy(url.toURI(), null); } // else not a file so keep going break; } // else not an installed module or no url so keep so keep looking } } // else no installed so keep going and ask the user } catch (BusinessException e) { log.warn("Could not get installade status for library:" + moduleName, e); } catch (URISyntaxException e) { log.warn("Could not get installade status for library:" + moduleName, e); } catch (IOException e) { log.warn("Could not get installade status for library:" + moduleName, e); } } if (!new File(jarMissingEvent.getExpectedLibFolder(), moduleName).exists()) { requiredJars.add(moduleName); } // else jar already installed to filter it by ignoring it. } if (!requiredJars.isEmpty()) { Display.getDefault() .syncExec( new Runnable() { @Override public void run() { ExternalModulesInstallDialogWithProgress dialog = new ExternalModulesInstallDialogWithProgress( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.getString( "ExternalModulesInstallDialog_Title_Missing_jars_for_plugin"), //$NON-NLS-1$ Messages.getString( "ExternalModulesInstallDialog_description_jars_to_be_installed_in"), SWT.APPLICATION_MODAL); //$NON-NLS-1$ dialog.showDialog(true, requiredJars.toArray(new String[requiredJars.size()])); } }); } // else there is not extension point defining the required bundles so do not ask the user // ignor. }