Last active
December 14, 2015 07:29
-
-
Save schmmd/5050790 to your computer and use it in GitHub Desktop.
Create an sbt file from a pom file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.xml._ | |
val scalaVersion = args.headOption | |
def quote(s: String) = "\"" + s + "\"" | |
val xml = XML.loadString(scala.io.Source.stdin.getLines.mkString("\n")) | |
val name = (xml \ "artifactId").text | |
val version = (xml \ "version").text | |
case class Repository(name: String, url: String) { | |
def sbtString = quote(name) + " at " + quote(url) | |
} | |
val repositories = (xml \\ "repository").map { repo => | |
Repository((repo \ "id").text, (repo \ "url").text) | |
} | |
case class Dependency(groupId: String, artifactId: String, version: String) { | |
def sbtString = scalaVersion match { | |
case Some(scalaVersion) if (artifactId contains ("_" + scalaVersion)) => quote(groupId) + " %% " + quote(artifactId.take(artifactId.indexOf("_" + scalaVersion))) + " % " + quote(version) | |
case _ => quote(groupId) + " % " + quote(artifactId) + " % " + quote(version) | |
} | |
} | |
val dependencies = (xml \\ "dependency").map { dep => | |
Dependency((dep \ "groupId").text, (dep \ "artifactId").text, (dep \ "version").text) | |
} | |
(Seq( | |
"name" -> name, | |
"version" -> version | |
) ++ scalaVersion.map("scalaVersion" -> _)).foreach { case (name, value) => println(name + " := " + quote(value)); println() } | |
println("resolvers ++= " + repositories.map(_.sbtString).mkString("Seq(", ",\n ", ")")); | |
println() | |
println("libraryDependencies ++= " + dependencies.map(_.sbtString).mkString("Seq(", ",\n ", ")")); | |
println() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment