Skip to content

Commit d029c59

Browse files
rlazogoogle-labs-jules[bot]gemini-code-assist[bot]
authored
Fix various Gradle warnings (#7164)
Addresses various warnings thrown from our plugin code --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 785785a commit d029c59

File tree

12 files changed

+159
-131
lines changed

12 files changed

+159
-131
lines changed

plugins/src/main/java/com/google/firebase/gradle/plugins/BaseFirebaseLibraryPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fun FirebaseLibraryExtension.resolveProjectLevelDependencies() =
290290
.allDependencies
291291
.mapNotNull { it as? ProjectDependency }
292292
.map {
293-
it.dependencyProject.extensions.findByType<FirebaseLibraryExtension>()
293+
project.project(it.dependencyProject.path).extensions.findByType<FirebaseLibraryExtension>()
294294
?: throw RuntimeException(
295295
"Project level dependencies must have the firebaseLibrary plugin. The following dependency does not: ${it.artifactName}"
296296
)

plugins/src/main/java/com/google/firebase/gradle/plugins/Changelog.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ data class Change(val type: ChangeType, val message: String) {
366366
fun fromString(string: String): Change {
367367
val (type, description) = REGEX.findOrThrow(string).destructured
368368

369-
return Change(ChangeType.valueOf(type.toUpperCase()), description.trim())
369+
return Change(ChangeType.valueOf(type.uppercase()), description.trim())
370370
}
371371
}
372372
}
@@ -384,5 +384,5 @@ enum class ChangeType {
384384
REMOVED,
385385
DEPRECATED;
386386

387-
override fun toString(): String = name.toLowerCase()
387+
override fun toString(): String = name.lowercase()
388388
}

plugins/src/main/java/com/google/firebase/gradle/plugins/GradleExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ import org.gradle.workers.WorkQueue
4747
*
4848
* Syntax sugar for:
4949
* ```
50-
* project.file("${project.buildDir}/$path)
50+
* project.file("${project.layout.buildDirectory.get().asFile}/$path)
5151
* ```
5252
*/
53-
fun Project.fileFromBuildDir(path: String) = file("$buildDir/$path")
53+
fun Project.fileFromBuildDir(path: String) = file("${layout.buildDirectory.get().asFile}/$path")
5454

5555
/**
5656
* Maps a file provider to another file provider as a sub directory.

plugins/src/main/java/com/google/firebase/gradle/plugins/LibraryGroups.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fun computeLibraryGroups(project: Project): Map<String, List<FirebaseLibraryExte
3939
}
4040

4141
fun fixLibraryGroupVersions(libraryGroups: Map<String, List<FirebaseLibraryExtension>>) {
42-
for ((name, libraryGroup) in libraryGroups) {
42+
for ((_, libraryGroup) in libraryGroups) {
4343
val maxVersion =
4444
libraryGroup.mapNotNull { it.moduleVersion }.maxOrNull()?.toString() ?: continue
4545
for (firebaseExtension in libraryGroup) {

plugins/src/main/java/com/google/firebase/gradle/plugins/MakeReleaseNotesTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ abstract class MakeReleaseNotesTask : DefaultTask() {
148148
"GitHub [#$id](//github.com/firebase/firebase-android-sdk/issues/$id){: .external}"
149149
}
150150

151-
return "* {{${type.name.toLowerCase()}}} $fixedMessage"
151+
return "* {{${type.name.lowercase()}}} $fixedMessage"
152152
}
153153

154154
companion object {

plugins/src/main/java/com/google/firebase/gradle/plugins/Metalava.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.google.firebase.gradle.plugins
1919
import java.io.File
2020
import java.io.FileOutputStream
2121
import java.io.OutputStream
22+
import javax.inject.Inject
2223
import org.gradle.api.DefaultTask
2324
import org.gradle.api.Project
2425
import org.gradle.api.artifacts.Configuration
@@ -33,6 +34,7 @@ import org.gradle.api.tasks.InputFiles
3334
import org.gradle.api.tasks.OutputDirectory
3435
import org.gradle.api.tasks.OutputFile
3536
import org.gradle.api.tasks.TaskAction
37+
import org.gradle.process.ExecOperations
3638

3739
val Project.metalavaConfig: Configuration
3840
get() =
@@ -46,9 +48,10 @@ val Project.metalavaConfig: Configuration
4648
}
4749

4850
val Project.docStubs: File?
49-
get() = project.file("${buildDir.path}/doc-stubs")
51+
get() = project.file("${project.layout.buildDirectory.get().asFile.path}/doc-stubs")
5052

5153
fun Project.runMetalavaWithArgs(
54+
execOperations: ExecOperations,
5255
arguments: List<String>,
5356
ignoreFailure: Boolean = false,
5457
stdOut: OutputStream? = null,
@@ -61,23 +64,25 @@ fun Project.runMetalavaWithArgs(
6164
"HiddenAbstractMethod",
6265
) + arguments
6366

64-
project.javaexec {
67+
execOperations.javaexec {
6568
mainClass.set("com.android.tools.metalava.Driver")
66-
classpath = project.metalavaConfig
69+
classpath = metalavaConfig
6770
args = allArgs
6871
isIgnoreExitValue = ignoreFailure
6972
if (stdOut != null) errorOutput = stdOut
7073
}
7174
}
7275

73-
abstract class GenerateStubsTask : DefaultTask() {
76+
abstract class GenerateStubsTask @Inject constructor(private val execOperations: ExecOperations) :
77+
DefaultTask() {
7478
/** Source files against which API signatures will be validated. */
7579
@get:InputFiles abstract val sources: ConfigurableFileCollection
7680

7781
@get:[InputFiles Classpath]
7882
lateinit var classPath: FileCollection
7983

80-
@get:OutputDirectory val outputDir: File = File(project.buildDir, "doc-stubs")
84+
@get:OutputDirectory
85+
val outputDir: File = File(project.layout.buildDirectory.get().asFile, "doc-stubs")
8186

8287
@TaskAction
8388
fun run() {
@@ -87,6 +92,7 @@ abstract class GenerateStubsTask : DefaultTask() {
8792
project.androidJar?.let { classPath += listOf(it.absolutePath) }
8893

8994
project.runMetalavaWithArgs(
95+
execOperations,
9096
listOf(
9197
"--source-path",
9298
sourcePath,
@@ -95,12 +101,13 @@ abstract class GenerateStubsTask : DefaultTask() {
95101
"--include-annotations",
96102
"--doc-stubs",
97103
outputDir.absolutePath,
98-
)
104+
),
99105
)
100106
}
101107
}
102108

103-
abstract class GenerateApiTxtTask : DefaultTask() {
109+
abstract class GenerateApiTxtTask @Inject constructor(private val execOperations: ExecOperations) :
110+
DefaultTask() {
104111
/** Source files against which API signatures will be validated. */
105112
@get:InputFiles abstract val sources: ConfigurableFileCollection
106113

@@ -120,6 +127,7 @@ abstract class GenerateApiTxtTask : DefaultTask() {
120127
project.androidJar?.let { classPath += listOf(it.absolutePath) }
121128

122129
project.runMetalavaWithArgs(
130+
execOperations,
123131
listOf(
124132
"--source-path",
125133
sourcePath,
@@ -138,7 +146,8 @@ abstract class GenerateApiTxtTask : DefaultTask() {
138146
}
139147
}
140148

141-
abstract class ApiInformationTask : DefaultTask() {
149+
abstract class ApiInformationTask @Inject constructor(private val execOperations: ExecOperations) :
150+
DefaultTask() {
142151
/** Source files against which API signatures will be validated. */
143152
@get:InputFiles abstract val sources: ConfigurableFileCollection
144153

@@ -162,6 +171,7 @@ abstract class ApiInformationTask : DefaultTask() {
162171
project.androidJar?.let { classPath += listOf(it.absolutePath) }
163172

164173
project.runMetalavaWithArgs(
174+
execOperations,
165175
listOf(
166176
"--source-path",
167177
sourcePath,
@@ -175,6 +185,7 @@ abstract class ApiInformationTask : DefaultTask() {
175185
)
176186

177187
project.runMetalavaWithArgs(
188+
execOperations,
178189
listOf(
179190
"--source-files",
180191
outputApiFile.get().asFile.absolutePath,

plugins/src/main/java/com/google/firebase/gradle/plugins/ProjectExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fun Project.isAndroid(): Boolean =
3131
}
3232

3333
fun toBoolean(value: Any?): Boolean {
34-
val trimmed = value?.toString()?.trim()?.toLowerCase()
34+
val trimmed = value?.toString()?.trim()?.lowercase()
3535
return "true" == trimmed || "y" == trimmed || "1" == trimmed
3636
}
3737

plugins/src/main/java/com/google/firebase/gradle/plugins/PublishingPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ abstract class PublishingPlugin : Plugin<Project> {
9191
val generateBom = registerGenerateBomTask(project)
9292
val generateBomReleaseNotes = registerGenerateBomReleaseNotesTask(project, generateBom)
9393
val generateTutorialBundle = registerGenerateTutorialBundleTask(project)
94-
val validatePomForRelease = registerValidatePomForReleaseTask(project, releasingProjects)
94+
registerValidatePomForReleaseTask(project, releasingProjects)
9595
val checkHeadDependencies =
9696
registerCheckHeadDependenciesTask(project, releasingFirebaseLibraries)
9797
val validateProjectsToPublish =

plugins/src/main/java/com/google/firebase/gradle/plugins/SemVerTask.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ package com.google.firebase.gradle.plugins
1818

1919
import com.google.firebase.gradle.plugins.semver.VersionDelta
2020
import java.io.ByteArrayOutputStream
21+
import javax.inject.Inject
2122
import org.gradle.api.DefaultTask
2223
import org.gradle.api.GradleException
2324
import org.gradle.api.file.RegularFileProperty
2425
import org.gradle.api.provider.Property
2526
import org.gradle.api.tasks.Input
2627
import org.gradle.api.tasks.InputFile
2728
import org.gradle.api.tasks.TaskAction
29+
import org.gradle.process.ExecOperations
2830

29-
abstract class SemVerTask : DefaultTask() {
31+
abstract class SemVerTask @Inject constructor(private val execOperations: ExecOperations) :
32+
DefaultTask() {
3033
@get:InputFile abstract val apiTxtFile: RegularFileProperty
3134
@get:InputFile abstract val otherApiFile: RegularFileProperty
3235
@get:Input abstract val currentVersionString: Property<String>
@@ -47,6 +50,7 @@ abstract class SemVerTask : DefaultTask() {
4750
}
4851
val stream = ByteArrayOutputStream()
4952
project.runMetalavaWithArgs(
53+
execOperations,
5054
listOf(
5155
"--source-files",
5256
apiTxtFile.get().asFile.absolutePath,
@@ -66,7 +70,6 @@ abstract class SemVerTask : DefaultTask() {
6670
val minorChanges = mutableListOf<String>()
6771
val majorChanges = mutableListOf<String>()
6872
for (match in reg.findAll(string)) {
69-
val loc = match.groups[1]!!.value
7073
val message = match.groups[2]!!.value
7174
val type = match.groups[3]!!.value
7275
if (IGNORED.contains(type)) {

plugins/src/main/java/com/google/firebase/gradle/plugins/ci/ChangedModulesTask.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ abstract class ChangedModulesTask : DefaultTask() {
5252
AffectedProjectFinder(project, changedGitPaths.toSet(), listOf())
5353
.find()
5454
.filter {
55-
val ext = it.extensions.findByType(FirebaseLibraryExtension::class.java)
5655
!onlyFirebaseSDKs || it.extensions.findByType<FirebaseLibraryExtension>() != null
5756
}
5857
.map { it.path }
@@ -62,12 +61,13 @@ abstract class ChangedModulesTask : DefaultTask() {
6261
project.rootProject.subprojects.forEach { p ->
6362
p.configurations.forEach { c ->
6463
c.dependencies.filterIsInstance<ProjectDependency>().forEach {
64+
val dependencyProject = project.project(it.dependencyProject.path)
6565
if (
6666
!onlyFirebaseSDKs ||
67-
it.dependencyProject.extensions.findByType<FirebaseLibraryExtension>() != null
67+
dependencyProject.extensions.findByType<FirebaseLibraryExtension>() != null
6868
) {
6969
if (!onlyFirebaseSDKs || p.extensions.findByType<FirebaseLibraryExtension>() != null) {
70-
result[it.dependencyProject.path]?.add(p.path)
70+
result[dependencyProject.path]?.add(p.path)
7171
}
7272
}
7373
}

0 commit comments

Comments
 (0)