use of org.talend.designer.codegen.config.JetBean in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method initializeEmittersPool.
/**
* real pool initialization.
*
* @param monitorWrap
*
* @return
* @throws JETException
*/
private static void initializeEmittersPool(List<JetBean> components, ECodeLanguage codeLanguage, IProgressMonitor monitorWrap) {
IProgressMonitor monitor = new NullProgressMonitor();
IProgressMonitor sub = new SubProgressMonitor(monitor, 1);
int monitorBuffer = 0;
HashMap<String, String> globalClasspath = new HashMap<String, String>();
for (JetBean jetBean : components) {
globalClasspath.putAll(jetBean.getClassPath());
// compute the CRC
jetBean.setCrc(extractTemplateHashCode(jetBean));
}
emitterPool = new HashMap<JetBean, JETEmitter>();
List<JetBean> alreadyCompiledEmitters = new ArrayList<JetBean>();
// try {
TalendJetEmitter dummyEmitter = null;
try {
dummyEmitter = new TalendJetEmitter(null, null, sub, globalClasspath, !ComponentCompilations.getMarkers());
} catch (JETException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.jetEmitterInitialException") + e.getMessage(), e);
}
boolean isSkeletonChanged = JetSkeletonManager.updateSkeletonPersistenceData();
if (!isSkeletonChanged) {
try {
alreadyCompiledEmitters = loadEmfPersistentData(EmfEmittersPersistenceFactory.getInstance(codeLanguage).loadEmittersPool(), components, monitorWrap);
for (JetBean jetBean : alreadyCompiledEmitters) {
TalendJetEmitter emitter = new TalendJetEmitter(jetBean, dummyEmitter.getTalendEclipseHelper());
emitterPool.put(jetBean, emitter);
monitorBuffer++;
if (monitorBuffer % 100 == 0) {
monitorWrap.worked(100);
monitorBuffer = 0;
}
}
} catch (BusinessException e) {
// error already loggued
emitterPool = new HashMap<JetBean, JETEmitter>();
}
} else {
ComponentCompilations.deleteMarkers();
}
synchronizedComponent(components, sub, alreadyCompiledEmitters, dummyEmitter, monitorBuffer, monitorWrap);
monitorWrap.worked(monitorBuffer);
try {
EmfEmittersPersistenceFactory.getInstance(codeLanguage).saveEmittersPool(extractEmfPersistenData(alreadyCompiledEmitters));
} catch (BusinessException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.PersitentData.Error") + e.getMessage(), e);
}
}
use of org.talend.designer.codegen.config.JetBean in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method initComponent.
/**
* initialization of the available components.
*
* @param codeLanguage
* @param jetBeans
* @param codePart
* @param component
*/
private static void initComponent(ECodeLanguage codeLanguage, List<JetBean> jetBeans, ECodePart codePart, IComponent component) {
if (component.getAvailableCodeParts().contains(codePart)) {
IComponentFileNaming fileNamingInstance = ComponentsFactoryProvider.getFileNamingInstance();
String templateURI = component.getPathSource() + TemplateUtil.DIR_SEP + component.getName() + TemplateUtil.DIR_SEP + fileNamingInstance.getJetFileName(component, codeLanguage.getExtension(), codePart);
String componentsPath = IComponentsFactory.COMPONENTS_LOCATION;
IBrandingService breaningService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
if (breaningService.isPoweredOnlyCamel()) {
componentsPath = IComponentsFactory.CAMEL_COMPONENTS_LOCATION;
}
if (component instanceof EmfComponent) {
componentsPath = ((EmfComponent) component).getSourceBundleName();
}
JetBean jetBean = new JetBean(componentsPath, templateURI, component.getName(), component.getVersion(), codeLanguage.getName(), codePart.getName());
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("EMF_ECORE", "org.eclipse.emf.ecore");
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("EMF_COMMON", "org.eclipse.emf.common");
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("CORERUNTIME_LIBRARIES", "org.talend.core.runtime");
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("MANAGEMENT_LIBRARIES", "org.talend.metadata.managment");
//$NON-NLS-1$
jetBean.addClassPath("CORE_LIBRARIES", CorePlugin.PLUGIN_ID);
//$NON-NLS-1$
jetBean.addClassPath("CODEGEN_LIBRARIES", CodeGeneratorActivator.PLUGIN_ID);
//$NON-NLS-1$
jetBean.addClassPath("COMMON_LIBRARIES", CommonsPlugin.PLUGIN_ID);
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("COMPONENT_FRAMEWORK", "org.talend.components.api");
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("DAIKON", "org.talend.daikon");
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("COMPONENT_CORE", "org.talend.designer.core.generic");
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("DESIGNER_CORE", "org.talend.designer.core");
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("HADOOP_DISTRIBUTIONS", "org.talend.hadoop.distribution");
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("HADOOP_CUSTOM_DISTRIBUTIONS", "org.talend.hadoop.distribution.custom");
if (PluginChecker.isGEFAbstractMapLoaded()) {
//$NON-NLS-1$ //$NON-NLS-2$
jetBean.addClassPath("GEF_MAP", "org.talend.designer.gefabstractmap");
}
for (String pluginDependency : component.getPluginDependencies()) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
jetBean.addClassPath(pluginDependency.toUpperCase().replaceAll("\\.", "_") + "_LIBRARIES", pluginDependency);
}
String familyName = component.getOriginalFamilyName();
if (familyName.contains("|")) {
//$NON-NLS-1$
//$NON-NLS-1$
familyName = component.getOriginalFamilyName().substring(0, component.getOriginalFamilyName().indexOf("|"));
}
jetBean.setFamily(StringUtils.removeSpecialCharsForPackage(familyName.toLowerCase()));
// Spark, M/R and Storm requires the plugin org.talend.designer.spark to be in the classpath in order to
// generate the code.
//$NON-NLS-1$
String sparkUtilsPluginName = "org.talend.designer.spark";
//$NON-NLS-1$
String bigDataUtilsPluginName = "org.talend.designer.bigdata";
if (PluginChecker.isPluginLoaded(sparkUtilsPluginName) && (//$NON-NLS-1$
"SPARK".equals(component.getPaletteType()) || "MR".equals(component.getPaletteType()) || //$NON-NLS-1$ //$NON-NLS-2$
"STORM".equals(component.getPaletteType()) || "SPARKSTREAMING".equals(component.getPaletteType()))) {
//$NON-NLS-1$
//$NON-NLS-1$
jetBean.addClassPath("BIGDATA_LIBRARIES", bigDataUtilsPluginName);
//$NON-NLS-1$
jetBean.addClassPath("SPARK_LIBRARIES", sparkUtilsPluginName);
jetBean.setClassLoader(createDelegateClassLoader(createDelegateClassLoader(new CodeGeneratorEmittersPoolFactory().getClass().getClassLoader(), bigDataUtilsPluginName, //$NON-NLS-1$
"org.talend.designer.bigdata.common.BigDataDataProcess"), sparkUtilsPluginName, //$NON-NLS-1$
"org.talend.designer.spark.SparkPlugin"));
// spark as a secondary, delegate classloader.
if (component.getPluginExtension() != null) {
jetBean.addClassPath(//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"EXTERNAL_COMPONENT_" + component.getPluginExtension().toUpperCase().replaceAll("\\.", "_"), component.getPluginExtension());
jetBean.setClassLoader(new DelegateClassLoader(ExternalNodesFactory.getInstance(component.getPluginExtension()).getClass().getClassLoader(), jetBean.getClassLoader()));
}
} else if (component.getPluginExtension() != null) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
jetBean.addClassPath(//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"EXTERNAL_COMPONENT_" + component.getPluginExtension().toUpperCase().replaceAll("\\.", "_"), component.getPluginExtension());
jetBean.setClassLoader(ExternalNodesFactory.getInstance(component.getPluginExtension()).getClass().getClassLoader());
} else {
jetBean.setClassLoader(new CodeGeneratorEmittersPoolFactory().getClass().getClassLoader());
}
jetBeans.add(jetBean);
}
// When building the main part of the component, also attempt to build the other parts.
if (codePart.compareTo(ECodePart.MAIN) == 0) {
for (ECodePart otherPart : ECodePart.values()) {
if (otherPart != ECodePart.MAIN && component.getAvailableCodeParts().contains(otherPart)) {
initComponent(codeLanguage, jetBeans, otherPart, component);
}
}
}
}
use of org.talend.designer.codegen.config.JetBean in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method extractEmfPersistenData.
/**
* DOC mhirt Comment method "extractEmfPersistenData".
*
* @param alreadyCompiledEmitters
* @return
*/
private static List<LightJetBean> extractEmfPersistenData(List<JetBean> alreadyCompiledEmitters) {
List<LightJetBean> toReturn = new ArrayList<LightJetBean>();
for (JetBean unit : alreadyCompiledEmitters) {
// long unitCRC = extractTemplateHashCode(unit);
long unitCRC = unit.getCrc();
toReturn.add(new LightJetBean(unit.getTemplateRelativeUri(), unit.getClassName(), unit.getMethodName(), unit.getVersion(), unit.getLanguage(), unitCRC));
}
return toReturn;
}
use of org.talend.designer.codegen.config.JetBean in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method synchronizedComponent.
private static void synchronizedComponent(List<JetBean> components, IProgressMonitor sub, List<JetBean> alreadyCompiledEmitters, TalendJetEmitter dummyEmitter, int monitorBuffer, IProgressMonitor monitorWrap) {
for (JetBean jetBean : components) {
if (!emitterPool.containsKey(jetBean)) {
ComponentCompilations.deleteMarkers();
// System.out.println("The new file is not in JetPersistence* cache:" + getFullTemplatePath(jetBean));
TalendJetEmitter emitter = new TalendJetEmitter(jetBean, dummyEmitter.getTalendEclipseHelper());
// wzhang modified to fix bug 11439
if (monitorWrap.isCanceled()) {
if (!CommonUIPlugin.isFullyHeadless()) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), //$NON-NLS-1$
Messages.getString("CodeGeneratorEmittersPoolFactory.operationCanceled"), //$NON-NLS-1$
Messages.getString("CodeGeneratorEmittersPoolFactory.dialogContent"));
}
});
}
return;
}
// 10901: Component synchronization fails
try {
emitter.initialize(sub);
} catch (JETException e) {
//$NON-NLS-1$
log.error(//$NON-NLS-1$
Messages.getString("CodeGeneratorEmittersPoolFactory.jetEmitterInitialException") + e.getMessage(), e);
continue;
}
if (emitter.isClassAvailable()) {
alreadyCompiledEmitters.add(jetBean);
} else {
jetFilesCompileFail.add(jetBean);
}
emitterPool.put(jetBean, emitter);
monitorBuffer++;
if (monitorBuffer % 100 == 0) {
monitorWrap.worked(100);
monitorBuffer = 0;
}
}
}
}
use of org.talend.designer.codegen.config.JetBean in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method loadEmfPersistentData.
private static List<JetBean> loadEmfPersistentData(List<LightJetBean> datas, List<JetBean> completeJetBeanList, IProgressMonitor monitorWrap) throws BusinessException {
List<JetBean> toReturn = new ArrayList<JetBean>();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
//$NON-NLS-1$
IProject project = workspace.getRoot().getProject(".JETEmitters");
URL url = null;
try {
IFile file = project.getFile(Path.fromOSString("runtime"));
url = file.getLocationURI().toURL();
int lightBeanIndex = 0;
LightJetBean lightBean = null;
LightJetBean myLightJetBean = null;
//$NON-NLS-1$
String unitTemplateFullURI = "";
long unitTemplateHashCode = 0;
HashMap<String, LightJetBean> mapOnName = new HashMap<String, LightJetBean>();
boolean forceMethodLoad = ComponentCompilations.getMarkers();
if (forceMethodLoad) {
// init specific map based on component name : mapOnName
for (LightJetBean ljb : datas) {
//$NON-NLS-1$
mapOnName.put(ljb.getTemplateRelativeUri().substring(ljb.getTemplateRelativeUri().lastIndexOf("/")), ljb);
}
}
int monitorBuffer = 0;
for (JetBean unit : completeJetBeanList) {
monitorBuffer++;
if (monitorBuffer % 200 == 0) {
monitorWrap.worked(200);
monitorBuffer = 0;
}
unitTemplateFullURI = unit.getTemplateRelativeUri();
unitTemplateHashCode = unit.getCrc();
myLightJetBean = new LightJetBean(unitTemplateFullURI, unit.getVersion(), unitTemplateHashCode);
if (((lightBeanIndex = datas.indexOf(myLightJetBean)) > -1) || forceMethodLoad) {
if (!forceMethodLoad) {
lightBean = datas.get(lightBeanIndex);
} else {
lightBean = mapOnName.get(myLightJetBean.getTemplateRelativeUri().substring(//$NON-NLS-1$
myLightJetBean.getTemplateRelativeUri().lastIndexOf("/")));
}
if (lightBean != null && lightBean.getCrc() == unit.getCrc()) {
unit.setClassName(lightBean.getClassName());
unit.setMethodName(lightBean.getMethodName());
toReturn.add(unit);
}
}
}
monitorWrap.worked(monitorBuffer);
} catch (MalformedURLException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.JETEmitters.NoPresent"));
throw new BusinessException(e);
}
return toReturn;
}
Aggregations