Search in sources :

Example 66 with IMarker

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

the class ApplauseBuilderParticipant method build.

public void build(final IBuildContext context, IProgressMonitor monitor) throws CoreException {
    if (!isEnabled(context)) {
        return;
    }
    final List<IResourceDescription.Delta> deltas = getRelevantDeltas(context);
    if (deltas.isEmpty()) {
        return;
    }
    final int numberOfDeltas = deltas.size();
    // monitor handling
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    SubMonitor subMonitor = SubMonitor.convert(monitor, numberOfDeltas + 3);
    ApplauseEclipseResourceFileSystemAccess2 access = fileSystemAccessProvider.get();
    final IProject builtProject = context.getBuiltProject();
    access.setProject(builtProject);
    final Map<String, OutputConfiguration> outputConfigurations = getOutputConfigurations(context);
    refreshOutputFolders(context, outputConfigurations, subMonitor.newChild(1));
    access.setOutputConfigurations(outputConfigurations);
    if (context.getBuildType() == BuildType.CLEAN || context.getBuildType() == BuildType.RECOVERY) {
        SubMonitor cleanMonitor = SubMonitor.convert(subMonitor.newChild(1), outputConfigurations.size());
        for (OutputConfiguration config : outputConfigurations.values()) {
            cleanOutput(context, config, cleanMonitor.newChild(1));
        }
        if (context.getBuildType() == BuildType.CLEAN)
            return;
    }
    Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = getGeneratorMarkers(builtProject, outputConfigurations.values());
    for (int i = 0; i < numberOfDeltas; i++) {
        final IResourceDescription.Delta delta = deltas.get(i);
        // monitor handling
        if (subMonitor.isCanceled())
            throw new OperationCanceledException();
        subMonitor.subTask("Compiling " + delta.getUri().lastSegment() + " (" + i + " of " + numberOfDeltas + ")");
        access.setMonitor(subMonitor.newChild(1));
        final String uri = delta.getUri().toString();
        final Set<IFile> derivedResources = newLinkedHashSet();
        for (OutputConfiguration config : outputConfigurations.values()) {
            if (config.isCleanUpDerivedResources()) {
                Iterable<IMarker> markers = generatorMarkers.get(config);
                for (IMarker marker : markers) {
                    String source = derivedResourceMarkers.getSource(marker);
                    if (source != null && source.equals(uri))
                        derivedResources.add((IFile) marker.getResource());
                }
            }
        }
        access.setPostProcessor(new ApplauseEclipseResourceFileSystemAccess2.IFileCallback() {

            public boolean beforeFileDeletion(IFile file) {
                derivedResources.remove(file);
                context.needRebuild();
                return true;
            }

            public void afterFileUpdate(IFile file) {
                handleFileAccess(file);
            }

            public void afterFileCreation(IFile file) {
                handleFileAccess(file);
            }

            protected void handleFileAccess(IFile file) {
                try {
                    derivedResources.remove(file);
                    derivedResourceMarkers.installMarker(file, uri);
                    context.needRebuild();
                } catch (CoreException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        if (delta.getNew() != null) {
            try {
                handleChangedContents(delta, context, access);
            } catch (OperationCanceledException e) {
                throw e;
            } catch (Exception e) {
                logger.error("Error during compilation of '" + delta.getUri() + "'.", e);
            }
        }
        access.flushSourceTraces();
        SubMonitor deleteMonitor = SubMonitor.convert(subMonitor.newChild(1), derivedResources.size());
        for (IFile iFile : newLinkedHashSet(derivedResources)) {
            IMarker marker = derivedResourceMarkers.findDerivedResourceMarker(iFile, uri);
            if (marker != null)
                marker.delete();
            if (derivedResourceMarkers.findDerivedResourceMarkers(iFile).length == 0) {
                access.deleteFile(iFile, deleteMonitor);
                context.needRebuild();
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) WrappedException(org.eclipse.emf.common.util.WrappedException) CoreException(org.eclipse.core.runtime.CoreException) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) IMarker(org.eclipse.core.resources.IMarker)

Example 67 with IMarker

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

the class ProjectBuildPage method loadMarkers.

private void loadMarkers(IMarker[] markers) {
    for (IMarker marker : markers) {
        int severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
        String message = marker.getAttribute(IMarker.MESSAGE, "");
        messageSeverityMap.put(message, severity);
        generateFixes(message, marker);
        problemSeverity = Math.max(problemSeverity, severity);
    }
}
Also used : IMarker(org.eclipse.core.resources.IMarker)

Example 68 with IMarker

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

the class BndMarkerAnnotationHover method getHoverInfo.

public String getHoverInfo(ISourceViewer sourceViewer, int lineNum) {
    @SuppressWarnings("rawtypes") Iterator iter = sourceViewer.getAnnotationModel().getAnnotationIterator();
    while (iter.hasNext()) {
        Object annotation = iter.next();
        if (annotation instanceof MarkerAnnotation) {
            IMarker marker = ((MarkerAnnotation) annotation).getMarker();
            int markerLine = marker.getAttribute(IMarker.LINE_NUMBER, 0);
            // Hover line is zero-based and marker line is one-based. FML.
            if (markerLine == lineNum + 1) {
                return marker.getAttribute(IMarker.MESSAGE, null);
            }
        }
    }
    return null;
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Iterator(java.util.Iterator) IMarker(org.eclipse.core.resources.IMarker)

Example 69 with IMarker

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

the class PackageInfoBaselineQuickFixProcessor method getCorrections.

@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
    ICompilationUnit compUnit = context.getCompilationUnit();
    IResource resource = compUnit.getResource();
    IMarker[] markers = resource.findMarkers(BndtoolsConstants.MARKER_JAVA_BASELINE, false, 1);
    for (IProblemLocation location : locations) {
        for (IMarker marker : markers) {
            int markerStart = marker.getAttribute(IMarker.CHAR_START, -1);
            int markerEnd = marker.getAttribute(IMarker.CHAR_END, -1);
            int markerLength = markerEnd - markerStart;
            if (location.getOffset() <= markerStart && markerStart < location.getOffset() + location.getLength()) {
                String newVersion = marker.getAttribute("suggestedVersion", null);
                if (newVersion != null) {
                    StringBuilder quotedVersion = new StringBuilder(newVersion.trim());
                    if (quotedVersion.charAt(0) != '"')
                        quotedVersion.insert(0, '"');
                    if (quotedVersion.charAt(quotedVersion.length() - 1) != '"')
                        quotedVersion.append('"');
                    CompilationUnitChange change = new CompilationUnitChange("Change package-info.java", compUnit);
                    change.setEdit(new ReplaceEdit(markerStart, markerLength, quotedVersion.toString()));
                    return new IJavaCompletionProposal[] { new ChangeCorrectionProposal("Change package version to " + newVersion, change, 1000) };
                }
            }
        }
    }
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) IMarker(org.eclipse.core.resources.IMarker) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal) IResource(org.eclipse.core.resources.IResource) ChangeCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 70 with IMarker

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

the class PackageInfoEditor method updateTitleIcon.

void updateTitleIcon() {
    IResource resource = ResourceUtil.getResource(getEditorInput());
    if (resource == null)
        return;
    int severity = IMarker.SEVERITY_INFO;
    try {
        IMarker[] markers = resource.findMarkers(BndtoolsConstants.MARKER_BND_PROBLEM, true, 0);
        if (markers != null) {
            for (IMarker marker : markers) severity = Math.max(severity, marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO));
        }
    } catch (CoreException e) {
        LOGGER.logError("Error updating packageinfo editor title icon", e);
    }
    if (severity >= IMarker.SEVERITY_ERROR) {
        titleImage = imgTitleError;
    } else if (severity >= IMarker.SEVERITY_WARNING) {
        titleImage = imgTitleWarning;
    } else {
        titleImage = imgTitleBase;
    }
    firePropertyChange(PROP_TITLE);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource)

Aggregations

IMarker (org.eclipse.core.resources.IMarker)115 CoreException (org.eclipse.core.runtime.CoreException)31 Test (org.junit.Test)31 IFile (org.eclipse.core.resources.IFile)23 IResource (org.eclipse.core.resources.IResource)16 ArrayList (java.util.ArrayList)15 IProject (org.eclipse.core.resources.IProject)8 IPath (org.eclipse.core.runtime.IPath)8 Position (org.eclipse.jface.text.Position)8 Annotation (org.eclipse.jface.text.source.Annotation)7 Matchers.anyString (org.mockito.Matchers.anyString)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Rule (net.sourceforge.pmd.Rule)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 BadLocationException (org.eclipse.jface.text.BadLocationException)6 RuleViolation (net.sourceforge.pmd.RuleViolation)5 JavaLanguageModule (net.sourceforge.pmd.lang.java.JavaLanguageModule)5 IDocument (org.eclipse.jface.text.IDocument)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5