public static void updateModuleList(Node node) {
    List<ModuleNeeded> moduleNeededList = ModulesNeededProvider.getModulesNeeded();
    Set<String> moduleNameList = new TreeSet<String>();
    Set<String> moduleValueList = new TreeSet<String>();
    for (ModuleNeeded module : moduleNeededList) {

      String moduleName = module.getModuleName();
      moduleNameList.add(moduleName);
      moduleValueList.add(TalendTextUtils.addQuotes(moduleName));
    }
    Comparator<String> comprarator = new IgnoreCaseComparator();
    String[] moduleNameArray = moduleNameList.toArray(new String[0]);
    String[] moduleValueArray = moduleValueList.toArray(new String[0]);
    Arrays.sort(moduleNameArray, comprarator);
    Arrays.sort(moduleValueArray, comprarator);

    for (int i = 0; i < node.getElementParameters().size(); i++) {
      IElementParameter param = node.getElementParameters().get(i);
      if (param.getFieldType() == EParameterFieldType.MODULE_LIST) {
        param.setListItemsDisplayName(moduleNameArray);
        param.setListItemsValue(moduleValueArray);
      } else if (param.getFieldType() == EParameterFieldType.TABLE) {
        Object[] listItemsValue = param.getListItemsValue();
        if (listItemsValue != null) {
          for (Object o : listItemsValue) {
            if (o instanceof IElementParameter
                && ((IElementParameter) o).getFieldType() == EParameterFieldType.MODULE_LIST) {
              ((IElementParameter) o).setListItemsDisplayName(moduleNameArray);
              ((IElementParameter) o).setListItemsValue(moduleValueArray);
            }
          }
        }
      }
    }
  }
 public void openDialog() {
   List<ModuleNeeded> updatedModules = new ArrayList<ModuleNeeded>();
   for (ModuleNeeded neededModule : ModulesNeededProvider.getModulesNeeded()) {
     if (neededModule.getStatus() != ELibraryInstallStatus.NOT_INSTALLED) {
       continue;
     }
     updatedModules.add(neededModule);
   }
   inputList.clear();
   RemoteModulesHelper.getInstance().getNotInstalledModules(updatedModules, inputList, this, true);
 }
Beispiel #3
0
    @Override
    public Map<ModuleNeeded, File> getFilesToShare(IProgressMonitor monitor) {
      Map<ModuleNeeded, File> files = new HashMap<ModuleNeeded, File>();
      SubMonitor mainSubMonitor = SubMonitor.convert(monitor, 1);
      mainSubMonitor.setTaskName(Messages.getString("ShareLibsJob.getFilesToShare")); // $NON-NLS-1$
      final List<ModuleNeeded> modulesNeeded =
          new ArrayList<ModuleNeeded>(ModulesNeededProvider.getModulesNeeded());
      ILibraryManagerService librariesService =
          (ILibraryManagerService)
              GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
      Set<String> filePaths = new HashSet<String>();
      for (ModuleNeeded module : modulesNeeded) {
        if (monitor.isCanceled()) {
          return null;
        }

        // only deploy libraries with group id org.talend.libraries
        MavenArtifact parseMvnUrl = MavenUrlHelper.parseMvnUrl(module.getMavenUri());
        if (parseMvnUrl == null
            || !MavenConstants.DEFAULT_LIB_GROUP_ID.equals(parseMvnUrl.getGroupId())) {
          continue;
        }

        final String jarPathFromMaven =
            librariesService.getJarPathFromMaven(module.getMavenUriSnapshot());
        if (jarPathFromMaven == null) {
          continue;
        }
        File jarFile = new File(jarPathFromMaven);
        if (jarFile.exists()) {
          if (!filePaths.contains(jarPathFromMaven)) {
            files.put(module, jarFile);
          }
          filePaths.add(jarPathFromMaven);
        }
      }
      mainSubMonitor.worked(1);
      return files;
    }
  /**
   * 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.
  }