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

#1114 print build path in projectHealth #1178

Merged
merged 1 commit into from
May 21, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
}
}