@@ -2,38 +2,24 @@ package lt.dvim.authors
22
33import sbt ._
44import sbt .Keys ._
5- import complete .DefaultParsers ._
5+ import sbt . complete .DefaultParsers ._
66
7- import scala .concurrent .Await
7+ import scala .concurrent .{ Await , Future }
88import scala .concurrent .duration ._
99
1010object AuthorsPlugin extends AutoPlugin {
1111 object autoImport extends AuthorsKeys
1212 import autoImport ._
1313
1414 override def trigger = AllRequirements
15- override def projectSettings : Seq [Setting [_]] = authorsSettings( Compile )
15+ override def buildSettings : Seq [Setting [_]] = authorsBuildSettings
1616
17- def authorsSettings ( config : Configuration ) : Seq [ Setting [_]] = authorsGlobalSettings ++ inConfig(config)( Seq () )
17+ private final val ArgsParser = spaceDelimited( " <from> <to> " )
1818
19- def authorsGlobalSettings : Seq [Setting [_]] = Seq (
19+ def authorsBuildSettings : Seq [Setting [_]] = Seq (
2020 authors := {
21- val (from, to) = spaceDelimited(" <from> <to>" ).parsed match {
22- case Seq (from, to) => (from, to)
23- case _ =>
24- sys.error(" Please specify the <from> and <to> tags as the arguments to the task." )
25- }
26-
27- // get the org/repo name from the scm info
28- val repo = scmInfo.value.map(_.browseUrl.getPath.drop(1 )).getOrElse {
29- sys.error(" Please set the scmInfo setting." )
30- }
31-
32- streams.value.log.info(s " Fetching authors summary for $repo between $from and $to" )
33-
3421 import scala .concurrent .ExecutionContext .Implicits .global
35- val summary = Authors
36- .summary(repo, from, to, baseDirectory.value.getAbsolutePath)
22+ val summary = authorsSummary(ArgsParser .parsed, scmInfo.value, baseDirectory.value, streams.value)
3723 .map { s =>
3824 import java .awt .Toolkit
3925 import java .awt .datatransfer ._
@@ -46,6 +32,41 @@ object AuthorsPlugin extends AutoPlugin {
4632
4733 Await .result(summary, 30 .seconds)
4834 },
49- aggregate in authors := false
35+ authors / aggregate := false ,
36+ authorsFile := {
37+ import scala .concurrent .ExecutionContext .Implicits .global
38+ val summary = authorsSummary(ArgsParser .parsed, scmInfo.value, baseDirectory.value, streams.value)
39+ .map { s =>
40+ val file = baseDirectory.value / " target" / " authors.md"
41+ IO .write(file, s)
42+ streams.value.log.info(s " Authors summary written to ${file.getAbsoluteFile}" )
43+ file
44+ }
45+
46+ Await .result(summary, 30 .seconds)
47+ },
48+ authorsFile / aggregate := false
5049 )
50+
51+ private def authorsSummary (
52+ args : Seq [String ],
53+ scmInfo : Option [ScmInfo ],
54+ baseDirectory : File ,
55+ streams : TaskStreams
56+ ): Future [String ] = {
57+ val (from, to) = args match {
58+ case Seq (from, to) => (from, to)
59+ case _ =>
60+ sys.error(" Please specify the <from> and <to> tags as the arguments to the task." )
61+ }
62+
63+ // get the org/repo name from the scm info
64+ val repo = scmInfo.map(_.browseUrl.getPath.drop(1 )).getOrElse {
65+ sys.error(" Please set the scmInfo setting." )
66+ }
67+
68+ streams.log.info(s " Fetching authors summary for $repo between $from and $to" )
69+
70+ Authors .summary(repo, from, to, baseDirectory.getAbsolutePath)
71+ }
5172}
0 commit comments