Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class WorkerExecutorProblemsApiIntegrationTest extends AbstractIntegrationSpec {
import java.io.File;
import java.io.FileWriter;
import org.gradle.api.problems.Problems;
import org.gradle.api.problems.ProblemId;
import org.gradle.api.problems.ProblemGroup;
import org.gradle.internal.operations.CurrentBuildOperationRef;

import org.gradle.workers.WorkAction;
Expand All @@ -77,8 +79,8 @@ class WorkerExecutorProblemsApiIntegrationTest extends AbstractIntegrationSpec {
Exception wrappedException = new Exception("Wrapped cause");
// Create and report a problem
// This needs to be Java 6 compatible, as we are in a worker
getProblems().getReporter().report(problem -> problem
.id(org.gradle.api.problems.ProblemId.create("type", "label", org.gradle.api.problems.ProblemGroup.create("generic", "Generic")))
ProblemId problemId = ProblemId.create("type", "label", ProblemGroup.create("generic", "Generic"));
getProblems().getReporter().report(problemId, problem -> problem
.stackLocation()
.withException(new RuntimeException("Exception message", wrappedException))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ interface Injected {
def problems = project.objects.newInstance(Injected).getProblems()
def problemGroup = ProblemGroup.create("root", "Root Group")

problems.getReporter().report {
it.id(ProblemId.create('adhoc-script-deprecation', 'Deprecated script plugin', problemGroup))
.contextualLabel("Deprecated script plugin 'demo-script-plugin'")
problems.getReporter().report(ProblemId.create('adhoc-script-deprecation', 'Deprecated script plugin', problemGroup)) {
it.contextualLabel("Deprecated script plugin 'demo-script-plugin'")
.severity(Severity.WARNING)
.solution("Please use 'standard-plugin-2' instead of this plugin")
}

tasks.register('warningTask') {
doLast {
problems.getReporter().report {
it.id(ProblemId.create('adhoc-task-deprecation', 'Deprecated task', problemGroup))
.contextualLabel("Task 'warningTask' is deprecated")
problems.getReporter().report(ProblemId.create('adhoc-task-deprecation', 'Deprecated task', problemGroup)) {
it.contextualLabel("Task 'warningTask' is deprecated")
.severity(Severity.WARNING)
.solution("Please use 'warningTask2' instead of this task")
}
Expand All @@ -30,9 +28,8 @@ tasks.register('warningTask') {

tasks.register('failingTask') {
doLast {
problems.getReporter().throwing(new RuntimeException("The 'failingTask' should not be called")) {
it.id(ProblemId.create('broken-task', 'Task should not be called', problemGroup))
.contextualLabel("Task 'failingTask' should not be called")
problems.getReporter().throwing(new RuntimeException("The 'failingTask' should not be called"), ProblemId.create('broken-task', 'Task should not be called', problemGroup)) {
it.contextualLabel("Task 'failingTask' should not be called")
.severity(Severity.ERROR)
.solution("Please use 'successfulTask' instead of this task")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ interface Injected {
val problems = project.objects.newInstance<Injected>().problems
val problemGroup = ProblemGroup.create("root", "Root Group")

problems.getReporter().report {
id(ProblemId.create("adhoc-script-deprecation", "Deprecated script plugin", problemGroup))
.contextualLabel("Deprecated script plugin 'demo-script-plugin'")
problems.getReporter().report(ProblemId.create("adhoc-script-deprecation", "Deprecated script plugin", problemGroup)) {
contextualLabel("Deprecated script plugin 'demo-script-plugin'")
.severity(Severity.WARNING)
.solution("Please use 'standard-plugin-2' instead of this plugin")
}

tasks {
val warningTask by registering {
doLast {
problems.getReporter().report {
id(ProblemId.create("adhoc-task-deprecation", "Deprecated task", problemGroup))
.contextualLabel("Task 'warningTask' is deprecated")
problems.getReporter().report(ProblemId.create("adhoc-task-deprecation", "Deprecated task", problemGroup)) {
contextualLabel("Task 'warningTask' is deprecated")
.severity(Severity.WARNING)
.solution("Please use 'warningTask2' instead of this task")
}
Expand All @@ -31,9 +29,8 @@ tasks {

val failingTask by registering {
doLast {
problems.getReporter().throwing(RuntimeException("The 'failingTask' should not be called")) {
id(ProblemId.create("broken-task", "Task should not be called", problemGroup))
.contextualLabel("Task 'failingTask' should not be called")
problems.getReporter().throwing(RuntimeException("The 'failingTask' should not be called"), ProblemId.create("broken-task", "Task should not be called", problemGroup)) {
contextualLabel("Task 'failingTask' should not be called")
.severity(Severity.ERROR)
.solution("Please use 'successfulTask' instead of this task")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public boolean canBuild(String modelName) {

@Override
public Object buildAll(String modelName, Project project) {
problems.getReporter().report(problem -> problem
.id(ProblemId.create("unused", "Demo model", ModelBuilderPlugin.PROBLEM_GROUP))
problems.getReporter().report(ProblemId.create("unused", "Demo model", ModelBuilderPlugin.PROBLEM_GROUP), problem -> problem
.severity(Severity.WARNING)
.details("This is a demo model and doesn't do anything useful")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public abstract class FailingTask extends DefaultTask {
@TaskAction
public void run() {
// tag::problems-api-fail-the-build[]
throw getProblems().getReporter().throwing((new RuntimeException("Message from runtime exception")), problemSpec -> {
problemSpec.id(ProblemId.create("sample-error", "Sample Error", StandardPlugin.PROBLEM_GROUP));
ProblemId id = ProblemId.create("sample-error", "Sample Error", StandardPlugin.PROBLEM_GROUP);
throw getProblems().getReporter().throwing((new RuntimeException("Message from runtime exception")), id, problemSpec -> {
problemSpec.contextualLabel("This happened because ProblemReporter.throwing() was called");
problemSpec.details("This is a demonstration of how to add\ndetailed information to a build failure");
problemSpec.documentedAt("https://example.com/docs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public StandardPlugin(Problems problems) {
public void apply(Project project) {
project.getTasks().register("myFailingTask", FailingTask.class);
// tag::problems-api-report[]
problems.getReporter().report(problem -> problem
.id(ProblemId.create("adhoc-plugin-deprecation", "Plugin is deprecated", PROBLEM_GROUP))
ProblemId problemId = ProblemId.create("adhoc-plugin-deprecation", "Plugin is deprecated", PROBLEM_GROUP);
problems.getReporter().report(problemId, problem -> problem
.contextualLabel("The 'standard-plugin' is deprecated")
.documentedAt("https://github.com/gradle/gradle/README.md")
.severity(Severity.WARNING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public ProblemReportingPlugin(Problems problems) { // <1>
}

public void apply(Project project) {
this.problemReporter.report(builder -> builder // <3>
.id(ProblemId.create("adhoc-deprecation", "Plugin 'x' is deprecated", PROBLEM_GROUP))
ProblemId problemId = ProblemId.create("adhoc-deprecation", "Plugin 'x' is deprecated", PROBLEM_GROUP);
this.problemReporter.report(problemId, builder -> builder // <3>
.details("The plugin 'x' is deprecated since version 2.5")
.solution("Please use plugin 'y'")
.severity(Severity.WARNING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ class DevelocityPluginEndOfBuildCallbackIntegrationTest extends AbstractIntegrat
${ProblemGroup.name} problemGroup = ${ProblemGroup.name}.create("generic", "group label");
${ProblemId.name} problemId = ${ProblemId.name}.create("type", "label", problemGroup)
${getProblemReportingScript """
problems.getReporter().throwing(new RuntimeException('failed')) {
it.id(problemId)
}"""}
problems.getReporter().throwing(new RuntimeException('failed'), problemId) {}
"""}

task $succeedingTaskName
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.gradle.plugin.devel.tasks.internal

import com.google.gson.Gson
import org.gradle.api.problems.ProblemId
import org.gradle.api.problems.GeneralData
import org.gradle.api.problems.ProblemId
import org.gradle.api.problems.Severity
import org.gradle.api.problems.internal.AdditionalDataBuilderFactory
import org.gradle.api.problems.internal.DefaultProblemReporter
Expand Down Expand Up @@ -52,9 +52,7 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize and deserialize a validation problem"() {
given:
def problem = problemReporter.create {
it.id(problemId)
}
def problem = problemReporter.create(problemId, {})

when:
def json = gson.toJson([problem])
Expand All @@ -76,9 +74,8 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize and deserialize a validation problem with a location"() {
given:
def problem = problemReporter.create {
it.id(problemId)
.lineInFileLocation("location", 1, 2, 3)
def problem = problemReporter.create(problemId) {
it.lineInFileLocation("location", 1, 2, 3)
}

when:
Expand All @@ -98,9 +95,8 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize and deserialize a validation problem with a documentation link"() {
given:
def problem = problemReporter.create {
it.id(problemId)
.documentedAt(new TestDocLink())
def problem = problemReporter.create(problemId) {
it.documentedAt(new TestDocLink())
.lineInFileLocation("location", 1, 1)
}

Expand Down Expand Up @@ -138,9 +134,8 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize and deserialize a validation problem with a cause"() {
given:
def problem = problemReporter.create {
it.id(problemId)
.withException(new RuntimeException("cause"))
def problem = problemReporter.create(problemId) {
it.withException(new RuntimeException("cause"))
}

when:
Expand All @@ -158,9 +153,8 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize and deserialize a validation problem with a severity"(Severity severity) {
given:
def problem = problemReporter.create {
it.id(problemId)
.severity(severity)
def problem = problemReporter.create(problemId) {
it.severity(severity)
}

when:
Expand All @@ -181,9 +175,8 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize and deserialize a validation problem with a solution"() {
given:
def problem = problemReporter.create {
it.id(problemId)
.solution("solution 0")
def problem = problemReporter.create(problemId) {
it.solution("solution 0")
.solution("solution 1")
}

Expand All @@ -203,7 +196,7 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize and deserialize a validation problem with additional data"() {
given:
def problem = problemReporter.create {
def problem = problemReporter.internalCreate {
it.id(problemId)
.additionalData(TypeValidationDataSpec.class) {
it.propertyName("property")
Expand Down Expand Up @@ -231,7 +224,7 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize generic additional data"() {
given:
def problem = problemReporter.create {
def problem = problemReporter.internalCreate {
it.id(problemId)
.additionalData(GeneralDataSpec) {
it.put('foo', 'bar')
Expand All @@ -252,7 +245,7 @@ class ValidationProblemSerializationTest extends Specification {

def "can serialize deprecation additional data"() {
given:
def problem = problemReporter.create {
def problem = problemReporter.internalCreate {
it.id(problemId)
.additionalData(DeprecationDataSpec) {
it.type(DeprecationData.Type.BUILD_INVOCATION)
Expand Down
Loading
Loading