Search in sources :

Example 16 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class JavaProcessUtil method getNeededModules.

public static Set<ModuleNeeded> getNeededModules(final IProcess process, boolean withChildrens, boolean forMR) {
    List<ModuleNeeded> modulesNeeded = new ArrayList<ModuleNeeded>();
    // see bug 4939: making tRunjobs work loop will cause a error of "out of memory"
    Set<ProcessItem> searchItems = new HashSet<ProcessItem>();
    if (withChildrens) {
        ProcessItem processItem = null;
        if (process.getVersion() != null) {
            processItem = ItemCacheManager.getProcessItem(process.getId(), process.getVersion());
        } else {
            processItem = ItemCacheManager.getProcessItem(process.getId());
        }
        if (processItem != null) {
            searchItems.add(processItem);
        }
    }
    // call recursive function to get all dependencies from job & subjobs
    getNeededModules(process, withChildrens, searchItems, modulesNeeded, forMR);
    /*
         * Remove duplicates in the modulesNeeded list after having prioritize the modules. Details in the
         * ModuleNeededComparator class.
         */
    Collections.sort(modulesNeeded, new ModuleNeededComparator());
    Set<String> dedupModulesList = new HashSet<String>();
    Iterator<ModuleNeeded> it = modulesNeeded.iterator();
    while (it.hasNext()) {
        ModuleNeeded module = it.next();
        // in some case it's not a real library, but just a text.
        if (!module.getModuleName().contains(".")) {
            //$NON-NLS-1$
            it.remove();
        } else if (dedupModulesList.contains(module.getModuleName())) {
            it.remove();
        } else {
            dedupModulesList.add(module.getModuleName());
        }
    }
    return new HashSet<ModuleNeeded>(modulesNeeded);
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) ArrayList(java.util.ArrayList) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) HashSet(java.util.HashSet)

Example 17 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class JavaProcessUtil method getNeededModules.

private static void getNeededModules(final IProcess process, boolean withChildrens, Set<ProcessItem> searchItems, List<ModuleNeeded> modulesNeeded, boolean forMR) {
    IElementParameter headerParameter = process.getElementParameter(EParameterName.HEADER_LIBRARY.getName());
    if (headerParameter != null) {
        Object value = headerParameter.getValue();
        if (value != null) {
            String headerLibraries = (String) value;
            if (headerLibraries.indexOf(File.separatorChar) > 0 && headerLibraries.length() > headerLibraries.lastIndexOf(File.separatorChar) + 1) {
                String substring = headerLibraries.substring(headerLibraries.lastIndexOf(File.separatorChar) + 1);
                if (!"".equals(substring)) {
                    //$NON-NLS-1$
                    modulesNeeded.add(getModuleValue(process, substring));
                }
            }
        }
    }
    IElementParameter footerParameter = process.getElementParameter(EParameterName.FOOTER_LIBRARY.getName());
    if (footerParameter != null) {
        Object value = footerParameter.getValue();
        if (value != null) {
            String footerLibraries = (String) value;
            if (footerLibraries.indexOf(File.separatorChar) > 0 && footerLibraries.length() > footerLibraries.lastIndexOf(File.separatorChar) + 1) {
                String substring = footerLibraries.substring(footerLibraries.lastIndexOf(File.separatorChar) + 1);
                if (!"".equals(substring)) {
                    //$NON-NLS-1$
                    modulesNeeded.add(getModuleValue(process, substring));
                }
            }
        }
    }
    IElementParameter elementParameter = process.getElementParameter(EParameterName.DRIVER_JAR.getName());
    if (elementParameter != null && elementParameter.getFieldType() == EParameterFieldType.TABLE) {
        getModulesInTable(process, elementParameter, modulesNeeded);
    }
    if (process instanceof IProcess2) {
        Item item = ((IProcess2) process).getProperty().getItem();
        if (item instanceof ProcessItem) {
            modulesNeeded.addAll(ModulesNeededProvider.getModulesNeededForProcess((ProcessItem) item, process));
        }
    }
    if (ProcessUtils.isTestContainer(process)) {
        // if it is a test container, add junit jars.
        addJunitNeededModules(modulesNeeded);
    }
    String hadoopItemId = null;
    List<? extends INode> nodeList = process.getGeneratingNodes();
    for (INode node : nodeList) {
        if (hadoopItemId == null) {
            String itemId = getHadoopClusterItemId(node);
            if (itemId != null) {
                hadoopItemId = itemId;
            }
        }
        if (process instanceof IProcess2) {
            ((IProcess2) node.getProcess()).setNeedLoadmodules(((IProcess2) process).isNeedLoadmodules());
        }
        Set<ModuleNeeded> nodeNeededModules = getNeededModules(node, searchItems, withChildrens, forMR);
        if (nodeNeededModules != null) {
            modulesNeeded.addAll(nodeNeededModules);
        }
    }
    if (hadoopItemId == null) {
        // Incase it is a bigdata process.
        //$NON-NLS-1$
        IElementParameter propertyParam = process.getElementParameter("MR_PROPERTY");
        if (propertyParam != null) {
            IElementParameter repositoryParam = propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            if (repositoryParam != null) {
                hadoopItemId = String.valueOf(repositoryParam.getValue());
            }
        }
    }
    if (hadoopItemId != null) {
        useCustomConfsJarIfNeeded(modulesNeeded, hadoopItemId);
    }
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) INode(org.talend.core.model.process.INode) ProcessItem(org.talend.core.model.properties.ProcessItem) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 18 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class ModulesInstallerUtil method installModules.

public static void installModules(Shell shell, List<IComponent> components) {
    if (!LibManagerUiPlugin.getDefault().getPreferenceStore().getBoolean(ExternalModulesInstallDialog.DO_NOT_SHOW_EXTERNALMODULESINSTALLDIALOG)) {
        //$NON-NLS-1$
        String text = Messages.getString("ModulesInstaller_text2");
        //$NON-NLS-1$
        String title = Messages.getString("ModulesInstaller_title2");
        List<ModuleNeeded> needed = new ArrayList<ModuleNeeded>();
        for (IComponent component : components) {
            needed.addAll(component.getModulesNeeded());
        }
        if (!needed.isEmpty()) {
            ComponentExternalModulesDialog dialog = new ComponentExternalModulesDialog(shell, text, title);
            dialog.showDialog(true, needed);
        }
    }
}
Also used : ComponentExternalModulesDialog(org.talend.librariesmanager.ui.dialogs.ComponentExternalModulesDialog) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 19 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class JavaProcessUtil method addJunitNeededModules.

private static void addJunitNeededModules(List<ModuleNeeded> modulesNeeded) {
    //$NON-NLS-1$ //$NON-NLS-2$
    ModuleNeeded junitModule = new ModuleNeeded("junit", "junit.jar", null, true);
    junitModule.setModuleLocaion("platform:/plugin/org.junit/junit.jar");
    junitModule.setMavenUri("mvn:org.talend.libraries/junit/6.0.0");
    modulesNeeded.add(junitModule);
}
Also used : ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 20 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded in project tdi-studio-se by Talend.

the class JavaProcessUtil method getModuleValue.

private static ModuleNeeded getModuleValue(final IProcess process, String moduleValue) {
    if (ContextParameterUtils.isContainContextParam(moduleValue)) {
        String var = ContextParameterUtils.getVariableFromCode(moduleValue);
        if (var != null) {
            IContext selectedContext = CorePlugin.getDefault().getRunProcessService().getSelectedContext();
            if (selectedContext == null) {
                selectedContext = process.getContextManager().getDefaultContext();
            }
            IContextParameter param = selectedContext.getContextParameter(var);
            if (param != null) {
                // add only the file name without path
                ModuleNeeded module = getModuleNeededForContextParam(param);
                return module;
            }
        }
    }
    return new ModuleNeeded(null, TalendTextUtils.removeQuotes(moduleValue), null, true);
}
Also used : IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Aggregations

ModuleNeeded (org.talend.core.model.general.ModuleNeeded)38 ArrayList (java.util.ArrayList)17 IElementParameter (org.talend.core.model.process.IElementParameter)11 HashSet (java.util.HashSet)9 File (java.io.File)8 Map (java.util.Map)8 List (java.util.List)5 Test (org.junit.Test)5 IComponent (org.talend.core.model.components.IComponent)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 ElementParameter (org.talend.designer.core.model.components.ElementParameter)5 Node (org.talend.designer.core.ui.editor.nodes.Node)5 IOException (java.io.IOException)4 URL (java.net.URL)4 INode (org.talend.core.model.process.INode)4 HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3