Search in sources :

Example 1 with IComponentFileNaming

use of org.talend.core.model.components.IComponentFileNaming 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 IComponentFileNaming

use of org.talend.core.model.components.IComponentFileNaming 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)

Example 3 with IComponentFileNaming

use of org.talend.core.model.components.IComponentFileNaming 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);
            }
        }
    }
}
Also used : IComponentFileNaming(org.talend.core.model.components.IComponentFileNaming) JetBean(org.talend.designer.codegen.config.JetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean) EmfComponent(org.talend.designer.core.model.components.EmfComponent) IBrandingService(org.talend.core.ui.branding.IBrandingService) ECodePart(org.talend.core.model.temp.ECodePart)

Example 4 with IComponentFileNaming

use of org.talend.core.model.components.IComponentFileNaming in project tesb-studio-se by Talend.

the class NodeUtil method getTemplateURI.

public static String getTemplateURI(IComponent component, ECodePart part) {
    String bundle = component.getPathSource();
    String path = component.getName();
    IComponentFileNaming fileNaming = ComponentsFactoryProvider.getFileNamingInstance();
    String file = fileNaming.getJetFileName(component, ProcessUtil.getCodeLanguageExtension(), part);
    return getTemplateURI(bundle, path, file);
}
Also used : IComponentFileNaming(org.talend.core.model.components.IComponentFileNaming)

Aggregations

IComponentFileNaming (org.talend.core.model.components.IComponentFileNaming)4 JetBean (org.talend.designer.codegen.config.JetBean)3 CoreException (org.eclipse.core.runtime.CoreException)2 JETException (org.eclipse.emf.codegen.jet.JETException)2 CodeGeneratorArgument (org.talend.designer.codegen.config.CodeGeneratorArgument)2 CodeGeneratorException (org.talend.designer.codegen.exception.CodeGeneratorException)2 JetProxy (org.talend.designer.codegen.proxy.JetProxy)2 IComponent (org.talend.core.model.components.IComponent)1 ECodePart (org.talend.core.model.temp.ECodePart)1 IBrandingService (org.talend.core.ui.branding.IBrandingService)1 LightJetBean (org.talend.designer.codegen.config.LightJetBean)1 EmfComponent (org.talend.designer.core.model.components.EmfComponent)1