-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuild.sbt
82 lines (66 loc) · 2.83 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
//import java.io.File
name := "ScalaFX Ensemble"
version := "21.0.0-R32"
organization := "org.scalafx"
val scala2Version = "2.13.12"
val scala3Version = "3.3.1"
// To cross compile with Scala 2 and Scala 3
crossScalaVersions := Seq(scala2Version, scala3Version)
scalaVersion := scala2Version
libraryDependencies ++= Seq(
"org.scalafx" %% "scalafx" % "21.0.0-R32",
"org.scalatest" %% "scalatest" % "3.2.17"
)
resolvers ++= Resolver.sonatypeOssRepos("snapshots")
scalacOptions ++= Seq("-unchecked", "-deprecation")
scalacOptions ++= (
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq("-explain", "-explain-types", "-rewrite", "-source", "3.3-migration")
case _ =>
Seq("-Xlint", "-explaintypes")
}
)
// Sources should also be copied to output, so the sample code, for the viewer,
// can be loaded from the same file that is used to execute the example
Compile / unmanagedResourceDirectories += baseDirectory(_ / "src/main/scala").value
// Set the prompt (for this build) to include the project id.
shellPrompt := { state => System.getProperty("user.name") + ":" + Project.extract(state).currentRef.project + "> " }
// Run in separate VM, so there are no issues with double initialization of JavaFX
fork := true
Test / fork := true
// Create file used to determine available examples at runtime.
Compile / resourceGenerators += Def.task {
/** Scan source directory for available examples
* Return pairs 'directory' -> 'collection of examples in that directory'.
*/
def loadExampleNames(inSourceDir: File): Array[(String, Array[String])] = {
val examplesDir = "/scalafx/ensemble/example/"
val examplePath = new File(inSourceDir, examplesDir)
val exampleRootFiles = examplePath.listFiles()
for (dir <- exampleRootFiles if dir.isDirectory) yield {
val leaves = for (f <- dir.listFiles() if f.getName.contains(".scala")) yield {
f.getName.stripSuffix(".scala").stripPrefix("Ensemble")
}
dir.getName.capitalize -> leaves.sorted
}
}
/** Create file representing names and directories for all availabe examples.
* It will be loaded by the application at runtime and used to popolate example tree.
*/
def generateExampleTreeFile(inSourceDir : File,
outSourceDir: File,
templatePath: String): Seq[File] = {
val exampleDirs = loadExampleNames(inSourceDir)
val contents = exampleDirs.map { case (dir, leaves) => dir + " -> " + leaves.mkString(", ") }.mkString("\n")
val outFile = new File(outSourceDir, templatePath)
IO.write(outFile, contents)
Seq(outFile)
}
generateExampleTreeFile(
(Compile / scalaSource).value,
(Compile / resourceManaged).value,
"/scalafx/ensemble/example/example.tree"
)
}.taskValue
Compile / mainClass := Some("scalafx.ensemble.Ensemble")