Search in sources :

Example 6 with CodeGeneratorException

use of org.talend.designer.codegen.exception.CodeGeneratorException in project tdi-studio-se by Talend.

the class CodeGenerator method generateProcessCode.

/**
     * Generate the code for the process given to the constructor.
     * 
     * @return the generated code
     * @throws CodeGeneratorException if an error occurs during Code Generation
     */
@Override
@SuppressWarnings("unchecked")
public String generateProcessCode() throws CodeGeneratorException {
    // Parse Process, generate Code for Individual Components
    // generate Assembly Code for individual Components
    StringBuffer componentsCode = new StringBuffer();
    long startTimer = System.currentTimeMillis();
    long endTimer = startTimer;
    try {
        while ((!CodeGeneratorEmittersPoolFactory.isInitialized()) && ((endTimer - startTimer) < INIT_TIMEOUT)) {
            Thread.sleep(INIT_PAUSE);
            endTimer = System.currentTimeMillis();
        }
    } catch (InterruptedException e) {
        log.error(e.getMessage(), e);
        throw new CodeGeneratorException(e);
    }
    if ((endTimer - startTimer) > INIT_TIMEOUT) {
        //$NON-NLS-1$
        throw new CodeGeneratorException(Messages.getString("CodeGenerator.JET.TimeOut"));
    } else {
        // ####0005204: Cannot Call SubJob with RunJob Component
        Vector headerArgument = new Vector(3);
        headerArgument.add(process);
        headerArgument.add(VersionUtils.getVersion());
        componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER, headerArgument));
        // ####
        componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER_ADDITIONAL, headerArgument));
        if ((processTree.getSubTrees() != null) && (processTree.getSubTrees().size() > 0)) {
            boolean displayMethodSize = isMethodSizeNeeded();
            for (NodesSubTree subTree : processTree.getSubTrees()) {
                subTree.setMethodSizeNeeded(displayMethodSize);
                if (!subTree.isMergeSubTree()) {
                    componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER, subTree));
                    componentsCode.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.BEGIN, null));
                    componentsCode.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.MAIN, null));
                    componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN, subTree.getRootNode()));
                    componentsCode.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.END, null));
                    StringBuffer finallyPart = new StringBuffer();
                    finallyPart.append(generateComponentsCode(subTree, subTree.getRootNode(), ECodePart.FINALLY, null));
                    Vector subprocess_footerArgument = new Vector(2);
                    subprocess_footerArgument.add(subTree);
                    subprocess_footerArgument.add(finallyPart.toString());
                    componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER, subprocess_footerArgument));
                } else {
                    StringBuffer finallyPart = new StringBuffer();
                    componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER, subTree));
                    for (INode mergeNode : subTree.getMergeNodes()) {
                        componentsCode.append(generateComponentsCode(subTree, mergeNode, ECodePart.BEGIN, null));
                    }
                    List<INode> sortedMergeBranchStarts = subTree.getSortedMergeBranchStarts();
                    for (INode startNode : sortedMergeBranchStarts) {
                        componentsCode.append(generateComponentsCode(subTree, startNode, ECodePart.BEGIN, null));
                        componentsCode.append(generateComponentsCode(subTree, startNode, ECodePart.MAIN, null));
                        componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN, subTree.getRootNode()));
                        componentsCode.append(generateComponentsCode(subTree, startNode, ECodePart.END, null));
                        finallyPart.append(generateComponentsCode(subTree, startNode, ECodePart.FINALLY, null));
                    }
                    for (INode mergeNode : subTree.getMergeNodes()) {
                        componentsCode.append(generateComponentsCode(subTree, mergeNode, ECodePart.END, null));
                        finallyPart.append(generateComponentsCode(subTree, mergeNode, ECodePart.FINALLY, null));
                    }
                    Vector subprocess_footerArgument = new Vector(2);
                    subprocess_footerArgument.add(subTree);
                    subprocess_footerArgument.add(finallyPart.toString());
                    componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER, subprocess_footerArgument));
                }
            }
        }
        // ####0005204: Cannot Call SubJob with RunJob Component
        Vector footerArgument = new Vector(2);
        footerArgument.add(process);
        footerArgument.add(processTree.getRootNodes());
        componentsCode.append(generateTypedComponentCode(EInternalTemplate.FOOTER, footerArgument));
        componentsCode.append(generateTypedComponentCode(EInternalTemplate.PROCESSINFO, componentsCode.length()));
        // ####
        return componentsCode.toString();
    }
}
Also used : INode(org.talend.core.model.process.INode) NodesSubTree(org.talend.designer.codegen.config.NodesSubTree) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) Vector(java.util.Vector)

Example 7 with CodeGeneratorException

use of org.talend.designer.codegen.exception.CodeGeneratorException in project tesb-studio-se by Talend.

the class JetUtil method checkEmittersPoolFactoryIsReady.

public static void checkEmittersPoolFactoryIsReady() throws CodeGeneratorException {
    long startTimer = System.currentTimeMillis();
    long endTimer = startTimer;
    try {
        while (!CodeGeneratorEmittersPoolFactory.isInitialized() && (endTimer - startTimer) < INIT_TIMEOUT) {
            Thread.sleep(INIT_PAUSE);
            endTimer = System.currentTimeMillis();
        }
    } catch (InterruptedException e) {
        log.error(e.getMessage(), e);
        throw new CodeGeneratorException(e);
    }
    if ((endTimer - startTimer) > INIT_TIMEOUT) {
        //$NON-NLS-1$
        throw new CodeGeneratorException(Messages.getString("CodeGenerator.JET.TimeOut"));
    }
}
Also used : CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException)

Example 8 with CodeGeneratorException

use of org.talend.designer.codegen.exception.CodeGeneratorException 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
     */
@Override
public String generateComponentCode(INode node, ECodePart part) throws CodeGeneratorException {
    CodeGeneratorArgument argument = new CodeGeneratorArgument();
    argument.setNode(node);
    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.setIsRunInMultiThread(getRunInMultiThread());
    argument.setPauseTime(CorePlugin.getDefault().getRunProcessService().getPauseTime());
    JetBean jetBean = initializeJetBean(argument);
    StringBuffer content = new StringBuffer();
    try {
        content.append(generateTypedComponentCode(EInternalTemplate.PART_HEADER, node, part));
        IComponentFileNaming componentFileNaming = ComponentsFactoryProvider.getFileNamingInstance();
        String templateURI = node.getComponent().getPathSource() + TemplateUtil.DIR_SEP + node.getComponent().getName() + TemplateUtil.DIR_SEP + componentFileNaming.getJetFileName(node.getComponent(), language.getExtension(), part);
        jetBean.setTemplateRelativeUri(templateURI);
        JetProxy proxy = new JetProxy(jetBean);
        content.append(proxy.generate());
        content.append(generateTypedComponentCode(EInternalTemplate.PART_FOOTER, node, part));
    } catch (JETException jetException) {
        log.error(jetException.getMessage(), jetException);
        throw new CodeGeneratorException(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) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) JetProxy(org.talend.designer.codegen.proxy.JetProxy) JETException(org.eclipse.emf.codegen.jet.JETException)

Aggregations

CodeGeneratorException (org.talend.designer.codegen.exception.CodeGeneratorException)8 CoreException (org.eclipse.core.runtime.CoreException)5 JETException (org.eclipse.emf.codegen.jet.JETException)5 CodeGeneratorArgument (org.talend.designer.codegen.config.CodeGeneratorArgument)4 JetProxy (org.talend.designer.codegen.proxy.JetProxy)4 JetBean (org.talend.designer.codegen.config.JetBean)3 Vector (java.util.Vector)2 IComponentFileNaming (org.talend.core.model.components.IComponentFileNaming)2 INode (org.talend.core.model.process.INode)2 NodesSubTree (org.talend.designer.codegen.config.NodesSubTree)2 ArrayList (java.util.ArrayList)1 IComponent (org.talend.core.model.components.IComponent)1 IContextParameter (org.talend.core.model.process.IContextParameter)1 TemplateUtil (org.talend.designer.codegen.config.TemplateUtil)1