diff options
-rw-r--r-- | examples/build-info-example/BuildInfo.scala | 8 | ||||
-rw-r--r-- | examples/build-info-example/Main.scala | 9 | ||||
-rw-r--r-- | examples/build-info-example/Readme.md | 3 | ||||
-rw-r--r-- | examples/build-info-example/build/build.scala | 27 | ||||
-rw-r--r-- | test/library-test/build/build.scala | 8 | ||||
-rw-r--r-- | test/simple-fixed-cbt/Main.scala | 6 | ||||
-rw-r--r-- | test/simple-fixed-cbt/build/build.scala | 14 | ||||
-rw-r--r-- | test/test.scala | 14 |
8 files changed, 83 insertions, 6 deletions
diff --git a/examples/build-info-example/BuildInfo.scala b/examples/build-info-example/BuildInfo.scala new file mode 100644 index 0000000..ac0e680 --- /dev/null +++ b/examples/build-info-example/BuildInfo.scala @@ -0,0 +1,8 @@ +// generated file +import java.io._ +object BuildInfo{ +def artifactId = "build-info-example" +def groupId = "cbt.examples" +def version = "0.1" +def scalaVersion = "2.11.8" +} diff --git a/examples/build-info-example/Main.scala b/examples/build-info-example/Main.scala new file mode 100644 index 0000000..cb4ad75 --- /dev/null +++ b/examples/build-info-example/Main.scala @@ -0,0 +1,9 @@ +object Main{ + def main(args: Array[String]): Unit = { + import BuildInfo._ + println("scalaVersion: "+scalaVersion) + println("groupId: "+groupId) + println("artifactId: "+artifactId) + println("version: "+version) + } +}
\ No newline at end of file diff --git a/examples/build-info-example/Readme.md b/examples/build-info-example/Readme.md new file mode 100644 index 0000000..acbb84e --- /dev/null +++ b/examples/build-info-example/Readme.md @@ -0,0 +1,3 @@ +This is an example how to propagate build-time information +such as version or scalaVersion to runtime. +The advantage of the approach taken here is simplicity. diff --git a/examples/build-info-example/build/build.scala b/examples/build-info-example/build/build.scala new file mode 100644 index 0000000..f6fc7a4 --- /dev/null +++ b/examples/build-info-example/build/build.scala @@ -0,0 +1,27 @@ +import cbt._ +import java.nio.file.Files._ + +class Build(val context: Context) extends PackageJars{ + def name = "build-info-example" + def groupId = "cbt.examples" + def defaultVersion = "0.1" + override def defaultScalaVersion = "2.11.8" + override def compile = { + val file = (projectDirectory ++ "/BuildInfo.scala").toPath + val contents = s"""// generated file +import java.io._ +object BuildInfo{ +def artifactId = "$artifactId" +def groupId = "$groupId" +def version = "$version" +def scalaVersion = "$scalaVersion" +} +""" + if( exists(file) && contents != new String(readAllBytes(file)) ) + write( + (projectDirectory ++ "/BuildInfo.scala").toPath, + contents.getBytes + ) + super.compile + } +} diff --git a/test/library-test/build/build.scala b/test/library-test/build/build.scala index a6e61af..d07e58e 100644 --- a/test/library-test/build/build.scala +++ b/test/library-test/build/build.scala @@ -1,7 +1,11 @@ import cbt._ -// cbt:https://github.com/cvogt/cbt.git#1f4f6097d3ca682d6fd20a7cc6dd277832350827 -class Build(val context: Context) extends BaseBuild{ +// cbt:https://github.com/cvogt/cbt.git#bf4ea112fe668fb7e2e95a2baca4989b16384783 +class Build(val context: Context) extends BaseBuild with PackageJars{ + def groupId = "cbt.test" + def defaultVersion = "0.1" + def name = "library-test" + override def dependencies = super.dependencies ++ // don't forget super.dependencies here for scala-library, etc. Seq( diff --git a/test/simple-fixed-cbt/Main.scala b/test/simple-fixed-cbt/Main.scala new file mode 100644 index 0000000..75f9349 --- /dev/null +++ b/test/simple-fixed-cbt/Main.scala @@ -0,0 +1,6 @@ +import lib_test.Foo +import org.eclipse.jgit.lib.Ref +import com.spotify.missinglink.ArtifactLoader +object Main extends App{ + println(Foo.bar) +} diff --git a/test/simple-fixed-cbt/build/build.scala b/test/simple-fixed-cbt/build/build.scala new file mode 100644 index 0000000..1d0640d --- /dev/null +++ b/test/simple-fixed-cbt/build/build.scala @@ -0,0 +1,14 @@ +import cbt._ + +// cbt:https://github.com/cvogt/cbt.git#bf4ea112fe668fb7e2e95a2baca4989b16384783 +class Build(val context: cbt.Context) extends PackageJars{ + override def dependencies = super.dependencies ++ Seq( + DirectoryDependency( context.cbtHome ++ "/test/library-test" ) + ) ++ Resolver( mavenCentral ).bind( + MavenDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r"), + MavenDependency("com.spotify", "missinglink-core", "0.1.1") + ) + def groupId: String = "cbt.test" + def defaultVersion: String = "0.1" + def name: String = "simple-fixed-cbt" +}
\ No newline at end of file diff --git a/test/test.scala b/test/test.scala index 685d7ce..5b4a4af 100644 --- a/test/test.scala +++ b/test/test.scala @@ -212,10 +212,10 @@ object Main{ compile("../examples/uber-jar-example") { - val res = task("docJar","library-test") - assert( res.out endsWith "library-test_2.11-0.1-javadoc.jar" ) - assert( res.err startsWith "model contains" ) - assert( res.err endsWith "documentable templates" ) + val res = task("docJar","simple-fixed-cbt") + assert( res.out endsWith "simple-fixed-cbt_2.11-0.1-javadoc.jar", res.out ) + assert( res.err contains "model contains", res.err ) + assert( res.err endsWith "documentable templates", res.err ) } { @@ -225,6 +225,12 @@ object Main{ } { + val res = runCbt("../examples/build-info-example", Seq("run")) + assert(res.exit0) + assert(res.out contains "version: 0.1", res.out) + } + + { val res = runCbt("forgot-extend", Seq("run")) assert(!res.exit0) assert(res.err contains "Build cannot be cast to cbt.BuildInterface", res.err) |