<commit_before>package io.kevinlee.maven2sbt

import scala.language.postfixOps
import scala.xml._

/**
  * @author <NAME>
  * @since 2017-04-03
  */
object Maven2Sbt extends App {

  val scalaVersion = "2.11.7"

  val pomXml = getClass.getResourceAsStream("/pom.xml")
  val pom = XML.load(pomXml)

  val groupId = pom \ "groupId" text
  val artifactId = pom \ "artifactId" text
  val version = pom \ "version" text

  val dotSeparatedPattern = """\$\{(.+)\}""".r

  def findPropertyName(name: String): Option[String] = name match {
    case dotSeparatedPattern(value) => Some(value.trim)
    case _ => None
  }

  def dotSeparatedToCamelCase(dotSeparated: String): String = {
      val names = dotSeparated.trim.split("\\.")
      if (names.length == 1)
        dotSeparated
      else
        names.head + names.tail.map(_.capitalize).mkString
  }


  val properties: Map[String, String] = (for {
    properties <- pom \ "properties"
    property <- properties.child
    label = property.label
    if !label.startsWith("#PCDATA")
  } yield label -> property.text).toMap

  case class Repository(id: String, name: String, url: String)

  val repositories: Seq[Repository] = for {
    repositories <- pom \ "repositories"
    repository <- repositories.child
    url = (repository \ "url").text
    if url.nonEmpty
    id = (repository \ "id").text
    name = (repository \ "name").text
  } yield Repository(id, name, url)


  case class Dependency(groupId: String,
                        artifactId: String,
                        version: String,
                        scope: Option[String]) {
    def toDependencyString: String =
      s""""$groupId" % "$artifactId" % ${findPropertyName(version).fold("\"" + version + "\"")(dotSeparatedToCamelCase)}${scope.fold("")(x => s""" % "$x"""")}"""
  }

  val dependencies: Seq[Dependency] =
    pom \ "dependencies" \ "dependency" map { dependency =>
      val groupId = dependency \ "groupId" text
      val artifactId = dependency \ "artifactId" text
      val version = dependency \ "version" text
      val scope = dependency \ "scope" text

      Dependency(groupId,
                 artifactId,
                 version,
                 Option(scope).filter(_.nonEmpty))
    }

  val resolvers = repositories match {
    case Nil =>
      ""
    case x :: Nil =>
      s"""resolvers += "${x.name}" at "${x.url}""""
    case x :: xs =>
      s"""resolvers ++= Seq(
         |  "${x.name}" at "${x.url}",
         |  ${xs.map(x => s""""${x.name}" at "${x.url}"""").mkString(",\n  ")}
         |)
         |""".stripMargin
  }

  val libraryDependencies = dependencies match {
    case Nil =>
      ""
    case x :: Nil =>
      s"""libraryDependencies += "${x.toDependencyString}"""
    case x :: xs =>
      s"""libraryDependencies ++= Seq(
         |  ${x.toDependencyString},
         |  ${xs.map(_.toDependencyString).mkString(",\n  ")}
         |)
         |""".stripMargin
  }

  val buildSbt =
    s"""
       |organization := "$groupId"
       |
       |name := "$artifactId"
       |
       |version := "$version"
       |
       |scalaVersion := "$scalaVersion"
       |
       |${properties map { case (k, v) => s"""val ${dotSeparatedToCamelCase(k)} = "$v"""" } mkString "\n"}
       |
       |$resolvers
       |
       |$libraryDependencies
       |
     """.stripMargin

  println(buildSbt)

}
<commit_msg>Changed: Formatting of the build.sbt generated by maven2sbt<commit_after>package io.kevinlee.maven2sbt

import scala.language.postfixOps
import scala.xml._

/**
  * @author <NAME>
  * @since 2017-04-03
  */
object Maven2Sbt extends App {

  val scalaVersion = "2.11.7"

  val pomXml = getClass.getResourceAsStream("/pom.xml")
  val pom = XML.load(pomXml)

  val groupId = pom \ "groupId" text
  val artifactId = pom \ "artifactId" text
  val version = pom \ "version" text

  val dotSeparatedPattern = """\$\{(.+)\}""".r

  def findPropertyName(name: String): Option[String] = name match {
    case dotSeparatedPattern(value) => Some(value.trim)
    case _ => None
  }

  def dotSeparatedToCamelCase(dotSeparated: String): String = {
      val names = dotSeparated.trim.split("\\.")
      if (names.length == 1)
        dotSeparated
      else
        names.head + names.tail.map(_.capitalize).mkString
  }


  val properties: Map[String, String] = (for {
    properties <- pom \ "properties"
    property <- properties.child
    label = property.label
    if !label.startsWith("#PCDATA")
  } yield label -> property.text).toMap

  case class Repository(id: String, name: String, url: String)

  val repositories: Seq[Repository] = for {
    repositories <- pom \ "repositories"
    repository <- repositories.child
    url = (repository \ "url").text
    if url.nonEmpty
    id = (repository \ "id").text
    name = (repository \ "name").text
  } yield Repository(id, name, url)


  case class Dependency(groupId: String,
                        artifactId: String,
                        version: String,
                        scope: Option[String]) {
    def toDependencyString: String =
      s""""$groupId" % "$artifactId" % ${findPropertyName(version).fold("\"" + version + "\"")(dotSeparatedToCamelCase)}${scope.fold("")(x => s""" % "$x"""")}"""
  }

  val dependencies: Seq[Dependency] =
    pom \ "dependencies" \ "dependency" map { dependency =>
      val groupId = dependency \ "groupId" text
      val artifactId = dependency \ "artifactId" text
      val version = dependency \ "version" text
      val scope = dependency \ "scope" text

      Dependency(groupId,
                 artifactId,
                 version,
                 Option(scope).filter(_.nonEmpty))
    }

  val resolvers = repositories match {
    case Nil =>
      ""
    case x :: Nil =>
      s"""resolvers += "${x.name}" at "${x.url}""""
    case x :: xs =>
      s"""resolvers ++= Seq(
         |    "${x.name}" at "${x.url}"
         |  , ${xs.map(x => s""""${x.name}" at "${x.url}"""").mkString("\n  , ")}
         |  )
         |""".stripMargin
  }

  val libraryDependencies = dependencies match {
    case Nil =>
      ""
    case x :: Nil =>
      s"""libraryDependencies += "${x.toDependencyString}"""
    case x :: xs =>
      s"""libraryDependencies ++= Seq(
         |    ${x.toDependencyString}
         |  , ${xs.map(_.toDependencyString).mkString("\n  , ")}
         |  )
         |""".stripMargin
  }

  val buildSbt =
    s"""
       |organization := "$groupId"
       |
       |name := "$artifactId"
       |
       |version := "$version"
       |
       |scalaVersion := "$scalaVersion"
       |
       |${properties map { case (k, v) => s"""val ${dotSeparatedToCamelCase(k)} = "$v"""" } mkString "\n"}
       |
       |$resolvers
       |
       |$libraryDependencies
       |""".stripMargin

  println(buildSbt)

}

{'fraction_non_alphanumeric': 0.15965892384592767, 'fraction_numerical': 0.00455748309320788, 'mean_word_length': 2.3201561737432894, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5039568', 'n_tokens_mistral': 2251, 'n_tokens_neox': 2072, 'n_words': 481}