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;
}
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 "";
}
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;
}
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()));
}
}
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;
}
Aggregations