aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-11-08 00:49:25 +0000
committerChristopher Vogt <oss.nsp@cvogt.org>2016-11-08 00:12:42 -0500
commit6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7 (patch)
tree6125586f4ae9fd427de6bc0bb3a94109302196a9
parent151dab0984902e5a9eb03fb1a18a0da833c2ab13 (diff)
downloadcbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.tar.gz
cbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.tar.bz2
cbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.zip
add context based task result cache
-rw-r--r--compatibility/Context.java1
-rw-r--r--stage1/ContextImplementation.scala1
-rw-r--r--stage1/cbt.scala1
-rw-r--r--stage2/BasicBuild.scala17
-rw-r--r--stage2/Stage2.scala1
-rw-r--r--test/test.scala1
6 files changed, 22 insertions, 0 deletions
diff --git a/compatibility/Context.java b/compatibility/Context.java
index 921087f..0e2fff5 100644
--- a/compatibility/Context.java
+++ b/compatibility/Context.java
@@ -14,6 +14,7 @@ public abstract class Context{
public abstract String scalaVersionOrNull(); // needed to propagate scalaVersion to dependendee builds
public abstract ConcurrentHashMap<String,Object> permanentKeys();
public abstract ConcurrentHashMap<Object,ClassLoader> permanentClassLoaders();
+ public abstract ConcurrentHashMap<Object,Object> taskCache();
public abstract File cache();
public abstract File cbtHome();
public abstract File cbtRootHome();
diff --git a/stage1/ContextImplementation.scala b/stage1/ContextImplementation.scala
index 91c54f4..c3f25fd 100644
--- a/stage1/ContextImplementation.scala
+++ b/stage1/ContextImplementation.scala
@@ -14,6 +14,7 @@ case class ContextImplementation(
scalaVersionOrNull: String,
permanentKeys: ConcurrentHashMap[String,AnyRef],
permanentClassLoaders: ConcurrentHashMap[AnyRef,ClassLoader],
+ taskCache: ConcurrentHashMap[AnyRef,AnyRef],
cache: File,
cbtHome: File,
cbtRootHome: File,
diff --git a/stage1/cbt.scala b/stage1/cbt.scala
index 7a239a1..08394f0 100644
--- a/stage1/cbt.scala
+++ b/stage1/cbt.scala
@@ -88,6 +88,7 @@ object `package`{
scalaVersion.getOrElse(null),
permanentKeys,
permanentClassLoaders,
+ taskCache,
cache,
cbtHome,
cbtRootHome,
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index 128d2f8..ef4757e 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -244,4 +244,21 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
// ========== cbt internals ==========
def finalBuild: BuildInterface = this
override def show = this.getClass.getSimpleName ++ "(" ++ projectDirectory.string ++ ")"
+
+ // TODO: allow people not provide the method name, maybe via macro
+ /**
+ caches given value in context keyed with given key and projectDirectory
+ the context is fresh on every complete run of cbt
+ */
+ def cached[T <: AnyRef](name: String)(task: => T): T = {
+ val cache = context.taskCache
+ val key = (projectDirectory,name)
+ if( cache.containsKey(key) ){
+ cache.get(key).asInstanceOf[T]
+ } else{
+ val value = task
+ cache.put( key, value )
+ value
+ }
+ }
}
diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala
index b1539bf..d585cd0 100644
--- a/stage2/Stage2.scala
+++ b/stage2/Stage2.scala
@@ -39,6 +39,7 @@ object Stage2 extends Stage2Base{
null,
args.permanentKeys,
args.permanentClassLoaders,
+ new java.util.concurrent.ConcurrentHashMap,
args.cache,
args.cbtHome,
args.cbtHome,
diff --git a/test/test.scala b/test/test.scala
index 039ee6a..72360d0 100644
--- a/test/test.scala
+++ b/test/test.scala
@@ -118,6 +118,7 @@ object Main{
null,
new ConcurrentHashMap[String,AnyRef],
new ConcurrentHashMap[AnyRef,ClassLoader],
+ new java.util.concurrent.ConcurrentHashMap[AnyRef,AnyRef],
cache,
cbtHome,
cbtHome,