Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

WIP: Add sbt 1.1.x support #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions plugin/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name := "sbtix"
organization := "se.nullable.sbtix"
version := "0.2-SNAPSHOT"

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15-1")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0")

ScriptedPlugin.scriptedSettings
ScriptedPlugin.projectSettings
scriptedLaunchOpts ++= Seq(
s"-Dplugin.version=${version.value}"
)
Expand Down
2 changes: 1 addition & 1 deletion plugin/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.15
sbt.version=1.1.0
4 changes: 2 additions & 2 deletions plugin/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15-1")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0")

resolvers += Resolver.typesafeIvyRepo("releases")
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import scala.collection.JavaConversions._
import java.util.concurrent.ExecutorService
import scala.concurrent.duration.Duration
import scala.util.control.NonFatal
import scala.collection.JavaConverters._
import java.nio.file.{ StandardCopyOption, Files => NioFiles }
case class GenericModule(primaryArtifact: Artifact, dep: Dependency, localFile: java.io.File) {
private val isIvy = localFile.getParentFile().getName() == "jars"
private val moduleId = ToSbt.moduleId(dep)
private val moduleId = ToSbt.moduleId((dep, Map()))
val url = new URL(primaryArtifact.url)

private val authedUri = authed(url)
Expand Down Expand Up @@ -63,17 +64,17 @@ case class MetaArtifact(artifactUrl: String, checkSum:String) extends Comparable
override def compareTo(other: MetaArtifact): Int = {
return artifactUrl.compareTo(other.artifactUrl)
}

def matchesGenericModule(gm:GenericModule) = {
val organ = gm.dep.module.organization
val name = gm.dep.module.name
val version = gm.dep.version

val slashOrgans = organ.replace(".", "/")

val mvn = s"$slashOrgans/$name/$version"
val ivy = s"$organ/$name/$version"

artifactUrl.contains(mvn) || artifactUrl.contains(ivy)
}
}
Expand All @@ -87,10 +88,10 @@ class CoursierArtifactFetcher(logger: Logger, resolvers: Set[Resolver], credenti
val (mods1,errors) = depends.map(x => buildNixProject(x)).unzip

val mods = mods1.flatten

//remove metaArtifacts that we already have a module for. We do not need to look them up twice.
val metaArtifacts = metaArtifactCollector.toSet.filterNot { meta =>mods.exists { meta.matchesGenericModule} }
val metaArtifacts = metaArtifactCollector.asScala.toSet.filterNot { meta =>mods.exists { meta.matchesGenericModule} }

//object to work with the rootUrl of Resolvers
val nixResolver = resolvers.map(NixResolver.resolve)

Expand All @@ -99,7 +100,7 @@ class CoursierArtifactFetcher(logger: Logger, resolvers: Set[Resolver], credenti

//retrieve metaArtifacts that were missed. Mostly parent POMS
val (metaRepoSeq, metaArtifactsSeqSeq) = nixResolver.flatMap(_.filterMetaArtifacts(logger, metaArtifacts)).unzip

val nixArtifacts = (artifactsSeqSeq.flatten ++ metaArtifactsSeqSeq.flatten)

val nixRepos = (repoSeq ++ metaRepoSeq)
Expand Down Expand Up @@ -130,7 +131,7 @@ class CoursierArtifactFetcher(logger: Logger, resolvers: Set[Resolver], credenti
).leftMap(_.describe).flatMap { f =>

def notFound(f: File) = Left(s"${f.getCanonicalPath} not found")

def read(f: File) =
try Right(new String(NioFiles.readAllBytes(f.toPath), "UTF-8").stripPrefix("\ufeff"))
catch {
Expand Down Expand Up @@ -180,7 +181,7 @@ class CoursierArtifactFetcher(logger: Logger, resolvers: Set[Resolver], credenti
read(f)
} else
notFound(f)

if (res.isRight) {
//only collect the http and https urls
if (artifact.url.startsWith("http")) {
Expand All @@ -192,7 +193,7 @@ class CoursierArtifactFetcher(logger: Logger, resolvers: Set[Resolver], credenti
EitherT.fromEither(Task.now[Either[String, String]](res))
}
}

//coursier must take dependencies one at a time, otherwise it only resolves the most recent version of a module, which causes missed dependencies.
private def buildNixProject(module: Dependency): (Seq[GenericModule],ResolutionErrors) = {
val res = Resolution(Set(module))
Expand All @@ -208,23 +209,23 @@ class CoursierArtifactFetcher(logger: Logger, resolvers: Set[Resolver], credenti
val modules = resolution.dependencyArtifacts.flatMap {
case ((dependency, artifact)) =>
val downloadedArtifact = Cache.file(artifact).run.unsafePerformSync

downloadedArtifact.toOption.map { localFile => GenericModule(artifact, dependency, localFile) }
}
(modules,ResolutionErrors(resolution.errors))
(modules,ResolutionErrors(resolution.metadataErrors))
}

private def ivyProps = Map("ivy.home" -> new File(sys.props("user.home"), ".ivy2").toString) ++ sys.props
}

case class ResolutionErrors(errors: Seq[(Dependency,Seq[String])]) {
case class ResolutionErrors(errors: Seq[(ModuleVersion, Seq[String])]) {

def +(other:ResolutionErrors) = {
ResolutionErrors(errors ++ other.errors)
ResolutionErrors(errors ++ other.errors)
}

def +(other:Seq[ResolutionErrors]) = {
ResolutionErrors(errors ++ other.flatMap(_.errors))
ResolutionErrors(errors ++ other.flatMap(_.errors))
}

}
2 changes: 1 addition & 1 deletion plugin/src/main/scala/se/nullable/sbtix/NixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object NixPlugin extends AutoPlugin {
.filterNot(_.extraAttributes.contains("e:nix"))
-- projectDependencies.value)

val depends = modules.flatMap(coursier.FromSbt.dependencies(_, scalaVersion.value, scalaBinaryVersion.value, "jar")).map(_._2)
val depends = modules.flatMap(coursier.FromSbt.dependencies(_, scalaVersion.value, scalaBinaryVersion.value)).map(_._2)
.filterNot {
_.module.organization == "se.nullable.sbtix"
} //ignore the sbtix dependency that gets added because of the global sbtix plugin
Expand Down
3 changes: 1 addition & 2 deletions plugin/src/main/scala/se/nullable/sbtix/NixResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ object NixResolver {
NixResolver(ivy.name, root, Some(pattern))
case mvn: MavenRepository => NixResolver(mvn.name, mvn.root, None)
case cr: ChainedResolver => ???
case jn1: JavaNet1Repository => ???
case raw: RawRepository => ???
}

Expand Down Expand Up @@ -44,4 +43,4 @@ case class NixResolver(private val name: String, rootUrl: String, pattern: Optio
case metas => Some((nixRepo, finder.findMetaArtifacts(logger, metas)))
}
}
}
}