Skip to content

Commit 2f1249d

Browse files
Merge pull request #425 from nebula-plugins/insight-when-rule-changesets-fail-to-apply
Provide more insight when lint rules fail to apply a patch change suc…
2 parents a6e7fad + 6d53723 commit 2f1249d

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

.github/workflows/nebula.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
name: "Gradle Wrapper Validation"
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v2
17-
- uses: gradle/actions/wrapper-validation@v3
16+
- uses: actions/checkout@v4
17+
- uses: gradle/actions/wrapper-validation@v4
1818
buildmultijdk:
1919
if: (!startsWith(github.ref, 'refs/tags/v'))
2020
needs: validation

src/main/groovy/com/netflix/nebula/lint/GradleLintPatchAction.groovy

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
package com.netflix.nebula.lint
1818

19+
import com.netflix.nebula.lint.plugin.UnexpectedLintRuleFailureException
1920
import groovy.transform.Canonical
2021
import org.apache.commons.lang.StringUtils
2122
import org.gradle.api.Project
2223

2324
import static FileMode.Symlink
24-
import static com.netflix.nebula.lint.PatchType.*
25+
import static com.netflix.nebula.lint.PatchType.Create
26+
import static com.netflix.nebula.lint.PatchType.Delete
27+
import static com.netflix.nebula.lint.PatchType.Update
2528
import static java.nio.file.Files.readSymbolicLink
2629

2730
@Canonical
@@ -34,9 +37,26 @@ class GradleLintPatchAction extends GradleLintViolationAction {
3437
void lintFinished(Collection<GradleViolation> violations) {
3538
File buildDir = project.layout.buildDirectory.asFile.getOrElse(new File(project.projectDir, "build"))
3639
buildDir.mkdirs()
37-
new File(buildDir, PATCH_NAME).withWriter { w ->
40+
try {
3841
def patch = patch(violations*.fixes.flatten() as List<GradleLintFix>)
39-
w.write(patch)
42+
new File(buildDir, PATCH_NAME).withWriter { w ->
43+
w.write(patch)
44+
}
45+
} catch (Exception e) {
46+
def rules = violations.findAll { it.rule != null }.collect { it.rule }
47+
def ruleFailureContexts = rules.collect { rule -> rule.ruleFailureContext() }
48+
.findAll { it -> !(it as String).isEmpty() }
49+
def ruleNames = rules.collect { rule -> rule.getName() }
50+
def ruleFailureContextMessage = ruleFailureContexts.isEmpty() ? '' : "- " + ruleFailureContexts.join('\n- ')
51+
52+
String errorMessage = """
53+
Error generating patch for the combined set of changes from these lint rule(s): [${ruleNames.join(", ")}]\n
54+
To resolve this, please try applying the rules individually.\n
55+
For example, if the related rules with combined set of changes are [rule1, rule2], you can run: './gradlew fixGradleLint -PgradleLint.rules=rule1' followed by './gradlew fixGradleLint -PgradleLint.rules=rule2' so that the changes are applied one at a time.\n
56+
${ruleFailureContextMessage}
57+
Exception: ${e.getMessage()}
58+
"""
59+
throw new UnexpectedLintRuleFailureException(errorMessage, e)
4060
}
4161
}
4262

0 commit comments

Comments
 (0)