src/Pure/Admin/component_xz.scala
author paulson
Fri, 17 Jan 2025 23:00:13 +0000
changeset 81873 e4ff4a4ee4ec
parent 81608 a38e80897c34
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81607
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/component_xz.scala
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     3
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     4
Build Isabelle xz-java component from official download.
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     5
*/
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     6
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     7
package isabelle
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     8
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
     9
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    10
object Component_XZ {
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    11
  /* build xz */
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    12
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    13
  val main_url = "https://tukaani.org/xz/java.html"
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    14
  val default_source_url = "https://github.com/tukaani-project/xz-java/releases/download"
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    15
  val default_download_url = "https://repo1.maven.org/maven2/org/tukaani/xz"
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    16
  val default_version = "1.10"
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    17
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    18
  def build_xz(
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    19
    target_dir: Path = Path.current,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    20
    source_url: String = default_source_url,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    21
    download_url: String = default_download_url,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    22
    version: String = default_version,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    23
    progress: Progress = new Progress,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    24
  ): Unit = {
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    25
    /* component */
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    26
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    27
    val component_name = "xz-java-" + version
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    28
    val component_dir =
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    29
      Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    30
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    31
    File.write(component_dir.README,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    32
      "This is " + component_name + " from " + main_url +
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    33
        "\n\n        Makarius\n        " + Date.Format.date(Date.now()) + "\n")
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    34
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    35
    Isabelle_System.with_tmp_file("tmp", ext = "zip") { tmp =>
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    36
      Isabelle_System.download_file(
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    37
        source_url + "/v" + version + "/xz-java-" + version + ".zip", tmp, progress = progress)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    38
      Isabelle_System.extract(tmp, component_dir.path)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    39
    }
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    40
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    41
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    42
    /* lib */
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    43
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    44
    val jar_name = "xz-" + version + ".jar"
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    45
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    46
    Isabelle_System.make_directory(component_dir.lib)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    47
    Isabelle_System.download_file(
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    48
      download_url + "/" + version + "/" + jar_name,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    49
      component_dir.lib + Path.basic(jar_name), progress = progress)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    50
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    51
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    52
    /* settings */
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    53
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    54
    component_dir.write_settings("""
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    55
ISABELLE_XZ_HOME="$COMPONENT"
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    56
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    57
classpath "$ISABELLE_XZ_HOME/lib/""" + jar_name + """"
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    58
""")
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    59
  }
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    60
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    61
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    62
  /* Isabelle tool wrapper */
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    63
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    64
  val isabelle_tool =
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    65
    Isabelle_Tool("component_xz", "build Isabelle xz-java component from official download",
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    66
      Scala_Project.here,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    67
      { args =>
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    68
        var target_dir = Path.current
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    69
        var source_url = default_source_url
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    70
        var download_url = default_download_url
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    71
        var version = default_version
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    72
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    73
        val getopts = Getopts("""
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    74
Usage: isabelle component_xz [OPTIONS]
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    75
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    76
  Options are:
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    77
    -D DIR       target directory (default ".")
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    78
    -S URL       source URL (default: """ + quote(default_source_url) + """)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    79
    -U URL       download URL (default: """ + quote(default_download_url) + """)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    80
    -V VERSION   version (default: """ + quote(default_version) + """)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    81
81608
a38e80897c34 spelling;
wenzelm
parents: 81607
diff changeset
    82
  Build xz-java component from the specified download base URL and VERSION,
81607
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    83
  see also """ + main_url + "\n",
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    84
          "D:" -> (arg => target_dir = Path.explode(arg)),
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    85
          "S:" -> (arg => source_url = arg),
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    86
          "U:" -> (arg => download_url = arg),
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    87
          "V:" -> (arg => version = arg))
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    88
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    89
        val more_args = getopts(args)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    90
        if (more_args.nonEmpty) getopts.usage()
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    91
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    92
        val progress = new Console_Progress()
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    93
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    94
        build_xz(target_dir = target_dir, source_url = source_url,
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    95
          download_url = download_url, version = version, progress = progress)
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    96
      })
f48597f265ff update to xz-java-1.10;
wenzelm
parents:
diff changeset
    97
}