aboutsummaryrefslogtreecommitdiff
path: root/internal/plugins/library/Library.scala
blob: 1a84341524044a7b0b4e35eff64fbaa6023c5cc7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cbt_internal
import cbt._
import java.io._
import scala.concurrent._
import scala.concurrent.duration._
trait Library extends PackageJars with Scalariform with GoogleJavaFormat with DynamicOverrides with AdvancedScala {
  def groupId = "org.cvogt"
  def inceptionYear: Int
  def description: String
  def version = "0.9-SNAPSHOT"
  override def compile = {
    googleJavaFormat()
    scalariform()
    super.compile
  }

  def publishIfChanged = newBuild[PublishIfChanged]({s"""
    def inceptionYear = $inceptionYear
    def description = ${description.quote}
    def apply = if(changedInMaster) publish
  """})
}

trait PublishIfChanged extends PackageJars with DynamicOverrides with Shared{
  override def url = super.url ++ "/libraries/" ++ name

  def gitHash = {
    val p = new ProcessBuilder(
        "git rev-parse HEAD".split(" "): _*
    )
    .directory( projectDirectory )
    .start

    val sout = new InputStreamReader(p.getInputStream);
    import scala.concurrent.ExecutionContext.Implicits.global
    val out = Future(blocking(Iterator.continually(sout.read).takeWhile(_ != -1).map(_.toChar).mkString))
    p.waitFor
    val revision = Await.result( out, Duration.Inf ).trim
    revision
  }
  override def version = "rev-"++gitHash

  def changedInMaster = (
    0 ===
    new ProcessBuilder(
        "git diff --exit-code --quiet master..master^ .".split(" "): _*
    )
    .directory( projectDirectory )
    .start
    .waitFor
  )
}