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