aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-20 22:09:38 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-27 19:56:13 -0400
commitbba2abe7ee38b8903822a07578c46466923d13ed (patch)
treea357fb8def6f58a9ea9a37411f3f5640dcb525fe /internal
parentd2f8cade709b7d55a93e18592b6e38247d648ca9 (diff)
downloadcbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.gz
cbt-bba2abe7ee38b8903822a07578c46466923d13ed.tar.bz2
cbt-bba2abe7ee38b8903822a07578c46466923d13ed.zip
start modularizing cbt into libraries
this extracts certain parts of cbt into stand-alone libraries, which can be published to maven and used outside of cbt. This also adds scalariform for these parts of the code. This slows down cbt’s own build a lot because of the number of projects involved! So we’ll follow this by a bunch of performance tweak commits.
Diffstat (limited to 'internal')
-rw-r--r--internal/plugins/library/Library.scala51
-rw-r--r--internal/plugins/library/build/build.scala7
-rw-r--r--internal/plugins/shared/Shared.scala2
3 files changed, 59 insertions, 1 deletions
diff --git a/internal/plugins/library/Library.scala b/internal/plugins/library/Library.scala
new file mode 100644
index 0000000..a9dec7c
--- /dev/null
+++ b/internal/plugins/library/Library.scala
@@ -0,0 +1,51 @@
+package cbt_internal
+import cbt._
+import java.io._
+import scala.concurrent._
+import scala.concurrent.duration._
+trait Library extends Scalariform with GoogleJavaFormat with DynamicOverrides with AdvancedScala{
+ def inceptionYear: Int
+ def description: String
+ def version = ???
+ override def compile = {
+ googleJavaFormat()
+ scalariform()
+ super.compile
+ }
+
+ def publishIfChanged = newBuild[PublishIfChanged]({s"""
+ def inceptionYear = $inceptionYear
+ def description = ${description.quote}
+ def apply = if(changedInMaster) publish
+ """})
+}
+
+trait PublishIfChanged extends PackageJars with DynamicOverrides with Shared{
+ override def url = super.url ++ "/libraries/" ++ name
+
+ def gitHash = {
+ val p = new ProcessBuilder(
+ "git rev-parse HEAD".split(" "): _*
+ )
+ .directory( projectDirectory )
+ .start
+
+ val sout = new InputStreamReader(p.getInputStream);
+ import scala.concurrent.ExecutionContext.Implicits.global
+ val out = Future(blocking(Iterator.continually(sout.read).takeWhile(_ != -1).map(_.toChar).mkString))
+ p.waitFor
+ val revision = Await.result( out, Duration.Inf ).trim
+ revision
+ }
+ override def version = "rev-"++gitHash
+
+ def changedInMaster = (
+ 0 ===
+ new ProcessBuilder(
+ "git diff --exit-code --quiet master..master^ .".split(" "): _*
+ )
+ .directory( projectDirectory )
+ .start
+ .waitFor
+ )
+}
diff --git a/internal/plugins/library/build/build.scala b/internal/plugins/library/build/build.scala
new file mode 100644
index 0000000..6b9432e
--- /dev/null
+++ b/internal/plugins/library/build/build.scala
@@ -0,0 +1,7 @@
+package cbt_build.cbt_internal.library_build_plugin
+import cbt._
+class Build(val context: Context) extends Plugin with CbtInternal{
+ override def dependencies = (
+ super.dependencies :+ cbtInternal.shared :+ plugins.scalariform :+ plugins.googleJavaFormat
+ )
+}
diff --git a/internal/plugins/shared/Shared.scala b/internal/plugins/shared/Shared.scala
index 90bc4b2..2db9770 100644
--- a/internal/plugins/shared/Shared.scala
+++ b/internal/plugins/shared/Shared.scala
@@ -1,7 +1,7 @@
package cbt_internal
import cbt._
import java.net.URL
-trait Shared extends SonatypeRelease with SnapshotVersion with GithubPom{
+trait Shared extends AdvancedScala with SonatypeRelease with SnapshotVersion with GithubPom{
override def user = "cvogt"
override def groupId = "org.cvogt"
override def organization = Some( Organization( "Jan Christopher Vogt", Some( new URL("http://cvogt.org") ) ) )