Search in sources :

Example 6 with IMarker

use of org.eclipse.core.resources.IMarker in project tdi-studio-se by Talend.

the class JobErrorsChecker method checkExportErrors.

public static boolean checkExportErrors(IStructuredSelection selection, boolean isJob) {
    if (!selection.isEmpty()) {
        final ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        Set<String> jobIds = new HashSet<String>();
        List<RepositoryNode> nodes = selection.toList();
        if (nodes.size() > 1) {
            // in case it's a multiple export, only check the status of the latest job to export
            for (RepositoryNode node : nodes) {
                Item item = node.getObject().getProperty().getItem();
                try {
                    IFile sourceFile = synchronizer.getFile(item);
                    if (sourceFile == null) {
                        return false;
                    }
                    // check the item has compile error when export job
                    boolean ret = false;
                    String message = null;
                    IMarker[] markers = sourceFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE);
                    for (IMarker marker : markers) {
                        Integer lineNr = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
                        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:
                                    ret = true;
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    if (ret) {
                        if (isJob) {
                            throw new ProcessorException(//$NON-NLS-1$
                            Messages.getString("JobErrorsChecker_compile_errors") + '\n' + Messages.getString("JobErrorsChecker_compile_error_content", //$NON-NLS-1$
                            item.getProperty().getLabel()) + '\n' + message);
                        } else {
                            throw new ProcessorException(//$NON-NLS-1$
                            Messages.getString("CamelJobErrorsChecker_compile_errors") + '\n' + Messages.getString("CamelJobErrorsChecker_compile_error_content", //$NON-NLS-1$
                            item.getProperty().getLabel()) + '\n' + message);
                        }
                    }
                    jobIds.add(item.getProperty().getId());
                    Problems.addRoutineFile(sourceFile, ProblemType.JOB, item.getProperty().getLabel(), item.getProperty().getVersion(), true);
                } catch (Exception e) {
                    MessageBoxExceptionHandler.process(e);
                    return true;
                }
            }
        } else {
            // if single export (normal case), check compilation status from latest generation.
            try {
                checkLastGenerationHasCompilationError(true);
            } catch (Exception e) {
                if (CommonsPlugin.isHeadless()) {
                    CommonExceptionHandler.process(e);
                    // trace in command status.
                    throw new RuntimeException(e);
                }
                MessageBoxExceptionHandler.process(e);
                return true;
            }
        }
        for (RepositoryNode node : nodes) {
            Item item = node.getObject().getProperty().getItem();
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            IProcess process = service.getProcessFromItem(item);
            if (process instanceof IProcess2) {
                ((IProcess2) process).checkProcess();
            }
        }
        Problems.refreshProblemTreeView();
        List<Problem> errors = Problems.getProblemList().getProblemsBySeverity(ProblemStatus.ERROR);
        ErrorDetailTreeBuilder builder = new ErrorDetailTreeBuilder();
        List<JobErrorEntry> input = builder.createTreeInput(errors, jobIds);
        try {
            if (input.size() > 0) {
                String label = input.get(0).getLabel();
                if (isJob) {
                    throw new ProcessorException(//$NON-NLS-1$
                    Messages.getString("JobErrorsChecker_compile_errors") + '\n' + //$NON-NLS-1$
                    Messages.getString("JobErrorsChecker_compile_error_content", label));
                } else {
                    throw new ProcessorException(//$NON-NLS-1$
                    Messages.getString("CamelJobErrorsChecker_compile_errors") + '\n' + //$NON-NLS-1$
                    Messages.getString("CamelJobErrorsChecker_compile_error_content", label));
                }
            }
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e);
            return true;
        }
    }
    return false;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) RepositoryNode(org.talend.repository.model.RepositoryNode) 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) IProcess2(org.talend.core.model.process.IProcess2) TalendProblem(org.talend.core.model.process.TalendProblem) Problem(org.talend.core.model.process.Problem) IMarker(org.eclipse.core.resources.IMarker) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) JobErrorEntry(org.talend.designer.runprocess.ErrorDetailTreeBuilder.JobErrorEntry) HashSet(java.util.HashSet)

Example 7 with IMarker

use of org.eclipse.core.resources.IMarker in project tdi-studio-se by Talend.

the class JobErrorsChecker method checkRoutinesCompilationError.

private static void checkRoutinesCompilationError() throws ProcessorException {
    Set<String> dependentRoutines = LastGenerationInfo.getInstance().getRoutinesNeededWithSubjobPerJob(LastGenerationInfo.getInstance().getLastMainJob().getJobId(), LastGenerationInfo.getInstance().getLastMainJob().getJobVersion());
    // from Problems
    List<Problem> errors = Problems.getProblemList().getProblemsBySeverity(ProblemStatus.ERROR);
    for (Problem p : errors) {
        if (p instanceof TalendProblem) {
            TalendProblem talendProblem = (TalendProblem) p;
            if (talendProblem.getType() == ProblemType.ROUTINE && dependentRoutines.contains(talendProblem.getJavaUnitName())) {
                int line = talendProblem.getLineNumber();
                String errorMessage = talendProblem.getDescription();
                throw new ProcessorException(Messages.getString("JobErrorsChecker_routines_compile_errors", talendProblem.getJavaUnitName()) + //$NON-NLS-1$
                '\n' + Messages.getString("JobErrorsChecker_compile_error_line") + ':' + ' ' + line + //$NON-NLS-1$
                '\n' + Messages.getString("JobErrorsChecker_compile_error_detailmessage") + ':' + ' ' + //$NON-NLS-1$
                errorMessage);
            }
        } else {
        // for now not to check components errors when building jobs in studio/commandline
        // throw new ProcessorException(Messages.getString("JobErrorsChecker_jobDesign_errors", p.getType().getTypeName(), //$NON-NLS-1$
        //      p.getJobInfo().getJobName(), p.getComponentName(), p.getDescription()));
        }
    }
    // if can't find the routines problem, try to check the file directly(mainly for commandline)
    try {
        final ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
        List<IRepositoryViewObject> routinesObjects = factory.getAll(ERepositoryObjectType.ROUTINES, false);
        if (routinesObjects != null) {
            for (IRepositoryViewObject obj : routinesObjects) {
                Property property = obj.getProperty();
                if (!dependentRoutines.contains(property.getLabel())) {
                    continue;
                }
                Item routinesitem = property.getItem();
                IFile routinesFile = synchronizer.getFile(routinesitem);
                IMarker[] markers = routinesFile.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:
                                throw new ProcessorException(//$NON-NLS-1$
                                Messages.getString("JobErrorsChecker_routines_compile_errors", property.getLabel()) + '\n' + Messages.getString("JobErrorsChecker_compile_error_line") + ':' + ' ' + lineNr + //$NON-NLS-1$
                                '\n' + Messages.getString("JobErrorsChecker_compile_error_detailmessage") + ':' + ' ' + //$NON-NLS-1$
                                message);
                            default:
                                break;
                        }
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    } catch (SystemException e) {
        ExceptionHandler.process(e);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) TalendProblem(org.talend.core.model.process.TalendProblem) Item(org.talend.core.model.properties.Item) SystemException(org.talend.commons.exception.SystemException) CoreException(org.eclipse.core.runtime.CoreException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) TalendProblem(org.talend.core.model.process.TalendProblem) Problem(org.talend.core.model.process.Problem) IMarker(org.eclipse.core.resources.IMarker) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 8 with IMarker

use of org.eclipse.core.resources.IMarker in project sling by apache.

the class SightlyNatureTest method testValidationMarkers.

private void testValidationMarkers(boolean invalidTag) throws Exception {
    final IProject project = projectRule.getProject();
    // create faceted project
    ProjectAdapter projectAdapter = new ProjectAdapter(project);
    projectAdapter.addNatures("org.eclipse.wst.common.project.facet.core.nature");
    projectAdapter.installFacet("sling.content", "1.0");
    projectAdapter.installFacet("sightly", "1.1");
    final IPath sightlyTemplatePath = Path.fromPortableString("/jcr_root/libs/my/component/html.html");
    String tagName = invalidTag ? "invalid-tag" : "sly";
    projectAdapter.createOrUpdateFile(sightlyTemplatePath, new ByteArrayInputStream(("<" + tagName + " />").getBytes()));
    ValidationFramework.getDefault().join(new NullProgressMonitor());
    IMarker[] markers = project.findMember(sightlyTemplatePath).findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
    if (invalidTag) {
        assertThat("markers.length", markers.length, equalTo(1));
        // might be overspecifying
        assertThat(markers[0].getAttribute(IMarker.MESSAGE, ""), equalTo("Unknown tag (invalid-tag)."));
    } else {
        assertThat("markers.length", markers.length, equalTo(0));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject)

Example 9 with IMarker

use of org.eclipse.core.resources.IMarker in project applause by applause.

the class ApplauseBuilderParticipant method getGeneratorMarkers.

/**
	 * @since 2.4
	 */
protected Map<OutputConfiguration, Iterable<IMarker>> getGeneratorMarkers(IProject builtProject, Collection<OutputConfiguration> outputConfigurations) throws CoreException {
    Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = newHashMap();
    for (OutputConfiguration config : outputConfigurations) {
        if (config.isCleanUpDerivedResources()) {
            IContainer container = getContainer(builtProject, config.getOutputDirectory());
            final Iterable<IMarker> markers = derivedResourceMarkers.findDerivedResourceMarkers(container, generatorIdProvider.getGeneratorIdentifier());
            generatorMarkers.put(config, markers);
        }
    }
    return generatorMarkers;
}
Also used : OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) IMarker(org.eclipse.core.resources.IMarker) IContainer(org.eclipse.core.resources.IContainer)

Example 10 with IMarker

use of org.eclipse.core.resources.IMarker in project bndtools by bndtools.

the class ComponentDecorator method decorate.

@Override
public void decorate(Object element, IDecoration decoration) {
    try {
        if (element instanceof CompilationUnit) {
            CompilationUnit unit = (CompilationUnit) element;
            if (!unit.getJavaProject().getProject().hasNature(BndtoolsConstants.NATURE_ID)) {
                return;
            }
            if (!isComponentInImports(unit)) {
                return;
            }
            IPackageDeclaration[] decs = unit.getPackageDeclarations();
            if (decs != null && decs.length > 0) {
                IPackageDeclaration dec = decs[0];
                if (dec != null) {
                    boolean found = false;
                    String customText = null;
                    for (IMarker marker : unit.getResource().findMarkers(BndtoolsConstants.MARKER_COMPONENT, true, IResource.DEPTH_ONE)) {
                        found = true;
                        customText = marker.getAttribute(IMarker.MESSAGE).toString();
                    }
                    if (found) {
                        decoration.addOverlay(componentIcon);
                        if (customText != null) {
                            if (customText.equals("OSGi Component")) {
                                decoration.addSuffix(" [Component]");
                            } else {
                                decoration.addSuffix(" [" + customText + "]");
                            }
                        }
                    }
                }
            }
        } else if (element instanceof SourceType) {
            SourceType type = (SourceType) element;
            if (!type.getJavaProject().getProject().hasNature(BndtoolsConstants.NATURE_ID)) {
                return;
            }
            if (!isComponentInImports(type.getCompilationUnit())) {
                return;
            }
            boolean found = false;
            String customText = null;
            for (IMarker marker : type.getCompilationUnit().getResource().findMarkers(BndtoolsConstants.MARKER_COMPONENT, true, IResource.DEPTH_ONE)) {
                found = true;
                customText = marker.getAttribute(IMarker.MESSAGE).toString();
            }
            if (found) {
                decoration.addOverlay(componentIcon);
                if (customText != null) {
                    if (customText.equals("OSGi Component")) {
                        decoration.addSuffix(" [Component]");
                    } else {
                        decoration.addSuffix(" [" + customText + "]");
                    }
                }
            }
        } else if (element instanceof IPackageFragment) {
            IPackageFragment frag = (IPackageFragment) element;
            if (!frag.getJavaProject().getProject().hasNature(BndtoolsConstants.NATURE_ID)) {
                return;
            }
            IResource resource = (IResource) frag.getAdapter(IResource.class);
            if (resource != null && countComponents(resource)) {
                decoration.addOverlay(componentIcon);
            }
        }
    } catch (CoreException e) {
        logger.logError("Component Decorator error", e);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CoreException(org.eclipse.core.runtime.CoreException) SourceType(org.eclipse.jdt.internal.core.SourceType) IMarker(org.eclipse.core.resources.IMarker) IPackageDeclaration(org.eclipse.jdt.core.IPackageDeclaration) IResource(org.eclipse.core.resources.IResource)

Aggregations

IMarker (org.eclipse.core.resources.IMarker)35 CoreException (org.eclipse.core.runtime.CoreException)20 IResource (org.eclipse.core.resources.IResource)9 IFile (org.eclipse.core.resources.IFile)7 IProject (org.eclipse.core.resources.IProject)6 IOException (java.io.IOException)5 BadLocationException (org.eclipse.jface.text.BadLocationException)4 Iterator (java.util.Iterator)3 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)3 IPath (org.eclipse.core.runtime.IPath)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IMarkerResolution (org.eclipse.ui.IMarkerResolution)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 IProcessTerminationListener (net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener)2