81764
|
1 |
/* Author: Fabian Huch, TU Muenchen
|
|
2 |
|
|
3 |
Build Isabelle Solr component from official downloads. See also: https://solr.apache.org/
|
|
4 |
*/
|
|
5 |
|
|
6 |
package isabelle
|
|
7 |
|
|
8 |
|
|
9 |
object Component_Solr {
|
|
10 |
val default_download_url = "https://dlcdn.apache.org/solr/solr/9.6.1/solr-9.6.1.tgz"
|
|
11 |
|
|
12 |
|
|
13 |
/* build solr */
|
|
14 |
|
|
15 |
def build_solr(
|
|
16 |
download_url: String = default_download_url,
|
|
17 |
progress: Progress = new Progress,
|
|
18 |
target_dir: Path = Path.current
|
|
19 |
): Unit =
|
|
20 |
Isabelle_System.with_tmp_dir("build") { tmp_dir =>
|
|
21 |
/* component */
|
|
22 |
|
|
23 |
val Archive_Name = """^.*/([^/]+)$""".r
|
|
24 |
val Version = """^solr-(.*)\.tgz$""".r
|
|
25 |
|
|
26 |
val archive_name =
|
|
27 |
download_url match {
|
|
28 |
case Archive_Name(name) => name
|
|
29 |
case _ => error("Failed to determine source archive name from " + quote(download_url))
|
|
30 |
}
|
|
31 |
|
|
32 |
val version =
|
|
33 |
archive_name match {
|
|
34 |
case Version(version) => version
|
|
35 |
case _ => error("Failed to determine component version from " + quote(archive_name))
|
|
36 |
}
|
|
37 |
|
|
38 |
val component_name = "solr-" + version
|
|
39 |
val component_dir =
|
|
40 |
Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress)
|
|
41 |
|
|
42 |
|
|
43 |
/* download */
|
|
44 |
|
|
45 |
val archive_path = tmp_dir + Path.basic(archive_name)
|
|
46 |
Isabelle_System.download_file(download_url, archive_path, progress = progress)
|
|
47 |
|
|
48 |
Isabelle_System.extract(archive_path, tmp_dir)
|
|
49 |
val source_dir = File.get_dir(tmp_dir, title = download_url)
|
|
50 |
|
|
51 |
Isabelle_System.copy_file(source_dir + Path.explode("LICENSE.txt"), component_dir.path)
|
|
52 |
|
|
53 |
val webapp_lib_dir = source_dir + Path.explode("server/solr-webapp/webapp/WEB-INF/lib")
|
|
54 |
val server_lib_dir = source_dir + Path.explode("server/lib")
|
|
55 |
|
|
56 |
|
|
57 |
/* jars */
|
|
58 |
|
|
59 |
Isabelle_System.make_directory(component_dir.lib)
|
|
60 |
|
|
61 |
val compile = List("solr-solrj", "solr-api", "solr-core")
|
|
62 |
|
|
63 |
val jars =
|
|
64 |
File.find_files(webapp_lib_dir.file, _.getName.endsWith(".jar")) ++
|
|
65 |
File.find_files(server_lib_dir.file, _.getName.endsWith(".jar"))
|
|
66 |
|
|
67 |
for (jar <- jars) Isabelle_System.copy_file(jar, component_dir.lib.file)
|
|
68 |
|
|
69 |
|
|
70 |
/* settings */
|
|
71 |
|
|
72 |
def jar_path(file: String): String = "$SOLR_HOME/lib/" + file
|
|
73 |
|
|
74 |
component_dir.write_settings("""
|
|
75 |
SOLR_HOME="$COMPONENT"
|
|
76 |
SOLR_JARS=""" + quote(compile.map(_ + "-" + version + ".jar").map(jar_path).mkString(":")) + """
|
|
77 |
classpath """ + quote(File.read_dir(component_dir.lib).map(jar_path).mkString(":")) + """
|
|
78 |
|
|
79 |
SOLR_LUCENE_VERSION="9.10"
|
|
80 |
SOLR_SCHEMA_VERSION="1.6"
|
|
81 |
""")
|
|
82 |
|
|
83 |
|
|
84 |
/* README */
|
|
85 |
|
|
86 |
File.write(component_dir.README,
|
|
87 |
"This Isabelle component provides Solr " + version + " jars from\n" + download_url + """
|
|
88 |
|
|
89 |
Fabian
|
|
90 |
""" + Date.Format.date(Date.now()) + "\n")
|
|
91 |
}
|
|
92 |
|
|
93 |
|
|
94 |
/* Isabelle tool wrapper */
|
|
95 |
|
|
96 |
val isabelle_tool =
|
|
97 |
Isabelle_Tool("component_solr", "build Isabelle solr jar distribution", Scala_Project.here,
|
|
98 |
{ args =>
|
|
99 |
var target_dir = Path.current
|
|
100 |
var download_url = default_download_url
|
|
101 |
var verbose = false
|
|
102 |
|
|
103 |
val getopts = Getopts("""
|
|
104 |
Usage: isabelle component_solr [OPTIONS]
|
|
105 |
|
|
106 |
Options are:
|
|
107 |
-D DIR target directory (default ".")
|
|
108 |
-U URL download URL
|
|
109 |
(default: """" + default_download_url + """")
|
|
110 |
-v verbose
|
|
111 |
|
|
112 |
Build solr component from official download.
|
|
113 |
""",
|
|
114 |
"D:" -> (arg => target_dir = Path.explode(arg)),
|
|
115 |
"U:" -> (arg => download_url = arg),
|
|
116 |
"v" -> (_ => verbose = true))
|
|
117 |
|
|
118 |
val more_args = getopts(args)
|
|
119 |
if (more_args.nonEmpty) getopts.usage()
|
|
120 |
|
|
121 |
val progress = new Console_Progress(verbose = verbose)
|
|
122 |
|
|
123 |
build_solr(download_url = download_url, progress = progress, target_dir = target_dir)
|
|
124 |
})
|
|
125 |
}
|