Skip to content

Commit

Permalink
Migrate to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
daymxn committed Jul 10, 2024
1 parent ec68af6 commit 65ad96b
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ 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 @@ -138,9 +140,9 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
firebaseLibrary.artifactId.get() // these dont get populated until afterEvaluate :(
groupId = firebaseLibrary.groupId.get()

firebaseLibrary.applyPomCustomization(pom)
firebaseLibrary.customizePom(pom)
firebaseLibrary.applyPomTransformations(pom)
from(components.findByName(firebaseLibrary.type.componentName))
from(components.findByName(firebaseLibrary.type.get().componentName))
}
}
}
Expand Down Expand Up @@ -209,7 +211,7 @@ 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 == LibraryType.ANDROID }.map { it.mavenName }
resolveProjectLevelDependencies().filter { it.type.get() == LibraryType.ANDROID }.map { it.mavenName.get() }

/**
* A list of project level dependencies.
Expand All @@ -221,8 +223,8 @@ fun FirebaseLibraryExtension.resolveAndroidDependencies() =
*/
// TODO(b/277607560): Remove when Gradle's MavenPublishPlugin adds functionality for aar types
fun FirebaseLibraryExtension.resolveProjectLevelDependencies() =
project.configurations
.getByName(runtimeClasspath)
project.get().configurations
.getByName(runtimeClasspath.get())
.allDependencies
.mapNotNull { it as? ProjectDependency }
.map {
Expand All @@ -245,8 +247,8 @@ fun FirebaseLibraryExtension.resolveProjectLevelDependencies() =
*/
// TODO(b/277607560): Remove when Gradle's MavenPublishPlugin adds functionality for aar types
fun FirebaseLibraryExtension.resolveExternalAndroidLibraries() =
project.configurations
.getByName(runtimeClasspath)
project.get().configurations
.getByName(runtimeClasspath.get())
.incoming
.artifactView { attributes { attribute("artifactType", "aar") } }
.artifacts
Expand Down Expand Up @@ -296,5 +298,5 @@ val FirebaseLibraryExtension.latestVersion: ModuleVersion
*/
val FirebaseLibraryExtension.namespace: String
get() =
project.extensions.getByType<LibraryExtension>().namespace
?: throw RuntimeException("Project doesn't have a defined namespace: ${project.path}")
project.get().extensions.getByType<LibraryExtension>().namespace
?: throw RuntimeException("Project doesn't have a defined namespace: ${project.get().path}")
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ abstract class DackkaPlugin : Plugin<Project> {

// TODO(b/270576405): remove afterEvalutate after fixed
project.afterEvaluate {
if (weShouldPublish(this)) {
if (weShouldPublish(this).get()) {
val dackkaOutputDirectory = provider { fileFromBuildDir("dackkaRawOutput") }
val transformedFilesDirectory = provider { fileFromBuildDir("dackkaTransformedFiles") }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {

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

firebaseLibrary.commonConfiguration(project, JAVA)
setupStaticAnalysis(project, firebaseLibrary)
setupApiInformationAnalysis(project)
getIsPomValidTask(project, firebaseLibrary)
Expand All @@ -59,33 +60,36 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {

private fun setupVersionCheckTasks(project: Project, firebaseLibrary: FirebaseLibraryExtension) {
project.tasks.register<GmavenVersionChecker>("gmavenVersionCheck") {
groupId.value(firebaseLibrary.groupId.get())
artifactId.value(firebaseLibrary.artifactId.get())
groupId.value(firebaseLibrary.groupId)
artifactId.value(firebaseLibrary.artifactId)
version.value(firebaseLibrary.version)
latestReleasedVersion.value(firebaseLibrary.latestReleasedVersion.orElseGet { "" })
latestReleasedVersion.value(firebaseLibrary.latestReleasedVersion.orElse(""))
}
project.mkdir("semver")
project.tasks.register<GmavenCopier>("copyPreviousArtifacts") {
dependsOn("jar")
project.file("semver/previous.jar").delete()
groupId.value(firebaseLibrary.groupId.get())
artifactId.value(firebaseLibrary.artifactId.get())
groupId.value(firebaseLibrary.groupId)
artifactId.value(firebaseLibrary.artifactId)
aarAndroidFile.value(false)
filePath.value(project.file("semver/previous.jar").absolutePath)
}
val currentJarFile =
project
.file("build/libs/${firebaseLibrary.artifactId.get()}-${firebaseLibrary.version}.jar")
.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()
}
}
project.tasks.register<ApiDiffer>("semverCheck") {
currentJar.value(currentJarFile)
previousJar.value(previousJarFile)
version.value(firebaseLibrary.version)
previousVersionString.value(
GmavenHelper(firebaseLibrary.groupId.get(), firebaseLibrary.artifactId.get())
.getLatestReleasedVersion()
)
previousVersionString.value(previousVersion)

dependsOn("copyPreviousArtifacts")
}
Expand Down

This file was deleted.

Loading

0 comments on commit 65ad96b

Please sign in to comment.