Skip to content

Commit bcda23f

Browse files
committed
[gemini] proposed solution to maven bom generator
1 parent 9cc0669 commit bcda23f

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

plugins/src/main/java/com/google/firebase/gradle/bomgenerator/GenerateTutorialBundleTask.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ abstract class GenerateTutorialBundleTask : DefaultTask() {
195195
} else {
196196
logger.info("Fetching the latest version for an artifact: $fullArtifactName")
197197

198-
return gmaven.get().latestNonAlphaVersionOrNull(fullArtifactName)
198+
return gmaven.get().latestStableVersionOrNull(fullArtifactName)
199199
?: throw RuntimeException(
200200
"An artifact required for the tutorial bundle is missing from gmaven: $fullArtifactName"
201201
)
@@ -206,10 +206,6 @@ abstract class GenerateTutorialBundleTask : DefaultTask() {
206206
val (name, alias, extra) = mappings[fullArtifactName]!!
207207

208208
val version = versionString(fullArtifactName)
209-
if (version.lowercase().contains("-alpha")) {
210-
logger.info("Ignoring alpha version of $fullArtifactName")
211-
return "" // Alpha versions should not be included in the tutorial bundle
212-
}
213209

214210
return multiLine("<!-- $name -->", "<!ENTITY $alias \"$fullArtifactName:${version}\">", extra)
215211
}

plugins/src/main/java/com/google/firebase/gradle/plugins/services/GmavenService.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,41 @@ abstract class GMavenService : BuildService<BuildServiceParameters.None> {
181181
return latestNonAlphaVersionOrNull(groupId, artifactId)
182182
}
183183

184+
/**
185+
* Gets the latest stable version of the artifact that has been uploaded to GMaven, if any.
186+
*
187+
* Stable versions do not include alpha or beta versions.
188+
*
189+
* ```
190+
* gmaven.latestStableVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1"
191+
* ```
192+
*
193+
* @param groupId The group to search under.
194+
* @param artifactId The artifact to search for.
195+
* @return The latest released version as a string, or null if the artifact couldn't be found.
196+
* @see latestVersion
197+
*/
198+
fun latestStableVersionOrNull(groupId: String, artifactId: String) =
199+
controller.latestStableVersionOrNull(groupId, artifactId)
200+
201+
/**
202+
* Gets the latest stable version of the artifact that has been uploaded to GMaven, if any.
203+
*
204+
* Stable versions do not include alpha or beta versions.
205+
*
206+
* ```
207+
* gmaven.latestStableVersionOrNull("com.google.firebase:firebase-components") // "18.0.1"
208+
* ```
209+
*
210+
* @param fullArtifactName The artifact to search for, represented as "groupId:artifactId".
211+
* @return The latest released version as a string, or null if the artifact couldn't be found.
212+
* @see latestVersion
213+
*/
214+
fun latestStableVersionOrNull(fullArtifactName: String): String? {
215+
val (groupId, artifactId) = fullArtifactName.split(":")
216+
return latestStableVersionOrNull(groupId, artifactId)
217+
}
218+
184219
/**
185220
* Gets the latest version of the artifact that has been uploaded to GMaven, if any.
186221
*
@@ -439,6 +474,11 @@ class GMavenServiceController(
439474
return findFirebaseArtifact(groupId, artifactId)?.latestNonAlphaVersion
440475
}
441476

477+
/** @see GMavenService.latestStableVersionOrNull */
478+
fun latestStableVersionOrNull(groupId: String, artifactId: String): String? {
479+
return findFirebaseArtifact(groupId, artifactId)?.latestStableVersion
480+
}
481+
442482
/** @see GMavenService.hasReleasedArtifact */
443483
fun hasReleasedArtifact(groupId: String, artifactId: String): Boolean {
444484
return findFirebaseArtifact(groupId, artifactId) !== null
@@ -592,6 +632,7 @@ data class GroupIndexArtifact(
592632
val versions: List<String>,
593633
val latestVersion: String = versions.last(),
594634
val latestNonAlphaVersion: String? = versions.findLast { !it.contains("alpha") },
635+
val latestStableVersion: String? = versions.findLast { !it.contains("alpha") && !it.contains("beta") },
595636
) {
596637

597638
/**

0 commit comments

Comments
 (0)