de.heikoseeberger.sbtheader.HeaderPlugin Scala Examples

The following examples show how to use de.heikoseeberger.sbtheader.HeaderPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: CopyrightHeader.scala    From lagom-akka-discovery-service-locator   with Apache License 2.0 5 votes vote down vote up
import sbt._, Keys._
import de.heikoseeberger.sbtheader.{ CommentCreator, HeaderPlugin }

object CopyrightHeader extends AutoPlugin {
  import HeaderPlugin.autoImport._

  override def requires = HeaderPlugin
  override def trigger = allRequirements

  override def projectSettings = Def.settings(
    Seq(Compile, Test).flatMap { config =>
      inConfig(config)(
        Seq(
          headerLicense := Some(HeaderLicense.Custom(headerFor(CurrentYear))),
          headerMappings := headerMappings.value ++ Map(
            HeaderFileType.scala       -> cStyleComment,
            HeaderFileType.java        -> cStyleComment,
            HeaderFileType("txt") -> twirlStyleBlockComment,
          ),
          unmanagedResourceDirectories in headerCreate += baseDirectory.value / "src" / "main" / "twirl"
        )
      )
    }
  )

  val CurrentYear = java.time.Year.now.getValue.toString
  val CopyrightPattern = "Copyright \\([Cc]\\) (\\d{4}(-\\d{4})?) (Lightbend|Typesafe) Inc. <.*>".r
  val CopyrightHeaderPattern = s"(?s).*${CopyrightPattern}.*".r

  def headerFor(year: String): String =
    s"Copyright (C) $year Lightbend Inc. <https://www.lightbend.com>"

  private def lightbendCommentCreator(commentCreator: CommentCreator) = new CommentCreator() {

    def updateLightbendHeader(header: String): String = header match {
      case CopyrightHeaderPattern(years, null, _) =>
        if (years != CurrentYear)
          CopyrightPattern.replaceFirstIn(header, headerFor(years + "-" + CurrentYear))
        else
          CopyrightPattern.replaceFirstIn(header, headerFor(years))
      case CopyrightHeaderPattern(years, endYears, _) =>
        CopyrightPattern.replaceFirstIn(header, headerFor(years.replace(endYears, "-" + CurrentYear)))
      case _ =>
        header
    }

    override def apply(text: String, existingText: Option[String]): String = {
      existingText
        .map(updateLightbendHeader)
        .getOrElse(commentCreator(text, existingText))
        .trim
    }
  }
  val cStyleComment = HeaderCommentStyle.cStyleBlockComment.copy(commentCreator = lightbendCommentCreator(HeaderCommentStyle.cStyleBlockComment.commentCreator))
  val twirlStyleBlockComment = HeaderCommentStyle.twirlStyleBlockComment.copy(commentCreator = lightbendCommentCreator(HeaderCommentStyle.twirlStyleBlockComment.commentCreator))
} 
Example 2
Source File: Build.scala    From healthchecks   with MIT License 5 votes vote down vote up
import bintray.BintrayPlugin
import bintray.BintrayPlugin.autoImport._
import com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin.autoImport._
import de.heikoseeberger.sbtheader.HeaderPlugin
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import sbtrelease.ReleasePlugin.autoImport._
import sbt.Keys._
import sbt.{AutoPlugin, _}
import sbt.plugins.JvmPlugin

object Build extends AutoPlugin {
  override def requires = JvmPlugin && HeaderPlugin && BintrayPlugin

  override def trigger = allRequirements

  override def projectSettings = Vector(
    // Core settings
    organization := "com.github.everpeace",
    organizationName := "Shingo Omura",
    startYear := Some(2017),
    licenses += ("MIT", url("https://opensource.org/licenses/MIT")),
    headerLicense := Some(HeaderLicense.MIT("2017", "Shingo Omura")),
    homepage := Some(url("https://github.com/everpeace/healthchecks")),
    pomIncludeRepository := (_ => false),
    pomExtra := <scm>
      <url>https://github.com/everpeace/healthchecks</url>
      <connection>scm:git:[email protected]:everpeace/healthchecks</connection>
    </scm>
      <developers>
        <developer>
          <id>everpeace</id>
          <name>Shingo Omura</name>
          <url>http://everpeace.github.io/</url>
        </developer>
      </developers>,
    scalaVersion := Version.Scala.head,
    crossScalaVersions := Version.Scala,
    scalacOptions ++= Vector(
      "-unchecked",
      "-deprecation",
      "-language:_",
      "-encoding", "UTF-8",
      "-Ywarn-unused-import",
      "-Ypartial-unification"
    ),

    // Scalafmt setting
    scalafmtOnCompile := true,
    scalafmtTestOnCompile := true,

    // macro compiler plugin
    addCompilerPlugin(
      "org.scalamacros" % "paradise" % Version.paradise cross CrossVersion.full
    ),

    // Bintray settings
    bintrayPackage := "healthchecks",
    bintrayRepository := "maven",

    releaseCrossBuild := true,
    releaseVersionBump := sbtrelease.Version.Bump.Next
  )
} 
Example 3
Source File: Common.scala    From play-soap   with Apache License 2.0 5 votes vote down vote up
import sbt.Keys._
import sbt._
import sbt.plugins.JvmPlugin
import Dependencies.ScalaVersions._
import de.heikoseeberger.sbtheader.HeaderPlugin

object Common extends AutoPlugin {

  import HeaderPlugin.autoImport._

  override def trigger = allRequirements

  override def requires = JvmPlugin && HeaderPlugin

  val repoName = "play-soap"

  override def globalSettings =
    Seq(
      // organization
      organization := "com.typesafe.play",
      organizationName := "Lightbend Inc.",
      organizationHomepage := Some(url("https://www.lightbend.com/")),
      // scala settings
      scalaVersion := scala212,
      scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-encoding", "utf8"),
      javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:-options"),
      // legal
      licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")),
      // on the web
      homepage := Some(url(s"https://github.com/playframework/${repoName}")),
      scmInfo := Some(
        ScmInfo(
          url(s"https://github.com/playframework/${repoName}"),
          s"scm:git:[email protected]:playframework/${repoName}.git"
        )
      ),
      developers += Developer(
        "contributors",
        "Contributors",
        "https://gitter.im/playframework/contributors",
        url("https://github.com/playframework")
      )
    )

  override def projectSettings =
    Seq(
      headerEmptyLine := false,
      headerLicense := Some(HeaderLicense.Custom("Copyright (C) Lightbend Inc. <https://www.lightbend.com>"))
    )
} 
Example 4
Source File: Build.scala    From scalalaz-gen   with Apache License 2.0 5 votes vote down vote up
import com.typesafe.sbt.GitPlugin
import de.heikoseeberger.sbtheader.HeaderPlugin
import org.scalafmt.sbt._
import play.twirl.sbt.SbtTwirl
import sbt._
import sbt.plugins.JvmPlugin
import sbt.Keys._

object Build extends AutoPlugin {

  override def requires = JvmPlugin && GitPlugin&& HeaderPlugin && SbtTwirl

  override def trigger = allRequirements

  override def projectSettings =
    Vector(
      // Core settings
      organization := "ru",
      licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
      mappings.in(Compile, packageBin) += baseDirectory.in(ThisBuild).value / "LICENSE" -> "LICENSE",
      scalaVersion := Version.Scala,
      crossScalaVersions := Vector(scalaVersion.value),
      scalacOptions ++= Vector(
        "-unchecked",
        "-deprecation",
        "-feature",
        "-language:_",
        "-target:jvm-1.8",
        "-encoding",
        "UTF-8"
      ),
      unmanagedSourceDirectories.in(Compile) := Vector(scalaSource.in(Compile).value),
      unmanagedSourceDirectories.in(Test) := Vector(scalaSource.in(Test).value),

      // Git settings
      GitPlugin.autoImport.git.useGitDescribe := true,

      // Header settings
      HeaderPlugin.autoImport.headerLicense := Some(HeaderPlugin.autoImport.HeaderLicense.ALv2("2016", "Scalalaz Podcast Team"))

    )
} 
Example 5
Source File: CopyrightHeader.scala    From play-grpc   with Apache License 2.0 5 votes vote down vote up
package build.play.grpc

import sbt._
import Keys._
import de.heikoseeberger.sbtheader.CommentCreator
import de.heikoseeberger.sbtheader.CommentStyle
import de.heikoseeberger.sbtheader.HeaderPlugin

object CopyrightHeader extends AutoPlugin {
  import HeaderPlugin.autoImport._

  override def requires = HeaderPlugin
  override def trigger  = allRequirements

  override def buildSettings = Seq(headerEmptyLine := false)

  override def projectSettings = Def.settings(
    Seq(Compile, Test).flatMap { config =>
      inConfig(config)(
        Seq(
          headerLicense := Some(HeaderLicense.Custom("Copyright (C) Lightbend Inc. <https://www.lightbend.com>")),
          headerMappings := headerMappings.value ++ Map(
            HeaderFileType.scala  -> HeaderCommentStyle.cStyleBlockComment,
            HeaderFileType.java   -> HeaderCommentStyle.cStyleBlockComment,
            HeaderFileType("txt") -> HeaderCommentStyle.twirlStyleBlockComment,
          ),
          unmanagedResourceDirectories in headerCreate += baseDirectory.value / "src" / "main" / "twirl",
        ),
      )
    },
  )

} 
Example 6
Source File: CopyrightHeader.scala    From akka-grpc   with Apache License 2.0 5 votes vote down vote up
package akka.grpc

import sbt._, Keys._
import de.heikoseeberger.sbtheader.{ CommentCreator, HeaderPlugin }

object CopyrightHeader extends AutoPlugin {
  import HeaderPlugin.autoImport._

  override def requires = HeaderPlugin
  override def trigger = allRequirements

  override def projectSettings =
    Def.settings(Seq(Compile, Test).flatMap { config =>
      inConfig(config)(
        Seq(
          headerLicense := Some(HeaderLicense.Custom(headerFor(CurrentYear))),
          headerMappings := headerMappings.value ++ Map(
              HeaderFileType.scala -> cStyleComment,
              HeaderFileType.java -> cStyleComment,
              HeaderFileType("txt") -> twirlStyleBlockComment),
          unmanagedResourceDirectories in headerCreate += baseDirectory.value / "src" / "main" / "twirl"))
    })

  // Not determined automatically so that it can be updated in a PR instead of
  // branches randomly starting to fail in the new year
  val CurrentYear = "2020"
  val CopyrightPattern = "Copyright \\([Cc]\\) (\\d{4}(-\\d{4})?) (Lightbend|Typesafe) Inc. <.*>".r
  val CopyrightHeaderPattern = s"(?s).*${CopyrightPattern}.*".r

  def headerFor(year: String): String =
    s"Copyright (C) $year Lightbend Inc. <https://www.lightbend.com>"

  private def lightbendCommentCreator(commentCreator: CommentCreator) =
    new CommentCreator() {
      def updateLightbendHeader(header: String): String =
        header match {
          case CopyrightHeaderPattern(years, null, _) =>
            if (years != CurrentYear)
              CopyrightPattern.replaceFirstIn(header, headerFor(years + "-" + CurrentYear))
            else
              CopyrightPattern.replaceFirstIn(header, headerFor(years))
          case CopyrightHeaderPattern(years, endYears, _) =>
            CopyrightPattern.replaceFirstIn(header, headerFor(years.replace(endYears, "-" + CurrentYear)))
          case _ =>
            header
        }

      override def apply(text: String, existingText: Option[String]): String =
        existingText.map(updateLightbendHeader).getOrElse(commentCreator(text, existingText)).trim
    }
  val cStyleComment = HeaderCommentStyle.cStyleBlockComment
    .copy(commentCreator = lightbendCommentCreator(HeaderCommentStyle.cStyleBlockComment.commentCreator))
  val twirlStyleBlockComment = HeaderCommentStyle.twirlStyleBlockComment
    .copy(commentCreator = lightbendCommentCreator(HeaderCommentStyle.twirlStyleBlockComment.commentCreator))
} 
Example 7
Source File: Build.scala    From troy   with Apache License 2.0 5 votes vote down vote up
import com.typesafe.sbt.{ GitPlugin, SbtScalariform }
import de.heikoseeberger.sbtheader.HeaderPlugin
import de.heikoseeberger.sbtheader.license.Apache2_0
import sbt._
import sbt.plugins.JvmPlugin
import sbt.Keys._
import scalariform.formatter.preferences.{ AlignSingleLineCaseStatements, DoubleIndentClassDeclaration }
import bintray.BintrayKeys._

object Build extends AutoPlugin {

  override def requires = JvmPlugin && HeaderPlugin && GitPlugin && SbtScalariform

  override def trigger = allRequirements

  def compileSettings = Vector(
    // Core settings
    organization := "io.github.cassandra-scala",
    licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
    scalaVersion := Version.Scala,
    scalaOrganization := "org.typelevel", // FIXME: Remove once literal-types is merged into lightbend Scala
    crossScalaVersions := Vector("2.11.8", "2.12.1"),
    scalacOptions ++= Vector(
      "-encoding", "UTF-8",
      "-target:jvm-1.8",
      "-language:_",
      "-unchecked",
      "-feature",
      "-deprecation",
      "-Xlint",
      "-Xfuture",
      "-Ywarn-dead-code",
      "-Ywarn-unused-import",
      "-Ywarn-unused",
      "-Ywarn-nullary-unit",
      "-Yliteral-types"
    ),
    scalacOptions in (Compile, console) := Seq("-Yliteral-types"),
    unmanagedSourceDirectories.in(Compile) := Vector(scalaSource.in(Compile).value),
    unmanagedSourceDirectories.in(Test) := Vector(scalaSource.in(Test).value)
  )

  def testSettings = Vector(
    parallelExecution in Test := false,
    publishArtifact in Test := false
  )

  def stablePublishSettings = Vector(
    publishArtifact in Test := false,

    pomExtra := (
      <modules>
        <module>cql-ast</module>
        <module>cql-parser</module>
        <module>troy-schema</module>
        <module>troy-driver</module>
        <module>troy</module>
      </modules>
        <scm>
          <url>[email protected]:cassandra-scala/troy.git</url>
          <connection>scm:git:[email protected]:cassandra-scala/troy.git</connection>
        </scm>
        <developers>
          <developer>
            <id>tabdulradi</id>
            <name>Tamer Abdulradi</name>
            <url>http://abdulradi.com</url>
          </developer>
        </developers>),
    licenses := ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.txt")) :: Nil
  )

  def snapshotPublishSettings = Seq() //TODO

  def publishSettings = stablePublishSettings

  def pluginsSettings = Vector(
    // Scalariform settings
    SbtScalariform.autoImport.scalariformPreferences := SbtScalariform.autoImport.scalariformPreferences.value
      .setPreference(AlignSingleLineCaseStatements, true)
      .setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 100)
      .setPreference(DoubleIndentClassDeclaration, true),

    // Git settings
    GitPlugin.autoImport.git.useGitDescribe := true,

    // Header settings
    HeaderPlugin.autoImport.headers := Map("scala" -> Apache2_0("2016", "Tamer AbdulRadi"))
  )

  override def projectSettings =
    Defaults.coreDefaultSettings ++
      compileSettings ++
      testSettings ++
      publishSettings ++
      pluginsSettings
} 
Example 8
Source File: Common.scala    From paradox   with Apache License 2.0 5 votes vote down vote up
import sbt._
import sbt.Keys._
import de.heikoseeberger.sbtheader.{ CommentStyle, FileType, License, HeaderPlugin, AutomateHeaderPlugin }
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._
import xerial.sbt.Sonatype.SonatypeKeys


object Common extends AutoPlugin {

  override def trigger  = allRequirements

  override def requires = plugins.JvmPlugin && HeaderPlugin

  // AutomateHeaderPlugin is not an allRequirements-AutoPlugin, so explicitly add settings here:
  override def projectSettings = AutomateHeaderPlugin.projectSettings ++ Seq(
    scalaVersion := "2.12.11",
    scalacOptions ++= Seq("-encoding", "UTF-8", "-unchecked", "-deprecation", "-feature"),
    javacOptions ++= Seq("-encoding", "UTF-8"),
    resolvers += Resolver.typesafeIvyRepo("releases"),
    // Scalariform settings
    ScalariformKeys.preferences := ScalariformKeys.preferences.value
      .setPreference(AlignSingleLineCaseStatements, true)
      .setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 100)
      .setPreference(DoubleIndentConstructorArguments, true)
      .setPreference(DanglingCloseParenthesis, Preserve)
      .setPreference(AlignParameters, true),
    // Header settings
    HeaderPlugin.autoImport.headerMappings := Map(
      FileType.scala -> CommentStyle.cStyleBlockComment,
      FileType.java -> CommentStyle.cStyleBlockComment,
      FileType.conf -> CommentStyle.hashLineComment
    ),
    HeaderPlugin.autoImport.headerLicense := Some(License.Custom(licenseText)),
    SonatypeKeys.sonatypeProfileName := "com.lightbend"
  )

  val licenseText: String = {
    """|Copyright © 2015 - 2019 Lightbend, Inc. <http://www.lightbend.com>

       |Licensed under the Apache License, Version 2.0 (the "License");
       |you may not use this file except in compliance with the License.
       |You may obtain a copy of the License at
       |
       |http://www.apache.org/licenses/LICENSE-2.0
       |
       |Unless required by applicable law or agreed to in writing, software
       |distributed under the License is distributed on an "AS IS" BASIS,
       |WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       |See the License for the specific language governing permissions and
       |limitations under the License.""".stripMargin
  }
}