Skip to content

Commit b029172

Browse files
author
David Motsonashvili
committed
add support for fetching non-alpha artifacts to fix BoM generation
1 parent 2253d3f commit b029172

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
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().latestVersionOrNull(fullArtifactName)
198+
return gmaven.get().latestNonAlphaVersionOrNull(fullArtifactName)
199199
?: throw RuntimeException(
200200
"An artifact required for the tutorial bundle is missing from gmaven: $fullArtifactName"
201201
)

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,37 @@ abstract class GMavenService : BuildService<BuildServiceParameters.None> {
150150
fun latestVersionOrNull(groupId: String, artifactId: String) =
151151
controller.latestVersionOrNull(groupId, artifactId)
152152

153+
/**
154+
* Gets the latest non-alpha version of the artifact that has been uploaded to GMaven, if any.
155+
*
156+
* ```
157+
* gmaven.latestVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1"
158+
* ```
159+
*
160+
* @param groupId The group to search under.
161+
* @param artifactId The artifact to search for.
162+
* @return The latest released version as a string, or null if the artifact couldn't be found.
163+
* @see latestVersion
164+
*/
165+
fun latestNonAlphaVersionOrNull(groupId: String, artifactId: String) =
166+
controller.latestNonAlphaVersionOrNull(groupId, artifactId)
167+
168+
/**
169+
* Gets the latest non-alpha version of the artifact that has been uploaded to GMaven, if any.
170+
*
171+
* ```
172+
* gmaven.latestVersionOrNull("com.google.firebase", "firebase-components") // "18.0.1"
173+
* ```
174+
*
175+
* @param fullArtifactName The artifact to search for, represented as "groupId:artifactId".
176+
* @return The latest released version as a string, or null if the artifact couldn't be found.
177+
* @see latestVersion
178+
*/
179+
fun latestNonAlphaVersionOrNull(fullArtifactName: String): String? {
180+
val (groupId, artifactId) = fullArtifactName.split(":")
181+
return latestNonAlphaVersionOrNull(groupId, artifactId)
182+
}
183+
153184
/**
154185
* Gets the latest version of the artifact that has been uploaded to GMaven, if any.
155186
*
@@ -184,6 +215,24 @@ abstract class GMavenService : BuildService<BuildServiceParameters.None> {
184215
"Failed to get the latest version from gmaven for \'$artifactId\'. Has it been published?"
185216
)
186217

218+
/**
219+
* Gets the latest non-alpha version of the artifact that has been uploaded to GMaven.
220+
*
221+
* ```
222+
* gmaven.latestVersion("com.google.firebase", "firebase-components") // "18.0.1"
223+
* ```
224+
*
225+
* @param groupId The group to search under.
226+
* @param artifactId The artifact to search for.
227+
* @return The latest released version as a string.
228+
* @see latestNonAlphaVersionOrNull
229+
*/
230+
fun latestNonAlphaVersion(groupId: String, artifactId: String) =
231+
latestVersionOrNull(groupId, artifactId)
232+
?: throw RuntimeException(
233+
"Failed to get the latest version from gmaven for \'$artifactId\'. Has it been published?"
234+
)
235+
187236
/**
188237
* Checks if an artifact has been published to GMaven.
189238
*
@@ -403,6 +452,11 @@ class GMavenServiceController(
403452
return findFirebaseArtifact(groupId, artifactId)?.latestVersion
404453
}
405454

455+
/** @see GMavenService.latestVersionOrNull */
456+
fun latestNonAlphaVersionOrNull(groupId: String, artifactId: String): String? {
457+
return findFirebaseArtifact(groupId, artifactId)?.latestNonAlphaVersion
458+
}
459+
406460
/** @see GMavenService.hasReleasedArtifact */
407461
fun hasReleasedArtifact(groupId: String, artifactId: String): Boolean {
408462
return findFirebaseArtifact(groupId, artifactId) !== null
@@ -555,6 +609,7 @@ data class GroupIndexArtifact(
555609
val artifactId: String,
556610
val versions: List<String>,
557611
val latestVersion: String = versions.last(),
612+
val latestNonAlphaVersion: String = versions.last { !it.contains("alpha") }
558613
) {
559614

560615
/**

0 commit comments

Comments
 (0)