Skip to content

Commit 0cb832e

Browse files
committed
Short circuit lint tasks on projects that have no physical build.gradle
1 parent 2804c81 commit 0cb832e

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/integTest/java/com/netflix/nebula/lint/plugin/GradleLintPluginSpec.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ class GradleLintPluginSpec extends IntegrationSpec {
3131
console.any { it.contains('dependency-tuple') }
3232
}
3333

34+
def 'run rules on multi-module project where one of the subprojects has no build.gradle'() {
35+
when:
36+
buildFile << """
37+
allprojects {
38+
apply plugin: 'java'
39+
apply plugin: ${GradleLintPlugin.name}
40+
gradleLint.rules = ['dependency-parentheses', 'dependency-tuple']
41+
}
42+
"""
43+
44+
addSubproject('sub')
45+
46+
then:
47+
runTasksSuccessfully('gradleLint')
48+
}
49+
3450
def 'auto correct all violations on a single module project'() {
3551
when:
3652
buildFile << """

src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintCorrectionTask.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class GradleLintCorrectionTask extends DefaultTask {
1919

2020
@TaskAction
2121
void lintCorrections() {
22+
if(!project.buildFile.exists()) {
23+
return
24+
}
25+
2226
def registry = new LintRuleRegistry(project)
2327
def ruleSet = RuleSetFactory.configureRuleSet(project.extensions
2428
.getByType(GradleLintExtension)

src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintReportTask.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class GradleLintReportTask extends DefaultTask implements VerificationTask, Repo
3535

3636
@TaskAction
3737
void generateReport() {
38+
if(!project.buildFile.exists()) {
39+
return
40+
}
41+
3842
if(reports.enabled) {
3943
def lintExt = project.extensions.getByType(GradleLintExtension)
4044
def registry = new LintRuleRegistry(project)

src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintTask.groovy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ class GradleLintTask extends DefaultTask {
1818

1919
@TaskAction
2020
void lint() {
21+
if(!project.buildFile.exists()) {
22+
return
23+
}
24+
2125
def textOutput = textOutputFactory.create('lint')
2226
def buildFilePath = relPath(project.rootDir, project.buildFile).path
2327

2428
def registry = new LintRuleRegistry(project)
25-
def ruleSet = RuleSetFactory.configureRuleSet(project
29+
def extension = project
2630
.extensions
2731
.getByType(GradleLintExtension)
28-
.rules
29-
.collect { registry.buildRules(it) }
32+
33+
def ruleSet = RuleSetFactory.configureRuleSet(extension.rules.collect { registry.buildRules(it) }
3034
.flatten() as List<Rule>)
3135

3236
def violations = new StringSourceAnalyzer(project.buildFile.text).analyze(ruleSet).violations

0 commit comments

Comments
 (0)