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

Idea: Fix dependency resolution of platform dependencies #6

Merged
merged 1 commit into from
Jan 27, 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
24 changes: 16 additions & 8 deletions src/main/scala/seed/artefact/Coursier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,22 @@ object Coursier {

def resolveSubset(resolution: Resolution,
deps: Set[Dep],
optionalArtefacts: Boolean): List[(Classifier, Artefact)] =
resolution.subset(coursierDependencies(deps))
.dependencyArtifacts(
Some(
overrideClassifiers(
sources = optionalArtefacts,
javaDoc = optionalArtefacts))
).map(a => (a._2.classifier, a._3)).toList
optionalArtefacts: Boolean): List[(Classifier, Artefact)] = {
val result =
resolution
.subset(coursierDependencies(deps))
.dependencyArtifacts(
Some(
overrideClassifiers(
sources = optionalArtefacts,
javaDoc = optionalArtefacts)))

require(deps.forall(d => result.map(_._1.module).exists(m =>
m.organization.value == d.organisation &&
m.name.value == d.artefact)), "Missing dependencies in artefact resolution")

result.map(a => (a._2.classifier, a._3)).toList
}

def overrideClassifiers(sources: Boolean, javaDoc: Boolean): Seq[Classifier] =
Seq(Classifier.empty) ++
Expand Down
16 changes: 8 additions & 8 deletions src/main/scala/seed/generation/Idea.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ object Idea {
collectJsDeps(build, module).map(dep =>
ArtefactResolution.dependencyFromDep(
dep, JavaScript,
build.project.scalaVersion,
build.project.scalaJsVersion.get)
build.project.scalaJsVersion.get,
build.project.scalaVersion)
).toSet,
optionalArtefacts = true),
resolvedTestDeps = module.test.toList.flatMap(test =>
Coursier.localArtefacts(resolution,
collectJsDeps(build, test).map(dep =>
ArtefactResolution.dependencyFromDep(
dep, JavaScript,
build.project.scalaVersion,
build.project.scalaJsVersion.get)
build.project.scalaJsVersion.get,
build.project.scalaVersion)
).toSet,
optionalArtefacts = true)),
moduleDeps =
Expand Down Expand Up @@ -257,17 +257,17 @@ object Idea {
collectNativeDeps(build, module).map(dep =>
ArtefactResolution.dependencyFromDep(
dep, Native,
build.project.scalaVersion,
build.project.scalaNativeVersion.get)
build.project.scalaNativeVersion.get,
build.project.scalaVersion)
).toSet,
optionalArtefacts = true),
resolvedTestDeps = module.test.toList.flatMap(test =>
Coursier.localArtefacts(resolution,
collectNativeDeps(build, test).map(dep =>
ArtefactResolution.dependencyFromDep(
dep, Native,
build.project.scalaVersion,
build.project.scalaNativeVersion.get)
build.project.scalaNativeVersion.get,
build.project.scalaVersion)
).toSet,
optionalArtefacts = true)),
moduleDeps =
Expand Down
15 changes: 15 additions & 0 deletions src/test/scala/seed/artefact/ArtefactResolutionSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package seed.artefact

import minitest.SimpleTestSuite
import seed.model.Build.Dep
import seed.model.Platform.JavaScript

object ArtefactResolutionSpec extends SimpleTestSuite {
test("dependencyFromDep()") {
val scalaDep = Dep("org.scala-js", "scalajs-dom", "0.9.6")
val javaDep = ArtefactResolution.dependencyFromDep(
scalaDep, JavaScript, "0.6", "2.12")
assertEquals(javaDep,
Dep("org.scala-js", "scalajs-dom_sjs0.6_2.12", "0.9.6"))
}
}
20 changes: 20 additions & 0 deletions src/test/scala/seed/artefact/CoursierSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package seed.artefact

import minitest.SimpleTestSuite
import seed.model.Build
import seed.model.Build.Dep

object CoursierSpec extends SimpleTestSuite {
test("Resolve dependency") {
val dep = Dep("org.scala-js", "scalajs-dom_sjs0.6_2.12", "0.9.6")
val resolution = Coursier.resolveAndDownload(Set(dep),
Build.Resolvers(), Coursier.DefaultIvyPath,
Coursier.DefaultCachePath, optionalArtefacts = true)

val result =
Coursier.localArtefacts(resolution, Set(dep), optionalArtefacts = true)
assert(
result.exists(_.javaDocJar.nonEmpty) &&
result.exists(_.sourcesJar.nonEmpty))
}
}