Skip to content

Commit

Permalink
Merge pull request #34 from tindzk/bug/version-ordering
Browse files Browse the repository at this point in the history
MavenCentral: Fix parsing of library artefacts
  • Loading branch information
tindzk authored Jul 25, 2019
2 parents 62cabd3 + cdfba60 commit ea4c24b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main/scala/seed/artefact/MavenCentral.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@ object MavenCentral {
.map(_.takeWhile(_ != '/'))
}

/** @param stable Only consider stable artefacts (as opposed to pre-releases)
* @return Found versions in ascending order
*/
def fetchLibraryArtefacts(artefact: Artefact, stable: Boolean, log: Log): List[
def parseLibraryArtefacts(artefacts: List[String], artefactName: String, stable: Boolean, log: Log): List[
(Platform, PlatformVersion, CompilerVersion)
] =
fetchOrganisationArtefacts(artefact.organisation, log)
.filter(_.startsWith(artefact.name))
.map(_.drop(artefact.name.length + 1))
artefacts
.filter(_.startsWith(artefactName + "_"))
.map(_.drop(artefactName.length + 1))
.filter(a =>
a.headOption.exists(_.isDigit) ||
a.startsWith("sjs") ||
Expand All @@ -72,6 +69,18 @@ object MavenCentral {
isArtefactEligible(stable, log)(a._3))
.sortBy(_._2)(new SemanticVersioning(log).versionOrdering)

/** @param stable Only consider stable artefacts (as opposed to pre-releases)
* @return Found versions in ascending order
*/
def fetchLibraryArtefacts(artefact: Artefact, stable: Boolean, log: Log): List[
(Platform, PlatformVersion, CompilerVersion)
] =
parseLibraryArtefacts(
fetchOrganisationArtefacts(artefact.organisation, log),
artefact.name,
stable,
log)

type PlatformVersion = String
type CompilerVersion = String
/** Derive from artefact name, supported platforms and compilers */
Expand Down
38 changes: 38 additions & 0 deletions src/test/scala/seed/artefact/MavenCentralSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package seed.artefact

import minitest.SimpleTestSuite
import seed.model.Platform.JVM
import seed.Log

object MavenCentralSpec extends SimpleTestSuite {
test("Parse library artefact versions") {
val artefacts = List(
"scribe-slf4j18_2.11",
"scribe-slf4j18_2.12",
"scribe-slf4j18_2.13",

// Only these should match
"scribe-slf4j_2.11",
"scribe-slf4j_2.12",
"scribe-slf4j_2.13",
"scribe-slf4j_2.13.0-RC2")

def parse(stable: Boolean) =
MavenCentral.parseLibraryArtefacts(
artefacts,
"scribe-slf4j",
stable,
Log.urgent)

assertEquals(parse(stable = false), List(
(JVM, "2.11", "2.11"),
(JVM, "2.12", "2.12"),
(JVM, "2.13.0-RC2", "2.13.0-RC2"),
(JVM, "2.13", "2.13")))

assertEquals(parse(stable = true), List(
(JVM, "2.11", "2.11"),
(JVM, "2.12", "2.12"),
(JVM, "2.13", "2.13")))
}
}

0 comments on commit ea4c24b

Please sign in to comment.