src/Pure/Admin/build_postgresql.scala
author wenzelm
Sun, 20 Nov 2022 23:37:54 +0100
changeset 76518 b30b8e23383c
parent 76075 2e7211754ef1
child 76547 9fe5d8c70352
permissions -rw-r--r--
clarified signature: more explicit types;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
76075
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/build_postgresql.scala
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
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    10
object Build_PostgreSQL {
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 =
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    14
    List("https://jdbc.postgresql.org", "https://jdbc.postgresql.org/download.html")
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    15
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    16
  val default_download_url = "https://jdbc.postgresql.org/download/postgresql-42.5.0.jar"
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 =
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76075
diff changeset
    40
      Components.Directory.create(target_dir + Path.basic(download_name), 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
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76075
diff changeset
    84
    File.write(component_dir.settings,
76075
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    85
"""# -*- shell-script -*- :mode=shellscript:
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
classpath "$COMPONENT/""" + download_name + """.jar"
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
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    90
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    91
    /* jar */
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    92
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76075
diff changeset
    93
    val jar = component_dir.path + Path.basic(download_name).ext("jar")
76075
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    94
    Isabelle_System.download_file(download_url, jar, progress = progress)
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
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    98
  /* Isabelle tool wrapper */
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
    99
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   100
  val isabelle_tool =
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   101
    Isabelle_Tool("build_postgresql", "build Isabelle postgresql component from official download",
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   102
      Scala_Project.here,
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   103
      { args =>
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   104
        var target_dir = Path.current
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   105
        var download_url = default_download_url
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   106
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   107
        val getopts = Getopts("""
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   108
Usage: isabelle build_postgresql [OPTIONS]
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   109
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   110
  Options are:
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   111
    -D DIR       target directory (default ".")
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   112
    -U URL       download URL
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   113
                 (default: """" + default_download_url + """")
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   114
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   115
  Build postgresql component from the specified download URL (JAR), see also
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   116
  """ + notable_urls.mkString(" and "),
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   117
          "D:" -> (arg => target_dir = Path.explode(arg)),
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   118
          "U:" -> (arg => download_url = arg))
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   119
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   120
        val more_args = getopts(args)
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   121
        if (more_args.nonEmpty) getopts.usage()
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   122
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   123
        val progress = new Console_Progress()
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   124
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   125
        build_postgresql(download_url, progress = progress, target_dir = target_dir)
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   126
      })
2e7211754ef1 tool to build Isabelle component for PostgreSQL JDBC;
wenzelm
parents:
diff changeset
   127
}