Skip to content

Commit 20b702a

Browse files
committed
Fixes
1 parent 4738ab4 commit 20b702a

File tree

1 file changed

+28
-16
lines changed
  • plugins/src/main/java/com/google/firebase/gradle/plugins

1 file changed

+28
-16
lines changed

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
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+
117
package com.google.firebase.gradle.plugins
218

319
import com.google.firebase.gradle.plugins.semver.VersionDelta
20+
import java.io.ByteArrayOutputStream
421
import org.gradle.api.DefaultTask
522
import org.gradle.api.GradleException
623
import org.gradle.api.file.RegularFileProperty
@@ -9,30 +26,25 @@ import org.gradle.api.tasks.Input
926
import org.gradle.api.tasks.InputFile
1027
import org.gradle.api.tasks.OutputFile
1128
import org.gradle.api.tasks.TaskAction
12-
import java.io.ByteArrayOutputStream
1329

1430
abstract class SemVerTask : DefaultTask() {
15-
@get:InputFile
16-
abstract val apiTxtFile: RegularFileProperty
17-
@get:InputFile
18-
abstract val otherApiFile: RegularFileProperty
19-
@get:Input
20-
abstract val currentVersionString: Property<String>
21-
@get:Input
22-
abstract val previousVersionString: Property<String>
31+
@get:InputFile abstract val apiTxtFile: RegularFileProperty
32+
@get:InputFile abstract val otherApiFile: RegularFileProperty
33+
@get:Input abstract val currentVersionString: Property<String>
34+
@get:Input abstract val previousVersionString: Property<String>
2335

24-
@get:OutputFile
25-
abstract val outputApiFile: RegularFileProperty
36+
@get:OutputFile abstract val outputApiFile: RegularFileProperty
2637

2738
@TaskAction
2839
fun run() {
29-
val regex = Regex("\\d+\\.\\d+\\.\\d.*")
30-
if (!previousVersionString.get().matches(regex) || !currentVersionString.get().matches(regex)) {
40+
val previous = ModuleVersion.fromStringOrNull(previousVersionString.get())
41+
val current = ModuleVersion.fromStringOrNull(currentVersionString.get())
42+
if (previous == null || current == null) {
3143
return // If these variables don't exist, no reason to check API
3244
}
33-
val (previousMajor, previousMinor, previousPatch) = previousVersionString.get().split(".")
34-
val (currentMajor, currentMinor, currentPatch) = currentVersionString.get().split(".")
35-
val bump = if (previousMajor != currentMajor) VersionDelta.MAJOR else if (previousMinor != currentMinor) VersionDelta.MINOR else VersionDelta.PATCH
45+
val bump =
46+
if (previous.major != current.major) VersionDelta.MAJOR
47+
else if (previous.minor != current.minor) VersionDelta.MINOR else VersionDelta.PATCH
3648
val stream = ByteArrayOutputStream()
3749
project.runMetalavaWithArgs(
3850
listOf(

0 commit comments

Comments
 (0)