Search in sources :

Example 31 with ModuleNeeded

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

the class JavaProcessUtil method getModuleNeededForContextParam.

private static ModuleNeeded getModuleNeededForContextParam(IContextParameter contextParam) {
    if (contextParam != null) {
        String values = contextParam.getValue();
        if (StringUtils.isNotBlank(values)) {
            // if it's path
            IPath path = new Path(values);
            // get the file name only.
            String fileName = path.lastSegment();
            ModuleNeeded module = new ModuleNeeded(null, fileName, null, true);
            return module;
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 32 with ModuleNeeded

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

the class JavaProcessUtil method getModulesInTable.

private static void getModulesInTable(final IProcess process, IElementParameter curParam, List<ModuleNeeded> modulesNeeded) {
    if (!(curParam.getValue() instanceof List)) {
        return;
    }
    List<Map<String, Object>> values = (List<Map<String, Object>>) curParam.getValue();
    if (values != null && !values.isEmpty()) {
        Object[] listItemsValue = curParam.getListItemsValue();
        if (listItemsValue != null && listItemsValue.length > 0 && listItemsValue[0] instanceof IElementParameter) {
            for (Object o : listItemsValue) {
                IElementParameter param = (IElementParameter) o;
                if (param.getFieldType() == EParameterFieldType.MODULE_LIST) {
                    for (Map<String, Object> line : values) {
                        String moduleName = (String) line.get(param.getName());
                        if (moduleName != null && !"".equals(moduleName)) {
                            //$NON-NLS-1$
                            boolean isContextMode = ContextParameterUtils.containContextVariables(moduleName);
                            if (isContextMode) {
                                List<IContext> listContext = process.getContextManager().getListContext();
                                for (IContext context : listContext) {
                                    List<IContextParameter> contextParameterList = context.getContextParameterList();
                                    for (IContextParameter contextPara : contextParameterList) {
                                        String var = ContextParameterUtils.getVariableFromCode(moduleName);
                                        if (var.equals(contextPara.getName())) {
                                            String value = context.getContextParameter(contextPara.getName()).getValue();
                                            if (curParam.getName().equals(EParameterName.DRIVER_JAR.getName()) && value.contains(";")) {
                                                //$NON-NLS-1$
                                                //$NON-NLS-1$
                                                String[] jars = value.split(";");
                                                for (String jar2 : jars) {
                                                    String jar = jar2;
                                                    //$NON-NLS-1$
                                                    jar = jar.substring(jar.lastIndexOf("\\") + 1);
                                                    ModuleNeeded module = new ModuleNeeded(null, jar, null, true);
                                                    modulesNeeded.add(module);
                                                }
                                            } else {
                                                //$NON-NLS-1$
                                                value = value.substring(value.lastIndexOf("\\") + 1);
                                                ModuleNeeded module = new ModuleNeeded(null, value, null, true);
                                                modulesNeeded.add(module);
                                            }
                                        }
                                    }
                                }
                            } else {
                                ModuleNeeded mn = getModuleValue(process, moduleName);
                                if (line.get("JAR_NEXUS_VERSION") != null) {
                                    String a = moduleName.replaceFirst("[.][^.]+$", "");
                                    mn.setMavenUri("mvn:org.talend.libraries/" + a + "/" + line.get("JAR_NEXUS_VERSION") + "/jar");
                                }
                                modulesNeeded.add(mn);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 33 with ModuleNeeded

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

the class JavaProcessUtil method getChildrenModules.

static List<ModuleNeeded> getChildrenModules(final INode node, Set<ProcessItem> searchItems, boolean forMR) {
    List<ModuleNeeded> modulesNeeded = new ArrayList<ModuleNeeded>();
    if (node.getComponent().getName().equals("tRunJob")) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        IElementParameter processIdparam = node.getElementParameter("PROCESS_TYPE_PROCESS");
        IElementParameter processVersionParam = node.getElementParameter(EParameterName.PROCESS_TYPE_VERSION.getName());
        ProcessItem processItem = null;
        if (processVersionParam != null) {
            processItem = ItemCacheManager.getProcessItem((String) processIdparam.getValue(), (String) processVersionParam.getValue());
        } else {
            processItem = ItemCacheManager.getProcessItem((String) processIdparam.getValue());
        }
        //$NON-NLS-1$
        String context = (String) node.getElementParameter("PROCESS_TYPE_CONTEXT").getValue();
        if (processItem != null && !searchItems.contains(processItem)) {
            boolean seperated = //$NON-NLS-1$
            getBooleanParamValue(node, "USE_INDEPENDENT_PROCESS") || //$NON-NLS-1$
            getBooleanParamValue(node, "USE_DYNAMIC_JOB");
            if (!seperated) {
                // avoid dead loop of method call
                searchItems.add(processItem);
                JobInfo subJobInfo = new JobInfo(processItem, context);
                IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
                IProcess child = service.getProcessFromItem(subJobInfo.getProcessItem());
                getNeededModules(child, true, searchItems, modulesNeeded, forMR);
            }
        }
    }
    return modulesNeeded;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) JobInfo(org.talend.core.model.process.JobInfo) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) IProcess(org.talend.core.model.process.IProcess)

Example 34 with ModuleNeeded

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

the class WSDL2JAVAController method addWsdlNeedLib.

// gcui:see bug 9733.
private void addWsdlNeedLib(RoutineItem routineItem) {
    List<IMPORTType> wsdlNeedImport = new ArrayList<IMPORTType>();
    IMPORTType type1 = ComponentFactory.eINSTANCE.createIMPORTType();
    type1.setMODULE("axis.jar");
    type1.setREQUIRED(true);
    type1.setNAME(routineItem.getProperty().getLabel());
    wsdlNeedImport.add(type1);
    IMPORTType type2 = ComponentFactory.eINSTANCE.createIMPORTType();
    type2.setMODULE("jaxrpc.jar");
    type2.setREQUIRED(true);
    type2.setNAME(routineItem.getProperty().getLabel());
    wsdlNeedImport.add(type2);
    routineItem.getImports().addAll(wsdlNeedImport);
    try {
        CorePlugin.getDefault().getProxyRepositoryFactory().save(routineItem);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
    CorePlugin.getDefault().getRunProcessService().updateLibraries(new HashSet<ModuleNeeded>(), null);
}
Also used : ArrayList(java.util.ArrayList) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 35 with ModuleNeeded

use of org.talend.core.model.general.ModuleNeeded 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)

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