use of org.eclipse.emf.codegen.jet.JETException 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();
}
use of org.eclipse.emf.codegen.jet.JETException in project tdi-studio-se by Talend.
the class CodeGenerator method instantiateJetProxy.
private StringBuffer instantiateJetProxy(JetBean jetBean) throws CodeGeneratorException {
JetProxy proxy = new JetProxy(jetBean);
StringBuffer content = new StringBuffer();
try {
content.append(proxy.generate());
} catch (JETException e) {
log.error(e.getMessage(), e);
throw new CodeGeneratorException(e);
} catch (CoreException e) {
log.error(e.getMessage(), e);
throw new CodeGeneratorException(e);
}
return content;
}
use of org.eclipse.emf.codegen.jet.JETException in project mdw-designer by CenturyLinkCloud.
the class JavaEditorValueProvider method getArtifactContent.
public byte[] getArtifactContent() {
String text = activity.getAttribute(getAttributeName());
if (text == null || text.trim().length() == 0) {
try {
// initialize from template
String template = "/templates/source/executors/JavaExecutor.javajet";
if (!getProject().checkRequiredVersion(6, 0))
template = "/templates/source/55/executors/JavaExecutor.javajet";
if (!getProject().checkRequiredVersion(5, 5))
template = "/templates/source/52/executors/JavaExecutor.javajet";
String templateUri = Platform.getBundle(MdwPlugin.getPluginId()).getEntry("/").toString() + template;
JETEmitter emitter = new JETEmitter(templateUri, getClass().getClassLoader());
emitter.addVariable(null, MdwPlugin.getPluginId());
Map<String, Object> map = new HashMap<String, Object>();
map.put("model", this);
map.put("settings", MdwPlugin.getSettings());
text = emitter.generate(new NullProgressMonitor(), new Object[] { map });
activity.setAttribute(getAttributeName(), text);
activity.fireDirtyStateChanged(true);
} catch (JETException ex) {
PluginMessages.uiError(ex, "Generate Java", getProject());
}
}
return text.getBytes();
}
use of org.eclipse.emf.codegen.jet.JETException in project tesb-studio-se by Talend.
the class JetUtil method jetGenerate.
public static String jetGenerate(JetBean jetBean) throws CodeGeneratorException {
JetProxy proxy = new JetProxy(jetBean);
try {
String codePart = proxy.generate();
String generationError = jetBean.getGenerationError();
if (generationError != null) {
throw new CodeGeneratorException(generationError);
}
return codePart;
} catch (JETException e) {
log.error(e.getMessage(), e);
CodeGeneratorArgument argument = (CodeGeneratorArgument) jetBean.getArgument();
throw new CodeGeneratorException(e + " in " + argument.getJobName() + " route", e);
} catch (CoreException e) {
log.error(e.getMessage(), e);
throw new CodeGeneratorException(e);
}
}
use of org.eclipse.emf.codegen.jet.JETException in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method initializeEmittersPool.
/**
* real pool initialization.
*
* @param monitorWrap
*
* @return
* @throws JETException
*/
private static void initializeEmittersPool(List<JetBean> components, ECodeLanguage codeLanguage, IProgressMonitor monitorWrap) {
IProgressMonitor monitor = new NullProgressMonitor();
IProgressMonitor sub = new SubProgressMonitor(monitor, 1);
int monitorBuffer = 0;
HashMap<String, String> globalClasspath = new HashMap<String, String>();
for (JetBean jetBean : components) {
globalClasspath.putAll(jetBean.getClassPath());
// compute the CRC
jetBean.setCrc(extractTemplateHashCode(jetBean));
}
emitterPool = new HashMap<JetBean, JETEmitter>();
List<JetBean> alreadyCompiledEmitters = new ArrayList<JetBean>();
// try {
TalendJetEmitter dummyEmitter = null;
try {
dummyEmitter = new TalendJetEmitter(null, null, sub, globalClasspath, !ComponentCompilations.getMarkers());
} catch (JETException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.jetEmitterInitialException") + e.getMessage(), e);
}
boolean isSkeletonChanged = JetSkeletonManager.updateSkeletonPersistenceData();
if (!isSkeletonChanged) {
try {
alreadyCompiledEmitters = loadEmfPersistentData(EmfEmittersPersistenceFactory.getInstance(codeLanguage).loadEmittersPool(), components, monitorWrap);
for (JetBean jetBean : alreadyCompiledEmitters) {
TalendJetEmitter emitter = new TalendJetEmitter(jetBean, dummyEmitter.getTalendEclipseHelper());
emitterPool.put(jetBean, emitter);
monitorBuffer++;
if (monitorBuffer % 100 == 0) {
monitorWrap.worked(100);
monitorBuffer = 0;
}
}
} catch (BusinessException e) {
// error already loggued
emitterPool = new HashMap<JetBean, JETEmitter>();
}
} else {
ComponentCompilations.deleteMarkers();
}
synchronizedComponent(components, sub, alreadyCompiledEmitters, dummyEmitter, monitorBuffer, monitorWrap);
monitorWrap.worked(monitorBuffer);
try {
EmfEmittersPersistenceFactory.getInstance(codeLanguage).saveEmittersPool(extractEmfPersistenData(alreadyCompiledEmitters));
} catch (BusinessException e) {
//$NON-NLS-1$
log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.PersitentData.Error") + e.getMessage(), e);
}
}
Aggregations