Search in sources :

Example 11 with ITalendSynchronizer

use of org.talend.designer.codegen.ITalendSynchronizer in project tdi-studio-se by Talend.

the class ProblemsView method restoreProblem.

/**
     * 
     * ggu Comment method "restoreProblem".
     * 
     * when restore the item, check the problem.
     */
private void restoreProblem(RoutineItem item) {
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ITalendSynchronizer routineSynchronizer = null;
    switch(LanguageManager.getCurrentLanguage()) {
        case JAVA:
            routineSynchronizer = service.createJavaRoutineSynchronizer();
            break;
        case PERL:
            routineSynchronizer = service.createPerlRoutineSynchronizer();
            break;
        default:
    }
    if (routineSynchronizer != null) {
        try {
            routineSynchronizer.syncRoutine(item, true);
            IFile file = routineSynchronizer.getFile(item);
            if (file == null) {
                return;
            }
            file.refreshLocal(IResource.DEPTH_ONE, null);
            Problems.addRoutineFile(file, item.getProperty());
        } catch (SystemException e) {
            ExceptionHandler.process(e);
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                Problems.refreshProblemTreeView();
            }
        });
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) SystemException(org.talend.commons.exception.SystemException) CoreException(org.eclipse.core.runtime.CoreException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService)

Example 12 with ITalendSynchronizer

use of org.talend.designer.codegen.ITalendSynchronizer in project tdi-studio-se by Talend.

the class JavaCompilationParticipant method updateProblems.

/**
     * yzhang Comment method "updateProblems".
     */
private void updateProblems(List<IRepositoryViewObject> routineObjectList, String filePath) {
    IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
    try {
        ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return;
        }
        final ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        IProject javaProject = talendProcessJavaProject.getProject();
        IFile file = javaProject.getFile(filePath);
        String fileName = file.getName();
        for (IRepositoryViewObject repositoryObject : routineObjectList) {
            Property property = repositoryObject.getProperty();
            Item item = property.getItem();
            IFile currentFile = synchronizer.getFile(item);
            if (currentFile != null && fileName.equals(currentFile.getName()) && currentFile.exists()) {
                Problems.addRoutineFile(currentFile, property);
                break;
            }
        }
    } catch (SystemException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) Item(org.talend.core.model.properties.Item) IFile(org.eclipse.core.resources.IFile) SystemException(org.talend.commons.exception.SystemException) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProject(org.eclipse.core.resources.IProject)

Example 13 with ITalendSynchronizer

use of org.talend.designer.codegen.ITalendSynchronizer in project tdi-studio-se by Talend.

the class JobErrorsChecker method checkLastGenerationHasCompilationError.

public static void checkLastGenerationHasCompilationError(boolean updateProblemsView) throws ProcessorException {
    if (updateProblemsView && CommonsPlugin.isHeadless()) {
        updateProblemsView = false;
    }
    boolean hasError = false;
    boolean isJob = true;
    Item item = null;
    final IProxyRepositoryFactory proxyRepositoryFactory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    final ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
    Integer line = null;
    String errorMessage = null;
    try {
        for (JobInfo jobInfo : LastGenerationInfo.getInstance().getLastGeneratedjobs()) {
            if (jobInfo.isTestContainer()) {
                continue;
            }
            item = null;
            List<IRepositoryViewObject> allVersions = proxyRepositoryFactory.getAllVersion(jobInfo.getJobId());
            for (IRepositoryViewObject repositoryObject2 : allVersions) {
                Property property2 = repositoryObject2.getProperty();
                if (jobInfo.getJobVersion().equals(property2.getVersion())) {
                    item = property2.getItem();
                    break;
                }
            }
            if (item == null) {
                continue;
            }
            IFile file = synchronizer.getFile(item);
            if (file == null) {
                return;
            }
            // check other java files related to the job . example : spark job will generate several java file for
            // one job
            final IResource[] members = file.getParent().members();
            for (IResource member : members) {
                if (member instanceof IFile && "java".equals(member.getFileExtension())) {
                    IMarker[] markers = ((IFile) member).findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE);
                    for (IMarker marker : markers) {
                        Integer lineNr = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
                        String message = (String) marker.getAttribute(IMarker.MESSAGE);
                        Integer severity = (Integer) marker.getAttribute(IMarker.SEVERITY);
                        Integer start = (Integer) marker.getAttribute(IMarker.CHAR_START);
                        Integer end = (Integer) marker.getAttribute(IMarker.CHAR_END);
                        if (lineNr != null && message != null && severity != null && start != null && end != null) {
                            switch(severity) {
                                case IMarker.SEVERITY_ERROR:
                                    hasError = true;
                                    line = lineNr;
                                    errorMessage = message;
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
            if (updateProblemsView) {
                Problems.addRoutineFile(file, ProblemType.JOB, item.getProperty().getLabel(), item.getProperty().getVersion(), true);
            }
            if (hasError) {
                break;
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    if (hasError && item != null) {
        if (isJob) {
            throw new ProcessorException(//$NON-NLS-1$
            Messages.getString("JobErrorsChecker_compile_errors") + " " + '\n' + Messages.getString("JobErrorsChecker_compile_error_message", item.getProperty().getLabel()) + //$NON-NLS-1$
            '\n' + Messages.getString("JobErrorsChecker_compile_error_line") + ':' + ' ' + line + //$NON-NLS-1$
            '\n' + Messages.getString("JobErrorsChecker_compile_error_detailmessage") + ':' + ' ' + errorMessage + //$NON-NLS-1$
            '\n' + //$NON-NLS-1$
            Messages.getString("JobErrorsChecker_compile_error_jvmmessage"));
        } else {
            throw new ProcessorException(//$NON-NLS-1$
            Messages.getString("CamelJobErrorsChecker_compile_errors") + " " + '\n' + Messages.getString("JobErrorsChecker_compile_error_message", item.getProperty().getLabel()) + //$NON-NLS-1$
            '\n' + Messages.getString("JobErrorsChecker_compile_error_line") + ':' + ' ' + line + //$NON-NLS-1$
            '\n' + Messages.getString("JobErrorsChecker_compile_error_detailmessage") + ':' + ' ' + errorMessage + //$NON-NLS-1$
            '\n' + //$NON-NLS-1$
            Messages.getString("JobErrorsChecker_compile_error_jvmmessage"));
        }
    }
    // if no error for job, check codes.
    checkRoutinesCompilationError();
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) JobInfo(org.talend.core.model.process.JobInfo) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IMarker(org.eclipse.core.resources.IMarker) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IResource(org.eclipse.core.resources.IResource)

Aggregations

ITalendSynchronizer (org.talend.designer.codegen.ITalendSynchronizer)13 IFile (org.eclipse.core.resources.IFile)11 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)7 CoreException (org.eclipse.core.runtime.CoreException)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 SystemException (org.talend.commons.exception.SystemException)6 Item (org.talend.core.model.properties.Item)5 Property (org.talend.core.model.properties.Property)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 IMarker (org.eclipse.core.resources.IMarker)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 Problem (org.talend.core.model.process.Problem)3 TalendProblem (org.talend.core.model.process.TalendProblem)3 RoutineItem (org.talend.core.model.properties.RoutineItem)3 HashSet (java.util.HashSet)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IEditorReference (org.eclipse.ui.IEditorReference)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2 IProcess (org.talend.core.model.process.IProcess)2