Skip to content

Commit c817207

Browse files
author
David Motsonashvili
committed
format
1 parent 78b0e62 commit c817207

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,8 @@ import org.gradle.kotlin.dsl.register
3737
*/
3838
abstract class CopyGoogleServicesPlugin : Plugin<Project> {
3939
override fun apply(project: Project) {
40-
val sourcePath =
41-
System.getenv("FIREBASE_GOOGLE_SERVICES_PATH") ?: "${project.rootDir}/google-services.json"
40+
val sourcePath = getSourcePath(project)
4241
val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project, sourcePath)
43-
if (!File(project.projectDir, "google-services.json").exists() && !File(sourcePath).exists()) {
44-
val createDummyGoogleServices = registerDummyGoogleServicesTask(project, sourcePath)
45-
copyRootGoogleServices.dependsOn(createDummyGoogleServices)
46-
}
4742

4843
project.allprojects {
4944
// fixes dependencies with gradle tasks that do not properly dependOn `preBuild`
@@ -66,15 +61,6 @@ abstract class CopyGoogleServicesPlugin : Plugin<Project> {
6661
return gradle.startParameter.taskNames.any { testTasks.any(it::contains) }
6762
}
6863

69-
private fun registerDummyGoogleServicesTask(project: Project, path: String) =
70-
project.tasks.register<Copy>("copyDummyGoogleServices") {
71-
logger.warn("Google services file not found, using fallback")
72-
73-
from("${project.rootDir}/plugins/resources/dummy-google-services.json")
74-
into(path)
75-
rename { "google-services.json" }
76-
}
77-
7864
private fun registerCopyRootGoogleServicesTask(project: Project, path: String) =
7965
project.tasks.register<Copy>("copyRootGoogleServices") {
8066
val library = project.extensions.getByType<BaseExtension>()
@@ -107,4 +93,13 @@ abstract class CopyGoogleServicesPlugin : Plugin<Project> {
10793

10894
return !file.readText().contains(targetPackageLine)
10995
}
96+
97+
private fun getSourcePath(project: Project): String {
98+
val path =
99+
System.getenv("FIREBASE_GOOGLE_SERVICES_PATH") ?: "${project.rootDir}/google-services.json"
100+
if (File(project.projectDir, "google-services.json").exists() || File(path).exists()) {
101+
return path
102+
}
103+
return "${project.rootDir}/plugins/resources/dummy-google-services.json"
104+
}
110105
}

0 commit comments

Comments
 (0)