Search in sources :

Example 1 with ModuleToInstall

use of org.talend.core.model.general.ModuleToInstall in project tdq-studio-se by Talend.

the class AbstractDQMissingJarsExtraUpdatesFactory method retrieveUninstalledExtraFeatures.

@Override
public void retrieveUninstalledExtraFeatures(IProgressMonitor monitor, Set<ExtraFeature> uninstalledExtraFeatures) throws Exception {
    Bundle bundle = Platform.getBundle(getPluginName());
    if (bundle == null) {
        // if the bundle is not installed then propose to download it.
        // $NON-NLS-1$
        String pathToStore = Platform.getInstallLocation().getURL().getFile() + "plugins";
        File jarfile = new File(pathToStore, getJarFileWithVersionNames().get(0));
        if (jarfile.exists()) {
            return;
        } else {
            SubMonitor mainSubMonitor = SubMonitor.convert(monitor, 2);
            // add all needed models into the allUninstalledModules
            List<ModuleNeeded> allUninstalledModules = getAllUninstalledModules();
            if (monitor.isCanceled()) {
                return;
            }
            // else keep going fetch missing jar information from remote web site.
            ArrayList<ModuleToInstall> modulesRequiredToBeInstalled = new ArrayList<ModuleToInstall>();
            IRunnableWithProgress notInstalledModulesRunnable = RemoteModulesHelper.getInstance().getNotInstalledModulesRunnable(allUninstalledModules, modulesRequiredToBeInstalled);
            // jface because it adds graphical dependencies.
            // some data need to be fetched
            runNotInstallModule(mainSubMonitor, notInstalledModulesRunnable);
            // else all data already fetched or already try and failed so keep going
            if (mainSubMonitor.isCanceled()) {
                return;
            }
            // else keep going.
            final ArrayList<ModuleToInstall> modulesForAutomaticInstall = TalendWebServiceUpdateExtraFeature.filterAllAutomaticInstallableModules(modulesRequiredToBeInstalled);
            if (modulesForAutomaticInstall.isEmpty()) {
                // if could not find anything to download log and error and
                // return nothing
                // $NON-NLS-1$
                log.error("failed to fetch missing third parties jars information for " + getJarFileNames().get(0));
                return;
            }
            // else something to dowload to return the Extra feature to dowload.
            addToSet(uninstalledExtraFeatures, new TalendWebServiceUpdateExtraFeature(modulesForAutomaticInstall, DefaultMessagesImpl.getString(getDownloadName()), DefaultMessagesImpl.getString("DownloadSqlexplorerPluginJarFactory.description", // $NON-NLS-1$
            getContainPluginNames()), // $NON-NLS-1$
            true) {

                @Override
                public boolean needRestart() {
                    return true;
                }

                @Override
                public IStatus install(IProgressMonitor progress, List<URI> allRepoUris) throws Exception {
                    IStatus installStatus = super.install(progress, allRepoUris);
                    // move the jar to plugins folder
                    if (installStatus.isOK()) {
                        try {
                            copyJars2PluginsFolder(modulesForAutomaticInstall);
                        } catch (MalformedURLException e) {
                            MultiStatus multiStatus = new MultiStatus(CorePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
                            multiStatus.add(installStatus);
                            return multiStatus;
                        } catch (IOException e) {
                            MultiStatus multiStatus = new MultiStatus(CorePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
                            multiStatus.add(installStatus);
                            return multiStatus;
                        }
                    }
                    // else install not ok so return the error status.
                    return installStatus;
                }

                private void copyJars2PluginsFolder(ArrayList<ModuleToInstall> modules) throws MalformedURLException, IOException {
                    List<File> jarFiles = new ArrayList<File>();
                    ILibraryManagerService librariesService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
                    if (librariesService != null) {
                        for (ModuleToInstall module : modules) {
                            String jarPathFromMaven = librariesService.getJarPathFromMaven(module.getMavenUri());
                            if (jarPathFromMaven == null) {
                                continue;
                            }
                            jarFiles.add(new File(jarPathFromMaven));
                        }
                    } else {
                        IMaven maven = MavenPlugin.getMaven();
                        String librariesPath = maven.getLocalRepositoryPath();
                        for (String jarFileName : getJarFileWithVersionNames()) {
                            jarFiles.addAll(FilesUtils.getJarFilesFromFolder(new File(librariesPath), jarFileName));
                        }
                    }
                    for (File jarFile : jarFiles) {
                        // $NON-NLS-1$
                        String pluginPath = Platform.getInstallLocation().getURL().getFile() + "plugins";
                        File movedfile = new File(pluginPath, jarFile.getName().replace(MavenConstants.SNAPSHOT, ""));
                        if (!movedfile.exists()) {
                            File target = new File(StringUtils.trimToEmpty(pluginPath));
                            if (!target.exists()) {
                                target.mkdirs();
                            }
                            FilesUtils.copyFile(jarFile, movedfile);
                        }
                    }
                }
            });
        }
    } else {
    // if it is not TOP loaded only, need not to do anyting
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MalformedURLException(java.net.MalformedURLException) Bundle(org.osgi.framework.Bundle) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) IOException(java.io.IOException) URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ModuleToInstall(org.talend.core.model.general.ModuleToInstall) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILibraryManagerService(org.talend.core.ILibraryManagerService) TalendWebServiceUpdateExtraFeature(org.talend.updates.runtime.model.TalendWebServiceUpdateExtraFeature) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) IMaven(org.eclipse.m2e.core.embedder.IMaven)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IMaven (org.eclipse.m2e.core.embedder.IMaven)1 Bundle (org.osgi.framework.Bundle)1 ILibraryManagerService (org.talend.core.ILibraryManagerService)1 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)1 ModuleToInstall (org.talend.core.model.general.ModuleToInstall)1 TalendWebServiceUpdateExtraFeature (org.talend.updates.runtime.model.TalendWebServiceUpdateExtraFeature)1