diff options
author | Jeremy Cloud <jeremycloud@twitter.com> | 2011-10-06 16:50:38 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:08:38 -0500 |
commit | 826033765c3c56b1d0244f973147f7853e97c268 (patch) | |
tree | b44fbda13478f126d26dbecb203e8411a55ed961 /libraries/eval/Eval.scala | |
parent | ec5d48ac3db80cf955535729d14fa36d188be130 (diff) | |
download | cbt-826033765c3c56b1d0244f973147f7853e97c268.tar.gz cbt-826033765c3c56b1d0244f973147f7853e97c268.tar.bz2 cbt-826033765c3c56b1d0244f973147f7853e97c268.zip |
[split] - recursively process includes - allow additional include path to be specified via system property
Diffstat (limited to 'libraries/eval/Eval.scala')
-rw-r--r-- | libraries/eval/Eval.scala | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala index 8f05ed1..a952b52 100644 --- a/libraries/eval/Eval.scala +++ b/libraries/eval/Eval.scala @@ -100,6 +100,10 @@ class Eval(target: Option[File]) { new ClassScopedResolver(getClass), new FilesystemResolver(new File(".")), new FilesystemResolver(new File("." + File.separator + "config")) + ) ++ ( + Option(System.getProperty("com.twitter.util.Eval.includePath")) map { path => + new FilesystemResolver(new File(path)) + } ) ) ) @@ -112,7 +116,7 @@ class Eval(target: Option[File]) { * to the text. * Last modified is computed here because we support includes */ - def sourceForString(code: String) = { + def sourceForString(code: String): LastMod = { preprocessors.foldLeft(LastMod(0L, code)) { (acc, p) => val processed = p(acc.code) LastMod(acc.timestamp max processed.timestamp, processed.code) @@ -300,7 +304,6 @@ class Eval(target: Option[File]) { private[this] def file(path: String): File = new File(root.getAbsolutePath + File.separator + path) - def resolvable(path: String): Boolean = file(path).exists @@ -344,7 +347,9 @@ class Eval(target: Option[File]) { * Note that it is *not* recursive. Included files cannot have includes */ class IncludePreprocessor(resolvers: Seq[Resolver]) extends Preprocessor { - def apply(code: String): LastMod = { + def maximumRecursionDepth = 100 + def apply(code: String): LastMod = apply(code, maximumRecursionDepth) + def apply(code: String, maxDepth: Int): LastMod = { var lastMod = 0L val lines = code.lines map { line: String => val tokens = line.trim.split(' ') @@ -355,7 +360,16 @@ class Eval(target: Option[File]) { } match { case Some(r: Resolver) => { lastMod = lastMod max r.lastModified(path) - StreamIO.buffer(r.get(path)).toString + // recursively process includes + if (maxDepth == 0) { + throw new IllegalStateException("Exceeded maximum recusion depth") + } else { + apply(StreamIO.buffer(r.get(path)).toString, maxDepth - 1) match { + case LastMod(timestamp, code) => + lastMod = lastMod max timestamp + code + } + } } case _ => throw new IllegalStateException("No resolver could find '%s'".format(path)) |