Skip to content

Commit

Permalink
Add sbt-header (#235)
Browse files Browse the repository at this point in the history
Add sbt-header
  • Loading branch information
dwijnand authored Jul 12, 2019
2 parents 8adb6af + 5c7d139 commit 0414f68
Show file tree
Hide file tree
Showing 45 changed files with 98 additions and 66 deletions.
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
language: scala
scala:
- 2.12.8
- 2.10.7
- 2.12.8
- 2.13.0

env:
matrix:
- [email protected]
- [email protected]
- TRAVIS_JDK=8
- TRAVIS_JDK=11

before_install: curl -Ls https://git.io/jabba | bash && . ~/.jabba/jabba.sh
install: jabba install "$TRAVIS_JDK" && jabba use "$_" && java -Xmx32m -version
install: jabba install "adopt@~1.$TRAVIS_JDK.0-0" && jabba use "$_" && java -Xmx32m -version

script:
- sbt "++ $TRAVIS_SCALA_VERSION test" || travis_terminate 1
- sbt +publishLocal || travis_terminate 1
- sbt plugin/test || travis_terminate 1
- sbt plugin/scripted || travis_terminate 1
- cd docs && sbt test validateDocs || travis_terminate 1
- ./scripts/validate-code.sh
- ./scripts/validate-docs.sh

cache:
directories:
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ stand-alone without any dependency on Play.
See the Play [documentation for the template engine][docs] for more information
about the template syntax.


sbt-twirl
---------
## sbt-twirl

Twirl can also be used outside of Play. An sbt plugin is provided for easy
integration with Scala or Java projects.

*sbt-twirl requires sbt 0.13.5 or higher*
> sbt-twirl requires sbt 0.13.5 or higher.
To add the sbt plugin to your project add the sbt plugin dependency in
`project/plugins.sbt`:
Expand Down Expand Up @@ -71,9 +69,7 @@ sources alongside Scala or Java source files:
sourceDirectories in (Compile, TwirlKeys.compileTemplates) := (unmanagedSourceDirectories in Compile).value
```


Credits
-------
## Credits

The name *twirl* was thought up by the [Spray team][spray] and refers to the
magic `@` character in the template language, which is sometimes called "twirl".
Expand All @@ -83,7 +79,6 @@ The first stand-alone version of Twirl was created by the [Spray team][spray].
An optimized version of the Twirl parser was contributed by the
[Scala IDE team][scala-ide].


[play-site]: http://www.playframework.com
[docs]: http://www.playframework.com/documentation/latest/ScalaTemplates
[spray]: https://github.com/spray
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2016 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api

Expand Down
2 changes: 1 addition & 1 deletion api/shared/src/main/scala/play/twirl/api/Content.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api

Expand Down
2 changes: 1 addition & 1 deletion api/shared/src/main/scala/play/twirl/api/Format.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api

Expand Down
2 changes: 1 addition & 1 deletion api/shared/src/main/scala/play/twirl/api/Formats.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api

Expand Down
2 changes: 1 addition & 1 deletion api/shared/src/main/scala/play/twirl/api/Template.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api

Expand Down
3 changes: 3 additions & 0 deletions api/shared/src/main/scala/play/twirl/api/package.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl

import scala.reflect.ClassTag
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2016 Lightbend Inc. (https://www.lightbend.com).
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api.utils

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2016 Lightbend Inc. (https://www.lightbend.com).
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api.test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2016 Lightbend Inc. (https://www.lightbend.com).
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api
package test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2016 Lightbend Inc. (https://www.lightbend.com).
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.api
package test
Expand Down
15 changes: 14 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ def scalacCompilerSettings(scalaVer: String) = if (scalaVer.equals(scala210)) {
scalacExtraParams
}

val commonSettings = javaCompilerSettings ++ Seq(
val headerSettings = Seq(
headerLicense := {
val currentYear = java.time.Year.now(java.time.Clock.systemUTC).getValue
Some(HeaderLicense.Custom(
s"Copyright (C) 2009-$currentYear Lightbend Inc. <https://www.lightbend.com>"
))
},
headerEmptyLine := false
)

val commonSettings = javaCompilerSettings ++ headerSettings ++ Seq(
scalaVersion := scala212,
crossScalaVersions := Seq(scala210, scala212, scala213),
scalacOptions ++= scalacCompilerSettings(scalaVersion.value),
Expand Down Expand Up @@ -111,6 +121,7 @@ lazy val plugin = project
.enablePlugins(PlaySbtPlugin, SbtPlugin)
.dependsOn(compiler)
.settings(javaCompilerSettings)
.settings(headerSettings)
.settings(
name := "sbt-twirl",
organization := "com.typesafe.sbt",
Expand Down Expand Up @@ -167,3 +178,5 @@ def scalaXml = Def.setting {
Seq.empty
}
}

addCommandAlias("validateCode", ";headerCheck;test:headerCheck")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.japi.twirl.compiler;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.compiler

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.japi.twirl.compiler;

import static org.junit.Assert.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.compiler.test

import java.io.File
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.compiler
package test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.compiler
package test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.compiler.test.imports.bar

// Used to test import priorities
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.compiler.test.imports.foo

// Used to test import priorities
Expand Down
9 changes: 8 additions & 1 deletion docs/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ lazy val docs = project
libraryDependencies += component("play-test") % "test",
libraryDependencies += component("play-specs2") % "test",
PlayDocsKeys.javaManualSourceDirectories := (baseDirectory.value / "manual" / "working" / "javaGuide" ** "code").get,
PlayDocsKeys.scalaManualSourceDirectories := (baseDirectory.value / "manual" / "working" / "scalaGuide" ** "code").get
PlayDocsKeys.scalaManualSourceDirectories := (baseDirectory.value / "manual" / "working" / "scalaGuide" ** "code").get,
headerLicense := {
val currentYear = java.time.Year.now(java.time.Clock.systemUTC).getValue
Some(HeaderLicense.Custom(
s"Copyright (C) 2009-$currentYear Lightbend Inc. <https://www.lightbend.com>"
))
},
headerEmptyLine := false
).settings(overrideTwirlSettings: _*)
.dependsOn(twirlApi)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package company.product.core

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package scalaguide.templates

Expand Down
4 changes: 3 additions & 1 deletion docs/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ lazy val sbtTwirl = ProjectRef(Path.fileProperty("user.dir").getParentFile, "plu

resolvers ++= DefaultOptions.resolvers(snapshot = true)

addSbtPlugin("com.typesafe.play" % "play-docs-sbt-plugin" % sys.props.getOrElse("play.version", "2.7.2"))
addSbtPlugin("com.typesafe.play" % "play-docs-sbt-plugin" % sys.props.getOrElse("play.version", "2.8.0-M3"))

addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
2 changes: 1 addition & 1 deletion parser/src/main/scala/play/twirl/parser/TreeNodes.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.parser

Expand Down
3 changes: 3 additions & 0 deletions parser/src/main/scala/play/twirl/parser/TwirlIO.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.parser

import java.io._
Expand Down
19 changes: 4 additions & 15 deletions parser/src/main/scala/play/twirl/parser/TwirlParser.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.parser

import scala.annotation.{elidable, tailrec}
import scala.annotation.elidable._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ListBuffer
import scala.util.parsing.input.OffsetPosition

/**
* TwirlParser is a recursive descent parser for a modified grammar of the Play2 template language as loosely defined [[http://www.playframework.com/documentation/2.1.x/ here]] and more rigorously defined by the original template parser, `play.templates.ScalaTemplateCompiler.TemplateParser`.
* TwirlParser is a recursive descent parser for a modified grammar of the Play2 template language as loosely defined [[http://www.playframework.com/documentation/latest/Home here]] and more rigorously defined by the original template parser, `play.templates.ScalaTemplateCompiler.TemplateParser`.
* TwirlParser is meant to be a near drop in replacement for `play.templates.ScalaTemplateCompiler.TemplateParser`.
*
* The original grammar, as reversed-engineered from `play.templates.ScalaTemplateCompiler.TemplateParser`, is defined as follows:
Expand Down Expand Up @@ -136,17 +135,7 @@ class TwirlParser(val shouldParseInclusiveDot: Boolean) {
def regress(decrement: Int): Unit = offset_ -= decrement

/** Backtrack to a known offset */
def regressTo(offset: Int): Unit = {
@noinline @elidable(INFO)
def updateRegressionStatistics() = {
val distance = offset_ - offset
val methodName = Thread.currentThread().getStackTrace()(2).getMethodName
val (count, charAccum) = regressionStatistics.getOrElse(methodName, (0, 0))
regressionStatistics(methodName) = (count + 1, charAccum + distance)
}

offset_ = offset
}
def regressTo(offset: Int): Unit = offset_ = offset

def isPastEOF(len: Int): Boolean = (offset_ + len-1) >= length_

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.parser
package test
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.4.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.sbt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.sbt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.sbt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.sbt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.sbt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package play.twirl.sbt

Expand Down
Loading

0 comments on commit 0414f68

Please sign in to comment.