Search in sources :

Example 11 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tdi-studio-se by Talend.

the class MavenDeployUtil method deployToLocalMaven.

public static void deployToLocalMaven(IProgressMonitor monitor, String[] jarsOrMvnURls) throws Exception {
    if (jarsOrMvnURls != null) {
        // unify
        Map<String, String> jarsForMvnUrlMap = new HashMap<String, String>();
        Set<String> unifiedMvnUrls = new LinkedHashSet<String>();
        for (String name : jarsOrMvnURls) {
            String mvnUrl = name;
            if (!MavenUrlHelper.isMvnUrl(name)) {
                mvnUrl = MavenUrlHelper.generateMvnUrlForJarName(name);
                jarsForMvnUrlMap.put(name, mvnUrl);
            }
            unifiedMvnUrls.add(mvnUrl);
        }
        // find the available
        Set<String> availableMvnUrls = PomUtil.availableArtifacts(monitor, unifiedMvnUrls.toArray(new String[0]));
        // left the unavailable
        Set<String> unavailableMvnUrls = new LinkedHashSet<String>(unifiedMvnUrls);
        if (availableMvnUrls != null) {
            unavailableMvnUrls.removeAll(availableMvnUrls);
        }
        // check the only jar name way for old system.
        for (String jarName : jarsForMvnUrlMap.keySet()) {
            String mvnUrl = jarsForMvnUrlMap.get(jarName);
            if (mvnUrl != null && !unavailableMvnUrls.contains(mvnUrl)) {
                // existed.
                // remove the existed in local maven repository, left the non-existed jars.
                jarsForMvnUrlMap.remove(jarName);
            }
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
            ILibraryManagerService libService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
            // if still have some jars are not installed
            for (String jarName : jarsForMvnUrlMap.keySet()) {
                String jarPath = libService.getJarPath(jarName);
                // if jar existed in old "talend.library.path" folder or in bundle, then install it
                if (jarPath != null) {
                    // assume if the jar is in "talend.library.path" folder, user have agree the jar license, so
                    // install directly.
                    installJarFile(jarPath);
                }
            }
            // 2, still not existed some.
            if (!unavailableMvnUrls.isEmpty() && !CommonsPlugin.isHeadless()) {
                // for studio, popup the install modules dialog to install
                File libDir = JavaProcessorUtilities.getJavaProjectLibFolder();
                if (libDir != null) {
                    libService.retrieve(unavailableMvnUrls, libDir.getAbsolutePath());
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ILibraryManagerService(org.talend.core.ILibraryManagerService) HashMap(java.util.HashMap) File(java.io.File)

Example 12 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tdi-studio-se by Talend.

the class JavaProcessorUtilities method sortClasspath.

// // see bug 3914, make the order of the jar files consistent with the
// command
// // line in run mode
private static void sortClasspath(Set<ModuleNeeded> jobModuleList, IProcess process, Set<ModuleNeeded> alreadyRetrievedModules) throws CoreException, ProcessorException {
    ITalendProcessJavaProject jProject = getTalendJavaProject();
    if (jProject == null) {
        return;
    }
    Set<ModuleNeeded> listModulesReallyNeeded = new HashSet<ModuleNeeded>();
    listModulesReallyNeeded.addAll(jobModuleList);
    Set<ModuleNeeded> optionalJarsOnlyForRoutines = new HashSet<ModuleNeeded>();
    // only for wizards or additional jars only to make the java project compile without any error.
    for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getSystemRunningModules()) {
        optionalJarsOnlyForRoutines.add(moduleNeeded);
    }
    // list contains all routines linked to job as well as routines not used in the job
    // rebuild the list to have only the libs linked to routines "not used".
    optionalJarsOnlyForRoutines.removeAll(listModulesReallyNeeded);
    // only to be able to compile java project without error.
    for (ModuleNeeded jar : optionalJarsOnlyForRoutines) {
        listModulesReallyNeeded.add(jar);
    }
    addLog4jToModuleList(listModulesReallyNeeded);
    listModulesReallyNeeded.removeAll(alreadyRetrievedModules);
    alreadyRetrievedModules.addAll(listModulesReallyNeeded);
    String missingJars = null;
    Set<String> missingJarsForRoutinesOnly = new HashSet<String>();
    Set<String> missingJarsForProcessOnly = new HashSet<String>();
    File libDir = getJavaProjectLibFolder();
    ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
    if ((libDir != null) && (libDir.isDirectory())) {
        Set<ModuleNeeded> jarsNeedRetrieve = new HashSet<ModuleNeeded>();
        for (ModuleNeeded moduleNeeded : listModulesReallyNeeded) {
            jarsNeedRetrieve.add(moduleNeeded);
        }
        if (!jarsNeedRetrieve.isEmpty()) {
            repositoryBundleService.retrieve(jarsNeedRetrieve, libDir.getAbsolutePath(), true);
            if (process instanceof IProcess2) {
                ((IProcess2) process).checkProcess();
            }
        }
        Set<ModuleNeeded> exist = new HashSet<ModuleNeeded>();
        for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
            for (ModuleNeeded module : jarsNeedRetrieve) {
                if (externalLib.getName().equals(module.getModuleName())) {
                    exist.add(module);
                }
            }
        }
        jarsNeedRetrieve.removeAll(exist);
        Set<String> jarStringListNeededByProcess = new HashSet<String>();
        for (ModuleNeeded moduleNeeded : jobModuleList) {
            jarStringListNeededByProcess.add(moduleNeeded.getModuleName());
        }
        for (ModuleNeeded jar : jarsNeedRetrieve) {
            if (jobModuleList.contains(jar)) {
                missingJarsForProcessOnly.add(jar.getModuleName());
            } else {
                missingJarsForRoutinesOnly.add(jar.getModuleName());
            }
            if (missingJars == null) {
                //$NON-NLS-1$
                missingJars = Messages.getString("JavaProcessorUtilities.msg.missingjar.forProcess") + jar;
            } else {
                //$NON-NLS-1$
                missingJars = missingJars + ", " + jar;
            }
        }
    }
    repositoryBundleService.deployModules(listModulesReallyNeeded, null);
    if (missingJars != null) {
        handleMissingJarsForProcess(missingJarsForRoutinesOnly, missingJarsForProcessOnly, missingJars);
    }
}
Also used : ILibraryManagerService(org.talend.core.ILibraryManagerService) IProcess2(org.talend.core.model.process.IProcess2) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) File(java.io.File) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) HashSet(java.util.HashSet)

Example 13 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tdi-studio-se by Talend.

the class ModuleListController method updateModuleList.

public static void updateModuleList(Node node) {
    ILibraryManagerService repositoryBundleService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
    Set<String> existLibraries = repositoryBundleService.list();
    Set<String> moduleNameList = new TreeSet<String>();
    Set<String> moduleValueList = new TreeSet<String>();
    for (String lib : existLibraries) {
        moduleNameList.add(lib);
        moduleValueList.add(TalendTextUtils.addQuotes(lib));
    }
    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);
                    }
                }
            }
        }
    }
}
Also used : ILibraryManagerService(org.talend.core.ILibraryManagerService) TreeSet(java.util.TreeSet) IElementParameter(org.talend.core.model.process.IElementParameter) Point(org.eclipse.swt.graphics.Point)

Example 14 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tbd-studio-se by Talend.

the class ExtractParquetFileSchemaService method initJarLibrary.

private void initJarLibrary() {
    List<File> libList = new ArrayList<File>();
    List<String> jars = new ArrayList<String>();
    List<File> jarFileList = new ArrayList<File>();
    List<ModuleNeeded> modulesNeeded = new ArrayList<ModuleNeeded>();
    if (classLoader instanceof DynamicClassLoader) {
        GlobalServiceRegister register = GlobalServiceRegister.getDefault();
        DynamicClassLoader loader = (DynamicClassLoader) classLoader;
        String libStorePath = loader.getLibStorePath();
        File libFolder = new File(libStorePath);
        File[] listFiles = libFolder.listFiles();
        libList = Arrays.asList(listFiles);
        if (register.isServiceRegistered(IComponentsService.class)) {
            IComponentsService componentsService = register.getService(IComponentsService.class);
            IComponent component = componentsService.getComponentsFactory().get("tFileInputParquet", ComponentCategory.CATEGORY_4_DI.getName());
            modulesNeeded = component.getModulesNeeded();
            modulesNeeded.forEach(module -> {
                jars.add(module.getMavenUri());
                jarFileList.add(new File(libStorePath + "/" + module.getModuleName()));
            });
        }
        if (register.isServiceRegistered(ILibraryManagerService.class)) {
            ILibraryManagerService service = GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
            service.retrieve(jars, libStorePath, true, new NullProgressMonitor());
        }
        for (File jarFile : jarFileList) {
            loader.addLibrary(jarFile.getAbsolutePath());
        }
    }
}
Also used : DynamicClassLoader(org.talend.core.classloader.DynamicClassLoader) IComponentsService(org.talend.core.model.components.IComponentsService) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) GlobalServiceRegister(org.talend.core.GlobalServiceRegister) ILibraryManagerService(org.talend.core.ILibraryManagerService) File(java.io.File) HDFSFile(org.talend.designer.hdfsbrowse.model.HDFSFile) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 15 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tbd-studio-se by Talend.

the class HadoopConfsUtils method createAndDeployConfJar.

private static void createAndDeployConfJar(HadoopClusterConnectionItem connectionItem, String confJarId, String confJarName) throws IOException {
    // If the conf jar has been deployed before then no need to deploy again.
    if (containsInDeployedCache(connectionItem, confJarName)) {
        return;
    }
    byte[] confFileBA = null;
    HadoopClusterConnection connection = (HadoopClusterConnection) connectionItem.getConnection();
    if (connection.isContextMode()) {
        ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
        if (contextItem != null) {
            EMap<String, byte[]> confFiles = connection.getConfFiles();
            EList<ContextType> contexts = contextItem.getContext();
            for (ContextType contextType : contexts) {
                String contextName = contextType.getName();
                byte[] bs = confFiles.get(contextName);
                if (confJarId.endsWith(contextName) && bs != null) {
                    confFileBA = bs;
                    break;
                }
            }
        }
        if (confFileBA == null) {
            // either conf jar name is wrong or it is a old item.
            // then take the old hadoop conf file content.
            confFileBA = connection.getConfFile();
        }
    } else {
        confFileBA = connection.getConfFile();
    }
    if (confFileBA != null) {
        File confsTempFolder = new File(getConfsJarTempFolder());
        File confFile = new File(confsTempFolder, confJarName);
        FileUtils.writeByteArrayToFile(confFile, confFileBA);
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
            ILibraryManagerService libService = GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
            if (libService != null && libService.isJarNeedToBeDeployed(confFile)) {
                if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
                    ILibrariesService service = GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
                    if (service != null) {
                        // Only deploy a new jar, no need to reset all
                        service.deployLibrary(confFile.toURI().toURL());
                        addToDeployedCache(connectionItem, confJarName);
                    }
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ILibraryManagerService(org.talend.core.ILibraryManagerService) ILibrariesService(org.talend.core.model.general.ILibrariesService) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) File(java.io.File)

Aggregations

ILibraryManagerService (org.talend.core.ILibraryManagerService)15 File (java.io.File)13 ArrayList (java.util.ArrayList)5 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 List (java.util.List)3 IPath (org.eclipse.core.runtime.IPath)3 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 IProject (org.eclipse.core.resources.IProject)2 Point (org.eclipse.swt.graphics.Point)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1