Skip to content

Commit

Permalink
Add simple test coverage to problems API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
donat committed Feb 16, 2024
1 parent ed49711 commit 13706c2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 13706c2

Please sign in to comment.