diff options
author | Nikolay Tatarinov <5min4eq.unity@gmail.com> | 2018-03-28 01:33:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 01:33:11 +0300 |
commit | 83aeb8976d90ad1637243953a9af37e6d4206c52 (patch) | |
tree | 346e52db0d80c7fb7bdab8013acb38ef8be55fbb /integration/test/resources/play-json/headers.sc | |
parent | a796f0a1381632560b6251a93466957319065966 (diff) | |
download | mill-83aeb8976d90ad1637243953a9af37e6d4206c52.tar.gz mill-83aeb8976d90ad1637243953a9af37e6d4206c52.tar.bz2 mill-83aeb8976d90ad1637243953a9af37e6d4206c52.zip |
WIP: Play json build (#182)
* play json build
* build progress
* add check task
* try to make play json js build
* scalariform and mima plugins in separate files. check mima
* better error message for mima compatibility check
* fix scala 2.10 compilation
* license headers support
* add jmh support
* fix reformat on compile; fix code validation; extract base module
* remove scala 2.13 from cross versions
* include play-json in integration tests
* add example .travis.yml
* bring back scala 2.13 support
* make reformat target, not command
* add release task
* update mill version in travis.yml
* update release script
* update release process
* add README.md for play json build
Diffstat (limited to 'integration/test/resources/play-json/headers.sc')
-rw-r--r-- | integration/test/resources/play-json/headers.sc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/integration/test/resources/play-json/headers.sc b/integration/test/resources/play-json/headers.sc new file mode 100644 index 00000000..a66eaedd --- /dev/null +++ b/integration/test/resources/play-json/headers.sc @@ -0,0 +1,63 @@ +import $ivy.`com.github.rockjam::license-headers:0.0.1` + +import ammonite.ops._ +import mill._, scalalib._ +import mill.eval.PathRef +import de.heikoseeberger.sbtheader.{CommentStyle, FileType, HeaderCreator, License} + +trait Headers extends ScalaModule { + + val headerMappings = Map( + FileType.scala.extension -> (FileType.scala, CommentStyle.cStyleBlockComment), + FileType.java.extension -> (FileType.java, CommentStyle.cStyleBlockComment) + ) + + val license = { + val currentYear = java.time.Year.now(java.time.Clock.systemUTC).getValue + License.Custom( + s"Copyright (C) 2009-$currentYear Lightbend Inc. <https://www.lightbend.com>" + ) + } + + def headerCreate() = T.command { + val withoutHeaders = filesWithoutHeaders(sources() ++ resources()) + + val updatedFiles = withoutHeaders.map { + case (file, updated) => + write.over(file, updated) + file + } + + if (updatedFiles.nonEmpty) { + T.ctx.log.info( + s"Headers created for ${updatedFiles.size} files:\n${updatedFiles.mkString("\n")}") + } + updatedFiles + } + + def headerCheck() = T.command { + val withoutHeaders = filesWithoutHeaders(sources() ++ resources()).map(_._1) + + if (withoutHeaders.nonEmpty) { + sys.error( + s"There are files without headers!\n${withoutHeaders.mkString("\n")}" + ) + } + } + + private def filesWithoutHeaders(input: Seq[PathRef]) = { + for { + ref <- input if exists(ref.path) + file <- ls.rec(ref.path) if file.isFile + (fileType, commentStyle) <- headerMappings.get(file.ext) + updatedContent <- HeaderCreator( + fileType, + commentStyle, + license, + log = _ => (), + read.getInputStream(file) + ).createText + } yield file -> updatedContent + } + +} |