Search in sources :

Example 1 with TemplateUtil

use of org.talend.designer.codegen.config.TemplateUtil in project tdi-studio-se by Talend.

the class CodeGenerator method generateTypedComponentCode.

/**
     * Generate Code Part for a given Component.
     * 
     * @param type the internal component template
     * @param argument the bean
     * @param part part of code to generate
     * @param subProcess
     * @return the genrated code
     * @throws CodeGeneratorException if an error occurs during Code Generation
     */
private StringBuffer generateTypedComponentCode(EInternalTemplate type, Object argument, ECodePart part, String incomingName, NodesSubTree subProcess) throws CodeGeneratorException {
    CodeGeneratorArgument codeGenArgument = new CodeGeneratorArgument();
    codeGenArgument.setNode(argument);
    if (subProcess != null) {
        codeGenArgument.setAllMainSubTreeConnections(subProcess.getAllMainSubTreeConnections());
        codeGenArgument.setSubTree(subProcess);
    }
    codeGenArgument.setCodePart(part);
    codeGenArgument.setStatistics(statistics);
    codeGenArgument.setTrace(trace);
    codeGenArgument.setInterpreterPath(interpreterPath);
    codeGenArgument.setLibPath(libPath);
    codeGenArgument.setRuntimeFilePath(runtimeFilePath);
    codeGenArgument.setCurrentProjectName(currentProjectName);
    codeGenArgument.setContextName(contextName);
    codeGenArgument.setJobName(jobName);
    codeGenArgument.setJobVersion(jobVersion);
    codeGenArgument.setCheckingSyntax(checkingSyntax);
    codeGenArgument.setIncomingName(incomingName);
    codeGenArgument.setIsRunInMultiThread(getRunInMultiThread());
    codeGenArgument.setPauseTime(CorePlugin.getDefault().getRunProcessService().getPauseTime());
    JetBean jetBean = initializeJetBean(codeGenArgument);
    StringBuffer content = new StringBuffer();
    for (TemplateUtil template : CodeGeneratorInternalTemplatesFactoryProvider.getInstance().getTemplatesFromType(type)) {
        jetBean.setJetPluginRepository(template.getJetPluginRepository());
        jetBean.setTemplateRelativeUri(template.getTemplateRelativeUri());
        content.append(instantiateJetProxy(jetBean));
    }
    return content;
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) TemplateUtil(org.talend.designer.codegen.config.TemplateUtil) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument)

Example 2 with TemplateUtil

use of org.talend.designer.codegen.config.TemplateUtil in project tdi-studio-se by Talend.

the class CodeGenerator method generateContextCode.

/**
     * Parse Process, and generate Code for Context Variables.
     * 
     * @param designerContext the context to generate code from
     * @return the generated code
     * @throws CodeGeneratorException if an error occurs during Code Generation
     */
@Override
public String generateContextCode(IContext designerContext) throws CodeGeneratorException {
    if (process != null) {
        if (designerContext == null) {
            designerContext = process.getContextManager().getDefaultContext();
        }
        List<IContextParameter> listParameters = designerContext.getContextParameterList();
        if (listParameters != null) {
            List<IContextParameter> listParametersCopy = new ArrayList<IContextParameter>(listParameters.size());
            CodeGeneratorArgument codeGenArgument = new CodeGeneratorArgument();
            // encrypt the password
            for (IContextParameter iContextParameter : listParameters) {
                if (PasswordEncryptUtil.isPasswordType(iContextParameter.getType())) {
                    IContextParameter icp = iContextParameter.clone();
                    String pwd = icp.getValue();
                    if (pwd != null && !pwd.isEmpty()) {
                        try {
                            icp.setValue(PasswordEncryptUtil.encryptPasswordHex(pwd));
                        } catch (Exception e) {
                            log.error(e.getMessage(), e);
                        }
                    }
                    listParametersCopy.add(icp);
                } else {
                    listParametersCopy.add(iContextParameter);
                }
            }
            codeGenArgument.setNode(listParametersCopy);
            codeGenArgument.setContextName(designerContext.getName());
            codeGenArgument.setCurrentProjectName(currentProjectName);
            codeGenArgument.setJobName(jobName);
            codeGenArgument.setJobVersion(jobVersion);
            codeGenArgument.setIsRunInMultiThread(getRunInMultiThread());
            codeGenArgument.setPauseTime(CorePlugin.getDefault().getRunProcessService().getPauseTime());
            JetBean jetBean = initializeJetBean(codeGenArgument);
            StringBuffer content = new StringBuffer();
            for (TemplateUtil template : CodeGeneratorInternalTemplatesFactoryProvider.getInstance().getTemplatesFromType(EInternalTemplate.CONTEXT)) {
                jetBean.setJetPluginRepository(template.getJetPluginRepository());
                jetBean.setTemplateRelativeUri(template.getTemplateRelativeUri());
                content.append(instantiateJetProxy(jetBean));
            }
            return content.toString();
        }
    }
    //$NON-NLS-1$
    return "";
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) TemplateUtil(org.talend.designer.codegen.config.TemplateUtil) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) CoreException(org.eclipse.core.runtime.CoreException) JETException(org.eclipse.emf.codegen.jet.JETException) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException)

Example 3 with TemplateUtil

use of org.talend.designer.codegen.config.TemplateUtil in project tdi-studio-se by Talend.

the class JetSkeletonManager method getSystemSkeletons.

/**
     * DOC xtan get the skeleton file: subprocess_header_java.skeleton.
     * 
     * @return
     */
private static List<String> getSystemSkeletons() {
    List<String> skeletonList = new ArrayList<String>();
    // here add the skeleton file in org.talend.designer.codegen\resources
    FileFilter skeletonFilter = new FileFilter() {

        @Override
        public boolean accept(final File file) {
            String fileName = file.getName();
            return file.isFile() && fileName.charAt(0) != '.' && (fileName.endsWith(SKELETON_SUFFIX) || fileName.endsWith(INCLUDEFILEINJET_SUFFIX));
        }
    };
    for (TemplateUtil template : CodeGeneratorInternalTemplatesFactoryProvider.getInstance().getTemplates()) {
        Bundle b = Platform.getBundle(template.getJetPluginRepository());
        URL resourcesUrl = null;
        try {
            resourcesUrl = FileLocator.toFileURL(FileLocator.find(b, new Path(template.getTemplateRelativeUri()), null));
        } catch (IOException e) {
            ExceptionHandler.process(e);
        }
        if (resourcesUrl != null) {
            File resourcesDir = new File(resourcesUrl.getFile());
            File[] skeletonFiles = resourcesDir.listFiles(skeletonFilter);
            if (skeletonFiles != null) {
                for (File file : skeletonFiles) {
                    // path
                    skeletonList.add(file.getAbsolutePath());
                }
            }
        }
    }
    return skeletonList;
}
Also used : Path(org.eclipse.core.runtime.Path) TemplateUtil(org.talend.designer.codegen.config.TemplateUtil) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileFilter(java.io.FileFilter) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URL(java.net.URL)

Example 4 with TemplateUtil

use of org.talend.designer.codegen.config.TemplateUtil in project tesb-studio-se by Talend.

the class CamelJetFileProviderTest method testInitialize.

/**
 * Test method for
 * {@link org.talend.camel.designer.codegen.jet.CamelJetFileProvider#initializeStubAdditionalJetFile()}.
 */
@Test
public void testInitialize() {
    List<String> resTemplates = Arrays.asList(new String[] { "header_route", "footer_route", "camel_speciallinks", "camel_run_if" });
    List<TemplateUtil> templates = new CamelJetFileProvider().initializeStubAdditionalJetFile();
    for (TemplateUtil t : templates) {
        Assert.assertTrue(resTemplates.contains(t.getType().getTemplateName()));
    }
}
Also used : TemplateUtil(org.talend.designer.codegen.config.TemplateUtil) CamelJetFileProvider(org.talend.camel.designer.codegen.jet.CamelJetFileProvider) Test(org.junit.Test)

Example 5 with TemplateUtil

use of org.talend.designer.codegen.config.TemplateUtil in project tdi-studio-se by Talend.

the class CodeGeneratorInternalTemplatesFactory method getTemplatesFrom.

public static List<TemplateUtil> getTemplatesFrom(String pluginId, String directory) {
    List<TemplateUtil> templates = new ArrayList<>();
    try {
        // System.out.println("plugin:" + pluginId); //$NON-NLS-1$
        // $NON-NLS-1$
        URL url = FileLocator.find(Platform.getBundle(pluginId), new Path(directory), null);
        File fileDirectory = new File(FileLocator.toFileURL(url).getPath());
        for (File file : fileDirectory.listFiles()) {
            EInternalTemplate curentTemplate = null;
            if (file.getName().contains(EInternalTemplate.HEADER_ADDITIONAL.getTemplateName()) && file.getName().endsWith(TemplateUtil.EXT_SEP + ECodeLanguage.JAVA.getExtension() + TemplateUtil.TEMPLATE_EXT)) {
                curentTemplate = EInternalTemplate.HEADER_ADDITIONAL;
            } else {
                for (EInternalTemplate utilTemplate : EInternalTemplate.values()) {
                    if (file.getName().equals(utilTemplate.getTemplateName() + TemplateUtil.EXT_SEP + ECodeLanguage.JAVA.getExtension() + TemplateUtil.TEMPLATE_EXT)) {
                        curentTemplate = utilTemplate;
                        break;
                    }
                }
            }
            if (curentTemplate != null) {
                TemplateUtil template = new TemplateUtil(curentTemplate);
                template.setJetPluginRepository(pluginId);
                template.setTemplateRelativeUri(directory + TemplateUtil.DIR_SEP + file.getName());
                templates.add(template);
            // System.out.println("----template:" + file.getName()); //$NON-NLS-1$
            }
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    return templates;
}
Also used : Path(org.eclipse.core.runtime.Path) TemplateUtil(org.talend.designer.codegen.config.TemplateUtil) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) EInternalTemplate(org.talend.designer.codegen.config.EInternalTemplate)

Aggregations

TemplateUtil (org.talend.designer.codegen.config.TemplateUtil)6 ArrayList (java.util.ArrayList)3 CodeGeneratorArgument (org.talend.designer.codegen.config.CodeGeneratorArgument)3 JetBean (org.talend.designer.codegen.config.JetBean)3 File (java.io.File)2 IOException (java.io.IOException)2 URL (java.net.URL)2 Path (org.eclipse.core.runtime.Path)2 IContextParameter (org.talend.core.model.process.IContextParameter)2 FileFilter (java.io.FileFilter)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 JETException (org.eclipse.emf.codegen.jet.JETException)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 CamelJetFileProvider (org.talend.camel.designer.codegen.jet.CamelJetFileProvider)1 EInternalTemplate (org.talend.designer.codegen.config.EInternalTemplate)1 CodeGeneratorException (org.talend.designer.codegen.exception.CodeGeneratorException)1 CodeGeneratorInternalTemplatesFactory (org.talend.designer.codegen.model.CodeGeneratorInternalTemplatesFactory)1