-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove usage of deprecated VersionNumber
Signed-off-by: Alex Saveau <[email protected]>
- Loading branch information
1 parent
1124e7a
commit aa73701
Showing
5 changed files
with
45 additions
and
53 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
common/validation/src/main/kotlin/com/github/triplet/gradle/common/validation/MinDeps.kt
This file contains 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,7 @@ | ||
package com.github.triplet.gradle.common.validation | ||
|
||
import com.android.build.api.AndroidPluginVersion | ||
import org.gradle.util.GradleVersion | ||
|
||
internal val MIN_GRADLE_VERSION = GradleVersion.version("7.0.2") | ||
internal val MIN_AGP_VERSION = AndroidPluginVersion(7, 0) |
18 changes: 2 additions & 16 deletions
18
...on/src/main/kotlin/com/github/triplet/gradle/common/validation/RuntimeValidationPlugin.kt
This file contains 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 |
---|---|---|
@@ -1,28 +1,14 @@ | ||
package com.github.triplet.gradle.common.validation | ||
|
||
import com.android.Version | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.util.GradleVersion | ||
import org.gradle.util.VersionNumber | ||
|
||
internal class RuntimeValidationPlugin : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
check(project === project.rootProject) | ||
|
||
val agpVersion = try { | ||
VersionNumber.parse(Version.ANDROID_GRADLE_PLUGIN_VERSION) | ||
} catch (e: NoClassDefFoundError) { | ||
null | ||
} | ||
val validator = RuntimeValidator( | ||
GradleVersion.current(), MIN_GRADLE_VERSION, agpVersion, MIN_AGP_VERSION) | ||
|
||
validator.validate() | ||
} | ||
|
||
private companion object { | ||
val MIN_GRADLE_VERSION = GradleVersion.version("7.0.2") | ||
val MIN_AGP_VERSION = VersionNumber.parse("7.0.0") | ||
GradleRuntimeValidator(GradleVersion.current(), MIN_GRADLE_VERSION) | ||
.validate() | ||
} | ||
} |
This file contains 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
9 changes: 9 additions & 0 deletions
9
common/validation/src/main/kotlin/com/github/triplet/gradle/common/validation/Validation.kt
This file contains 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
45 changes: 19 additions & 26 deletions
45
...ation/src/test/kotlin/com/github/triplet/gradle/common/validation/RuntimeValidatorTest.kt
This file contains 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 |
---|---|---|
@@ -1,75 +1,68 @@ | ||
package com.github.triplet.gradle.common.validation | ||
|
||
import com.android.build.api.AndroidPluginVersion | ||
import org.gradle.util.GradleVersion | ||
import org.gradle.util.VersionNumber | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
||
class RuntimeValidatorTest { | ||
@Test | ||
fun `Gradle version below minimum throws`() { | ||
val validator = newValidator( | ||
currentGradle = GradleVersion.version("0.0.0"), | ||
minGradle = GradleVersion.version("1.0.0") | ||
val validator = GradleRuntimeValidator( | ||
currentGradleVersion = GradleVersion.version("0.0.0"), | ||
minGradleVersion = GradleVersion.version("1.0.0"), | ||
) | ||
|
||
assertThrows<IllegalStateException> { validator.validate() } | ||
} | ||
|
||
@Test | ||
fun `Gradle version at minimum succeeds`() { | ||
val validator = newValidator( | ||
currentGradle = GradleVersion.version("1.0.0"), | ||
minGradle = GradleVersion.version("1.0.0") | ||
val validator = GradleRuntimeValidator( | ||
currentGradleVersion = GradleVersion.version("1.0.0"), | ||
minGradleVersion = GradleVersion.version("1.0.0"), | ||
) | ||
|
||
validator.validate() | ||
} | ||
|
||
@Test | ||
fun `Gradle version above minimum succeeds`() { | ||
val validator = newValidator( | ||
currentGradle = GradleVersion.version("2.0.0"), | ||
minGradle = GradleVersion.version("1.0.0") | ||
val validator = GradleRuntimeValidator( | ||
currentGradleVersion = GradleVersion.version("2.0.0"), | ||
minGradleVersion = GradleVersion.version("1.0.0"), | ||
) | ||
|
||
validator.validate() | ||
} | ||
|
||
@Test | ||
fun `Agp version below minimum throws`() { | ||
val validator = newValidator( | ||
currentAgp = VersionNumber.parse("0.0.0"), | ||
minAgp = VersionNumber.parse("1.0.0") | ||
val validator = AgpRuntimeValidator( | ||
currentAgpVersion = AndroidPluginVersion(0, 0), | ||
minAgpVersion = AndroidPluginVersion(1, 0), | ||
) | ||
|
||
assertThrows<IllegalStateException> { validator.validate() } | ||
} | ||
|
||
@Test | ||
fun `Agp version at minimum succeeds`() { | ||
val validator = newValidator( | ||
currentAgp = VersionNumber.parse("1.0.0"), | ||
minAgp = VersionNumber.parse("1.0.0") | ||
val validator = AgpRuntimeValidator( | ||
currentAgpVersion = AndroidPluginVersion(1, 0), | ||
minAgpVersion = AndroidPluginVersion(1, 0), | ||
) | ||
|
||
validator.validate() | ||
} | ||
|
||
@Test | ||
fun `Agp version above minimum succeeds`() { | ||
val validator = newValidator( | ||
currentAgp = VersionNumber.parse("2.0.0"), | ||
minAgp = VersionNumber.parse("1.0.0") | ||
val validator = AgpRuntimeValidator( | ||
currentAgpVersion = AndroidPluginVersion(2, 0), | ||
minAgpVersion = AndroidPluginVersion(1, 0), | ||
) | ||
|
||
validator.validate() | ||
} | ||
|
||
private fun newValidator( | ||
currentGradle: GradleVersion = GradleVersion.version("0.0.0"), | ||
minGradle: GradleVersion = GradleVersion.version("0.0.0"), | ||
currentAgp: VersionNumber = VersionNumber.parse("0.0.0"), | ||
minAgp: VersionNumber = VersionNumber.parse("0.0.0"), | ||
) = RuntimeValidator(currentGradle, minGradle, currentAgp, minAgp) | ||
} |