Search in sources :

Example 11 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method generateCode.

/**
     * DOC bqian Comment method "generateCode".
     */
protected void generateCode() {
    final IProcess2 process = getProcess();
    if (!(process.getProperty().getItem() instanceof ProcessItem)) {
        // shouldn't work for joblet
        return;
    }
    if (process.getGeneratingNodes().size() != 0) {
        Job job = new //$NON-NLS-1$
        AccessingEmfJob(//$NON-NLS-1$
        "Generating code") {

            @Override
            protected IStatus doRun(IProgressMonitor monitor) {
                try {
                    ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), false, false, true, ProcessorUtilities.GENERATE_WITH_FIRST_CHILD);
                } catch (ProcessorException e) {
                    ExceptionHandler.process(e);
                }
                return Status.OK_STATUS;
            }
        };
        job.setUser(true);
        job.setPriority(Job.BUILD);
        // start as soon as possible
        job.schedule();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProcessorException(org.talend.designer.runprocess.ProcessorException) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) AccessingEmfJob(org.talend.core.model.utils.AccessingEmfJob) IProcess2(org.talend.core.model.process.IProcess2) AccessingEmfJob(org.talend.core.model.utils.AccessingEmfJob) Job(org.eclipse.core.runtime.jobs.Job)

Example 12 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class JavaProcessor method generateCode.

/*
     * Append the generated java code form context into java file wihtin the project. If the file not existed new one
     * will be created.
     * 
     * @see org.talend.designer.runprocess.IProcessor#generateCode(org.talend.core .model.process.IContext, boolean,
     * boolean, boolean)
     */
@Override
public void generateCode(boolean statistics, boolean trace, boolean javaProperties, int option) throws ProcessorException {
    super.generateCode(statistics, trace, javaProperties, option);
    try {
        // hywang modified for 6484
        String currentJavaProject = ProjectManager.getInstance().getProject(property).getTechnicalLabel();
        ICodeGenerator codeGen;
        ICodeGeneratorService service = RunProcessPlugin.getDefault().getCodeGeneratorService();
        if (javaProperties) {
            //$NON-NLS-1$
            String javaInterpreter = "";
            //$NON-NLS-1$
            String javaLib = "";
            String javaContext = getContextPath().toPortableString();
            codeGen = service.createCodeGenerator(process, statistics, trace, javaInterpreter, javaLib, javaContext, currentJavaProject);
        } else {
            codeGen = service.createCodeGenerator(process, statistics, trace);
        }
        // set the selected context. if don't find, will keep default
        if (!process.getContextManager().getDefaultContext().getName().equals(context.getName())) {
            boolean found = false;
            for (IContext c : process.getContextManager().getListContext()) {
                if (c.getName().equals(context.getName())) {
                    found = true;
                }
            }
            if (found) {
                codeGen.setContextName(context.getName());
            }
        }
        //$NON-NLS-1$
        String processCode = "";
        try {
            // must before codegen for job to set the rule flag.
            if (PluginChecker.isRulesPluginLoaded()) {
                IRulesProviderService rulesService = (IRulesProviderService) GlobalServiceRegister.getDefault().getService(IRulesProviderService.class);
                if (rulesService != null) {
                    boolean useGenerateRuleFiles = false;
                    List<? extends INode> allNodes = this.process.getGeneratingNodes();
                    for (int i = 0; i < allNodes.size(); i++) {
                        if (allNodes.get(i) instanceof INode) {
                            INode node = allNodes.get(i);
                            if (rulesService.isRuleComponent(node) && !node.getElementParameter(EParameterName.PROPERTY_TYPE.getName()).getValue().toString().equals("BUILT_IN")) {
                                //$NON-NLS-1$
                                useGenerateRuleFiles = true;
                                break;
                            }
                        }
                    }
                    if (useGenerateRuleFiles && rulesService != null && currentJavaProject != null) {
                        rulesService.generateFinalRuleFiles(currentJavaProject, this.process);
                        LastGenerationInfo.getInstance().setUseRules(this.process.getId(), this.process.getVersion(), true);
                    }
                }
            }
            processCode = codeGen.generateProcessCode();
        } catch (SystemException e) {
            //$NON-NLS-1$
            throw new ProcessorException(Messages.getString("Processor.generationFailed"), e);
        } catch (IOException e) {
            ExceptionHandler.process(e);
        }
        if (!BitwiseOptionUtils.containOption(option, TalendProcessOptionConstants.GENERATE_WITHOUT_FORMAT)) {
            processCode = doFormat(processCode);
        }
        // see feature 4610:option to see byte length of each code method
        processCode = computeMethodSizeIfNeeded(processCode);
        InputStream codeStream = new ByteArrayInputStream(processCode.getBytes());
        // Generating files
        IFile codeFile = this.getCodeProject().getFile(this.getSrcCodePath());
        if (!codeFile.exists()) {
            // in win.
            try {
                org.talend.commons.utils.io.FilesUtils.removeExistedResources(null, codeFile, true, true);
            } catch (Exception e) {
                throw new ProcessorException(e);
            }
            IFolder parentFolder = (IFolder) codeFile.getParent();
            if (!parentFolder.exists()) {
                parentFolder.create(true, true, null);
            }
            codeFile.create(codeStream, true, null);
        } else {
            codeFile.setContents(codeStream, true, false, null);
        }
        // codeFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
        processCode = null;
        // updateContextCode(codeGen);
        //$NON-NLS-1$
        codeFile.getProject().deleteMarkers("org.eclipse.jdt.debug.javaLineBreakpointMarker", true, IResource.DEPTH_INFINITE);
        List<INode> breakpointNodes = CorePlugin.getContext().getBreakpointNodes(process);
        if (!breakpointNodes.isEmpty()) {
            String[] nodeNames = new String[breakpointNodes.size()];
            int pos = 0;
            String nodeName;
            for (INode node : breakpointNodes) {
                nodeName = node.getUniqueName();
                if (node.getComponent().getMultipleComponentManagers().size() > 0) {
                    //$NON-NLS-1$
                    nodeName += "_" + node.getComponent().getMultipleComponentManagers().get(0).getInput().getName();
                }
                //$NON-NLS-1$ //$NON-NLS-2$
                nodeNames[pos++] = "[" + nodeName + " main ] start";
            }
            int[] lineNumbers = getLineNumbers(codeFile, nodeNames);
            setBreakpoints(codeFile, getMainClass(), lineNumbers);
        }
    } catch (CoreException e1) {
        if (e1.getStatus() != null && e1.getStatus().getException() != null) {
            ExceptionHandler.process(e1.getStatus().getException());
        }
        //$NON-NLS-1$
        throw new ProcessorException(Messages.getString("Processor.tempFailed"), e1);
    }
}
Also used : INode(org.talend.core.model.process.INode) IContext(org.talend.core.model.process.IContext) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) IRulesProviderService(org.talend.core.ui.services.IRulesProviderService) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) ZipInputStream(java.util.zip.ZipInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) FilterInputStream(java.io.FilterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IJavaBreakpoint(org.eclipse.jdt.debug.core.IJavaBreakpoint) IJavaLineBreakpoint(org.eclipse.jdt.debug.core.IJavaLineBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) IOException(java.io.IOException) SystemException(org.talend.commons.exception.SystemException) ProcessorException(org.talend.designer.runprocess.ProcessorException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ICodeGenerator(org.talend.designer.codegen.ICodeGenerator) SystemException(org.talend.commons.exception.SystemException) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IFolder(org.eclipse.core.resources.IFolder)

Example 13 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class JavaProcessorUtilities method handleMissingJarsForProcess.

/**
     * 
     * Added by Marvin Wang on Nov 7, 2012.
     * 
     * @param missingJarsForRoutines
     * @param missingJarsForProcess
     * @param missingJars
     * @throws BusinessException
     */
private static void handleMissingJarsForProcess(Set<String> missingJarsForRoutines, final Set<String> missingJarsForProcess, String missingJars) throws ProcessorException {
    //$NON-NLS-1$
    final StringBuffer sb = new StringBuffer("");
    if (missingJarsForProcess.size() > 0) {
        //$NON-NLS-1$
        sb.append(Messages.getString("JavaProcessorUtilities.msg.missingjar.forProcess"));
        for (String missingJar : missingJarsForProcess) {
            sb.append(missingJar);
            //$NON-NLS-1$
            sb.append(", ");
        }
        if (missingJarsForRoutines.size() > 0) {
            // subForMsg(sb.toString());
            //$NON-NLS-1$
            sb.append("\r\n\r\n\r\n");
            //$NON-NLS-1$
            sb.append(Messages.getString("JavaProcessorUtilities.msg.missingjar.note"));
            //$NON-NLS-1$
            sb.append("\r\n");
            //$NON-NLS-1$
            sb.append(Messages.getString("JavaProcessorUtilities.msg.missingjar.onlyforroutine"));
            //$NON-NLS-1$
            sb.append("\r\n");
            for (String missingJar : missingJarsForRoutines) {
                sb.append(missingJar);
                //$NON-NLS-1$
                sb.append(", ");
            }
            subForMsg(sb.toString());
        } else {
            subForMsg(sb.toString());
        }
        if (!CommonsPlugin.isHeadless()) {
            Display display = DisplayUtils.getDisplay();
            if (display != null) {
                display.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        // fix for TDI-24906
                        MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), Messages.getString("JavaProcessorUtilities.msg.missingjar.warningtitle"), null, subForMsg(sb.toString()), 4, new String[] { IDialogConstants.OK_LABEL }, 0) {

                            /*
                                 * (non-Javadoc)
                                 * 
                                 * @see org.eclipse.jface.window.Window#setShellStyle(int)
                                 */
                            @Override
                            protected void setShellStyle(int newShellStyle) {
                                super.setShellStyle(getShellStyle() | SWT.APPLICATION_MODAL);
                            }
                        };
                        dialog.open();
                    }
                });
            }
        } else {
            throw new ProcessorException(missingJars);
        }
    } else {
        if (missingJarsForRoutines.size() > 0) {
            //$NON-NLS-1$
            sb.append(Messages.getString("JavaProcessorUtilities.msg.missingjar.onlyforroutine"));
            for (String missingJar : missingJarsForRoutines) {
                sb.append(missingJar);
                //$NON-NLS-1$
                sb.append(", ");
            }
            CommonExceptionHandler.warn(subForMsg(sb.toString()));
        }
    }
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Display(org.eclipse.swt.widgets.Display)

Example 14 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class AbstractJavaProcessor method buildExportZip.

protected String buildExportZip(ProcessItem processItem, IProgressMonitor progressMonitor) throws ProcessorException {
    Map<ExportChoice, Object> exportChoiceMap = JobScriptsManagerFactory.getDefaultExportChoiceMap();
    exportChoiceMap.put(ExportChoice.needLauncher, false);
    exportChoiceMap.put(ExportChoice.needJobItem, true);
    // exportChoiceMap.put(ExportChoice.needJobScript, true); //?? for old build? no need
    if (CommonsPlugin.isDebugMode()) {
        exportChoiceMap.put(ExportChoice.needSourceCode, true);
    } else {
        exportChoiceMap.put(ExportChoice.needSourceCode, false);
    }
    exportChoiceMap.put(ExportChoice.binaries, true);
    exportChoiceMap.put(ExportChoice.includeLibs, true);
    exportChoiceMap.put(ExportChoice.needAssembly, true);
    if (progressMonitor.isCanceled()) {
        throw new ProcessorException(new InterruptedException());
    }
    final String archiveFilePath = Path.fromOSString(CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.FILE_PATH_TEMP)).append(getFilePathPrefix() + '_' + process.getName() + FileExtensions.ZIP_FILE_SUFFIX).toString();
    try {
        exportChoiceMap.put(ExportChoice.needContext, true);
        String contextName = processItem.getProcess().getDefaultContext();
        exportChoiceMap.put(ExportChoice.contextName, contextName);
        buildJob(archiveFilePath, processItem, processItem.getProperty().getVersion(), contextName, exportChoiceMap, JobExportType.POJO, progressMonitor);
    } catch (Exception e) {
        throw new ProcessorException(e);
    } finally {
        ProcessorUtilities.resetExportConfig();
    }
    return archiveFilePath;
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) ProcessorException(org.talend.designer.runprocess.ProcessorException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 15 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class ExportProcessorHelper method exportPigudf.

public void exportPigudf(IProcessor processor, Property property, int statisticsPort, int tracePort) throws ProcessorException {
    // build java project
    CorePlugin.getDefault().getRunProcessService().buildJavaProject();
    Map<ExportChoice, Object> exportChoiceMap = new EnumMap<ExportChoice, Object>(ExportChoice.class);
    exportChoiceMap.put(ExportChoice.needPigudf, true);
    ProcessItem processItem = (ProcessItem) property.getItem();
    ExportFileResource fileResource = new ExportFileResource(processItem, property.getLabel());
    ExportFileResource[] exportFileResources = new ExportFileResource[] { fileResource };
    JobScriptsManager jobScriptsManager = JobScriptsManagerFactory.createManagerInstance(exportChoiceMap, processor.getContext().getName(), JobScriptsManager.ALL_ENVIRONMENTS, statisticsPort, tracePort, JobExportType.POJO);
    URL url = jobScriptsManager.getExportPigudfResources(exportFileResources);
    if (url == null) {
        return;
    }
    File file = new File(url.getFile());
    File libFolder = JavaProcessorUtilities.getJavaProjectLibFolder();
    if (libFolder == null) {
        return;
    }
    File target = new File(libFolder.getAbsolutePath() + property.getLabel() + "_" + property.getVersion() + "_" + file.getName());
    try {
        FilesUtils.copyFile(file, target);
    } catch (IOException e) {
        throw new ProcessorException(e.getMessage());
    }
}
Also used : JobScriptsManager(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager) ProcessorException(org.talend.designer.runprocess.ProcessorException) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) IOException(java.io.IOException) EnumMap(java.util.EnumMap) File(java.io.File) URL(java.net.URL)

Aggregations

ProcessorException (org.talend.designer.runprocess.ProcessorException)40 IOException (java.io.IOException)15 File (java.io.File)11 IProcessor (org.talend.designer.runprocess.IProcessor)11 CoreException (org.eclipse.core.runtime.CoreException)10 ProcessItem (org.talend.core.model.properties.ProcessItem)10 CsvArray (org.talend.core.utils.CsvArray)10 IContext (org.talend.core.model.process.IContext)9 Status (org.eclipse.core.runtime.Status)8 IProcess (org.talend.core.model.process.IProcess)8 ExportFileResource (org.talend.repository.documentation.ExportFileResource)7 IFile (org.eclipse.core.resources.IFile)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)5 PersistenceException (org.talend.commons.exception.PersistenceException)5 ExportChoice (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 IStatus (org.eclipse.core.runtime.IStatus)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4