Created
January 8, 2016 20:14
-
-
Save metasim/31192966922376995ed9 to your computer and use it in GitHub Desktop.
Attempt at a command to convert a pom.xml dependency specification into sbt syntax.
This file contains hidden or 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
| /** Utility command to convert in SBT a maven dependency fragment into SBT syntax. */ | |
| def Pom2SbtCommand = "pom2sbt" | |
| def Pom2SbtHelp = " <pom.xml>" | |
| import complete.DefaultParsers._ | |
| lazy val pomLibs2Sbt = Command(Pom2SbtCommand, | |
| Help((Pom2SbtCommand, Pom2SbtHelp)))(_ ⇒ fileParser(new File("./"))) { (state, file) ⇒ | |
| import scala.xml.XML | |
| val deps = XML.loadFile(file) \\ "dependency" | |
| val sbtdeps = deps map ((dependency) ⇒ { | |
| val coords = Seq("groupId", "artifactId", "version", "scope") | |
| val coordParts = coords.map(coord ⇒ (dependency \ coord).text.trim).filter(_.nonEmpty) | |
| coordParts.mkString("\"", "\" % \"", "\"") | |
| }) | |
| println(s"Read ${sbtdeps.size} dependency entries from $file") | |
| println(sbtdeps.mkString("\n")) | |
| state | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment