Search in sources :

Example 71 with IMarker

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

the class ComponentMarker method findAndMarkComponentAnnotations.

private static void findAndMarkComponentAnnotations(ICompilationUnit c) throws CoreException, JavaModelException {
    Document document = null;
    boolean found = false;
    String key = null;
    for (IType t : c.getTypes()) {
        for (IAnnotation annot : t.getAnnotations()) {
            if ("Component".equals(annot.getElementName())) {
                if (document == null)
                    document = new Document(c.getBuffer().getContents());
                found = true;
                key = getNameFromComponent(annot);
                int lineNumber;
                try {
                    lineNumber = document.getLineOfOffset(t.getSourceRange().getOffset()) + 1;
                    String message = key == null ? "OSGi Component" : key;
                    IMarker marker = c.getResource().createMarker(BndtoolsConstants.MARKER_COMPONENT);
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
                    marker.setAttribute(IMarker.MESSAGE, message);
                    marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
                    marker.setAttribute(IMarker.LOCATION, "line " + lineNumber);
                } catch (BadLocationException e) {
                    logger.logError("Component Marker error", e);
                    lineNumber = -1;
                }
            }
        }
    }
    if (!found) {
        c.getResource().deleteMarkers(BndtoolsConstants.MARKER_COMPONENT, true, IResource.DEPTH_ONE);
    }
}
Also used : IAnnotation(org.eclipse.jdt.core.IAnnotation) IMarker(org.eclipse.core.resources.IMarker) Document(org.eclipse.jface.text.Document) BadLocationException(org.eclipse.jface.text.BadLocationException) IType(org.eclipse.jdt.core.IType)

Example 72 with IMarker

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

the class BaselineErrorHandler method getResolutions.

@Override
public List<IMarkerResolution> getResolutions(IMarker marker) {
    List<IMarkerResolution> result = new LinkedList<IMarkerResolution>();
    final String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
    if (suggestedVersion != null) {
        result.add(new IMarkerResolution() {

            @Override
            public void run(IMarker marker) {
                final IFile file = (IFile) marker.getResource();
                final IWorkspace workspace = file.getWorkspace();
                try {
                    workspace.run(new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor monitor) throws CoreException {
                            String input = "version " + suggestedVersion;
                            ByteArrayInputStream stream = new ByteArrayInputStream(input.getBytes());
                            file.setContents(stream, false, true, monitor);
                        }
                    }, null);
                } catch (CoreException e) {
                    logger.logError("Error applying baseline version quickfix.", e);
                }
            }

            @Override
            public String getLabel() {
                return "Change package version to " + suggestedVersion;
            }
        });
    }
    return result;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IMarkerResolution(org.eclipse.ui.IMarkerResolution) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) IMarker(org.eclipse.core.resources.IMarker) LinkedList(java.util.LinkedList)

Example 73 with IMarker

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

the class MarkerSupport method createMarker.

void createMarker(Processor model, int severity, String formatted, String markerType) throws Exception {
    Location location = model != null ? model.getLocation(formatted) : null;
    if (location != null) {
        String type = location.details != null ? location.details.getClass().getName() : null;
        BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
        List<MarkerData> markers = handler.generateMarkerData(project, model, location);
        for (MarkerData markerData : markers) {
            IResource resource = markerData.getResource();
            if (resource != null && resource.exists()) {
                String typeOverride = markerData.getTypeOverride();
                IMarker marker = resource.createMarker(typeOverride != null ? typeOverride : markerType);
                marker.setAttribute(IMarker.SEVERITY, severity);
                marker.setAttribute("$bndType", type);
                // Set location information
                if (location.header != null)
                    marker.setAttribute(BNDTOOLS_MARKER_HEADER_ATTR, location.header);
                if (location.context != null)
                    marker.setAttribute(BNDTOOLS_MARKER_CONTEXT_ATTR, location.context);
                if (location.file != null)
                    marker.setAttribute(BNDTOOLS_MARKER_FILE_ATTR, location.file);
                if (location.reference != null)
                    marker.setAttribute(BNDTOOLS_MARKER_REFERENCE_ATTR, location.reference);
                marker.setAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, markerData.hasResolutions());
                for (Entry<String, Object> attrib : markerData.getAttribs().entrySet()) marker.setAttribute(attrib.getKey(), attrib.getValue());
            }
        }
        return;
    }
    String defaultResource = model instanceof Project ? Project.BNDFILE : model instanceof Workspace ? Workspace.BUILDFILE : null;
    IResource resource = DefaultBuildErrorDetailsHandler.getDefaultResource(project, defaultResource);
    if (resource.exists()) {
        IMarker marker = resource.createMarker(markerType);
        marker.setAttribute(IMarker.SEVERITY, severity);
        marker.setAttribute(IMarker.MESSAGE, formatted);
    }
}
Also used : DefaultBuildErrorDetailsHandler(org.bndtools.build.api.DefaultBuildErrorDetailsHandler) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) MarkerData(org.bndtools.build.api.MarkerData) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) SetLocation(aQute.service.reporter.Reporter.SetLocation) Location(aQute.service.reporter.Report.Location) Workspace(aQute.bnd.build.Workspace)

Example 74 with IMarker

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

the class MissingWorkspaceMarkerResolutionGenerator method getResolutions.

@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    return new IMarkerResolution[] { new IMarkerResolution() {

        @Override
        public void run(IMarker marker) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
            WorkspaceSetupWizard wizard = new WorkspaceSetupWizard();
            wizard.init(workbench, StructuredSelection.EMPTY);
            WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
            dialog.open();
        }

        @Override
        public String getLabel() {
            return "Open 'New Bnd OSGi Workspace' Wizard";
        }
    } };
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IMarkerResolution(org.eclipse.ui.IMarkerResolution) IMarker(org.eclipse.core.resources.IMarker) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 75 with IMarker

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

the class LegacyMavenBundleProjectTest method testLegacyMavenBundleProjectHasErrorMarker.

@Test
public void testLegacyMavenBundleProjectHasErrorMarker() throws Exception {
    // create project
    final IProject bundleProject = projectRule.getProject();
    MavenProjectAdapter project = new MavenProjectAdapter(bundleProject);
    project.createOrUpdateFile(Path.fromPortableString("pom.xml"), getClass().getResourceAsStream("legacy-pom.xml"));
    project.convertToMavenProject();
    // wait up to 1 minute for the build to succeed due to time needed to retrieve dependencies
    Poller markerPoller = new Poller(TimeUnit.MINUTES.toMillis(1));
    markerPoller.pollUntilSuccessful(new Runnable() {

        @Override
        public void run() {
            try {
                IMarker[] markers = bundleProject.findMarkers(null, true, IResource.DEPTH_ONE);
                for (IMarker marker : markers) {
                    if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) != IMarker.SEVERITY_ERROR) {
                        continue;
                    }
                    if (marker.getAttribute(IMarker.MESSAGE, "").startsWith("Missing m2e incremental build support")) {
                        return;
                    }
                }
                throw new RuntimeException("Did not find error message starting with 'Missing m2e incremental support'");
            } catch (CoreException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
Also used : MavenProjectAdapter(org.apache.sling.ide.eclipse.m2e.impl.helpers.MavenProjectAdapter) CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject) Poller(org.apache.sling.ide.test.impl.helpers.Poller) Test(org.junit.Test)

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