Search in sources :

Example 6 with JETException

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;
            }
        }
    }
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean) TalendJetEmitter(org.talend.designer.codegen.config.TalendJetEmitter) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 7 with JETException

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Method(java.lang.reflect.Method) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) JETException(org.eclipse.emf.codegen.jet.JETException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 8 with JETException

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();
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) IComponentFileNaming(org.talend.core.model.components.IComponentFileNaming) CoreException(org.eclipse.core.runtime.CoreException) CodeGeneratorArgument(org.talend.designer.codegen.config.CodeGeneratorArgument) CodeGeneratorException(org.talend.designer.codegen.exception.CodeGeneratorException) JetProxy(org.talend.designer.codegen.proxy.JetProxy) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 9 with JETException

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IContainer(org.eclipse.core.resources.IContainer) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) JETException(org.eclipse.emf.codegen.jet.JETException)

Example 10 with JETException

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IContainer(org.eclipse.core.resources.IContainer) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) JETException(org.eclipse.emf.codegen.jet.JETException)

Aggregations

JETException (org.eclipse.emf.codegen.jet.JETException)13 CoreException (org.eclipse.core.runtime.CoreException)5 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 IContainer (org.eclipse.core.resources.IContainer)4 IFile (org.eclipse.core.resources.IFile)4 IPath (org.eclipse.core.runtime.IPath)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Path (org.eclipse.core.runtime.Path)4 JetBean (org.talend.designer.codegen.config.JetBean)4 CodeGeneratorException (org.talend.designer.codegen.exception.CodeGeneratorException)4 JetProxy (org.talend.designer.codegen.proxy.JetProxy)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 JETEmitter (org.eclipse.emf.codegen.jet.JETEmitter)3 CodeGeneratorArgument (org.talend.designer.codegen.config.CodeGeneratorArgument)3 IComponentFileNaming (org.talend.core.model.components.IComponentFileNaming)2 LightJetBean (org.talend.designer.codegen.config.LightJetBean)2 TalendJetEmitter (org.talend.designer.codegen.config.TalendJetEmitter)2 JavaCode (com.centurylink.mdw.plugin.codegen.meta.JavaCode)1