Skip to content

Commit

Permalink
Merge pull request #92 from tindzk/issue/91
Browse files Browse the repository at this point in the history
MavenCentral: Fix resolution of Scala.js 1.0 artefacts
  • Loading branch information
tindzk authored Mar 23, 2020
2 parents 62d654e + d432978 commit dffd692
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 28 deletions.
32 changes: 20 additions & 12 deletions src/main/scala/seed/artefact/MavenCentral.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ object MavenCentral {
}
}

def scalaJsBinaryVersion(version: String): String =
SemanticVersioning.parseVersion(version) match {
case Some(v) if v.preRelease.isDefined => version
case Some(v) if v.major >= 1 => v.major.toString
case Some(v) => v.major + "." + v.minor
case None => version
}

def scalaNativeBinaryVersion(version: String): String =
trimCompilerVersion(version)

def platformBinaryTag(platform: Platform, platformVersion: String): String =
platform match {
case JVM => ""
case JavaScript => "sjs" + scalaJsBinaryVersion(platformVersion) + "_"
case Native => "native" + scalaNativeBinaryVersion(platformVersion) + "_"
}

def formatArtefactName(
artefactName: String,
versionTag: VersionTag,
Expand All @@ -172,18 +190,8 @@ object MavenCentral {
versionTag match {
case VersionTag.PlatformBinary =>
val trimmedCompilerVersion = trimCompilerVersion(compilerVersion)

val version = platform match {
case JVM => trimmedCompilerVersion
case JavaScript =>
"sjs" + trimCompilerVersion(platformVersion) +
"_" + trimmedCompilerVersion
case Native =>
"native" + trimCompilerVersion(platformVersion) +
"_" + trimmedCompilerVersion
}

artefactName + "_" + version
val version = platformBinaryTag(platform, platformVersion)
artefactName + "_" + version + trimmedCompilerVersion

case VersionTag.Full =>
val trimmedCompilerVersion = trimCompilerVendor(compilerVersion)
Expand Down
30 changes: 15 additions & 15 deletions src/main/scala/seed/cli/Publish.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import seed.artefact.ArtefactResolution.{
ModuleRef,
RuntimeResolution
}
import seed.artefact.{ArtefactResolution, Coursier, SemanticVersioning}
import seed.artefact.{
ArtefactResolution,
Coursier,
MavenCentral,
SemanticVersioning
}
import seed.cli.util.{
Ansi,
ConsoleOutput,
Expand All @@ -22,8 +27,7 @@ import seed.cli.util.{
import seed.config.BuildConfig
import seed.config.BuildConfig.Build
import seed.generation.util.PathUtil
import seed.model.Build.{JavaDep, Resolvers}
import seed.model.Platform.{JavaScript, Native}
import seed.model.Build.{JavaDep, Resolvers, VersionTag}
import seed.model.{Config, Platform}
import seed.publish.Bintray
import seed.publish.util.Http
Expand Down Expand Up @@ -400,10 +404,6 @@ object Publish {
""".toXml
}

def encodeVersion(version: String): String =
if (SemanticVersioning.isPreRelease(version)) version
else SemanticVersioning.majorMinorVersion(version)

def getVersion(
projectPath: Path,
version: Option[String],
Expand Down Expand Up @@ -630,14 +630,14 @@ object Publish {
platform: Platform,
platformModule: seed.model.Build.Module
): String = {
val packageArtefactPlatform =
if (platform == JavaScript)
"_sjs" + encodeVersion(platformModule.scalaJsVersion.get)
else if (platform == Native)
"_native" + encodeVersion(platformModule.scalaNativeVersion.get)
else ""
val scalaVersion = "_" + encodeVersion(platformModule.scalaVersion.get)
s"$module$packageArtefactPlatform$scalaVersion"
val platformVersion = BuildConfig.platformVersion(platformModule, platform)
MavenCentral.formatArtefactName(
module,
VersionTag.PlatformBinary,
platform,
platformVersion,
platformModule.scalaVersion.get
)
}

def resolveArtefactsAndCreatePom(
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/seed/generation/util/ScalaCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import seed.artefact.ArtefactResolution.CompilerResolution
import seed.config.BuildConfig.Build
import seed.model.Build.Module
import seed.model.Platform.{JavaScript, Native}
import seed.model.{Artefact, Build, Platform}
import seed.model.{Artefact, Platform}

object ScalaCompiler {
private def resolveCompiler(
Expand Down
31 changes: 31 additions & 0 deletions src/test/scala/seed/artefact/MavenCentralSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package seed.artefact
import minitest.SimpleTestSuite
import seed.model.Platform.JVM
import seed.Log
import seed.model.Build.VersionTag
import seed.model.Platform

object MavenCentralSpec extends SimpleTestSuite {
test("Parse library artefact versions") {
Expand Down Expand Up @@ -40,4 +42,33 @@ object MavenCentralSpec extends SimpleTestSuite {
List((JVM, "2.11", "2.11"), (JVM, "2.12", "2.12"), (JVM, "2.13", "2.13"))
)
}

test("Format Scala.js artefact names") {
val sjs06 = MavenCentral.formatArtefactName(
"slinky-core",
VersionTag.PlatformBinary,
Platform.JavaScript,
"0.6.32",
"2.13.1"
)
assertEquals(sjs06, "slinky-core_sjs0.6_2.13")

val sjs10rc2 = MavenCentral.formatArtefactName(
"slinky-core",
VersionTag.PlatformBinary,
Platform.JavaScript,
"1.0-RC2",
"2.13.1"
)
assertEquals(sjs10rc2, "slinky-core_sjs1.0-RC2_2.13")

val sjs10 = MavenCentral.formatArtefactName(
"slinky-core",
VersionTag.PlatformBinary,
Platform.JavaScript,
"1.0.1",
"2.13.1"
)
assertEquals(sjs10, "slinky-core_sjs1_2.13")
}
}

0 comments on commit dffd692

Please sign in to comment.