Skip to content

Commit

Permalink
Fix copyright and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
daymxn committed Jul 10, 2024
1 parent 65ad96b commit 6e298a3
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ package com.google.firebase.gradle.plugins

import com.android.build.gradle.LibraryExtension
import com.google.firebase.gradle.plugins.ci.Coverage
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabExtension
import java.io.File
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.provider.Provider
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
Expand Down Expand Up @@ -211,7 +209,9 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
// TODO(b/277607560): Remove when Gradle's MavenPublishPlugin adds functionality for aar types
fun FirebaseLibraryExtension.resolveAndroidDependencies() =
resolveExternalAndroidLibraries() +
resolveProjectLevelDependencies().filter { it.type.get() == LibraryType.ANDROID }.map { it.mavenName.get() }
resolveProjectLevelDependencies()
.filter { it.type.get() == LibraryType.ANDROID }
.map { it.mavenName.get() }

/**
* A list of project level dependencies.
Expand All @@ -223,7 +223,9 @@ fun FirebaseLibraryExtension.resolveAndroidDependencies() =
*/
// TODO(b/277607560): Remove when Gradle's MavenPublishPlugin adds functionality for aar types
fun FirebaseLibraryExtension.resolveProjectLevelDependencies() =
project.get().configurations
project
.get()
.configurations
.getByName(runtimeClasspath.get())
.allDependencies
.mapNotNull { it as? ProjectDependency }
Expand All @@ -247,7 +249,9 @@ fun FirebaseLibraryExtension.resolveProjectLevelDependencies() =
*/
// TODO(b/277607560): Remove when Gradle's MavenPublishPlugin adds functionality for aar types
fun FirebaseLibraryExtension.resolveExternalAndroidLibraries() =
project.get().configurations
project
.get()
.configurations
.getByName(runtimeClasspath.get())
.incoming
.artifactView { attributes { attribute("artifactType", "aar") } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {
}

private fun setupFirebaseLibraryExtension(project: Project) {
val firebaseLibrary =
project.extensions.create<FirebaseLibraryExtension>("firebaseLibrary")
val firebaseLibrary = project.extensions.create<FirebaseLibraryExtension>("firebaseLibrary")

firebaseLibrary.commonConfiguration(project, JAVA)
setupStaticAnalysis(project, firebaseLibrary)
Expand All @@ -74,17 +73,19 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {
aarAndroidFile.value(false)
filePath.value(project.file("semver/previous.jar").absolutePath)
}
val currentJarFile = firebaseLibrary.artifactId.flatMap { artifactId ->
firebaseLibrary.version.map { version ->
project.file("build/libs/$artifactId-$version").absolutePath
val currentJarFile =
firebaseLibrary.artifactId.flatMap { artifactId ->
firebaseLibrary.version.map { version ->
project.file("build/libs/$artifactId-$version").absolutePath
}
}
}
val previousJarFile = project.file("semver/previous.jar").absolutePath
val previousVersion = firebaseLibrary.artifactId.flatMap { artifactId ->
firebaseLibrary.groupId.map { groupId ->
GmavenHelper(groupId, artifactId).getLatestReleasedVersion()
val previousVersion =
firebaseLibrary.artifactId.flatMap { artifactId ->
firebaseLibrary.groupId.map { groupId ->
GmavenHelper(groupId, artifactId).getLatestReleasedVersion()
}
}
}
project.tasks.register<ApiDiffer>("semverCheck") {
currentJar.value(currentJarFile)
previousJar.value(previousJarFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.gradle.plugins

import com.android.build.gradle.LibraryExtension
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabExtension
import java.io.File
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
Expand All @@ -10,129 +27,119 @@ import org.gradle.api.provider.Provider
import org.gradle.api.publish.maven.MavenPom
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.invoke
import java.io.File
import javax.inject.Inject

// TODO(b/XXXX): Identify proper property usage
// TODO(b/XXXX): Ensure correct downstream property usage
// TODO(b/XXXX): Move functions and extra variables to proper location
abstract class FirebaseLibraryExtension {
abstract val project: Property<Project>
abstract val type: Property<LibraryType>

abstract val publishJavadoc: Property<Boolean>
abstract val publishReleaseNotes: Property<Boolean>
abstract val publishSources: Property<Boolean>

abstract val previewMode: Property<String>

abstract val groupId: Property<String>
abstract val artifactId: Property<String>

abstract val libraryGroup: Property<String>

fun commonConfiguration(target: Project, libraryType: LibraryType) {
project.convention(target)
type.convention(libraryType)
publishJavadoc.convention(true)
publishReleaseNotes.convention(true)
publishSources.convention(true)
previewMode.convention("")
target.extensions.create<FirebaseTestLabExtension>("testLab", target.objects)

if(target.name === "ktx" && target.parent !== null) {
artifactId.convention("${target.parent?.name}-ktx")
groupId.convention(target.parent?.group?.toString())
} else {
artifactId.convention(target.name)
groupId.convention(target.group.toString())
}
abstract val project: Property<Project>
abstract val type: Property<LibraryType>

abstract val publishJavadoc: Property<Boolean>
abstract val publishReleaseNotes: Property<Boolean>
abstract val publishSources: Property<Boolean>

abstract val previewMode: Property<String>

abstract val groupId: Property<String>
abstract val artifactId: Property<String>

abstract val libraryGroup: Property<String>

fun commonConfiguration(target: Project, libraryType: LibraryType) {
project.convention(target)
type.convention(libraryType)
publishJavadoc.convention(true)
publishReleaseNotes.convention(true)
publishSources.convention(true)
previewMode.convention("")
target.extensions.create<FirebaseTestLabExtension>("testLab", target.objects)

if (target.name === "ktx" && target.parent !== null) {
artifactId.convention("${target.parent?.name}-ktx")
groupId.convention(target.parent?.group?.toString())
} else {
artifactId.convention(target.name)
groupId.convention(target.group.toString())
}

val lintProjects = target.provideProperty<String>("firebase.checks.lintProjects").map {
it.orEmpty().split(",")
}
val lintProjects =
target.provideProperty<String>("firebase.checks.lintProjects").map { it.orEmpty().split(",") }

target.extensions.create<FirebaseStaticAnalysis>("staticAnalysis", lintProjects.get().toSet())
libraryGroup.convention(artifactId)
}
target.extensions.create<FirebaseStaticAnalysis>("staticAnalysis", lintProjects.get().toSet())
libraryGroup.convention(artifactId)
}

fun testLab(action: Action<FirebaseTestLabExtension>) {
project.get().extensions.configure<FirebaseTestLabExtension> {
action.execute(this)
}
}
fun testLab(action: Action<FirebaseTestLabExtension>) {
project.get().extensions.configure<FirebaseTestLabExtension> { action.execute(this) }
}

fun customizePom(pom: MavenPom) {
pom.licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
pom.scm {
connection.set("scm:git:https://github.com/firebase/firebase-android-sdk.git")
url.set("https://github.com/firebase/firebase-android-sdk")
}
fun customizePom(pom: MavenPom) {
pom.licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}

fun libraryGroup(name: String) {
libraryGroup.set(name)
pom.scm {
connection.set("scm:git:https://github.com/firebase/firebase-android-sdk.git")
url.set("https://github.com/firebase/firebase-android-sdk")
}

val version: Provider<String>
get() = project.map { it.version.toString() }

val latestReleasedVersion: Provider<String?>
get() = project.flatMap {
it.provideProperty<String>("latestReleasedVersion")
}

val mavenName: Provider<String>
get() = groupId.flatMap { groupId ->
artifactId.map { artifactId ->
"$groupId:$artifactId"
}
}

fun libraryGroup(name: String) {
libraryGroup.set(name)
}

val version: Provider<String>
get() = project.map { it.version.toString() }

val latestReleasedVersion: Provider<String?>
get() = project.flatMap { it.provideProperty<String>("latestReleasedVersion") }

val mavenName: Provider<String>
get() = groupId.flatMap { groupId -> artifactId.map { artifactId -> "$groupId:$artifactId" } }

val path: Provider<String>
get() = project.map { it.path }

val srcDirs: Provider<Set<File>>
get() =
project.flatMap { project ->
type.map {
when (it) {
LibraryType.ANDROID ->
project.extensions
.getByType<LibraryExtension>()
.sourceSets
.getByName("main")
.java
.srcDirs
LibraryType.JAVA ->
project.extensions
.getByType<JavaPluginExtension>()
.sourceSets
.getByName("main")
.java
.srcDirs
null -> throw IllegalStateException("Project type was unset.")
}
}
}

val path: Provider<String>
get() = project.map { it.path }

val srcDirs: Provider<Set<File>>
get() = project.flatMap { project ->
type.map {
when(it) {
LibraryType.ANDROID ->
project.extensions.getByType<LibraryExtension>()
.sourceSets
.getByName("main")
.java
.srcDirs
LibraryType.JAVA ->
project.extensions.getByType<JavaPluginExtension>()
.sourceSets
.getByName("main")
.java
.srcDirs
null -> throw IllegalStateException("Project type was unset.")
}
}
}
val runtimeClasspath: Provider<String>
get() =
type.map { if (it === LibraryType.ANDROID) "releaseRuntimeClasspath" else "runtimeClasspath" }

val runtimeClasspath: Provider<String>
get() = type.map {
if (it === LibraryType.ANDROID) "releaseRuntimeClasspath" else "runtimeClasspath"
}
val staticAnalysis: FirebaseStaticAnalysis
get() = project.get().extensions.getByType()

val staticAnalysis: FirebaseStaticAnalysis
get() = project.get().extensions.getByType()
val testLab: FirebaseTestLabExtension
get() = project.get().extensions.getByType()

val testLab: FirebaseTestLabExtension
get() = project.get().extensions.getByType()

override fun toString(): String {
return """FirebaseLibraryExtension{name="${mavenName.get()}", project="${project.get()}", type="${type.get()}" """
}
}
override fun toString(): String {
return """FirebaseLibraryExtension{name="${mavenName.get()}", project="${project.get()}", type="${type.get()}" """
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class FirebaseLibraryPlugin : BaseFirebaseLibraryPlugin() {

private fun setupAndroidLibraryExtension(project: Project) {
val firebaseLibrary =
project.extensions.create<FirebaseLibraryExtension>("firebaseLibrary",)
project.extensions.create<FirebaseLibraryExtension>(
"firebaseLibrary",
)
val android = project.extensions.getByType<LibraryExtension>()
android.compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ fun fixLibraryGroupVersions(libraryGroups: Map<String, List<FirebaseLibraryExten
val maxVersion =
libraryGroup.mapNotNull { it.moduleVersion }.maxOrNull()?.toString() ?: continue
for (firebaseExtension in libraryGroup) {
if (ModuleVersion.fromStringOrNull(firebaseExtension.project.get().version.toString()) == null) {
if (
ModuleVersion.fromStringOrNull(firebaseExtension.project.get().version.toString()) == null
) {
firebaseExtension.project.get().version = maxVersion
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ abstract class PublishingPlugin : Plugin<Project> {

return releaseConfigFile?.let {
val releaseConfig = ReleaseConfig.fromFile(it)
val librariesToRelease = allFirebaseLibraries.filter { it.path.get() in releaseConfig.libraries }
val librariesToRelease =
allFirebaseLibraries.filter { it.path.get() in releaseConfig.libraries }

val missingLibrariesToRelease =
computeMissingLibrariesToRelease(librariesToRelease, libraryGroups)
Expand Down Expand Up @@ -560,7 +561,10 @@ abstract class PublishingPlugin : Plugin<Project> {
project.tasks.register(PUBLISH_ALL_TO_BUILD_TASK) {
for (firebaseLibrary in allFirebaseLibraries) {
val publishTask =
firebaseLibrary.project.get().tasks.named("publishMavenAarPublicationToBuildDirRepository")
firebaseLibrary.project
.get()
.tasks
.named("publishMavenAarPublicationToBuildDirRepository")

dependsOn(publishTask)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ abstract class ReleaseGenerator : DefaultTask() {
)
}
.flatMap {
libraryGroups.getOrDefault(it.firebaseLibrary.libraryGroup.get(), listOf(it.firebaseLibrary))
libraryGroups.getOrDefault(
it.firebaseLibrary.libraryGroup.get(),
listOf(it.firebaseLibrary)
)
}
.map { it.project.get() }
.toSet()
Expand Down
Loading

0 comments on commit 6e298a3

Please sign in to comment.