@Override
  public void syncLibraries(IProgressMonitor... monitorWrap) {
    // TODO system routine libraries seems no use ,need to check more...
    // deploy system routine libraries
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerUIService.class)) {
      ILibraryManagerUIService libUiService =
          (ILibraryManagerUIService)
              GlobalServiceRegister.getDefault().getService(ILibraryManagerUIService.class);
      libUiService.initializeSystemLibs();
    }

    if (TalendCacheUtils.cleanComponentCache()) {
      repositoryBundleService.clearCache();
    }
    // Add a new system file, if exists, means all components libs are already setup, so no need to
    // do again.
    // if clean the component cache, it will automatically recheck all libs still.
    if (!repositoryBundleService.isInitialized()) {
      // 2. Components libraries
      if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsService.class)) {
        repositoryBundleService.deployComponentsLibs(monitorWrap);
        repositoryBundleService.setInitialized();
      }
    }

    checkInstalledLibraries();

    // clean the temp library of job needed in .java\lib
    cleanLibs();

    log.debug(Messages.getString("JavaLibrariesService.synchronization")); // $NON-NLS-1$
    isLibSynchronized = true;
  }
 public static void saveResource() {
   if (isModified()) {
     String installLocation =
         new Path(Platform.getConfigurationLocation().getURL().getPath())
             .toFile()
             .getAbsolutePath();
     try {
       Resource resource = createComponentCacheResource(installLocation);
       resource.getContents().add(cache);
       EmfHelper.saveResource(cache.eResource());
     } catch (PersistenceException e1) {
       ExceptionHandler.process(e1);
     }
     ILibraryManagerService repositoryBundleService =
         (ILibraryManagerService)
             GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
     repositoryBundleService.clearCache();
     if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
       ILibrariesService libService =
           (ILibrariesService)
               GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
       if (libService != null) {
         libService.syncLibraries();
       }
     }
     setModified(false);
   }
 }
 @Override
 public void checkInstalledLibraries() {
   Set<String> existLibraries = repositoryBundleService.list();
   List<String> modulesNeededNames = ModulesNeededProvider.getModulesNeededNames();
   ModulesNeededProvider.getUnUsedModules().clear();
   for (String library : existLibraries) {
     if (!modulesNeededNames.contains(library)) {
       ModulesNeededProvider.userAddUnusedModules("Unknown", library); // $NON-NLS-1$
     }
   }
 }
Exemple #4
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;
    }
 /** DOC ycbai Comment method "initializeSystemLibs". */
 public void initializeSystemLibs() {
   if (!initialized) {
     ILibraryManagerService libManagerService = null;
     if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
       libManagerService =
           (ILibraryManagerService)
               GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
     }
     for (IConfigurationElement current : configurationElements) {
       String bundleName = current.getContributor().getName();
       Bundle bundle = Platform.getBundle(bundleName);
       Enumeration entryPaths = bundle.getEntryPaths(LIB_FOLDER);
       if (entryPaths == null) {
         continue;
       }
       while (entryPaths.hasMoreElements()) {
         Object entryPath = entryPaths.nextElement();
         if (entryPath != null && entryPath instanceof String) {
           String path = (String) entryPath;
           if (path.endsWith(FileExtensions.JAR_FILE_SUFFIX)) {
             URL entry = bundle.getEntry(path);
             if (entry != null && libManagerService != null) {
               try {
                 URL fileUrl = FileLocator.toFileURL(entry);
                 libManagerService.deploy(fileUrl.toURI());
               } catch (Exception e) {
                 log.warn("Cannot deploy: " + bundleName + path);
                 continue;
               }
             }
           }
         }
       }
     }
     initialized = true;
   }
 }
  /**
   * 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.
  }