diff --git a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/marker/GradleErrorMarkerTest.groovy b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/marker/GradleErrorMarkerTest.groovy index d4e12ffe6..947a059a8 100644 --- a/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/marker/GradleErrorMarkerTest.groovy +++ b/org.eclipse.buildship.core.test/src/main/groovy/org/eclipse/buildship/core/internal/marker/GradleErrorMarkerTest.groovy @@ -11,6 +11,8 @@ package org.eclipse.buildship.core.internal.marker import org.gradle.tooling.BuildException +import org.eclipse.core.resources.IMarker + import org.eclipse.buildship.core.internal.test.fixtures.ProjectSynchronizationSpecification class GradleErrorMarkerTest extends ProjectSynchronizationSpecification { @@ -120,4 +122,36 @@ class GradleErrorMarkerTest extends ProjectSynchronizationSpecification { findProject('sub') numOfGradleErrorMarkers == 0 } + + + def "Convers problem reports to error markers"() { + setup: + File projectDir = dir('error-marker-test') { + file 'build.gradle', ''' + import org.gradle.api.internal.GradleInternal + import org.gradle.api.problems.Problems + import org.gradle.api.problems.Severity + + def gradleInternal = gradle as GradleInternal + def problems = gradleInternal.services.get(Problems) + + problems.forNamespace('buildscript').reporting { + it.label("Problem label") + .category('deprecation', 'plugin') + .severity(Severity.WARNING) + .solution("Please use 'standard-plugin-2' instead of this plugin") + } + /**/ + ''' + } + + when: + importAndWait(projectDir) + + then: + numOfGradleErrorMarkers == 1 + gradleErrorMarkers[0].getAttribute(IMarker.MESSAGE) == 'Problem label' + gradleErrorMarkers[0].getAttribute(GradleErrorMarker.ATTRIBUTE_PROBLEM_CATEGORY) == 'buildscript:deprecation:plugin' + + } } diff --git a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemsReportingProgressListener.java b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemsReportingProgressListener.java index 5e7a5e675..4f3abe5ce 100644 --- a/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemsReportingProgressListener.java +++ b/org.eclipse.buildship.core/src/main/java/org/eclipse/buildship/core/internal/util/progress/ProblemsReportingProgressListener.java @@ -117,7 +117,7 @@ private static IResource toResource(FileLocation location) { IPath absolutePath = Path.fromOSString(location.getPath()); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile workspacePath = workspaceRoot.getFileForLocation(absolutePath); - if (workspacePath.exists()) { + if (workspacePath != null && workspacePath.exists()) { return workspacePath; } return ResourcesPlugin.getWorkspace().getRoot();