Skip to content

Commit 33e3c6b

Browse files
Fix various Gradle warnings
1 parent a0f67be commit 33e3c6b

File tree

12 files changed

+154
-134
lines changed

12 files changed

+154
-134
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: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ 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
23+
import org.gradle.api.Action
2224
import org.gradle.api.DefaultTask
2325
import org.gradle.api.Project
2426
import org.gradle.api.artifacts.Configuration
@@ -33,6 +35,8 @@ import org.gradle.api.tasks.InputFiles
3335
import org.gradle.api.tasks.OutputDirectory
3436
import org.gradle.api.tasks.OutputFile
3537
import org.gradle.api.tasks.TaskAction
38+
import org.gradle.process.ExecOperations
39+
import org.gradle.process.JavaExecSpec
3640

3741
val Project.metalavaConfig: Configuration
3842
get() =
@@ -46,9 +50,10 @@ val Project.metalavaConfig: Configuration
4650
}
4751

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

5155
fun Project.runMetalavaWithArgs(
56+
execOperations: ExecOperations,
5257
arguments: List<String>,
5358
ignoreFailure: Boolean = false,
5459
stdOut: OutputStream? = null,
@@ -61,23 +66,25 @@ fun Project.runMetalavaWithArgs(
6166
"HiddenAbstractMethod",
6267
) + arguments
6368

64-
project.javaexec {
69+
execOperations.javaexec {
6570
mainClass.set("com.android.tools.metalava.Driver")
66-
classpath = project.metalavaConfig
71+
classpath = metalavaConfig
6772
args = allArgs
6873
isIgnoreExitValue = ignoreFailure
6974
if (stdOut != null) errorOutput = stdOut
7075
}
7176
}
7277

73-
abstract class GenerateStubsTask : DefaultTask() {
78+
abstract class GenerateStubsTask @Inject constructor(private val execOperations: ExecOperations) :
79+
DefaultTask() {
7480
/** Source files against which API signatures will be validated. */
7581
@get:InputFiles abstract val sources: ConfigurableFileCollection
7682

7783
@get:[InputFiles Classpath]
7884
lateinit var classPath: FileCollection
7985

80-
@get:OutputDirectory val outputDir: File = File(project.buildDir, "doc-stubs")
86+
@get:OutputDirectory
87+
val outputDir: File = File(project.layout.buildDirectory.get().asFile, "doc-stubs")
8188

8289
@TaskAction
8390
fun run() {
@@ -87,6 +94,7 @@ abstract class GenerateStubsTask : DefaultTask() {
8794
project.androidJar?.let { classPath += listOf(it.absolutePath) }
8895

8996
project.runMetalavaWithArgs(
97+
execOperations,
9098
listOf(
9199
"--source-path",
92100
sourcePath,
@@ -100,7 +108,8 @@ abstract class GenerateStubsTask : DefaultTask() {
100108
}
101109
}
102110

103-
abstract class GenerateApiTxtTask : DefaultTask() {
111+
abstract class GenerateApiTxtTask @Inject constructor(private val execOperations: ExecOperations) :
112+
DefaultTask() {
104113
/** Source files against which API signatures will be validated. */
105114
@get:InputFiles abstract val sources: ConfigurableFileCollection
106115

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

122131
project.runMetalavaWithArgs(
132+
execOperations,
123133
listOf(
124134
"--source-path",
125135
sourcePath,
@@ -138,7 +148,8 @@ abstract class GenerateApiTxtTask : DefaultTask() {
138148
}
139149
}
140150

141-
abstract class ApiInformationTask : DefaultTask() {
151+
abstract class ApiInformationTask @Inject constructor(private val execOperations: ExecOperations) :
152+
DefaultTask() {
142153
/** Source files against which API signatures will be validated. */
143154
@get:InputFiles abstract val sources: ConfigurableFileCollection
144155

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

164175
project.runMetalavaWithArgs(
176+
execOperations,
165177
listOf(
166178
"--source-path",
167179
sourcePath,
@@ -175,6 +187,7 @@ abstract class ApiInformationTask : DefaultTask() {
175187
)
176188

177189
project.runMetalavaWithArgs(
190+
execOperations,
178191
listOf(
179192
"--source-files",
180193
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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,21 @@ abstract class ChangedModulesTask : DefaultTask() {
5151
val projects =
5252
AffectedProjectFinder(project, changedGitPaths.toSet(), listOf())
5353
.find()
54-
.filter {
55-
val ext = it.extensions.findByType(FirebaseLibraryExtension::class.java)
56-
!onlyFirebaseSDKs || it.extensions.findByType<FirebaseLibraryExtension>() != null
57-
}
54+
.filter { !onlyFirebaseSDKs || it.extensions.findByType<FirebaseLibraryExtension>() != null }
5855
.map { it.path }
5956
.toSet()
6057

6158
val result = project.rootProject.subprojects.associate { it.path to mutableSetOf<String>() }
6259
project.rootProject.subprojects.forEach { p ->
6360
p.configurations.forEach { c ->
6461
c.dependencies.filterIsInstance<ProjectDependency>().forEach {
62+
val dependencyProject = project.project(it.dependencyProject.path)
6563
if (
6664
!onlyFirebaseSDKs ||
67-
it.dependencyProject.extensions.findByType<FirebaseLibraryExtension>() != null
65+
dependencyProject.extensions.findByType<FirebaseLibraryExtension>() != null
6866
) {
6967
if (!onlyFirebaseSDKs || p.extensions.findByType<FirebaseLibraryExtension>() != null) {
70-
result[it.dependencyProject.path]?.add(p.path)
68+
result[dependencyProject.path]?.add(p.path)
7169
}
7270
}
7371
}

0 commit comments

Comments
 (0)