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

Replace uses of Poperty<File> with FileProperty in plugins #6516

Merged
merged 8 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -23,6 +23,7 @@ import java.nio.file.Paths
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.provider.Provider
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
Expand Down Expand Up @@ -124,7 +125,10 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
Coverage.apply(library)
}

protected fun getApiInfo(project: Project, srcDirs: Set<File>): TaskProvider<ApiInformationTask> {
protected fun getApiInfo(
project: Project,
srcDirs: ConfigurableFileCollection,
): TaskProvider<ApiInformationTask> {
val outputFile =
project.rootProject.file(
Paths.get(
Expand All @@ -138,7 +142,7 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
project.file("api.txt").takeIf { it.exists() } ?: project.rootProject.file("empty-api.txt")
val apiInfo =
project.tasks.register<ApiInformationTask>("apiInformation") {
sources.value(project.provider { srcDirs })
sources.from(project.provider { srcDirs })
apiTxtFile.set(apiTxt)
baselineFile.set(project.file("baseline.txt"))
this.outputFile.set(outputFile)
Expand All @@ -157,17 +161,17 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
}
}

protected fun getGenerateApiTxt(project: Project, srcDirs: Set<File>) =
protected fun getGenerateApiTxt(project: Project, srcDirs: ConfigurableFileCollection) =
project.tasks.register<GenerateApiTxtTask>("generateApiTxtFile") {
sources.value(project.provider { srcDirs })
sources.from(project.provider { srcDirs })
apiTxtFile.set(project.file("api.txt"))
baselineFile.set(project.file("baseline.txt"))
updateBaseline.set(project.hasProperty("updateBaseline"))
}

protected fun getDocStubs(project: Project, srcDirs: Set<File>) =
protected fun getDocStubs(project: Project, srcDirs: ConfigurableFileCollection) =
project.tasks.register<GenerateStubsTask>("docStubs") {
sources.value(project.provider { srcDirs })
sources.from(project.provider { srcDirs })
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.io.File
import javax.inject.Inject
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
Expand Down Expand Up @@ -53,7 +54,7 @@ import org.json.JSONObject
@CacheableTask
abstract class GenerateDocumentationTaskExtension : DefaultTask() {
@get:[InputFile Classpath]
abstract val dackkaJarFile: Property<File>
abstract val dackkaJarFile: RegularFileProperty

@get:[InputFiles Classpath]
abstract val dependencies: Property<FileCollection>
Expand All @@ -72,7 +73,7 @@ abstract class GenerateDocumentationTaskExtension : DefaultTask() {

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

@get:OutputDirectory abstract val outputDirectory: Property<File>
@get:OutputDirectory abstract val outputDirectory: RegularFileProperty
}

/**
Expand Down Expand Up @@ -123,7 +124,7 @@ constructor(private val workerExecutor: WorkerExecutor) : GenerateDocumentationT
val jsonMap =
mapOf(
"moduleName" to "",
"outputDir" to outputDirectory.get().absolutePath,
"outputDir" to outputDirectory.get().asFile.absolutePath,
"globalLinks" to "",
"sourceSets" to
listOf(
Expand Down Expand Up @@ -215,7 +216,7 @@ constructor(private val workerExecutor: WorkerExecutor) : GenerateDocumentationT
*/
interface DackkaParams : WorkParameters {
val args: ListProperty<String>
val dackkaFile: Property<File>
val dackkaFile: RegularFileProperty
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package com.google.firebase.gradle.plugins

import com.android.build.api.attributes.BuildTypeAttr
import com.android.build.gradle.LibraryExtension
import java.io.File
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Delete
Expand Down Expand Up @@ -204,26 +204,26 @@ abstract class DackkaPlugin : Plugin<Project> {
private fun GenerateDocumentationTask.applyCommonConfigurations() {
dependsOnAndMustRunAfter("createFullJarRelease")

val dackkaFile = project.provider { project.dackkaConfig.singleFile }
val dackkaFile = project.layout.projectDirectory.file(project.dackkaConfig.singleFile.path)

dackkaJarFile.set(dackkaFile)
dackkaJarFile.convention(dackkaFile)
clientName.set(project.firebaseLibrary.artifactId)
}

private fun registerFiresiteTransformTask(
project: Project,
dackkaOutputDirectory: Provider<File>,
dackkaOutputDirectory: Provider<RegularFile>,
) =
project.tasks.register<FiresiteTransformTask>("firesiteTransform") {
val outputDir by tempFile("dackkaTransformedFiles")

dackkaFiles.set(dackkaOutputDirectory.childFile("docs/reference"))
dackkaFiles.set(dackkaOutputDirectory.get().asFile.childFile("docs/reference"))
rlazo marked this conversation as resolved.
Show resolved Hide resolved
outputDirectory.set(outputDir)
}

private fun registerCopyDocsToCommonDirectoryTask(
project: Project,
transformedFilesDirectory: Provider<File>,
transformedFilesDirectory: Provider<RegularFile>,
) =
project.tasks.register<Copy>("copyDocsToCommonDirectory") {
from(transformedFilesDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.google.firebase.gradle.plugins.ci.device.FirebaseTestServer
import com.google.firebase.gradle.plugins.license.LicenseResolverPlugin
import com.google.firebase.gradle.plugins.semver.ApiDiffer
import com.google.firebase.gradle.plugins.semver.GmavenCopier
import java.io.File
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.attributes.Attribute
Expand Down Expand Up @@ -164,14 +163,14 @@ class FirebaseAndroidLibraryPlugin : BaseFirebaseLibraryPlugin() {
}

private fun setupApiInformationAnalysis(project: Project, android: LibraryExtension) {
val srcDirs = android.sourceSets.getByName("main").java.srcDirs
val srcDirs = project.files(android.sourceSets.getByName("main").java.srcDirs)

val mainSourceSets = android.sourceSets.getByName("main")
val getKotlinDirectories = mainSourceSets::class.java.getDeclaredMethod("getKotlinDirectories")
val kotlinSrcDirs = getKotlinDirectories.invoke(mainSourceSets)

val apiInfo = getApiInfo(project, kotlinSrcDirs as Set<File>)
val generateApiTxt = getGenerateApiTxt(project, kotlinSrcDirs)
val apiInfo = getApiInfo(project, srcDirs)
val generateApiTxt = getGenerateApiTxt(project, project.files(kotlinSrcDirs))
val docStubs = getDocStubs(project, srcDirs)

project.tasks.getByName("check").dependsOn(docStubs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {

private fun setupApiInformationAnalysis(project: Project) {
val srcDirs =
project.convention.getPlugin<JavaPluginConvention>().sourceSets.getByName("main").java.srcDirs
project.files(
project.convention
.getPlugin<JavaPluginConvention>()
.sourceSets
.getByName("main")
.java
.srcDirs
)

val apiInfo = getApiInfo(project, srcDirs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.google.firebase.gradle.plugins

import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.OutputDirectory
Expand Down Expand Up @@ -46,16 +46,16 @@ import org.gradle.api.tasks.TaskAction
abstract class FiresiteTransformTask : DefaultTask() {
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val dackkaFiles: Property<File>
abstract val dackkaFiles: RegularFileProperty

@get:OutputDirectory abstract val outputDirectory: Property<File>
@get:OutputDirectory abstract val outputDirectory: RegularFileProperty

@TaskAction
fun build() {
val namesOfFilesWeDoNotNeed =
listOf("index.html", "classes.html", "packages.html", "package-list")
val rootDirectory = dackkaFiles.get()
val targetDirectory = outputDirectory.get()
val rootDirectory = dackkaFiles.get().asFile
val targetDirectory = outputDirectory.get().asFile
targetDirectory.deleteRecursively()

rootDirectory.walkTopDown().forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.google.firebase.gradle.plugins
import java.io.File
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.Exec
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.register
Expand All @@ -30,7 +30,7 @@ import org.gradle.kotlin.dsl.register
* @param submodules the parent directory of the SDK's Git Submodules. Defaults to `src/third_party`
*/
interface GitSubmodulePluginExtension {
val submodules: Property<File>
val submodules: RegularFileProperty
}

/**
Expand All @@ -56,15 +56,15 @@ abstract class GitSubmodulePlugin : Plugin<Project> {

override fun apply(project: Project) {
with(configureExtension(project)) {
registerInitializeGitSubmodulesTask(project, submodules.get())
registerUpdateGitSubmodulesTask(project, submodules.get())
registerRemoveGitSubmodulesTask(project, submodules.get())
registerInitializeGitSubmodulesTask(project, submodules.get().asFile)
registerUpdateGitSubmodulesTask(project, submodules.get().asFile)
registerRemoveGitSubmodulesTask(project, submodules.get().asFile)
}
}

private fun configureExtension(project: Project) =
project.extensions.create<GitSubmodulePluginExtension>("GitSubmodule").apply {
submodules.convention(project.file("src/third_party"))
submodules.convention(project.layout.projectDirectory.file("src/third_party"))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import java.io.OutputStream
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
Expand Down Expand Up @@ -72,7 +73,7 @@ fun Project.runMetalavaWithArgs(

abstract class GenerateStubsTask : DefaultTask() {
/** Source files against which API signatures will be validated. */
@get:InputFiles abstract val sources: SetProperty<File>
@get:InputFiles abstract val sources: ConfigurableFileCollection

@get:[InputFiles Classpath]
lateinit var classPath: FileCollection
Expand All @@ -81,8 +82,7 @@ abstract class GenerateStubsTask : DefaultTask() {

@TaskAction
fun run() {
val sourcePath =
sources.get().asSequence().filter { it.exists() }.map { it.absolutePath }.joinToString(":")
val sourcePath = sources.files.filter { it.exists() }.map { it.absolutePath }.joinToString(":")

val classPath = classPath.files.asSequence().map { it.absolutePath }.toMutableList()
project.androidJar?.let { classPath += listOf(it.absolutePath) }
Expand All @@ -103,20 +103,19 @@ abstract class GenerateStubsTask : DefaultTask() {

abstract class GenerateApiTxtTask : DefaultTask() {
/** Source files against which API signatures will be validated. */
@get:InputFiles abstract val sources: SetProperty<File>
@get:InputFiles abstract val sources: ConfigurableFileCollection

@get:InputFiles lateinit var classPath: FileCollection

@get:OutputFile abstract val apiTxtFile: Property<File>
@get:OutputFile abstract val apiTxtFile: RegularFileProperty

@get:OutputFile abstract val baselineFile: Property<File>
@get:OutputFile abstract val baselineFile: RegularFileProperty

@get:Input abstract val updateBaseline: Property<Boolean>

@TaskAction
fun run() {
val sourcePath =
sources.get().asSequence().filter { it.exists() }.map { it.absolutePath }.joinToString(":")
val sourcePath = sources.files.filter { it.exists() }.map { it.absolutePath }.joinToString(":")

val classPath = classPath.files.asSequence().map { it.absolutePath }.toMutableList()
project.androidJar?.let { classPath += listOf(it.absolutePath) }
Expand All @@ -128,11 +127,12 @@ abstract class GenerateApiTxtTask : DefaultTask() {
"--classpath",
classPath.joinToString(":"),
"--api",
apiTxtFile.get().absolutePath,
apiTxtFile.get().asFile.absolutePath,
"--format=v2",
) +
if (updateBaseline.get()) listOf("--update-baseline")
else if (baselineFile.get().exists()) listOf("--baseline", baselineFile.get().absolutePath)
else if (baselineFile.get().asFile.exists())
listOf("--baseline", baselineFile.get().asFile.absolutePath)
else listOf(),
ignoreFailure = true,
)
Expand All @@ -141,24 +141,23 @@ abstract class GenerateApiTxtTask : DefaultTask() {

abstract class ApiInformationTask : DefaultTask() {
/** Source files against which API signatures will be validated. */
@get:InputFiles abstract val sources: SetProperty<File>
@get:InputFiles abstract val sources: ConfigurableFileCollection

@get:InputFiles lateinit var classPath: FileCollection

@get:InputFile abstract val apiTxtFile: Property<File>
@get:InputFile abstract val apiTxtFile: RegularFileProperty

@get:OutputFile abstract val outputApiFile: Property<File>
@get:OutputFile abstract val outputApiFile: RegularFileProperty

@get:OutputFile abstract val baselineFile: Property<File>
@get:OutputFile abstract val baselineFile: RegularFileProperty

@get:OutputFile abstract val outputFile: Property<File>
@get:OutputFile abstract val outputFile: RegularFileProperty

@get:Input abstract val updateBaseline: Property<Boolean>

@TaskAction
fun run() {
val sourcePath =
sources.get().asSequence().filter { it.exists() }.map { it.absolutePath }.joinToString(":")
val sourcePath = sources.files.filter { it.exists() }.map { it.absolutePath }.joinToString(":")

val classPath = classPath.files.asSequence().map { it.absolutePath }.toMutableList()
project.androidJar?.let { classPath += listOf(it.absolutePath) }
Expand All @@ -170,7 +169,7 @@ abstract class ApiInformationTask : DefaultTask() {
"--classpath",
classPath.joinToString(":"),
"--api",
outputApiFile.get().absolutePath,
outputApiFile.get().asFile.absolutePath,
"--format=v2",
),
ignoreFailure = true,
Expand All @@ -179,9 +178,9 @@ abstract class ApiInformationTask : DefaultTask() {
project.runMetalavaWithArgs(
listOf(
"--source-files",
outputApiFile.get().absolutePath,
outputApiFile.get().asFile.absolutePath,
"--check-compatibility:api:released",
apiTxtFile.get().absolutePath,
apiTxtFile.get().asFile.absolutePath,
"--error",
"AddedClass",
"--error",
Expand All @@ -192,10 +191,11 @@ abstract class ApiInformationTask : DefaultTask() {
"--no-color",
) +
if (updateBaseline.get()) listOf("--update-baseline")
else if (baselineFile.get().exists()) listOf("--baseline", baselineFile.get().absolutePath)
else if (baselineFile.get().asFile.exists())
listOf("--baseline", baselineFile.get().asFile.absolutePath)
else listOf(),
ignoreFailure = true,
stdOut = FileOutputStream(outputFile.get()),
stdOut = FileOutputStream(outputFile.get().asFile),
)
}
}
Loading
Loading