Search in sources :

Example 1 with JETException

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

the class CodeGenerator method generateComponentCode.

/**
     * Generate Part Code for a given Component.
     * 
     * @param node the component
     * @param part the component's part
     * @return the generated code
     * @throws CodeGeneratorException if an error occurs during Code Generation
     */
public String generateComponentCode(NodesSubTree subProcess, INode node, ECodePart part, String incomingName, ETypeGen typeGen) throws CodeGeneratorException {
    CodeGeneratorArgument argument = new CodeGeneratorArgument();
    argument.setNode(node);
    argument.setAllMainSubTreeConnections(subProcess.getAllMainSubTreeConnections());
    argument.setCodePart(part);
    argument.setStatistics(statistics);
    argument.setTrace(trace);
    argument.setInterpreterPath(interpreterPath);
    argument.setLibPath(libPath);
    argument.setRuntimeFilePath(runtimeFilePath);
    argument.setCurrentProjectName(currentProjectName);
    argument.setContextName(contextName);
    argument.setJobName(jobName);
    argument.setJobVersion(jobVersion);
    argument.setCheckingSyntax(checkingSyntax);
    argument.setIncomingName(incomingName);
    argument.setIsRunInMultiThread(getRunInMultiThread());
    argument.setPauseTime(CorePlugin.getDefault().getRunProcessService().getPauseTime());
    JetBean jetBean = initializeJetBean(argument);
    StringBuffer content = new StringBuffer();
    try {
        if (typeGen == ETypeGen.ETL) {
            content.append(generateTypedComponentCode(EInternalTemplate.PART_HEADER, node, part, incomingName, subProcess));
        }
        IComponentFileNaming componentFileNaming = ComponentsFactoryProvider.getFileNamingInstance();
        IComponent component = node.getComponent();
        String templateURI = component.getPathSource() + TemplateUtil.DIR_SEP + node.getComponent().getName() + TemplateUtil.DIR_SEP + componentFileNaming.getJetFileName(node.getComponent(), language.getExtension(), part);
        // Need rewrite templateURI for generic component since create a new JetBean .
        if (EComponentType.GENERIC.equals(component.getComponentType())) {
            templateURI = TemplateUtil.JET_STUB_DIRECTORY + TemplateUtil.DIR_SEP + TemplateUtil.RESOURCES_DIRECTORY_GENERIC + TemplateUtil.DIR_SEP + "component_" + //$NON-NLS-1$
            part.getName() + TemplateUtil.EXT_SEP + language.getExtension() + TemplateUtil.TEMPLATE_EXT;
        }
        jetBean.setTemplateRelativeUri(templateURI);
        JetProxy proxy = new JetProxy(jetBean);
        content.append(proxy.generate());
        if (jetBean.getGenerationError() != null) {
            throw new CodeGeneratorException(jetBean.getGenerationError());
        }
        if (typeGen == ETypeGen.ETL) {
            content.append(generateTypedComponentCode(EInternalTemplate.PART_FOOTER, node, part, incomingName, subProcess));
        }
    } catch (JETException jetException) {
        log.error(jetException.getMessage(), jetException);
        throw new CodeGeneratorException(//$NON-NLS-1$
        jetException.toString() + " in " + argument.getJobName() + " job", //$NON-NLS-1$
        jetException);
    } catch (CoreException coreException) {
        log.error(coreException.getMessage(), coreException);
        throw new CodeGeneratorException(coreException);
    }
    return content.toString();
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) IComponentFileNaming(org.talend.core.model.components.IComponentFileNaming) CoreException(org.eclipse.core.runtime.CoreException) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) IComponent(org.talend.core.model.components.IComponent) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) JetProxy(org.talend.designer.codegen.proxy.JetProxy) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 2 with JETException

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

the class CodeGenerator method instantiateJetProxy.

private StringBuffer instantiateJetProxy(JetBean jetBean) throws CodeGeneratorException {
    JetProxy proxy = new JetProxy(jetBean);
    StringBuffer content = new StringBuffer();
    try {
        content.append(proxy.generate());
    } catch (JETException e) {
        log.error(e.getMessage(), e);
        throw new CodeGeneratorException(e);
    } catch (CoreException e) {
        log.error(e.getMessage(), e);
        throw new CodeGeneratorException(e);
    }
    return content;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) JetProxy(org.talend.designer.codegen.proxy.JetProxy) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 3 with JETException

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

use of org.eclipse.emf.codegen.jet.JETException in project tesb-studio-se by Talend.

the class JetUtil method jetGenerate.

public static String jetGenerate(JetBean jetBean) throws CodeGeneratorException {
    JetProxy proxy = new JetProxy(jetBean);
    try {
        String codePart = proxy.generate();
        String generationError = jetBean.getGenerationError();
        if (generationError != null) {
            throw new CodeGeneratorException(generationError);
        }
        return codePart;
    } catch (JETException e) {
        log.error(e.getMessage(), e);
        CodeGeneratorArgument argument = (CodeGeneratorArgument) jetBean.getArgument();
        throw new CodeGeneratorException(e + " in " + argument.getJobName() + " route", e);
    } catch (CoreException e) {
        log.error(e.getMessage(), e);
        throw new CodeGeneratorException(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) JetProxy(org.talend.designer.codegen.proxy.JetProxy) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 5 with JETException

use of org.eclipse.emf.codegen.jet.JETException 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)

Aggregations

JETException (org.eclipse.emf.codegen.jet.JETException)13 CoreException (org.eclipse.core.runtime.CoreException)5 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 IContainer (org.eclipse.core.resources.IContainer)4 IFile (org.eclipse.core.resources.IFile)4 IPath (org.eclipse.core.runtime.IPath)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Path (org.eclipse.core.runtime.Path)4 JetBean (org.talend.designer.codegen.config.JetBean)4 CodeGeneratorException (org.talend.designer.codegen.exception.CodeGeneratorException)4 JetProxy (org.talend.designer.codegen.proxy.JetProxy)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 JETEmitter (org.eclipse.emf.codegen.jet.JETEmitter)3 CodeGeneratorArgument (org.talend.designer.codegen.config.CodeGeneratorArgument)3 IComponentFileNaming (org.talend.core.model.components.IComponentFileNaming)2 LightJetBean (org.talend.designer.codegen.config.LightJetBean)2 TalendJetEmitter (org.talend.designer.codegen.config.TalendJetEmitter)2 JavaCode (com.centurylink.mdw.plugin.codegen.meta.JavaCode)1