diff --git a/.jvmopts b/.jvmopts new file mode 100644 index 0000000..7fecadb --- /dev/null +++ b/.jvmopts @@ -0,0 +1 @@ +-Dfile.encoding=UTF-8 diff --git a/README.md b/README.md index 73664e2..bb37c23 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ but perhaps shows off a few standard library APIs. ## Building 1. Update the highlights notes in `hand-written.md`. -2. run `sbt -Dfile.encoding=UTF-8`, and then: +2. run `sbt`, and then: ``` > runMain MakeReleaseNotes $PrevVersion $CurrentVersion $ReleaseYear/$ReleaseMonth/$ReleaseDay "$pathToScalaScalaCheckout" ``` ## Contributing -Feel free to improve. Make sure to sign the Scala CLA. +Feel free to improve. Make sure to sign the Scala CLA. diff --git a/build.sbt b/build.sbt index ab05af2..fc19391 100644 --- a/build.sbt +++ b/build.sbt @@ -1,14 +1,11 @@ name := "make-release-notes" scalaVersion := "2.13.8" - -scalacOptions ++= Seq("-feature", "-deprecation", "-Xfatal-warnings") - -libraryDependencies += "org.pegdown" % "pegdown" % "1.6.0" -libraryDependencies += "org.apache.commons" % "commons-text" % "1.9" -libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "2.0.1" - -{ - require(sys.props("file.encoding") == "UTF-8", "Please rerun with -Dfile.encoding=UTF-8") - Nil -} +scalacOptions ++= Seq("-feature", "-deprecation", "-Werror") + +libraryDependencies ++= Seq( + "org.pegdown" % "pegdown" % "1.6.0", + "org.apache.commons" % "commons-text" % "1.9", + "org.scala-lang.modules" %% "scala-xml" % "2.0.1", + "org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.3", +) diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..487b6eb --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,7 @@ +locally { + require(sys.props("file.encoding") == "UTF-8", + "Please rerun with -Dfile.encoding=UTF-8") + Nil +} + +scalacOptions ++= Seq("-feature", "-deprecation", "-Xfatal-warnings") diff --git a/src/main/scala/GitInfo.scala b/src/main/scala/GitInfo.scala index bd35ce1..2551f9f 100644 --- a/src/main/scala/GitInfo.scala +++ b/src/main/scala/GitInfo.scala @@ -1,3 +1,4 @@ +import scala.collection.parallel.CollectionConverters._ // for .par case class Commit(sha: String, author: String, header: String, body: String) { def trimmedHeader = header.take(80) @@ -9,11 +10,11 @@ object GitHelper { def processGitCommits(gitDir: java.io.File, previousTag: String, currentTag: String): IndexedSeq[Commit] = { import sys.process._ val gitFormat = "%h %s" // sha and subject - val log = Process(Seq("git", "--no-pager", "log", s"${previousTag}..${currentTag}", "--format=format:" + gitFormat, "--no-merges", "--topo-order"), gitDir).lineStream + val log = Process(Seq("git", "--no-pager", "log", s"${previousTag}..${currentTag}", "--format=format:" + gitFormat, "--no-merges", "--topo-order"), gitDir).lazyLines log.par.map(_.split(" ", 2)).collect { case Array(sha, title) => - val (author :: body) = Process(Seq("git", "--no-pager", "show", sha, "--format=format:%aN%n%b", "--quiet"), gitDir).lineStream.toList + val (author :: body) = Process(Seq("git", "--no-pager", "show", sha, "--format=format:%aN%n%b", "--quiet"), gitDir).lazyLines.toList Commit(sha, author, title, body.mkString("\n")) }.toVector } @@ -41,10 +42,12 @@ class GitInfo(gitDir: java.io.File, val previousTag: String, val currentTag: Str import GitHelper._ val commits = processGitCommits(gitDir, previousTag, currentTag) - val authors: Seq[(String, Int)] = { - val grouped: Vector[(String, Int)] = (commits groupBy (_.author)).map { case (a, c) => a -> c.length } { collection.breakOut } - (grouped sortBy (_._2)).reverse - } + val authors: Seq[(String, Int)] = + commits + .groupBy(_.author) + .map{case (a, c) => a -> c.length} + .toVector + .sortBy(_._2) val fixCommits = for { diff --git a/src/main/scala/IO.scala b/src/main/scala/IO.scala index 3f9064b..6fd889a 100644 --- a/src/main/scala/IO.scala +++ b/src/main/scala/IO.scala @@ -1,8 +1,8 @@ import java.io.File object IO { - def write(f: java.io.File, contents: String) { - val buf = new java.io.BufferedWriter(new java.io.FileWriter(f)) + def write(f: java.io.File, contents: String): Unit = { + val buf = new java.io.BufferedWriter(new java.io.FileWriter(f)) try buf.write(contents) finally buf.close() } diff --git a/src/main/scala/MakeDownloadPage.scala b/src/main/scala/MakeDownloadPage.scala index 043769c..fd03d94 100644 --- a/src/main/scala/MakeDownloadPage.scala +++ b/src/main/scala/MakeDownloadPage.scala @@ -18,7 +18,7 @@ class MakeDownloadPage(version: String, releaseDate: Date = new Date()) { import scala.sys.process._ println("## fetching size of "+ url) scala.util.Try { - val responseHeader = Process(s"curl -m 5 --silent -D - -X HEAD $url").lineStream + val responseHeader = Process(s"curl -m 5 --silent -D - -X HEAD $url").lazyLines val contentLength = responseHeader.map(_.toLowerCase).find(_.startsWith("content-length")) val bytes = contentLength.map(_.split(":",2)(1).trim.toInt) bytes map (b => (responseHeader.head, b)) diff --git a/src/main/scala/MakeReleaseNotes.scala b/src/main/scala/MakeReleaseNotes.scala index fc3fabc..6c4b337 100644 --- a/src/main/scala/MakeReleaseNotes.scala +++ b/src/main/scala/MakeReleaseNotes.scala @@ -37,9 +37,10 @@ object MakeReleaseNotes { } } - def apply(scalaDir: String, version: String, previousTag: String, currentTag: String, releaseDate: Date) { - Seq(Html, MarkDown).foreach(fmt => apply(new java.io.File(scalaDir), version, previousTag, currentTag, fmt, releaseDate)) - } + def apply(scalaDir: String, version: String, previousTag: String, currentTag: String, releaseDate: Date): Unit = + Seq(Html, MarkDown).foreach(fmt => + apply(new java.io.File(scalaDir), version, previousTag, currentTag, fmt, releaseDate)) + def apply(scalaDir: java.io.File, version: String, previousTag: String, currentTag: String, targetLanguage: TargetLanguage = MarkDown, releaseDate: Date = new Date()): Unit = { val out = targetLanguage match { case Html => new java.io.File("release-notes.html") @@ -75,7 +76,7 @@ object MakeReleaseNotes { def rawHandWrittenNotes(file: java.io.File = new java.io.File(s"hand-written.md")): String = { val lines: List[String] = if (file.exists) { val src = Source.fromFile(file) - src.getLines.toList + src.getLines().toList } else Nil // if you don't have the next line, sub-bullets would be screwed! // please take this case into account and comment out 2 next lines and uncomment the line after!