Search in sources :

Example 1 with JETEmitter

use of org.eclipse.emf.codegen.jet.JETEmitter in project mdw-designer by CenturyLinkCloud.

the class JetAccess method generate.

/**
 * Invokes the JET template specified in the Config. Uses a JETEmitter to
 * translate the template to an implementation class. The translated class
 * is created the hidden .JETEmitters project.
 *
 * @param monitor
 *            the progress monitor to use (may be null) - 3 units are used
 * @return the source code text generated by the JET template
 */
public String generate(IProgressMonitor monitor) throws CoreException, JETException {
    monitor = createIfNull(monitor);
    JetConfig config = getConfig();
    JETEmitter emitter = new JETEmitter(config.getTemplateFullUri(), getClass().getClassLoader());
    emitter.addVariable(config.getClasspathVariable(), config.getPluginId());
    IProgressMonitor sub = new SubProgressMonitor(monitor, 2);
    Object[] params = null;
    if (config.getSettings() != null) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("model", config.getModel());
        map.put("settings", config.getSettings());
        params = new Object[] { map };
    } else {
        params = new Object[] { config.getModel() };
    }
    String result = emitter.generate(sub, params);
    monitor.worked(1);
    return result;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) HashMap(java.util.HashMap) JETEmitter(org.eclipse.emf.codegen.jet.JETEmitter) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 2 with JETEmitter

use of org.eclipse.emf.codegen.jet.JETEmitter in project mdw-designer by CenturyLinkCloud.

the class JavaEditorValueProvider method getArtifactContent.

public byte[] getArtifactContent() {
    String text = activity.getAttribute(getAttributeName());
    if (text == null || text.trim().length() == 0) {
        try {
            // initialize from template
            String template = "/templates/source/executors/JavaExecutor.javajet";
            if (!getProject().checkRequiredVersion(6, 0))
                template = "/templates/source/55/executors/JavaExecutor.javajet";
            if (!getProject().checkRequiredVersion(5, 5))
                template = "/templates/source/52/executors/JavaExecutor.javajet";
            String templateUri = Platform.getBundle(MdwPlugin.getPluginId()).getEntry("/").toString() + template;
            JETEmitter emitter = new JETEmitter(templateUri, getClass().getClassLoader());
            emitter.addVariable(null, MdwPlugin.getPluginId());
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("model", this);
            map.put("settings", MdwPlugin.getSettings());
            text = emitter.generate(new NullProgressMonitor(), new Object[] { map });
            activity.setAttribute(getAttributeName(), text);
            activity.fireDirtyStateChanged(true);
        } catch (JETException ex) {
            PluginMessages.uiError(ex, "Generate Java", getProject());
        }
    }
    return text.getBytes();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) JETEmitter(org.eclipse.emf.codegen.jet.JETEmitter) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 3 with JETEmitter

use of org.eclipse.emf.codegen.jet.JETEmitter 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 4 with JETEmitter

use of org.eclipse.emf.codegen.jet.JETEmitter in project tdi-studio-se by Talend.

the class JetProxy method generate.

/**
     * Get the initalized Emitter for this Bean and use it to generate code.
     * 
     * @param monitor
     * @return
     * @throws CoreException
     * @throws JETException
     */
public String generate() throws CoreException, JETException {
    JETEmitter emitter = CodeGeneratorEmittersPoolFactory.getJETEmitter(jetBean);
    IProgressMonitor sub = new SubProgressMonitor(monitor, 1);
    //$NON-NLS-1$
    String result = "";
    if (emitter != null) {
        result = emitter.generate(sub, new Object[] { jetBean });
        sub.worked(1);
    }
    return result;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JETEmitter(org.eclipse.emf.codegen.jet.JETEmitter) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 5 with JETEmitter

use of org.eclipse.emf.codegen.jet.JETEmitter in project mdw-designer by CenturyLinkCloud.

the class JavaSource method getDefaultContent.

@Override
public String getDefaultContent() {
    try {
        // initialize from template
        String templateUri = Platform.getBundle(MdwPlugin.getPluginId()).getEntry("/").toString() + "/templates/source/JavaSource.javajet";
        JETEmitter emitter = new JETEmitter(templateUri, getClass().getClassLoader());
        emitter.addVariable(null, MdwPlugin.getPluginId());
        Map<String, Object> map = new HashMap<String, Object>();
        JavaCode javaCode = new JavaCode(getJavaPackageName(), getJavaClassName());
        map.put("model", javaCode);
        map.put("settings", MdwPlugin.getSettings());
        return emitter.generate(new NullProgressMonitor(), new Object[] { map });
    } catch (JETException ex) {
        PluginMessages.uiError(ex, "Generate Java", getProject());
        return null;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) JavaCode(com.centurylink.mdw.plugin.codegen.meta.JavaCode) JETEmitter(org.eclipse.emf.codegen.jet.JETEmitter) JETException(org.eclipse.emf.codegen.jet.JETException)

Aggregations

JETEmitter (org.eclipse.emf.codegen.jet.JETEmitter)5 HashMap (java.util.HashMap)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 JETException (org.eclipse.emf.codegen.jet.JETException)3 JavaCode (com.centurylink.mdw.plugin.codegen.meta.JavaCode)1 ArrayList (java.util.ArrayList)1 BusinessException (org.talend.commons.exception.BusinessException)1 JetBean (org.talend.designer.codegen.config.JetBean)1 LightJetBean (org.talend.designer.codegen.config.LightJetBean)1 TalendJetEmitter (org.talend.designer.codegen.config.TalendJetEmitter)1