Skip to content

Commit c42175d

Browse files
committed
modernize build and code
1 parent 4b4a354 commit c42175d

File tree

8 files changed

+35
-26
lines changed

8 files changed

+35
-26
lines changed

.jvmopts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Dfile.encoding=UTF-8

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ but perhaps shows off a few standard library APIs.
77
## Building
88

99
1. Update the highlights notes in `hand-written.md`.
10-
2. run `sbt -Dfile.encoding=UTF-8`, and then:
10+
2. run `sbt`, and then:
1111
```
1212
> runMain MakeReleaseNotes $PrevVersion $CurrentVersion $ReleaseYear/$ReleaseMonth/$ReleaseDay "$pathToScalaScalaCheckout"
1313
```
1414

1515
## Contributing
1616

17-
Feel free to improve. Make sure to sign the Scala CLA.
17+
Feel free to improve. Make sure to sign the Scala CLA.

build.sbt

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
name := "make-release-notes"
22

33
scalaVersion := "2.13.8"
4-
5-
scalacOptions ++= Seq("-feature", "-deprecation", "-Xfatal-warnings")
6-
7-
libraryDependencies += "org.pegdown" % "pegdown" % "1.6.0"
8-
libraryDependencies += "org.apache.commons" % "commons-text" % "1.9"
9-
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "2.0.1"
10-
11-
{
12-
require(sys.props("file.encoding") == "UTF-8", "Please rerun with -Dfile.encoding=UTF-8")
13-
Nil
14-
}
4+
scalacOptions ++= Seq("-feature", "-deprecation", "-Werror")
5+
6+
libraryDependencies ++= Seq(
7+
"org.pegdown" % "pegdown" % "1.6.0",
8+
"org.apache.commons" % "commons-text" % "1.9",
9+
"org.scala-lang.modules" %% "scala-xml" % "2.0.1",
10+
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.3",
11+
)

project/plugins.sbt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
locally {
2+
require(sys.props("file.encoding") == "UTF-8",
3+
"Please rerun with -Dfile.encoding=UTF-8")
4+
Nil
5+
}
6+
7+
scalacOptions ++= Seq("-feature", "-deprecation", "-Xfatal-warnings")

src/main/scala/GitInfo.scala

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import scala.collection.parallel.CollectionConverters._ // for .par
12

23
case class Commit(sha: String, author: String, header: String, body: String) {
34
def trimmedHeader = header.take(80)
@@ -9,11 +10,11 @@ object GitHelper {
910
def processGitCommits(gitDir: java.io.File, previousTag: String, currentTag: String): IndexedSeq[Commit] = {
1011
import sys.process._
1112
val gitFormat = "%h %s" // sha and subject
12-
val log = Process(Seq("git", "--no-pager", "log", s"${previousTag}..${currentTag}", "--format=format:" + gitFormat, "--no-merges", "--topo-order"), gitDir).lineStream
13+
val log = Process(Seq("git", "--no-pager", "log", s"${previousTag}..${currentTag}", "--format=format:" + gitFormat, "--no-merges", "--topo-order"), gitDir).lazyLines
1314

1415
log.par.map(_.split(" ", 2)).collect {
1516
case Array(sha, title) =>
16-
val (author :: body) = Process(Seq("git", "--no-pager", "show", sha, "--format=format:%aN%n%b", "--quiet"), gitDir).lineStream.toList
17+
val (author :: body) = Process(Seq("git", "--no-pager", "show", sha, "--format=format:%aN%n%b", "--quiet"), gitDir).lazyLines.toList
1718
Commit(sha, author, title, body.mkString("\n"))
1819
}.toVector
1920
}
@@ -41,10 +42,12 @@ class GitInfo(gitDir: java.io.File, val previousTag: String, val currentTag: Str
4142
import GitHelper._
4243
val commits = processGitCommits(gitDir, previousTag, currentTag)
4344

44-
val authors: Seq[(String, Int)] = {
45-
val grouped: Vector[(String, Int)] = (commits groupBy (_.author)).map { case (a, c) => a -> c.length } { collection.breakOut }
46-
(grouped sortBy (_._2)).reverse
47-
}
45+
val authors: Seq[(String, Int)] =
46+
commits
47+
.groupBy(_.author)
48+
.map{case (a, c) => a -> c.length}
49+
.toVector
50+
.sortBy(_._2)
4851

4952
val fixCommits =
5053
for {

src/main/scala/IO.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import java.io.File
22

33
object IO {
4-
def write(f: java.io.File, contents: String) {
5-
val buf = new java.io.BufferedWriter(new java.io.FileWriter(f))
4+
def write(f: java.io.File, contents: String): Unit = {
5+
val buf = new java.io.BufferedWriter(new java.io.FileWriter(f))
66
try buf.write(contents)
77
finally buf.close()
88
}

src/main/scala/MakeDownloadPage.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MakeDownloadPage(version: String, releaseDate: Date = new Date()) {
1818
import scala.sys.process._
1919
println("## fetching size of "+ url)
2020
scala.util.Try {
21-
val responseHeader = Process(s"curl -m 5 --silent -D - -X HEAD $url").lineStream
21+
val responseHeader = Process(s"curl -m 5 --silent -D - -X HEAD $url").lazyLines
2222
val contentLength = responseHeader.map(_.toLowerCase).find(_.startsWith("content-length"))
2323
val bytes = contentLength.map(_.split(":",2)(1).trim.toInt)
2424
bytes map (b => (responseHeader.head, b))

src/main/scala/MakeReleaseNotes.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ object MakeReleaseNotes {
3737
}
3838
}
3939

40-
def apply(scalaDir: String, version: String, previousTag: String, currentTag: String, releaseDate: Date) {
41-
Seq(Html, MarkDown).foreach(fmt => apply(new java.io.File(scalaDir), version, previousTag, currentTag, fmt, releaseDate))
42-
}
40+
def apply(scalaDir: String, version: String, previousTag: String, currentTag: String, releaseDate: Date): Unit =
41+
Seq(Html, MarkDown).foreach(fmt =>
42+
apply(new java.io.File(scalaDir), version, previousTag, currentTag, fmt, releaseDate))
43+
4344
def apply(scalaDir: java.io.File, version: String, previousTag: String, currentTag: String, targetLanguage: TargetLanguage = MarkDown, releaseDate: Date = new Date()): Unit = {
4445
val out = targetLanguage match {
4546
case Html => new java.io.File("release-notes.html")
@@ -75,7 +76,7 @@ object MakeReleaseNotes {
7576
def rawHandWrittenNotes(file: java.io.File = new java.io.File(s"hand-written.md")): String = {
7677
val lines: List[String] = if (file.exists) {
7778
val src = Source.fromFile(file)
78-
src.getLines.toList
79+
src.getLines().toList
7980
} else Nil
8081
// if you don't have the next line, sub-bullets would be screwed!
8182
// please take this case into account and comment out 2 next lines and uncomment the line after!

0 commit comments

Comments
 (0)