74055
|
1 |
/* Title: Pure/Tools/scala_build.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Manage and build Isabelle/Scala/Java components.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
import java.util.{Properties => JProperties}
|
|
11 |
import java.nio.file.Files
|
|
12 |
|
|
13 |
import scala.jdk.CollectionConverters._
|
|
14 |
|
|
15 |
|
|
16 |
object Scala_Build
|
|
17 |
{
|
74056
|
18 |
class Context private[Scala_Build](java_context: isabelle.setup.Build.Context)
|
|
19 |
{
|
74057
|
20 |
override def toString: String = java_context.toString
|
|
21 |
|
74056
|
22 |
def is_module(path: Path): Boolean =
|
|
23 |
{
|
74057
|
24 |
val module_name = java_context.module_name()
|
74056
|
25 |
module_name.nonEmpty && File.eq(java_context.path(module_name).toFile, path.file)
|
|
26 |
}
|
|
27 |
|
|
28 |
def sources: List[Path] =
|
|
29 |
java_context.sources().asScala.toList.map(s => File.path(java_context.path(s).toFile))
|
|
30 |
|
|
31 |
def requirements: List[Path] =
|
|
32 |
(for {
|
|
33 |
s <- java_context.requirements().asScala.iterator
|
|
34 |
p <- java_context.requirement_paths(s).asScala.iterator
|
|
35 |
} yield (File.path(p.toFile))).toList
|
|
36 |
|
|
37 |
def build(fresh: Boolean = false): Unit =
|
|
38 |
isabelle.setup.Build.build(java_context, fresh)
|
|
39 |
}
|
74055
|
40 |
|
|
41 |
def context(dir: Path,
|
|
42 |
component: Boolean = false,
|
74060
|
43 |
no_title: Boolean = false,
|
74057
|
44 |
do_build: Boolean = false,
|
|
45 |
module: Option[Path] = None): Context =
|
74055
|
46 |
{
|
|
47 |
val props_name =
|
|
48 |
if (component) isabelle.setup.Build.COMPONENT_BUILD_PROPS
|
|
49 |
else isabelle.setup.Build.BUILD_PROPS
|
|
50 |
val props_path = dir + Path.explode(props_name)
|
|
51 |
|
|
52 |
val props = new JProperties
|
|
53 |
props.load(Files.newBufferedReader(props_path.java_path))
|
74060
|
54 |
if (no_title) props.remove(isabelle.setup.Build.TITLE)
|
74057
|
55 |
if (do_build) props.remove(isabelle.setup.Build.NO_BUILD)
|
|
56 |
if (module.isDefined) props.put(isabelle.setup.Build.MODULE, File.standard_path(module.get))
|
74055
|
57 |
|
74056
|
58 |
new Context(new isabelle.setup.Build.Context(dir.java_path, props, props_path.implode))
|
74055
|
59 |
}
|
|
60 |
|
|
61 |
def build(dir: Path,
|
|
62 |
fresh: Boolean = false,
|
|
63 |
component: Boolean = false,
|
74060
|
64 |
no_title: Boolean = false,
|
74057
|
65 |
do_build: Boolean = false,
|
|
66 |
module: Option[Path] = None): Unit =
|
74055
|
67 |
{
|
74060
|
68 |
context(dir, component = component, no_title = no_title, do_build = do_build, module = module)
|
|
69 |
.build(fresh = fresh)
|
|
70 |
}
|
|
71 |
|
|
72 |
def build_result(dir: Path, component: Boolean = false): Bytes =
|
|
73 |
{
|
|
74 |
Isabelle_System.with_tmp_file("result", "jar")(tmp_file =>
|
|
75 |
{
|
|
76 |
build(dir, component = component, no_title = true, do_build = true, module = Some(tmp_file))
|
|
77 |
Bytes.read(tmp_file)
|
|
78 |
})
|
74055
|
79 |
}
|
|
80 |
|
|
81 |
def component_contexts(): List[Context] =
|
74056
|
82 |
isabelle.setup.Build.component_contexts().asScala.toList.map(new Context(_))
|
74055
|
83 |
}
|