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);
}
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);
}
}
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);
}
}
}
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);
}
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);
}
Aggregations