Skip to content

Commit 61539b1

Browse files
committed
Deprecate BuildInfoKey.of and BuildInfoKey.ofN
Ref #119
1 parent 2b049ff commit 61539b1

File tree

9 files changed

+47
-92
lines changed

9 files changed

+47
-92
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ lazy val root = (project in file("."))
1111
.settings(
1212
name := "sbt-buildinfo",
1313
pluginCrossBuild / sbtVersion := "1.2.8",
14-
scalacOptions := Seq("-Xfuture", "-unchecked", "-deprecation", "-feature", "-language:implicitConversions"),
14+
scalacOptions := Seq("-Xlint", "-Xfatal-warnings", "-unchecked", "-deprecation", "-feature", "-language:implicitConversions"),
1515
scalacOptions += "-language:experimental.macros",
1616
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
1717
description := "sbt plugin to generate build info",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package sbtbuildinfo
2+
3+
import scala.reflect.macros.blackbox
4+
5+
final class BuildInfoKeyMacros(val c: blackbox.Context) {
6+
import c.universe._
7+
8+
val BuildInfoKey = q"_root_.sbtbuildinfo.BuildInfoKey"
9+
10+
def taskImpl(key: Tree): Tree = {
11+
val A = key.tpe.typeArgs.head
12+
q"$BuildInfoKey.sbtbuildinfoTaskValueEntry[$A]($key.taskValue)($key.key.manifest.typeArguments.head.asInstanceOf[_root_.scala.reflect.Manifest[$A]])"
13+
}
14+
}

src/main/scala/sbtbuildinfo/BuildInfoOption.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package sbtbuildinfo
22

3-
import sbt._
4-
53
sealed trait BuildInfoOption
64

75
object BuildInfoOption {

src/main/scala/sbtbuildinfo/package.scala

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ import sbt._
33
package object sbtbuildinfo {
44
type BuildInfoKey = BuildInfoKey.Entry[_]
55
object BuildInfoKey {
6-
implicit def setting[A](key: SettingKey[A]): Entry[A] = Setting(key)
7-
implicit def task[A](key: TaskKey[A]): Entry[A] = macro BuildInfoKeyMacros.taskImpl
8-
implicit def taskValue[A: Manifest](task: sbt.Task[A]): Entry[A] = TaskValue(task)
9-
implicit def constant[A: Manifest](tuple: (String, A)): Entry[A] = Constant(tuple)
10-
6+
implicit def sbtbuildinfoSettingEntry[A](key: SettingKey[A]): Entry[A] = Setting(key)
7+
implicit def sbtbuildinfoTaskEntry[A](key: TaskKey[A]): Entry[A] = macro BuildInfoKeyMacros.taskImpl
8+
implicit def sbtbuildinfoTaskValueEntry[A: Manifest](task: sbt.Task[A]): Entry[A] = TaskValue(task)
9+
implicit def sbtbuildinfoConstantEntry[A: Manifest](tuple: (String, A)): Entry[A] = Constant(tuple)
10+
1111
def apply[A](key: SettingKey[A]): Entry[A] = Setting(key)
1212
def apply[A](key: TaskKey[A]): Entry[A] = macro BuildInfoKeyMacros.taskImpl
1313
def apply[A: Manifest](tuple: (String, A)): Entry[A] = Constant(tuple)
1414
def map[A, B: Manifest](from: Entry[A])(fun: ((String, A)) => (String, B)): Entry[B] =
1515
BuildInfoKey.Mapped(from, fun)
1616
def action[A: Manifest](name: String)(fun: => A): Entry[A] = Action(name, () => fun)
1717

18+
@deprecated("use += (x: BuildInfoKey) instead", "0.10.0")
1819
def of[A](x: BuildInfoKey.Entry[A]): BuildInfoKey.Entry[A] = x
20+
@deprecated("use ++= Seq[BuildInfoKey](...) instead", "0.10.0")
1921
def ofN(xs: BuildInfoKey*): Seq[BuildInfoKey] = xs
2022

2123
def outOfGraphUnsafe[A](key: TaskKey[A]): Entry[A] = Task(key)
@@ -44,40 +46,4 @@ package object sbtbuildinfo {
4446
private[sbtbuildinfo] def manifest: Manifest[A]
4547
}
4648
}
47-
48-
import scala.reflect.macros.blackbox
49-
50-
final class BuildInfoKeyMacros(val c: blackbox.Context) {
51-
import c.universe._
52-
53-
val BuildInfoKey = q"_root_.sbtbuildinfo.BuildInfoKey"
54-
55-
def taskImpl(key: Tree): Tree = {
56-
val A = key.tpe.typeArgs.head
57-
q"$BuildInfoKey.taskValue[$A]($key.taskValue)($key.key.manifest.typeArguments.head.asInstanceOf[_root_.scala.reflect.Manifest[$A]])"
58-
}
59-
60-
@deprecated("No longer used", "0.9.0")
61-
def ofImpl(x: Tree): Tree = {
62-
x.tpe match {
63-
case tpe if tpe <:< typeOf[SettingKey[_]] =>
64-
val A = tpe.typeArgs.head
65-
q"$BuildInfoKey.setting[$A]($x)"
66-
67-
case tpe if tpe <:< typeOf[TaskKey[_]] =>
68-
val A = tpe.typeArgs.head
69-
q"$BuildInfoKey.taskValue[$A]($x.taskValue)($x.key.manifest.typeArguments.head.asInstanceOf[_root_.scala.reflect.Manifest[$A]])"
70-
71-
case tpe if tpe <:< typeOf[(_, _)] =>
72-
val A = tpe.typeArgs.tail.head
73-
q"$BuildInfoKey.constant[$A]($x)"
74-
75-
case tpe if tpe <:< typeOf[BuildInfoKey] => x
76-
}
77-
}
78-
79-
@deprecated("No longer used", "0.9.0")
80-
def ofNImpl(xs: Tree*): Tree = q"_root_.scala.collection.immutable.Seq(..${xs map ofImpl})"
81-
82-
}
8349
}

src/sbt-test/sbt-buildinfo/finalcaseobjectrenderer/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lazy val root = (project in file(".")).
99
version := "0.1",
1010
scalaVersion := "2.12.7",
1111
TaskKey[Classpath]("someCp") := Seq(Attributed.blank(file("/tmp/f.txt"))),
12-
buildInfoKeys := BuildInfoKey.ofN(
12+
buildInfoKeys := Seq[BuildInfoKey](
1313
name,
1414
BuildInfoKey.map(version) { case (n, v) => "projectVersion" -> v.toDouble },
1515
scalaVersion,

src/sbt-test/sbt-buildinfo/simple/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ lazy val root = (project in file(".")).
77
version := "0.1",
88
scalaVersion := "2.12.7",
99
TaskKey[Classpath]("someCp") := Seq(Attributed.blank(file("/tmp/f.txt"))),
10-
buildInfoKeys := BuildInfoKey.ofN(
10+
buildInfoKeys := Seq[BuildInfoKey](
1111
name,
1212
BuildInfoKey.map(version) { case (n, v) => "projectVersion" -> v.toDouble },
1313
scalaVersion,

src/sbt-test/sbt-buildinfo/task/build.sbt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@ import StableState.{ counterOutOfTaskGraph, counterInTaskGraph }
22

33
scalaVersion in ThisBuild := "2.12.4"
44

5-
val projOutOfTaskGraph1 = project settings (
6-
sourceGenerators in Compile += Def.task { counterOutOfTaskGraph.incrementAndGet(); Nil }.taskValue
7-
)
5+
val projOutOfTaskGraph1 = project
6+
.settings (
7+
sourceGenerators in Compile += Def.task { counterOutOfTaskGraph.incrementAndGet(); Nil }.taskValue
8+
)
89

9-
val projOutOfTaskGraph2 = project dependsOn projOutOfTaskGraph1 settings (
10-
BuildInfoPlugin.buildInfoDefaultSettings,
11-
addBuildInfoToConfig(Test),
12-
buildInfoKeys in Test += BuildInfoKey.outOfGraphUnsafe(fullClasspath in Compile),
13-
)
10+
val projOutOfTaskGraph2 = project
11+
.dependsOn(projOutOfTaskGraph1)
12+
.settings (
13+
BuildInfoPlugin.buildInfoDefaultSettings,
14+
addBuildInfoToConfig(Test),
15+
buildInfoKeys in Test += BuildInfoKey.outOfGraphUnsafe(fullClasspath in Compile),
16+
)
1417

15-
val projInTaskGraph1 = project settings (
16-
sourceGenerators in Compile += Def.task { counterInTaskGraph.incrementAndGet(); Nil }.taskValue
17-
)
18+
val projInTaskGraph1 = project
19+
.settings (
20+
sourceGenerators in Compile += Def.task { counterInTaskGraph.incrementAndGet(); Nil }.taskValue
21+
)
1822

19-
val projInTaskGraph2 = project dependsOn projInTaskGraph1 settings (
20-
BuildInfoPlugin.buildInfoDefaultSettings,
21-
addBuildInfoToConfig(Test),
22-
buildInfoKeys in Test += BuildInfoKey.of(fullClasspath in Compile)
23-
)
23+
val projInTaskGraph2 = project
24+
.dependsOn(projInTaskGraph1)
25+
.settings (
26+
BuildInfoPlugin.buildInfoDefaultSettings,
27+
addBuildInfoToConfig(Test),
28+
buildInfoKeys in Test += (fullClasspath in Compile: BuildInfoKey)
29+
)
2430

2531
TaskKey[Unit]("checkOutOfTaskGraph") := {
2632
val value = counterOutOfTaskGraph.get()

src/sbt-test/sbt-buildinfo/usepackageaspath/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ lazy val root = (project in file(".")).
77
version := "0.1",
88
scalaVersion := "2.12.7",
99
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.1.0",
10-
buildInfoKeys := BuildInfoKey.ofN(
10+
buildInfoKeys := Seq[BuildInfoKey](
1111
name,
1212
BuildInfoKey.map(version) { case (n, v) => "projectVersion" -> v.toDouble },
1313
scalaVersion,

src/test/scala/sbtbuildinfo/BuildInfoKeySpec.scala

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,4 @@ object BuildInfoKeySpec {
3636
BuildInfoKey.map(version) { case (_, v) => "projectVersion" -> v.toDouble },
3737
BuildInfoKey.map(fullClasspath) { case (ident, cp) => ident -> cp.files },
3838
)
39-
40-
41-
buildInfoKeys := BuildInfoKey.ofN(name, version) // test `:=` works with setting keys
42-
buildInfoKeys := BuildInfoKey.ofN(products, fullClasspath) // test `:=` works with task keys
43-
buildInfoKeys := BuildInfoKey.ofN(name, fullClasspath) // test `:=` works with setting and task keys
44-
buildInfoKeys := BuildInfoKey.ofN( // test `:=` works with misc things
45-
name,
46-
fullClasspath,
47-
"year" -> 2012,
48-
BuildInfoKey.action("buildTime") { 1234L },
49-
BuildInfoKey.map(version) { case (_, v) => "projectVersion" -> v.toDouble },
50-
BuildInfoKey.map(fullClasspath) { case (ident, cp) => ident -> cp.files },
51-
)
52-
53-
buildInfoKeys += BuildInfoKey.of(name) // test `+=` works with a setting key
54-
buildInfoKeys += BuildInfoKey.of(fullClasspath) // test `+=` works with a task key
55-
56-
buildInfoKeys ++= BuildInfoKey.ofN(name, version) // test `++=` works with setting keys
57-
buildInfoKeys ++= BuildInfoKey.ofN(fullClasspath) // test `++=` works with 1 task key
58-
buildInfoKeys ++= BuildInfoKey.ofN(products, fullClasspath) // test `++=` works with n task keys
59-
buildInfoKeys ++= BuildInfoKey.ofN(name, fullClasspath) // test `++=` works with setting and task keys
60-
buildInfoKeys ++= BuildInfoKey.ofN( // test `++=` works with misc things
61-
name,
62-
fullClasspath,
63-
"year" -> 2012,
64-
BuildInfoKey.action("buildTime") { 1234L },
65-
BuildInfoKey.map(version) { case (_, v) => "projectVersion" -> v.toDouble },
66-
BuildInfoKey.map(fullClasspath) { case (ident, cp) => ident -> cp.files },
67-
)
6839
}

0 commit comments

Comments
 (0)