use of org.eclipse.emf.codegen.jet.JETException in project tdi-studio-se by Talend.
the class CodeGeneratorEmittersPoolFactory method synchronizedComponent.
private static void synchronizedComponent(List<JetBean> components, IProgressMonitor sub, List<JetBean> alreadyCompiledEmitters, TalendJetEmitter dummyEmitter, int monitorBuffer, IProgressMonitor monitorWrap) {
for (JetBean jetBean : components) {
if (!emitterPool.containsKey(jetBean)) {
ComponentCompilations.deleteMarkers();
// System.out.println("The new file is not in JetPersistence* cache:" + getFullTemplatePath(jetBean));
TalendJetEmitter emitter = new TalendJetEmitter(jetBean, dummyEmitter.getTalendEclipseHelper());
// wzhang modified to fix bug 11439
if (monitorWrap.isCanceled()) {
if (!CommonUIPlugin.isFullyHeadless()) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), //$NON-NLS-1$
Messages.getString("CodeGeneratorEmittersPoolFactory.operationCanceled"), //$NON-NLS-1$
Messages.getString("CodeGeneratorEmittersPoolFactory.dialogContent"));
}
});
}
return;
}
// 10901: Component synchronization fails
try {
emitter.initialize(sub);
} catch (JETException e) {
//$NON-NLS-1$
log.error(//$NON-NLS-1$
Messages.getString("CodeGeneratorEmittersPoolFactory.jetEmitterInitialException") + e.getMessage(), e);
continue;
}
if (emitter.isClassAvailable()) {
alreadyCompiledEmitters.add(jetBean);
} else {
jetFilesCompileFail.add(jetBean);
}
emitterPool.put(jetBean, emitter);
monitorBuffer++;
if (monitorBuffer % 100 == 0) {
monitorWrap.worked(100);
monitorBuffer = 0;
}
}
}
}
use of org.eclipse.emf.codegen.jet.JETException in project tdi-studio-se by Talend.
the class TalendJetEmitter method getMethod.
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.codegen.jet.JETEmitter#getMethod()
*/
@Override
public Method getMethod() {
Method localMethod = super.getMethod();
if (localMethod == null) {
try {
localMethod = loadMethod();
} catch (Exception e) {
// nothing since if got exception here, the method will be reloaded bellow. (normal case)
// real error should be logged if the initialize fail.
}
// This might be also called for custom components.
if (localMethod == null) {
try {
talendEclipseHelper.initialize(BasicMonitor.toMonitor(new NullProgressMonitor()), this, componentFamily, templateName, templateLanguage, codePart);
localMethod = super.getMethod();
} catch (JETException e) {
ExceptionHandler.process(e);
}
} else {
setMethod(localMethod);
}
}
return localMethod;
}
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
*/
@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();
}
use of org.eclipse.emf.codegen.jet.JETException in project mdw-designer by CenturyLinkCloud.
the class JetAccess method mergeXml.
/**
* Merges jet-generated XML into the JetAccess save file based on the
* specified outer containing element. The generated output is inserted
* before every occurrence of the closing tag of outerElement.
*
* @param monitor
* - 3 units are used
* @param contents
* @param outerElement
* @return
* @throws IOException
* @throws CoreException
*/
public IFile mergeXml(IProgressMonitor monitor, byte[] contents, String outerElement) throws IOException, CoreException, JETException {
monitor = createIfNull(monitor);
JetConfig config = getConfig();
IContainer container = findOrCreateContainer(monitor, config.getTargetFolder(), config.getPackageName());
if (container == null) {
throw new JETException("Cound not find or create container for package " + config.getPackageName() + " in " + config.getTargetFolder());
}
IFile targetFile = container.getFile(new Path(config.getTargetFile()));
IFile result = getWritableTargetFile(targetFile, container, config.getTargetFile());
InputStream newContents = new ByteArrayInputStream(contents);
if (result.exists()) {
newContents = addNewXml(result, new String(contents), outerElement);
result.setContents(newContents, true, true, new SubProgressMonitor(monitor, 2));
} else {
result.create(newContents, true, new SubProgressMonitor(monitor, 1));
}
return result;
}
use of org.eclipse.emf.codegen.jet.JETException in project mdw-designer by CenturyLinkCloud.
the class JetAccess method save.
/**
* Saves bytes to a location specified by the Config settings. The location
* of the file to save is determined by finding or creating the container
* (folder) for the Config's package in the Config's target folder. The name
* of the file to save is the Config's target file.
*
* @param monitor
* the progress monitor to use (may be null) - 2 units are used
* @param contents
* the byte contents of the file to save
* @throws CoreException
*/
public IFile save(IProgressMonitor monitor, byte[] contents) throws CoreException, JETException {
monitor = createIfNull(monitor);
JetConfig config = getConfig();
IContainer container = findOrCreateContainer(monitor, config.getTargetFolder(), config.getPackageName());
if (container == null) {
throw new JETException("Cound not find or create container for package " + config.getPackageName() + " in " + config.getTargetFolder());
}
IFile targetFile = container.getFile(new Path(config.getTargetFile()));
IFile result = getWritableTargetFile(targetFile, container, config.getTargetFile());
InputStream newContents = new ByteArrayInputStream(contents);
if (result.exists()) {
result.setContents(newContents, true, true, new SubProgressMonitor(monitor, 1));
} else {
result.create(newContents, true, new SubProgressMonitor(monitor, 1));
}
return result;
}
Aggregations