src/Pure/Admin/component_javamail.scala
author wenzelm
Thu, 02 Nov 2023 12:03:30 +0100
changeset 78877 45d570945fe4
parent 78827 06f0e720b913
child 79443 0d7c7fe65638
permissions -rw-r--r--
more detailed progress for build_log_database, to see better what happens when;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
     1
/*  Title:      Pure/Admin/component_javamail.scala
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
     2
    Author:     Fabian Huch, TU Muenchen
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
     3
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
     4
Build Isabelle javax-mail component from official download. See also:
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
     5
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
     6
  - https://javaee.github.io/javamail/
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
     7
  - https://mvnrepository.com/artifact/javax.mail/mail
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
     8
*/
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
     9
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    10
package isabelle
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    11
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    12
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    13
object Component_Javamail {
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    14
  /* build javamail */
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    15
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    16
  val default_download_url =
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    17
    "https://repo1.maven.org/maven2/javax/mail/mail/1.4.7/mail-1.4.7.jar"
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    18
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    19
  def build_javamail(
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    20
    download_url: String = default_download_url,
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    21
    progress: Progress = new Progress,
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    22
    target_dir: Path = Path.current
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    23
  ): Unit = {
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    24
    val Download_Name = """^.*/([^/]+)\.jar""".r
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    25
    val download_name =
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    26
      download_url match {
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    27
        case Download_Name(download_name) => download_name
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    28
        case _ => error("Malformed jar download URL: " + quote(download_url))
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    29
      }
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    30
    val component_name = "java" + download_name
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    31
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    32
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    33
    /* component */
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    34
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    35
    val component_dir =
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    36
      Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress)
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    37
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    38
    File.write(component_dir.LICENSE,
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    39
      Url.read("https://raw.githubusercontent.com/javaee/javamail/master/LICENSE.txt"))
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    40
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    41
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    42
    /* README */
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    43
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    44
    File.write(component_dir.README,
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    45
      "This is " + component_name + " from\n" + download_url +
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    46
        "\n\nSee also https://javaee.github.io/javamail and https://mvnrepository.com/artifact/javax.mail/mail" +
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    47
        "\n\n        Fabian\n        " + Date.Format.date(Date.now()) + "\n")
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    48
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    49
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    50
    /* settings */
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    51
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    52
    component_dir.write_settings("""
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    53
classpath "$COMPONENT/lib/""" + download_name + """.jar"
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    54
""")
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    55
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    56
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    57
    /* jar */
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    58
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    59
    val jar = component_dir.lib + Path.basic(download_name).jar
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    60
    Isabelle_System.make_directory(jar.dir)
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    61
    Isabelle_System.download_file(download_url, jar, progress = progress)
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    62
  }
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    63
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    64
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    65
  /* Isabelle tool wrapper */
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    66
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    67
  val isabelle_tool =
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    68
    Isabelle_Tool("component_javamail", "build Isabelle javamail component from official download",
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    69
      Scala_Project.here,
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    70
      { args =>
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    71
        var target_dir = Path.current
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    72
        var download_url = default_download_url
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    73
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    74
        val getopts = Getopts("""
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    75
Usage: isabelle component_javamail [OPTIONS] DOWNLOAD
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    76
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    77
  Options are:
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    78
    -D DIR       target directory (default ".")
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    79
    -U URL       download URL
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    80
                 (default: """" + default_download_url + """")
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    81
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    82
  Build javamail component from the specified download URL (JAR).
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    83
""",
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    84
          "D:" -> (arg => target_dir = Path.explode(arg)),
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    85
          "U:" -> (arg => download_url = arg))
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    86
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    87
        val more_args = getopts(args)
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    88
        if (more_args.nonEmpty) getopts.usage()
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    89
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    90
        val progress = new Console_Progress()
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    91
78827
06f0e720b913 added component for javax mail;
Fabian Huch <huch@in.tum.de>
parents: 77619
diff changeset
    92
        build_javamail(download_url = download_url, progress = progress, target_dir = target_dir)
77619
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    93
      })
6d0985955872 discontinued apache-commons in favour of jsoup, which is smaller and more useful;
wenzelm
parents:
diff changeset
    94
}