Skip to content

Commit

Permalink
#1114 print build path in projectHealth
Browse files Browse the repository at this point in the history
  • Loading branch information
seregamorph committed May 5, 2024
1 parent 731bef1 commit 9a02fcc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2024. Tony Robalik.
// SPDX-License-Identifier: Apache-2.0
package com.autonomousapps.jvm

import com.autonomousapps.jvm.projects.AbiGenericsProject
import com.autonomousapps.jvm.projects.AbiGenericsProject.SourceKind

import static com.autonomousapps.utils.Runner.build
import static com.google.common.truth.Truth.assertThat

final class ProjectHealthSpec extends AbstractJvmSpec {

def "projectHealth prints build file path (#gradleVersion)"() {
given:
def project = new AbiGenericsProject(SourceKind.METHOD)
gradleProject = project.gradleProject
when:
def result = build(gradleVersion, gradleProject.rootDir, 'projectHealth')
then:
assertThat(result.output).contains(
"""${gradleProject.rootDir.getPath()}/proj/build.gradle
|Existing dependencies which should be modified to be as indicated:
| api project(':genericsBar') (was implementation)
| api project(':genericsFoo') (was implementation)
|""".stripMargin())
where:
gradleVersion << gradleVersions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ internal class ProjectPlugin(private val project: Project) {
}

tasks.register<ProjectHealthTask>("projectHealth") {
buildFilePath.set(project.buildFile.path)
projectAdvice.set(filterAdviceTask.flatMap { it.output })
consoleReport.set(generateProjectHealthReport.flatMap { it.output })
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/kotlin/com/autonomousapps/tasks/ProjectHealthTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.autonomousapps.internal.utils.fromJson
import com.autonomousapps.model.ProjectAdvice
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
Expand All @@ -20,6 +22,9 @@ abstract class ProjectHealthTask : DefaultTask() {
description = "Prints advice for this project"
}

@get:Input
abstract val buildFilePath: Property<String>

@get:PathSensitive(PathSensitivity.NONE)
@get:InputFile
abstract val projectAdvice: RegularFileProperty
Expand All @@ -34,9 +39,13 @@ abstract class ProjectHealthTask : DefaultTask() {

if (projectAdvice.shouldFail) {
check(consoleReport.isNotBlank()) { "Console report should not be blank if projectHealth should fail" }
throw BuildHealthException(consoleReport)
throw BuildHealthException(prependBuildPath(consoleReport))
} else if (consoleReport.isNotBlank()) {
logger.quiet(consoleReport)
logger.quiet(prependBuildPath(consoleReport))
}
}

private fun prependBuildPath(consoleReport: String): String {
return "${buildFilePath.get()}\n$consoleReport"
}
}

0 comments on commit 9a02fcc

Please sign in to comment.