diff --git a/plugin/build.sbt b/plugin/build.sbt index ef1f6b8..32dbcb1 100644 --- a/plugin/build.sbt +++ b/plugin/build.sbt @@ -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}" ) diff --git a/plugin/project/build.properties b/plugin/project/build.properties index 64317fd..8b697bb 100644 --- a/plugin/project/build.properties +++ b/plugin/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.15 +sbt.version=1.1.0 diff --git a/plugin/project/plugins.sbt b/plugin/project/plugins.sbt index 76637df..9236453 100644 --- a/plugin/project/plugins.sbt +++ b/plugin/project/plugins.sbt @@ -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") diff --git a/plugin/src/main/scala/se/nullable/sbtix/CoursierArtifactFetcher.scala b/plugin/src/main/scala/se/nullable/sbtix/CoursierArtifactFetcher.scala index f7309b3..d51758c 100644 --- a/plugin/src/main/scala/se/nullable/sbtix/CoursierArtifactFetcher.scala +++ b/plugin/src/main/scala/se/nullable/sbtix/CoursierArtifactFetcher.scala @@ -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) @@ -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) } } @@ -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) @@ -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) @@ -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 { @@ -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")) { @@ -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)) @@ -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)) } - + } diff --git a/plugin/src/main/scala/se/nullable/sbtix/NixPlugin.scala b/plugin/src/main/scala/se/nullable/sbtix/NixPlugin.scala index b2e8c80..9868d18 100644 --- a/plugin/src/main/scala/se/nullable/sbtix/NixPlugin.scala +++ b/plugin/src/main/scala/se/nullable/sbtix/NixPlugin.scala @@ -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 diff --git a/plugin/src/main/scala/se/nullable/sbtix/NixResolver.scala b/plugin/src/main/scala/se/nullable/sbtix/NixResolver.scala index 2fd780d..a50f504 100644 --- a/plugin/src/main/scala/se/nullable/sbtix/NixResolver.scala +++ b/plugin/src/main/scala/se/nullable/sbtix/NixResolver.scala @@ -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 => ??? } @@ -44,4 +43,4 @@ case class NixResolver(private val name: String, rootUrl: String, pattern: Optio case metas => Some((nixRepo, finder.findMetaArtifacts(logger, metas))) } } -} \ No newline at end of file +}