Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to removing root project restriction #242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -38,63 +38,61 @@ class GradleLintPlugin implements Plugin<Project> {
LintRuleRegistry.classLoader = getClass().classLoader
def lintExt = project.extensions.create('gradleLint', GradleLintExtension)

if (project.rootProject == project) {
def autoLintTask = project.tasks.create(AUTO_LINT_GRADLE, LintGradleTask)
autoLintTask.listeners = lintExt.listeners
def autoLintTask = project.tasks.create(AUTO_LINT_GRADLE, LintGradleTask)
autoLintTask.listeners = lintExt.listeners

def manualLintTask = project.tasks.create('lintGradle', LintGradleTask)
manualLintTask.group = 'lint'
manualLintTask.failOnWarning = true
def manualLintTask = project.tasks.create('lintGradle', LintGradleTask)
manualLintTask.group = 'lint'
manualLintTask.failOnWarning = true

def criticalLintTask = project.tasks.create('criticalLintGradle', LintGradleTask)
criticalLintTask.group = 'lint'
criticalLintTask.onlyCriticalRules = true
def criticalLintTask = project.tasks.create('criticalLintGradle', LintGradleTask)
criticalLintTask.group = 'lint'
criticalLintTask.onlyCriticalRules = true

def fixTask = project.tasks.create('fixGradleLint', FixGradleLintTask)
fixTask.userDefinedListeners = lintExt.listeners
def fixTask = project.tasks.create('fixGradleLint', FixGradleLintTask)
fixTask.userDefinedListeners = lintExt.listeners

def fixTask2 = project.tasks.create('fixLintGradle', FixGradleLintTask)
fixTask2.userDefinedListeners = lintExt.listeners
def fixTask2 = project.tasks.create('fixLintGradle', FixGradleLintTask)
fixTask2.userDefinedListeners = lintExt.listeners

project.gradle.addListener(new LintListener() {
def allTasks
project.gradle.addListener(new LintListener() {
def allTasks

@Override
void graphPopulated(TaskExecutionGraph graph) {
allTasks = graph.allTasks
}
@Override
void graphPopulated(TaskExecutionGraph graph) {
allTasks = graph.allTasks
}

@Override
void buildFinished(BuildResult result) {
if (onlyIf()) {
autoLintTask.lint()
}
@Override
void buildFinished(BuildResult result) {
if (onlyIf()) {
autoLintTask.lint()
}
}

private boolean onlyIf() {
def shouldLint = project.hasProperty('gradleLint.alwaysRun') ?
Boolean.valueOf(project.property('gradleLint.alwaysRun').toString()) : lintExt.alwaysRun
def excludedAutoLintGradle = project.gradle.startParameter.excludedTaskNames.contains(AUTO_LINT_GRADLE)
def skipForSpecificTask = project.gradle.startParameter.taskNames.any { lintExt.skipForTasks.contains(it) }
def hasFailedTask = !lintExt.autoLintAfterFailure && allTasks.any { it.state.failure != null }
//when we already have failed critical lint task we don't want to run autolint
def hasFailedCriticalLintTask = allTasks.any { it == criticalLintTask && it.state.failure != null }
def hasExplicitLintTask = allTasks.any {
it == fixTask || it == fixTask2 || it == manualLintTask || it == autoLintTask
}
shouldLint && !excludedAutoLintGradle && !skipForSpecificTask && !hasFailedTask &&
!hasExplicitLintTask && !hasFailedCriticalLintTask
private boolean onlyIf() {
def shouldLint = project.hasProperty('gradleLint.alwaysRun') ?
Boolean.valueOf(project.property('gradleLint.alwaysRun').toString()) : lintExt.alwaysRun
def excludedAutoLintGradle = project.gradle.startParameter.excludedTaskNames.contains(AUTO_LINT_GRADLE)
def skipForSpecificTask = project.gradle.startParameter.taskNames.any { lintExt.skipForTasks.contains(it) }
def hasFailedTask = !lintExt.autoLintAfterFailure && allTasks.any { it.state.failure != null }
//when we already have failed critical lint task we don't want to run autolint
def hasFailedCriticalLintTask = allTasks.any { it == criticalLintTask && it.state.failure != null }
def hasExplicitLintTask = allTasks.any {
it == fixTask || it == fixTask2 || it == manualLintTask || it == autoLintTask
}
})
}
shouldLint && !excludedAutoLintGradle && !skipForSpecificTask && !hasFailedTask &&
!hasExplicitLintTask && !hasFailedCriticalLintTask
}
})

configureReportTask(project, lintExt)

project.plugins.withType(JavaBasePlugin) {
project.tasks.withType(AbstractCompile) { task ->
project.rootProject.tasks.getByName('fixGradleLint').dependsOn(task)
project.rootProject.tasks.getByName('lintGradle').dependsOn(task)
project.rootProject.tasks.getByName('fixLintGradle').dependsOn(task)
project.tasks.getByName('fixGradleLint').dependsOn(task)
project.tasks.getByName('lintGradle').dependsOn(task)
project.tasks.getByName('fixLintGradle').dependsOn(task)
}
}

Expand Down