Skip to content

Commit ba0941b

Browse files
authored
Add copyApiTxtFile task (#6724)
Prerequisite of Metalava based SemVer
1 parent 91ea30e commit ba0941b

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.gradle.plugins
18+
19+
import org.gradle.api.DefaultTask
20+
import org.gradle.api.file.RegularFileProperty
21+
import org.gradle.api.tasks.InputFile
22+
import org.gradle.api.tasks.OutputFile
23+
import org.gradle.api.tasks.TaskAction
24+
25+
abstract class CopyApiTask : DefaultTask() {
26+
@get:InputFile abstract val apiTxtFile: RegularFileProperty
27+
@get:OutputFile abstract val output: RegularFileProperty
28+
29+
@TaskAction
30+
fun run() {
31+
output.get().asFile.writeText(apiTxtFile.get().asFile.readText())
32+
}
33+
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ class FirebaseAndroidLibraryPlugin : BaseFirebaseLibraryPlugin() {
160160
.getLatestReleasedVersion()
161161
)
162162
}
163+
164+
project.tasks.register<CopyApiTask>("copyApiTxtFile") {
165+
apiTxtFile.set(project.file("api.txt"))
166+
output.set(project.file("previous_api.txt"))
167+
}
163168
}
164169

165170
private fun setupApiInformationAnalysis(project: Project, android: LibraryExtension) {

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

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {
103103

104104
dependsOn("copyPreviousArtifacts")
105105
}
106+
107+
project.tasks.register<CopyApiTask>("copyApiTxtFile") {
108+
apiTxtFile.set(project.file("api.txt"))
109+
output.set(project.file("previous_api.txt"))
110+
}
106111
}
107112

108113
private fun setupApiInformationAnalysis(project: Project) {

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

+3
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ constructor(val project: Project, val type: LibraryType) {
241241
val version: String
242242
get() = project.version.toString()
243243

244+
val previousVersion: String
245+
get() = project.properties["latestReleasedVersion"].toString()
246+
244247
val path: String = project.path
245248

246249
val runtimeClasspath: String =

0 commit comments

Comments
 (0)