forked from ashawley/ccssi-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
105 lines (75 loc) · 2.45 KB
/
build.sbt
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// build.sbt --- Scala build tool settings
import sbt.complete.Parser
import sbt.complete.Parsers._
scalaVersion := "2.11.8" // "2.12.0-M5"
// https://tpolecat.github.io/2014/04/11/scalac-flags.html
scalacOptions in (Compile) ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused-import",
"-Yno-predef",
"-Yno-imports"
)
libraryDependencies ++= List(
"org.scalacheck" %% "scalacheck" % "1.13.2" % "test",
"org.scala-lang.modules" %% "scala-xml" % "1.0.5",
"org.json4s" %% "json4s-native" % "3.4.0"
)
lazy val xmlToJson = inputKey[Unit]("Convert an XML standard to JSON")
// file("src/main/xml/ela-literacy.xml")
lazy val xmlFileParser = fileParser(file(".")).filter(
(f: java.io.File) => !f.isFile || f.isFile && ".xml\\Z".r.findFirstIn(f.name).map(_ => true).getOrElse(false),
(msg: String) => msg match {
case _ => "Not an XML file"
}
)
xmlToJson := Def.inputTaskDyn {
val log = streams.value.log
val xmlFile = xmlFileParser.parsed
Def.taskDyn {
log.info(s"Converting XML file to JSON...")
val runTask = (run in Compile).toTask(s" $xmlFile")
runTask
}
}.evaluated
lazy val xmlToJsonDir = inputKey[Unit]("Convert XML standards to JSON")
// file("src/main/xml")
lazy val dirParser = fileParser(file(".")).filter(
_.isDirectory,
(msg: String) => msg match {
case _ => "Not a directory"
}
)
xmlToJsonDir := Def.inputTaskDyn {
val log = streams.value.log
val dir = dirParser.parsed
Def.taskDyn {
log.info(s"Loooking for XML files in $dir...")
val xmlFiles = dir ** "*.xml"
// Find only XML files with standards in them...
val tagMatcher = "\\A<LearningStandards>".r
val peekLines = 3 // First N lines to check...
implicit def optionToBoolean(o: Option[_]): Boolean = o.isDefined
def isLearningStandard(file: java.io.File): Boolean =
scala.io.Source.fromFile(file).getLines.take(peekLines).find {
line: String => tagMatcher.findPrefixOf(line)
}
val xmlMatches = xmlFiles filter (isLearningStandard _)
log.info(s"Converting XML files to JSON...")
val paths = xmlMatches.get.map(_.getPath).mkString(" ")
val runTask = (run in Compile).toTask(s" $paths")
runTask
}
}.evaluated