author | wenzelm |
Wed, 07 Jun 2023 15:27:52 +0200 | |
changeset 78146 | 5faedbc01c07 |
parent 77566 | 2a99fcb283ee |
child 79507 | 928b58ef9599 |
permissions | -rw-r--r-- |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77035
diff
changeset
|
1 |
/* Title: Pure/Admin/component_postgresql.scala |
76075 | 2 |
Author: Makarius |
3 |
||
4 |
Build Isabelle postgresql component from official download. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77035
diff
changeset
|
10 |
object Component_PostgreSQL { |
76075 | 11 |
/* URLs */ |
12 |
||
13 |
val notable_urls = |
|
78146 | 14 |
List("https://jdbc.postgresql.org", "https://jdbc.postgresql.org/download") |
76075 | 15 |
|
78146 | 16 |
val default_download_url = "https://jdbc.postgresql.org/download/postgresql-42.6.0.jar" |
76075 | 17 |
|
18 |
||
19 |
/* build postgresql */ |
|
20 |
||
21 |
def build_postgresql( |
|
22 |
download_url: String = default_download_url, |
|
23 |
progress: Progress = new Progress, |
|
24 |
target_dir: Path = Path.current |
|
25 |
): Unit = { |
|
26 |
/* name and version */ |
|
27 |
||
28 |
def err(): Nothing = error("Malformed jar download URL: " + quote(download_url)) |
|
29 |
||
30 |
val Name = """^.*/([^/]+)\.jar""".r |
|
31 |
val download_name = download_url match { case Name(name) => name case _ => err() } |
|
32 |
||
33 |
val Version = """^.[^0-9]*([0-9].*)$""".r |
|
34 |
val download_version = download_name match { case Version(version) => version case _ => err() } |
|
35 |
||
36 |
||
37 |
/* component */ |
|
38 |
||
76518 | 39 |
val component_dir = |
76547 | 40 |
Components.Directory(target_dir + Path.basic(download_name)).create(progress = progress) |
76075 | 41 |
|
42 |
||
43 |
/* LICENSE */ |
|
44 |
||
76518 | 45 |
File.write(component_dir.LICENSE, |
76075 | 46 |
"""Copyright (c) 1997, PostgreSQL Global Development Group |
47 |
All rights reserved. |
|
48 |
||
49 |
Redistribution and use in source and binary forms, with or without |
|
50 |
modification, are permitted provided that the following conditions are met: |
|
51 |
||
52 |
1. Redistributions of source code must retain the above copyright notice, |
|
53 |
this list of conditions and the following disclaimer. |
|
54 |
2. Redistributions in binary form must reproduce the above copyright notice, |
|
55 |
this list of conditions and the following disclaimer in the documentation |
|
56 |
and/or other materials provided with the distribution. |
|
57 |
||
58 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
59 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
60 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
61 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|
62 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
63 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
64 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
65 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
66 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
67 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
68 |
POSSIBILITY OF SUCH DAMAGE. |
|
69 |
""") |
|
70 |
||
71 |
||
72 |
/* README */ |
|
73 |
||
76518 | 74 |
File.write(component_dir.README, |
76075 | 75 |
"""This is PostgreSQL JDBC """ + download_version + """ from |
76 |
""" + notable_urls.mkString(" and ") + """ |
|
77 |
||
78 |
Makarius |
|
79 |
""" + Date.Format.date(Date.now()) + "\n") |
|
80 |
||
81 |
||
82 |
/* settings */ |
|
83 |
||
76548 | 84 |
component_dir.write_settings(""" |
76075 | 85 |
classpath "$COMPONENT/""" + download_name + """.jar" |
86 |
""") |
|
87 |
||
88 |
||
89 |
/* jar */ |
|
90 |
||
77035 | 91 |
val jar = component_dir.path + Path.basic(download_name).jar |
76075 | 92 |
Isabelle_System.download_file(download_url, jar, progress = progress) |
93 |
} |
|
94 |
||
95 |
||
96 |
/* Isabelle tool wrapper */ |
|
97 |
||
98 |
val isabelle_tool = |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77035
diff
changeset
|
99 |
Isabelle_Tool("component_postgresql", "build Isabelle postgresql component from official download", |
76075 | 100 |
Scala_Project.here, |
101 |
{ args => |
|
102 |
var target_dir = Path.current |
|
103 |
var download_url = default_download_url |
|
104 |
||
105 |
val getopts = Getopts(""" |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77035
diff
changeset
|
106 |
Usage: isabelle component_postgresql [OPTIONS] |
76075 | 107 |
|
108 |
Options are: |
|
109 |
-D DIR target directory (default ".") |
|
110 |
-U URL download URL |
|
111 |
(default: """" + default_download_url + """") |
|
112 |
||
113 |
Build postgresql component from the specified download URL (JAR), see also |
|
114 |
""" + notable_urls.mkString(" and "), |
|
115 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
116 |
"U:" -> (arg => download_url = arg)) |
|
117 |
||
118 |
val more_args = getopts(args) |
|
119 |
if (more_args.nonEmpty) getopts.usage() |
|
120 |
||
121 |
val progress = new Console_Progress() |
|
122 |
||
123 |
build_postgresql(download_url, progress = progress, target_dir = target_dir) |
|
124 |
}) |
|
125 |
} |