Search in sources :

Example 1 with TalendJetEmitter

use of org.talend.designer.codegen.config.TalendJetEmitter 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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JetBean(org.talend.designer.codegen.config.JetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TalendJetEmitter(org.talend.designer.codegen.config.TalendJetEmitter) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) JETEmitter(org.eclipse.emf.codegen.jet.JETEmitter) JETException(org.eclipse.emf.codegen.jet.JETException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BusinessException(org.talend.commons.exception.BusinessException)

Example 2 with TalendJetEmitter

use of org.talend.designer.codegen.config.TalendJetEmitter 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;
            }
        }
    }
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean) TalendJetEmitter(org.talend.designer.codegen.config.TalendJetEmitter) JETException(org.eclipse.emf.codegen.jet.JETException)

Aggregations

JETException (org.eclipse.emf.codegen.jet.JETException)2 JetBean (org.talend.designer.codegen.config.JetBean)2 LightJetBean (org.talend.designer.codegen.config.LightJetBean)2 TalendJetEmitter (org.talend.designer.codegen.config.TalendJetEmitter)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 JETEmitter (org.eclipse.emf.codegen.jet.JETEmitter)1 BusinessException (org.talend.commons.exception.BusinessException)1