Search in sources :

Example 6 with SystemException

use of org.talend.commons.exception.SystemException 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 7 with SystemException

use of org.talend.commons.exception.SystemException in project tdi-studio-se by Talend.

the class LogRowNode method getGeneratedCode.

/*
     * (non-Java)
     * 
     * @see org.talend.core.model.process.INode#getGeneratedCode()
     */
public String getGeneratedCode() {
    String generatedCode;
    try {
        ICodeGeneratorService service = PluginUtils.getCodeGeneratorService();
        generatedCode = service.createCodeGenerator().generateComponentCode(this, ECodePart.MAIN);
    } catch (SystemException e) {
        generatedCode = null;
    }
    return generatedCode;
}
Also used : SystemException(org.talend.commons.exception.SystemException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService)

Example 8 with SystemException

use of org.talend.commons.exception.SystemException in project tdi-studio-se by Talend.

the class WSDL2JAVAController method syncRoutine.

/**
     * DOC xtan there will be refactor for this method with JavaRoutineSynchronizer.syncRoutine().
     * 
     * @param routineItem
     * @param copyToTemp
     * @return
     * @throws SystemException
     */
private IFile syncRoutine(RoutineItem routineItem, boolean copyToTemp, String name) throws SystemException {
    FileOutputStream fos = null;
    try {
        IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return null;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IFile file = srcFolder.getFile(JavaUtils.JAVA_ROUTINES_DIRECTORY + '/' + routineItem.getProperty().getLabel() + JavaUtils.JAVA_EXTENSION);
        if (copyToTemp) {
            String routineContent = new String(routineItem.getContent().getInnerContent());
            routineContent = chanageRoutinesPackage(routineContent, name);
            String label = routineItem.getProperty().getLabel();
            if (!label.equals(ITalendSynchronizer.TEMPLATE)) {
                routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
                File f = file.getLocation().toFile();
                fos = new FileOutputStream(f);
                fos.write(routineContent.getBytes());
                fos.close();
            }
        }
        if (!file.exists()) {
            file.refreshLocal(1, null);
        }
        return file;
    } catch (CoreException e) {
        throw new SystemException(e);
    } catch (IOException e) {
        throw new SystemException(e);
    } finally {
        try {
            fos.close();
        } catch (Exception e) {
            // ignore me even if i'm null
            ExceptionHandler.process(e);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) FileOutputStream(java.io.FileOutputStream) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Example 9 with SystemException

use of org.talend.commons.exception.SystemException in project tdi-studio-se by Talend.

the class EditRoutineAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
protected void doRun() {
    if (repositoryNode == null) {
        repositoryNode = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    }
    RoutineItem routineItem = (RoutineItem) repositoryNode.getObject().getProperty().getItem();
    try {
        openRoutineEditor(routineItem, false);
        refresh(repositoryNode);
        // CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
        CorePlugin.getDefault().getRunProcessService().updateLibraries(new HashSet<ModuleNeeded>(), null);
    } catch (PartInitException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (SystemException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : SystemException(org.talend.commons.exception.SystemException) RoutineItem(org.talend.core.model.properties.RoutineItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 10 with SystemException

use of org.talend.commons.exception.SystemException in project tdi-studio-se by Talend.

the class ReadRoutineAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
protected void doRun() {
    if (repositoryNode == null && getSelection() != null) {
        repositoryNode = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    }
    RoutineItem routineItem = (RoutineItem) repositoryNode.getObject().getProperty().getItem();
    Property updatedProperty = null;
    try {
        updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(routineItem)), routineItem.getProperty().getId()).getProperty();
    // repositoryNode.getObject().setProperty(updatedProperty);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    routineItem = (RoutineItem) repositoryNode.getObject().getProperty().getItem();
    try {
        openRoutineEditor(routineItem, true);
    } catch (PartInitException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (SystemException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : Project(org.talend.core.model.general.Project) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) RoutineItem(org.talend.core.model.properties.RoutineItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) Property(org.talend.core.model.properties.Property)

Aggregations

SystemException (org.talend.commons.exception.SystemException)24 IFile (org.eclipse.core.resources.IFile)10 PartInitException (org.eclipse.ui.PartInitException)9 CoreException (org.eclipse.core.runtime.CoreException)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 IOException (java.io.IOException)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 Property (org.talend.core.model.properties.Property)5 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)5 RepositoryNode (org.talend.repository.model.RepositoryNode)5 File (java.io.File)4 RoutineItem (org.talend.core.model.properties.RoutineItem)4 FileOutputStream (java.io.FileOutputStream)3 IPath (org.eclipse.core.runtime.IPath)3 ISelection (org.eclipse.jface.viewers.ISelection)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 Project (org.talend.core.model.general.Project)3 Item (org.talend.core.model.properties.Item)3 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)3 BufferedInputStream (java.io.BufferedInputStream)2