-
Notifications
You must be signed in to change notification settings - Fork 624
Converty library plugins to kotlin #4627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
405f5be
Converty library plugins to kotlin
emilypgoogle 1fbd1bb
Refactor shared logic out
emilypgoogle a0d3709
Add copyright notices
emilypgoogle a603f73
debug api info
yifanyang d5519c1
Merge branch 'master' into ep/firebase-library-plugin-kotlin
emilypgoogle 9bdaf57
Added util method for more idiomatic Plugin application
daymxn a0c2e3c
Resolve comments
emilypgoogle ea5151a
Simplify publishing
emilypgoogle 181c2a8
Refactor plugin base class
emilypgoogle fcc015e
Add copyright notice
emilypgoogle c3ae814
Adjust leftover plugin apply
emilypgoogle c7a53f6
Use takeIf
emilypgoogle 1f34a39
Merge branch 'master' into ep/firebase-library-plugin-kotlin
emilypgoogle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
buildSrc/src/main/java/com/google/firebase/gradle/plugins/BaseFirebaseLibraryPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright 2023 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.google.firebase.gradle.plugins.ci.Coverage | ||
import java.io.File | ||
import java.nio.file.Paths | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.publish.PublishingExtension | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin | ||
import org.gradle.api.tasks.TaskProvider | ||
import org.gradle.kotlin.dsl.apply | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.create | ||
import org.gradle.kotlin.dsl.register | ||
|
||
abstract class BaseFirebaseLibraryPlugin : Plugin<Project> { | ||
|
||
protected fun kotlinModuleName(project: Project): String { | ||
val fullyQualifiedProjectPath = project.path.replace(":".toRegex(), "-") | ||
return project.rootProject.name + fullyQualifiedProjectPath | ||
} | ||
|
||
protected fun setupStaticAnalysis(project: Project, library: FirebaseLibraryExtension) { | ||
project.afterEvaluate { | ||
configurations.all { | ||
if ("lintChecks" == name) { | ||
for (checkProject in library.staticAnalysis.androidLintCheckProjects) { | ||
project.dependencies.add("lintChecks", project.project(checkProject!!)) | ||
} | ||
} | ||
} | ||
} | ||
project.tasks.register("firebaseLint") { dependsOn("lint") } | ||
Coverage.apply(library) | ||
} | ||
|
||
protected fun getApiInfo(project: Project, srcDirs: Set<File>): TaskProvider<ApiInformationTask> { | ||
val outputFile = | ||
project.rootProject.file( | ||
Paths.get( | ||
project.rootProject.buildDir.path, | ||
"apiinfo", | ||
project.path.substring(1).replace(":", "_") | ||
) | ||
) | ||
val outputApiFile = File(outputFile.absolutePath + "_api.txt") | ||
val apiTxt = | ||
project.file("api.txt").takeIf { it.exists() } ?: project.rootProject.file("empty-api.txt") | ||
val apiInfo = | ||
project.tasks.register<ApiInformationTask>("apiInformation") { | ||
sources.value(project.provider { srcDirs }) | ||
apiTxtFile.set(apiTxt) | ||
baselineFile.set(project.file("baseline.txt")) | ||
this.outputFile.set(outputFile) | ||
this.outputApiFile.set(outputApiFile) | ||
emilypgoogle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
updateBaseline.set(project.hasProperty("updateBaseline")) | ||
} | ||
return apiInfo | ||
} | ||
|
||
protected fun getGenerateApiTxt(project: Project, srcDirs: Set<File>) = | ||
project.tasks.register<GenerateApiTxtTask>("generateApiTxtFile") { | ||
sources.value(project.provider { srcDirs }) | ||
apiTxtFile.set(project.file("api.txt")) | ||
baselineFile.set(project.file("baseline.txt")) | ||
updateBaseline.set(project.hasProperty("updateBaseline")) | ||
} | ||
|
||
protected fun getDocStubs(project: Project, srcDirs: Set<File>) = | ||
project.tasks.register<GenerateStubsTask>("docStubs") { | ||
sources.value(project.provider { srcDirs }) | ||
} | ||
|
||
protected fun configurePublishing(project: Project, firebaseLibrary: FirebaseLibraryExtension) { | ||
project.afterEvaluate { | ||
project.apply<MavenPublishPlugin>() | ||
project.extensions.configure<PublishingExtension> { | ||
repositories.maven { | ||
val s = project.rootProject.buildDir.toString() + "/m2repository" | ||
url = File(s).toURI() | ||
name = "BuildDir" | ||
} | ||
publications.create<MavenPublication>("mavenAar") { | ||
from(project.components.findByName(firebaseLibrary.type.componentName)) | ||
artifactId = firebaseLibrary.artifactId.get() | ||
groupId = firebaseLibrary.groupId.get() | ||
firebaseLibrary.applyPomCustomization(pom) | ||
} | ||
} | ||
} | ||
} | ||
} |
207 changes: 0 additions & 207 deletions
207
buildSrc/src/main/java/com/google/firebase/gradle/plugins/FirebaseJavaLibraryPlugin.java
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
buildSrc/src/main/java/com/google/firebase/gradle/plugins/FirebaseJavaLibraryPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2023 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.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatExtension | ||
import com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatPlugin | ||
import com.google.common.collect.ImmutableList | ||
import com.google.firebase.gradle.plugins.LibraryType.JAVA | ||
import org.gradle.api.Project | ||
import org.gradle.api.attributes.Attribute | ||
import org.gradle.api.plugins.JavaLibraryPlugin | ||
import org.gradle.api.plugins.JavaPluginConvention | ||
import org.gradle.kotlin.dsl.* | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() { | ||
|
||
override fun apply(project: Project) { | ||
project.apply<JavaLibraryPlugin>() | ||
project.apply<GoogleJavaFormatPlugin>() | ||
project.extensions.getByType<GoogleJavaFormatExtension>().toolVersion = "1.10.0" | ||
|
||
setupFirebaseLibraryExtension(project) | ||
|
||
// reduce the likelihood of kotlin module files colliding. | ||
project.tasks.withType<KotlinCompile> { | ||
kotlinOptions.freeCompilerArgs = ImmutableList.of("-module-name", kotlinModuleName(project)) | ||
} | ||
} | ||
|
||
private fun setupFirebaseLibraryExtension(project: Project) { | ||
val firebaseLibrary = | ||
project.extensions.create<FirebaseLibraryExtension>("firebaseLibrary", project, JAVA) | ||
|
||
setupStaticAnalysis(project, firebaseLibrary) | ||
setupApiInformationAnalysis(project) | ||
configurePublishing(project, firebaseLibrary) | ||
} | ||
|
||
private fun setupApiInformationAnalysis(project: Project) { | ||
val srcDirs = | ||
project.convention.getPlugin<JavaPluginConvention>().sourceSets.getByName("main").java.srcDirs | ||
|
||
val apiInfo = getApiInfo(project, srcDirs) | ||
val generateApiTxt = getGenerateApiTxt(project, srcDirs) | ||
val docStubs = getDocStubs(project, srcDirs) | ||
|
||
project.tasks.getByName("check").dependsOn(docStubs) | ||
project.afterEvaluate { | ||
val classpath = | ||
configurations | ||
.getByName("runtimeClasspath") | ||
.incoming | ||
.artifactView { | ||
attributes { attribute(Attribute.of("artifactType", String::class.java), "jar") } | ||
} | ||
.artifacts | ||
.artifactFiles | ||
apiInfo.configure { classPath = classpath } | ||
generateApiTxt.configure { classPath = classpath } | ||
docStubs.configure { classPath = classpath } | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.