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