Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MavenCentral: Fix parsing of library artefacts #34

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")))
}
}