/
DataPreprocessor.scala
54 lines (50 loc) · 1.59 KB
/
DataPreprocessor.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package scala.build.preprocessing
import java.nio.charset.StandardCharsets
import scala.build.EitherCps.{either, value}
import scala.build.Logger
import scala.build.errors.BuildException
import scala.build.input.{Inputs, SingleElement, VirtualData}
import scala.build.options.BuildRequirements
import scala.build.preprocessing.PreprocessingUtil.optionsAndPositionsFromDirectives
case object DataPreprocessor extends Preprocessor {
def preprocess(
input: SingleElement,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException] = e => Some(e),
allowRestrictedFeatures: Boolean
): Option[Either[BuildException, Seq[PreprocessedSource]]] =
input match {
case file: VirtualData =>
val res = either {
val content = new String(file.content, StandardCharsets.UTF_8)
val (updatedOptions, directivesPositions) = value {
optionsAndPositionsFromDirectives(
content,
file.scopePath,
Left(file.subPath.toString),
logger,
maybeRecoverOnError,
allowRestrictedFeatures
)
}
val inMemory = Seq(
PreprocessedSource.InMemory(
Left(file.source),
file.subPath,
content,
0,
Some(updatedOptions.global),
Some(BuildRequirements()),
Nil,
None,
file.scopePath,
directivesPositions
)
)
inMemory
}
Some(res)
case _ =>
None
}
}