# HG changeset patch # User wenzelm # Date 1626637576 -7200 # Node ID 6bf9f94198a77dbc0a7211863ac425bd85dc6be7 # Parent aa36845ad5ade22ad6cb4d09ddf03d61ef9817e5 updated documentation on Isabelle/Scala; diff -r aa36845ad5ad -r 6bf9f94198a7 lib/Tools/scala_build --- a/lib/Tools/scala_build Sun Jul 18 13:41:20 2021 +0200 +++ b/lib/Tools/scala_build Sun Jul 18 21:46:16 2021 +0200 @@ -17,6 +17,9 @@ echo " -f force fresh build" echo " -q quiet mode: suppress stdout/stderr" echo + echo " Build Isabelle/Scala/Java modules of all registered components" + echo " (if required)." + echo exit 1 } diff -r aa36845ad5ad -r 6bf9f94198a7 src/Doc/System/Scala.thy --- a/src/Doc/System/Scala.thy Sun Jul 18 13:41:20 2021 +0200 +++ b/src/Doc/System/Scala.thy Sun Jul 18 21:46:16 2021 +0200 @@ -31,30 +31,22 @@ operates on the running Java application, using the Scala read-eval-print-loop (REPL). - The main Isabelle/Scala functionality is provided by \<^verbatim>\isabelle.jar\, but - further add-ons are bundled with Isabelle, e.g.\ to access SQLite or - PostgreSQL using JDBC (Java Database Connectivity). - - Other components may augment the system environment by providing a suitable - \<^path>\etc/settings\ shell script in the component directory. Some shell - functions are available to help with that: - - \<^item> Function \<^bash_function>\classpath\ adds \<^verbatim>\jar\ files in Isabelle path - notation (POSIX). On Windows, this is converted to native path names - before invoking @{tool java} or @{tool scala} (\secref{sec:scala-tools}). + The main Isabelle/Scala/jEdit functionality is provided by + \<^file>\$ISABELLE_HOME/lib/classes/isabelle.jar\. Further underlying Scala and + Java libraries are bundled with Isabelle, e.g.\ to access SQLite or + PostgreSQL via JDBC. - \<^item> Function \<^bash_function>\isabelle_scala_service\ registers global - service providers as subclasses of - \<^scala_type>\isabelle.Isabelle_System.Service\, using the raw Java name - according to @{scala_method (in java.lang.Object) getClass} (it should be - enclosed in single quotes to avoid special characters like \<^verbatim>\$\ to be - interpreted by the shell). + Add-on Isabelle components may augment the system environment by providing + suitable configuration in \<^path>\etc/settings\ (GNU bash script). The + shell function \<^bash_function>\classpath\ helps to write + \<^path>\etc/settings\ in a portable manner: it refers to library \<^verbatim>\jar\ + files in standard POSIX path notation. On Windows, this is converted to + native platform format, before invoking Java (\secref{sec:scala-tools}). - Particular Isabelle/Scala services require particular subclasses: - instances are filtered according to their dynamic type. For example, class - \<^scala_type>\isabelle.Isabelle_Scala_Tools\ collects Scala command-line - tools, and class \<^scala_type>\isabelle.Scala.Functions\ - collects Scala functions (\secref{sec:scala-functions}). + \<^medskip> + There is also an implicit build process for Isabelle/Scala/Java modules, + based on \<^path>\etc/build.props\ within the component directory (see also + \secref{sec:scala-build}). \ @@ -103,25 +95,6 @@ \ -subsection \Scala compiler \label{sec:tool-scalac}\ - -text \ - The @{tool_def scalac} tool is a direct wrapper for the Scala compiler; see - also @{tool scala} above. The command line arguments are that of the - bundled Scala distribution. - - This allows to compile further Scala modules, depending on existing - Isabelle/Scala functionality. The resulting \<^verbatim>\class\ or \<^verbatim>\jar\ files can be - added to the Java classpath using the shell function - \<^bash_function>\classpath\. Thus add-on components can register themselves - in a modular manner, see also \secref{sec:components}. - - Note that Isabelle/jEdit @{cite "isabelle-jedit"} has its own mechanisms for - adding plugin components. This needs special attention, since it overrides - the standard Java class loader. -\ - - subsection \Scala script wrapper\ text \ @@ -143,11 +116,156 @@ \ -subsection \Project setup for common Scala IDEs\ +subsection \Scala compiler \label{sec:tool-scalac}\ + +text \ + The @{tool_def scalac} tool is a direct wrapper for the Scala compiler; see + also @{tool scala} above. The command line arguments are that of the + bundled Scala distribution. + + This provides a low-level mechanism to compile further Scala modules, + depending on existing Isabelle/Scala functionality; the resulting \<^verbatim>\class\ + or \<^verbatim>\jar\ files can be added to the Java classpath using the shell function + \<^bash_function>\classpath\. + + A more convenient high-level approach works via \<^path>\etc/build.props\ + (see \secref{sec:scala-build}). +\ + + +section \Isabelle/Scala/Java modules \label{sec:scala-build}\ + +subsection \Component configuration via \<^path>\etc/build.props\\ text \ - The @{tool_def scala_project} tool creates a project configuration for - Isabelle/Scala/jEdit: + Isabelle components may augment the Isabelle/Scala/Java environment + declaratively via properties given in \<^path>\etc/build.props\ (within the + component directory). This specifies an output \<^verbatim>\jar\ \<^emph>\module\, based on + Scala or Java \<^emph>\sources\, and arbitrary \<^emph>\resources\. Moreover, a module can + specify \<^emph>\services\ that are subclasses of + \<^scala_type>\isabelle.Isabelle_System.Service\; these have a particular + meaning to Isabelle/Scala tools. + + Before running a Scala or Java process, the Isabelle system implicitly + ensures that all provided modules are compiled and packaged (as jars). It is + also possible to invoke @{tool scala_build} explicitly, with extra options. + + \<^medskip> + The syntax of in \<^path>\etc/build.props\ follows a regular Java properties + file\<^footnote>\\<^url>\https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/Properties.html#load(java.io.Reader)\\, + but the encoding is \<^verbatim>\UTF-8\, instead of historic \<^verbatim>\ISO 8859-1\ from the API + documentation. + + The subsequent properties are relevant for the Scala/Java build process. + Most properties are optional: the default is an empty string (or list). File + names are relative to the main component directory and may refer to Isabelle + settings variables (e.g. \<^verbatim>\$ISABELLE_HOME\). + + \<^item> \<^verbatim>\title\ (required) is a human-readable description of the module, used + in printed messages. + + \<^item> \<^verbatim>\module\ specifies a \<^verbatim>\jar\ file name for the output module, as result + of compiling the specified sources (and resources). If this is absent, + there is no build process, but contributing sources may still be given, + possibly together with \<^verbatim>\no_module\ as described below. + + \<^item> \<^verbatim>\no_module\ means that there is no build process, but the specified + \<^verbatim>\jar\ is provided by other means. This is relevant for @{tool + scala_project} (\secref{sec:tool-scala-project}), which includes all + Scala/Java sources of components, but suppresses \<^verbatim>\jar\ modules to avoid + duplication of content. + + \<^item> \<^verbatim>\scalac_options\ and \<^verbatim>\javac_options\ augment the default settings + @{setting_ref ISABELLE_SCALAC_OPTIONS} and @{setting_ref + ISABELLE_JAVAC_OPTIONS} for this component; option syntax follows the + regular command-line tools \<^verbatim>\scalac\ and \<^verbatim>\javac\, respectively. + + \<^item> \<^verbatim>\main\ specifies the main entry point for the \<^verbatim>\jar\ module. This is + only relevant for direct invocation like ``\<^verbatim>\java -jar test.jar\''. + + \<^item> \<^verbatim>\requirements\ is a list of \<^verbatim>\jar\ modules that are needed in the + compilation process, but not provided by the regular classpath (notably + @{setting ISABELLE_CLASSPATH}). + + A \emph{normal entry} refers to a single \<^verbatim>\jar\ file name, possibly with + settings variables as usual. E.g. \<^file>\$ISABELLE_SCALA_JAR\ for the main + \<^file>\$ISABELLE_HOME/lib/classes/isabelle.jar\ (especially relevant for + add-on modules). + + A \emph{special entry} is of of the form \<^verbatim>\env:\\variable\ and refers to a + settings variable from the Isabelle environment: its value may consist of + multiple \<^verbatim>\jar\ entries (separated by colons). Environment variables are + not expanded recursively. + + \<^item> \<^verbatim>\resources\ is a list of files that should be included in the resulting + \<^verbatim>\jar\ file. Each item consists of a pair separated by colon: + \source\\<^verbatim>\:\\target\ means to copy an existing source file (relative to + the component directory) to the given target file or directory (relative + to the \<^verbatim>\jar\ name space). A \file\ specification without colon + abbreviates \file\\<^verbatim>\:\\file\, i.e. the file is copied while retaining its + relative path name. + + \<^item> \<^verbatim>\sources\ is a list of \<^verbatim>\.scala\ or \<^verbatim>\.java\ files that contribute to + the specified module. It is possible to use both languages simultaneously: + the Scala and Java compiler will be invoked consecutively to make this + work. + + \<^item> \<^verbatim>\services\ is a list of class names to be registered as Isabelle + service providers (subclasses of + \<^scala_type>\isabelle.Isabelle_System.Service\). Internal class names of + the underlying JVM need to be given: e.g. see method @{scala_method (in + java.lang.Object) getClass}. + + Particular services require particular subclasses: instances are filtered + according to their dynamic type. For example, class + \<^scala_type>\isabelle.Isabelle_Scala_Tools\ collects Scala command-line + tools, and class \<^scala_type>\isabelle.Scala.Functions\ collects Scala + functions (\secref{sec:scala-functions}). +\ + + +subsection \Explicit Isabelle/Scala/Java build \label{sec:tool-scala-build}\ + +text \ + The @{tool_def scala_build} tool explicitly invokes the build process for + all registered components. + @{verbatim [display] +\Usage: isabelle scala_build [OPTIONS] + + Options are: + -f force fresh build + -q quiet mode: suppress stdout/stderr + + Build Isabelle/Scala/Java modules of all registered components + (if required). +\} + + For each registered Isabelle component that provides + \<^path>\etc/build.props\, the specified output \<^verbatim>\module\ is checked against + the corresponding input \<^verbatim>\requirements\, \<^verbatim>\resources\, \<^verbatim>\sources\. If + required, there is an automatic build using \<^verbatim>\scalac\ or \<^verbatim>\javac\ (or both). + The identity of input files is recorded within the output \<^verbatim>\jar\, using SHA1 + digests in \<^verbatim>\META-INF/isabelle/shasum\. + + \<^medskip> + Option \<^verbatim>\-f\ forces a fresh build, regardless of the up-to-date status of + input files vs. the output module. + + \<^medskip> + Option \<^verbatim>\-q\ suppresses all output on stdout/stderr produced by the Scala or + Java compiler. + + \<^medskip> Explicit invocation of \<^verbatim>\isabelle scala_build\ mainly serves testing or + applications with special options: the Isabelle system normally does an + automatic the build on demand. +\ + + +subsection \Project setup for common Scala IDEs \label{sec:tool-scala-project}\ + +text \ + The @{tool_def scala_project} tool creates a project configuration for all + Isabelle/Scala/Java modules specified in components via \<^path>\etc/build.props\: @{verbatim [display] \Usage: isabelle scala_project [OPTIONS] PROJECT_DIR @@ -172,9 +290,9 @@ editing them within the IDE has no permanent effect. Option \<^verbatim>\-L\ produces \<^emph>\symlinks\ to the original files: this allows to - develop Isabelle/Scala/jEdit within an external Scala IDE. Note that - building the result always requires \<^verbatim>\isabelle jedit -b\ on the - command-line. + develop Isabelle/Scala/jEdit within an external Scala IDE. Note that the + result cannot be built within the IDE: it requires implicit or explicit + \<^verbatim>\isabelle scala_build\ (\secref{sec:tool-scala-build}). \ @@ -185,13 +303,10 @@ text \ A Scala functions of type \<^scala_type>\String => String\ may be wrapped as \<^scala_type>\isabelle.Scala.Fun\ and collected via an instance of the - class \<^scala_type>\isabelle.Scala.Functions\. A system component - can then register that class via \<^bash_function>\isabelle_scala_service\ - in \<^path>\etc/settings\ (\secref{sec:components}). An example is the - predefined collection of \<^scala_type>\isabelle.Scala.Functions\ in - \<^verbatim>\isabelle.jar\ with the following line in - \<^file>\$ISABELLE_HOME/etc/settings\: - @{verbatim [display, indent = 2] \isabelle_scala_service 'isabelle.Functions'\} + class \<^scala_type>\isabelle.Scala.Functions\. A system component can then + register that class via \<^verbatim>\services\ in \<^path>\etc/build.props\ + (\secref{sec:scala-build}). An example is the predefined collection of + \<^scala_type>\isabelle.Scala.Functions\ in \<^file>\$ISABELLE_HOME/etc/build.props\. The overall list of registered functions is accessible in Isabelle/Scala as \<^scala_object>\isabelle.Scala.functions\.