-
-
Save martinbonnin/bdbc85d782acf72019661753526292a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Makes sure both Maven and Gradle support SemVer | |
| */ | |
| import org.apache.maven.artifact.versioning.ComparableVersion | |
| import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionComparator | |
| import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version | |
| import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionParser | |
| import org.junit.jupiter.api.Assertions.assertEquals | |
| import kotlin.collections.sortedBy | |
| buildscript { | |
| repositories { | |
| mavenCentral() | |
| } | |
| dependencies { | |
| classpath("org.apache.maven:maven-artifact:3.8.6") | |
| classpath("org.junit.jupiter:junit-jupiter-api:5.10.1") | |
| } | |
| } | |
| val comparator = DefaultVersionComparator().asVersionComparator() | |
| val parser = VersionParser() | |
| class GradleVersion(version: String): Comparable<GradleVersion> { | |
| val version: Version = parser.transform(version) | |
| override fun compareTo(other: GradleVersion): Int { | |
| return comparator.compare(this.version, other.version) | |
| } | |
| } | |
| val versions = listOf( | |
| "0.1.1-SNAPSHOT", | |
| "0.1.1", | |
| "0.1.2", | |
| "0.1.10", | |
| "1.0.0-alpha.1-SNAPSHOT", | |
| "1.0.0-alpha.1", | |
| "1.0.0-alpha.2", | |
| "1.0.0-alpha.10", | |
| "1.0.0-beta.1-SNAPSHOT", | |
| "1.0.0-beta.1", | |
| "1.0.0-beta.2", | |
| "1.0.0-beta.10", | |
| "1.0.0-rc.1-SNAPSHOT", | |
| "1.0.0-rc.1", | |
| "1.0.0-rc.2", | |
| "1.0.0-rc.10", | |
| "1.0.1", | |
| "1.0.2", | |
| "1.0.10", | |
| "1.1.0", | |
| "2.0.0", | |
| "10.0.0", | |
| ) | |
| fun <Version: Comparable<Version>> assertOrdering(versions: List<String>, block: (String) -> Version) { | |
| val sorted = versions.sortedBy(block) | |
| assertEquals(versions, sorted) | |
| } | |
| // Maven | |
| assertOrdering(versions) { | |
| ComparableVersion(it) | |
| } | |
| // Gradle | |
| assertOrdering(versions) { | |
| GradleVersion(it) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment