Search in sources :

Example 1 with EInternalTemplate

use of org.talend.designer.codegen.config.EInternalTemplate 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

File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Path (org.eclipse.core.runtime.Path)1 EInternalTemplate (org.talend.designer.codegen.config.EInternalTemplate)1 TemplateUtil (org.talend.designer.codegen.config.TemplateUtil)1