aboutsummaryrefslogtreecommitdiff
path: root/project/DriverConfigurations.scala
blob: 4044f340a62c7f0b71d22656ad961d00ce0c28cf (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import com.typesafe.sbt.SbtGit.git
import com.typesafe.sbt.{GitBranchPrompt, GitVersioning}
import org.scalafmt.sbt.ScalaFmtPlugin.autoImport._
import sbt.Keys._
import sbt._
import sbtrelease.{Version, _}
import wartremover.WartRemover.autoImport._
// we hide the existing definition for setReleaseVersion to replace it with our own
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
import sbtrelease.ReleasePlugin.autoImport._
import sbtrelease.ReleaseStateTransformations.{setReleaseVersion => _}


object DriverConfigurations {

  lazy val wartRemoverSettings = Seq(
    wartremoverErrors in (Compile, compile) ++= Warts.allBut(
      Wart.AsInstanceOf, Wart.Nothing, Wart.Overloading, Wart.DefaultArguments, Wart.Any,
      Wart.Option2Iterable, Wart.ExplicitImplicitTypes, Wart.Throw, Wart.ToString, Wart.NoNeedForMonad
    )
  )

  lazy val acyclicSettings = Seq(
    autoCompilerPlugins := true,
    addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.4")
  )

  lazy val scalafmtSettings = Seq(
    scalafmtConfig in ThisBuild := Some(file(".scalafmt")),
    testExecution in (Test, test) <<=
      (testExecution in (Test, test)) dependsOn (scalafmtTest in Compile, scalafmtTest in Test)
  )

  lazy val compileScalastyle = taskKey[Unit]("compileScalastyle")

  def publicationSettings() = Seq(
    publishTo := Some(Resolver.file("file", new File("releases")))
    // publishTo := { // TODO: For actual Driver jar repo
    //   val nexus = "https://my.artifact.repo.net/"
    //   if (isSnapshot.value)
    //     Some("snapshots" at nexus + "content/repositories/snapshots")
    //   else
    //     Some("releases"  at nexus + "service/local/staging/deploy/maven2")
    // }
  )

  def releaseSettings() = {
    def setVersionOnly(selectVersion: Versions => String): ReleaseStep =  { st: State =>
      val vs = st.get(ReleaseKeys.versions).getOrElse(
        sys.error("No versions are set! Was this release part executed before inquireVersions?"))
      val selected = selectVersion(vs)

      st.log.info("Setting version to '%s'." format selected)
      val useGlobal = Project.extract(st).get(releaseUseGlobalVersion)

      reapply(Seq(
        if (useGlobal) version in ThisBuild := selected else version := selected
      ), st)
    }

    lazy val setReleaseVersion: ReleaseStep = setVersionOnly(_._1)

    Seq(
      releaseIgnoreUntrackedFiles := true,
      // Check http://blog.byjean.eu/2015/07/10/painless-release-with-sbt.html for details
      releaseVersionBump := sbtrelease.Version.Bump.Minor,
      releaseVersion <<= releaseVersionBump(bumper => {
        ver => Version(ver)
          .map(_.withoutQualifier)
          .map(_.bump(bumper).string).getOrElse(versionFormatError)
      }),
      releaseProcess := Seq[ReleaseStep](
        checkSnapshotDependencies,
        inquireVersions,
        runTest, // probably, runTest after setReleaseVersion, if tests depend on version
        setReleaseVersion,
        commitReleaseVersion, // performs the initial git checks
        tagRelease,
        publishArtifacts,
        setNextVersion,
        commitNextVersion,
        pushChanges // also checks that an upstream branch is properly configured
      )
    )
  }

  implicit class driverConfigurations(project: Project) {

    def gitPluginConfiguration: Project = {
      val VersionRegex = "v([0-9]+.[0-9]+.[0-9]+)-?(.*)?".r

      project
        .enablePlugins(GitVersioning, GitBranchPrompt)
        .settings(
          git.useGitDescribe := true,
          git.baseVersion := "0.0.0",
          git.gitTagToVersionNumber := {
            case VersionRegex(v, "SNAPSHOT") => Some(s"$v-SNAPSHOT")
            case VersionRegex(v, "") => Some(v)
            case VersionRegex(v, s) => Some(s"$v-$s-SNAPSHOT")
            case _ => None
          })
    }
  }
}