src/Tools/Setup/src/Build.java
author wenzelm
Wed, 22 Sep 2021 21:20:36 +0200
changeset 74355 f77474665b2f
parent 74061 203dfa8bc0fc
child 74738 cba1da393958
permissions -rw-r--r--
tuned message;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74031
09821ca262d3 clarified directories;
wenzelm
parents: 74030
diff changeset
     1
/*  Title:      Tools/Setup/src/Build.java
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
     3
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
     4
Build Isabelle/Scala/Java modules.
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
     5
*/
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
     6
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
     7
package isabelle.setup;
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
     8
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
     9
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
    10
import java.io.BufferedOutputStream;
74018
9d6c9a55f450 more informative errors: capture low-level compiler output;
wenzelm
parents: 73987
diff changeset
    11
import java.io.ByteArrayOutputStream;
9d6c9a55f450 more informative errors: capture low-level compiler output;
wenzelm
parents: 73987
diff changeset
    12
import java.io.CharArrayWriter;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    13
import java.io.File;
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    14
import java.io.IOException;
74018
9d6c9a55f450 more informative errors: capture low-level compiler output;
wenzelm
parents: 73987
diff changeset
    15
import java.io.PrintStream;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    16
import java.math.BigInteger;
73946
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
    17
import java.nio.charset.StandardCharsets;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    18
import java.nio.file.Files;
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    19
import java.nio.file.Path;
73918
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
    20
import java.nio.file.StandardCopyOption;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    21
import java.security.MessageDigest;
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    22
import java.security.NoSuchAlgorithmException;
73930
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
    23
import java.util.ArrayList;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    24
import java.util.Comparator;
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    25
import java.util.LinkedList;
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    26
import java.util.List;
73919
429c1ffb5a36 proper treatment of leading zero;
wenzelm
parents: 73918
diff changeset
    27
import java.util.Locale;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    28
import java.util.Properties;
73967
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
    29
import java.util.TreeMap;
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
    30
import java.util.jar.Attributes;
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
    31
import java.util.jar.JarEntry;
73946
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
    32
import java.util.jar.JarFile;
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
    33
import java.util.jar.JarOutputStream;
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
    34
import java.util.jar.Manifest;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    35
import java.util.stream.Stream;
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    36
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
    37
import javax.tools.JavaCompiler;
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
    38
import javax.tools.JavaFileObject;
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
    39
import javax.tools.StandardJavaFileManager;
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
    40
import javax.tools.ToolProvider;
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
    41
73930
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
    42
import scala.tools.nsc.MainClass;
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
    43
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    44
73944
3cee9d20308e clarified modules;
wenzelm
parents: 73931
diff changeset
    45
public class Build
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    46
{
73951
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    47
    /** context **/
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    48
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    49
    public static String BUILD_PROPS = "build.props";
73961
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    50
    public static String COMPONENT_BUILD_PROPS = "etc/build.props";
74059
55505e7bbfb3 clarified props: more permissive;
wenzelm
parents: 74058
diff changeset
    51
55505e7bbfb3 clarified props: more permissive;
wenzelm
parents: 74058
diff changeset
    52
    public static String TITLE = "title";
74057
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
    53
    public static String MODULE = "module";
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
    54
    public static String NO_BUILD = "no_build";
73951
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    55
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    56
    public static Context component_context(Path dir)
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    57
        throws IOException
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    58
    {
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    59
        Properties props = new Properties();
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
    60
        Path props_path = dir.resolve(COMPONENT_BUILD_PROPS);
74055
0ee44ed80290 clarified signature;
wenzelm
parents: 74031
diff changeset
    61
        props.load(Files.newBufferedReader(props_path));
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
    62
        return new Context(dir, props, props_path.toString());
73951
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    63
    }
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
    64
73961
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    65
    public static List<Context> component_contexts()
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    66
        throws IOException, InterruptedException
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    67
    {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    68
        List<Context> result = new LinkedList<Context>();
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    69
        for (String p : Environment.getenv("ISABELLE_COMPONENTS").split(":", -1)) {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    70
            if (!p.isEmpty()) {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    71
                Path dir = Path.of(Environment.platform_path(p));
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    72
                if (Files.exists(dir.resolve(COMPONENT_BUILD_PROPS))) {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    73
                    result.add(component_context(dir));
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    74
                }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    75
            }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    76
        }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    77
        return List.copyOf(result);
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    78
    }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
    79
73967
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
    80
    private static String sha_digest(MessageDigest sha, String name)
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
    81
    {
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
    82
        String digest = String.format(Locale.ROOT, "%040x", new BigInteger(1, sha.digest()));
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
    83
        return digest + " " + name + "\n";
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
    84
    }
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
    85
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    86
    public static class Context
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    87
    {
73951
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    88
        private final Path _dir;
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    89
        private final Properties _props;
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
    90
        private final String _location;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    91
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
    92
        public Context(Path dir, Properties props, String location)
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    93
        {
73951
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    94
            _dir = dir;
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    95
            _props = props;
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
    96
            _location = location;
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    97
        }
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
    98
73951
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
    99
        @Override public String toString() { return _dir.toString(); }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   100
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   101
        public String error_message(String msg)
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   102
        {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   103
            if (_location == null || _location.isEmpty()) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   104
                return msg;
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   105
            }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   106
            else {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   107
                return msg +" (in " + Library.quote(_location) + ")";
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   108
            }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   109
        }
73915
wenzelm
parents: 73914
diff changeset
   110
74057
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   111
        public boolean get_bool(String name) {
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   112
            String prop = _props.getProperty(name, "false");
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   113
            switch(prop) {
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   114
                case "true": return true;
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   115
                case "false": return false;
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   116
                default:
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   117
                    throw new RuntimeException(
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   118
                        error_message("Bad boolean property " + Library.quote(name) + ": " + Library.quote(prop)));
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   119
            }
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   120
        }
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   121
74059
55505e7bbfb3 clarified props: more permissive;
wenzelm
parents: 74058
diff changeset
   122
        public String title() { return _props.getProperty(TITLE, ""); }
74057
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   123
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   124
        public String module_name() { return _props.getProperty(MODULE, ""); }
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   125
        public String module_result() { return get_bool(NO_BUILD) ? "" : module_name(); }
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   126
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   127
        public String scalac_options() { return _props.getProperty("scalac_options", ""); }
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   128
        public String javac_options() { return _props.getProperty("javac_options", ""); }
73951
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
   129
        public String main() { return _props.getProperty("main", ""); }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   130
73931
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   131
        private List<String> get_list(String name)
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   132
        {
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   133
            List<String> list = new LinkedList<String>();
73951
f209845d3a5d clarified signature;
wenzelm
parents: 73950
diff changeset
   134
            for (String s : _props.getProperty(name, "").split("\\s+")) {
73931
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   135
                if (!s.isEmpty()) { list.add(s); }
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   136
            }
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   137
            return List.copyOf(list);
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   138
        }
73948
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   139
        public List<String> requirements() { return get_list("requirements"); }
73931
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   140
        public List<String> sources() { return get_list("sources"); }
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   141
        public List<String> resources() { return get_list("resources"); }
4a708e150908 more robust treatment of empty string;
wenzelm
parents: 73930
diff changeset
   142
        public List<String> services() { return get_list("services"); }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   143
73965
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   144
        public boolean is_vacuous()
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   145
        {
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   146
            return sources().isEmpty() && resources().isEmpty() && services().isEmpty();
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   147
        }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   148
73957
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   149
        public Path path(String file)
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   150
            throws IOException, InterruptedException
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   151
        {
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   152
            return _dir.resolve(Environment.expand_platform_path(file));
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   153
        }
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   154
        public boolean exists(String file)
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   155
            throws IOException, InterruptedException
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   156
        {
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   157
            return Files.exists(path(file));
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   158
        }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   159
74030
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   160
        public List<Path> requirement_paths(String s)
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   161
            throws IOException, InterruptedException
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   162
        {
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   163
            if (s.startsWith("env:")) {
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   164
                List<Path> paths = new LinkedList<Path>();
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   165
                for (String p : Environment.getenv(s.substring(4)).split(":", -1)) {
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   166
                    if (!p.isEmpty()) {
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   167
                        Path path = Path.of(Environment.platform_path(p));
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   168
                        paths.add(path);
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   169
                    }
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   170
                }
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   171
                return List.copyOf(paths);
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   172
            }
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   173
            else { return List.of(path(s)); }
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   174
        }
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   175
73921
1f31ed84c467 tuned signature;
wenzelm
parents: 73920
diff changeset
   176
        public String item_name(String s)
73918
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   177
        {
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   178
            int i = s.indexOf(':');
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   179
            return i > 0 ? s.substring(0, i) : s;
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   180
        }
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   181
73921
1f31ed84c467 tuned signature;
wenzelm
parents: 73920
diff changeset
   182
        public String item_target(String s)
73918
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   183
        {
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   184
            int i = s.indexOf(':');
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   185
            return i > 0 ? s.substring(i + 1) : s;
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   186
        }
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   187
73948
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   188
        public String shasum(String name, List<Path> paths)
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   189
            throws IOException, NoSuchAlgorithmException
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   190
        {
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   191
            MessageDigest sha = MessageDigest.getInstance("SHA");
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   192
            for (Path file : paths) {
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   193
                if (Files.exists(file)) {
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   194
                    sha.update(Files.readAllBytes(file));
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   195
                }
73966
472bdccfba62 even more strict shasum (amending c9771e1b3223);
wenzelm
parents: 73965
diff changeset
   196
                else {
472bdccfba62 even more strict shasum (amending c9771e1b3223);
wenzelm
parents: 73965
diff changeset
   197
                    throw new RuntimeException(
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   198
                        error_message("Missing input file " + Library.quote(file.toString())));
73966
472bdccfba62 even more strict shasum (amending c9771e1b3223);
wenzelm
parents: 73965
diff changeset
   199
                }
73948
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   200
            }
73967
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   201
            return sha_digest(sha, name);
73948
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   202
        }
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   203
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   204
        public String shasum(String file)
73957
110a027a5473 expand file paths, e.g. to allow $ISABELLE_HOME, $ISABELLE_HOME_USER;
wenzelm
parents: 73955
diff changeset
   205
            throws IOException, NoSuchAlgorithmException, InterruptedException
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   206
        {
73966
472bdccfba62 even more strict shasum (amending c9771e1b3223);
wenzelm
parents: 73965
diff changeset
   207
            return shasum(file, List.of(path(file)));
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   208
        }
73967
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   209
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   210
        public String shasum_props()
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   211
            throws NoSuchAlgorithmException
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   212
        {
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   213
            TreeMap<String,Object> sorted = new TreeMap<String,Object>();
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   214
            for (Object x : _props.entrySet()) {
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   215
                sorted.put(x.toString(), _props.get(x));
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   216
            }
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   217
            MessageDigest sha = MessageDigest.getInstance("SHA");
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   218
            sha.update(sorted.toString().getBytes(StandardCharsets.UTF_8));
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   219
            return sha_digest(sha, "<props>");
90652c0ef969 shasum for project meta-info;
wenzelm
parents: 73966
diff changeset
   220
        }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   221
    }
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   222
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   223
73930
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   224
    /** compile sources **/
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   225
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   226
    private static void add_options(List<String> options_list, String options)
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   227
    {
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   228
        if (options != null) {
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   229
            for (String s : options.split("\\s+")) {
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   230
                if (!s.isEmpty()) { options_list.add(s); }
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   231
            }
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   232
        }
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   233
    }
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   234
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   235
    public static void compile_scala_sources(
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   236
        PrintStream output,  // ignored, but see scala.Console.withOut/withErr
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   237
        Path target_dir,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   238
        String more_options,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   239
        List<Path> deps,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   240
        List<Path> sources) throws IOException, InterruptedException
73930
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   241
    {
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   242
        ArrayList<String> args = new ArrayList<String>();
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   243
        add_options(args, Environment.getenv("ISABELLE_SCALAC_OPTIONS"));
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   244
        add_options(args, more_options);
73930
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   245
        args.add("-d");
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   246
        args.add(target_dir.toString());
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   247
        args.add("-bootclasspath");
73960
027f837d18ee clarified signature;
wenzelm
parents: 73957
diff changeset
   248
        args.add(Environment.join_platform_paths(deps));
73930
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   249
        args.add("--");
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   250
73955
2b9ae1aa9257 skip scalac for Java build;
wenzelm
parents: 73954
diff changeset
   251
        boolean scala_sources = false;
2b9ae1aa9257 skip scalac for Java build;
wenzelm
parents: 73954
diff changeset
   252
        for (Path p : sources) {
2b9ae1aa9257 skip scalac for Java build;
wenzelm
parents: 73954
diff changeset
   253
            args.add(p.toString());
2b9ae1aa9257 skip scalac for Java build;
wenzelm
parents: 73954
diff changeset
   254
            if (p.toString().endsWith(".scala")) { scala_sources = true; }
2b9ae1aa9257 skip scalac for Java build;
wenzelm
parents: 73954
diff changeset
   255
        }
2b9ae1aa9257 skip scalac for Java build;
wenzelm
parents: 73954
diff changeset
   256
        if (scala_sources) {
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   257
            boolean ok = new MainClass().process(args.toArray(String[]::new));
74355
f77474665b2f tuned message;
wenzelm
parents: 74061
diff changeset
   258
            if (!ok) { throw new RuntimeException("Failed to compile Scala sources"); }
73955
2b9ae1aa9257 skip scalac for Java build;
wenzelm
parents: 73954
diff changeset
   259
        }
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   260
    }
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   261
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   262
    public static void compile_java_sources(
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   263
        PrintStream output,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   264
        Path target_dir,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   265
        String more_options,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   266
        List<Path> deps,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   267
        List<Path> sources) throws IOException, InterruptedException
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   268
    {
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   269
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   270
        StandardJavaFileManager file_manager =
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   271
            compiler.getStandardFileManager(null, Locale.ROOT, StandardCharsets.UTF_8);
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   272
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   273
        List<String> options = new LinkedList<String>();
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   274
        add_options(options, Environment.getenv("ISABELLE_JAVAC_OPTIONS"));
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   275
        add_options(options, more_options);
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   276
        options.add("-d");
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   277
        options.add(target_dir.toString());
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   278
        options.add("-classpath");
73960
027f837d18ee clarified signature;
wenzelm
parents: 73957
diff changeset
   279
        options.add(Environment.join_platform_paths(deps));
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   280
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   281
        List<JavaFileObject> java_sources = new LinkedList<JavaFileObject>();
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   282
        for (Path p : sources) {
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   283
            if (p.toString().endsWith(".java")) {
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   284
                for (JavaFileObject o : file_manager.getJavaFileObjectsFromPaths(List.of(p))) {
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   285
                    java_sources.add(o);
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   286
                }
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   287
            }
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   288
        }
74018
9d6c9a55f450 more informative errors: capture low-level compiler output;
wenzelm
parents: 73987
diff changeset
   289
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   290
        if (!java_sources.isEmpty()) {
74018
9d6c9a55f450 more informative errors: capture low-level compiler output;
wenzelm
parents: 73987
diff changeset
   291
            CharArrayWriter out = new CharArrayWriter();
9d6c9a55f450 more informative errors: capture low-level compiler output;
wenzelm
parents: 73987
diff changeset
   292
            boolean ok = compiler.getTask(out, file_manager, null, options, null, java_sources).call();
74025
d609fa3e816d more robust;
wenzelm
parents: 74022
diff changeset
   293
            out.flush();
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   294
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   295
            String msg = Library.trim_line(out.toString());
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   296
            if (ok) { if (!msg.isEmpty()) { output.print(msg + "\n"); } }
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   297
            else {
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   298
                throw new RuntimeException(
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   299
                    (msg.isEmpty() ? "" : msg + "\n") + "Failed to compile Java sources");
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   300
            }
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   301
        }
73930
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   302
    }
17c09d1b3588 invoke Scala compiler from Java, without external process;
wenzelm
parents: 73922
diff changeset
   303
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   304
73946
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   305
    /** shasum for jar content **/
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   306
73965
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   307
    private static String SHASUM = "META-INF/isabelle/shasum";
73946
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   308
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   309
    public static String get_shasum(Path jar_path)
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   310
    {
74058
4b15a1e25537 more robust;
wenzelm
parents: 74057
diff changeset
   311
        try {
73946
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   312
            try (JarFile jar_file = new JarFile(jar_path.toFile()))
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   313
            {
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   314
                JarEntry entry = jar_file.getJarEntry(SHASUM);
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   315
                if (entry != null) {
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   316
                    byte[] bytes = jar_file.getInputStream(entry).readAllBytes();
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   317
                    return new String(bytes, StandardCharsets.UTF_8);
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   318
                }
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   319
                else { return ""; }
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   320
            }
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   321
        }
74058
4b15a1e25537 more robust;
wenzelm
parents: 74057
diff changeset
   322
        catch (IOException exn) { return ""; }
73946
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   323
    }
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   324
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   325
    public static void create_shasum(Path dir, String shasum)
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   326
        throws IOException
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   327
    {
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   328
        Path path = dir.resolve(SHASUM);
73948
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   329
        Files.createDirectories(path.getParent());
73946
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   330
        Files.writeString(path, shasum);
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   331
    }
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   332
4d4c806cb7c8 clarified shasum: sources / resources within jar;
wenzelm
parents: 73944
diff changeset
   333
73965
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   334
    /** services **/
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   335
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   336
    private static String SERVICES = "META-INF/isabelle/services";
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   337
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   338
    public static List<String> get_services(Path jar_path)
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   339
        throws IOException
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   340
    {
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   341
        if (Files.exists(jar_path)) {
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   342
            try (JarFile jar_file = new JarFile(jar_path.toFile()))
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   343
            {
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   344
                JarEntry entry = jar_file.getJarEntry(SERVICES);
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   345
                if (entry != null) {
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   346
                    byte[] bytes = jar_file.getInputStream(entry).readAllBytes();
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   347
                    return Library.split_lines(new String(bytes, StandardCharsets.UTF_8));
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   348
                }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   349
                else { return List.of(); }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   350
            }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   351
        }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   352
        else { return List.of(); }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   353
    }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   354
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   355
    public static void create_services(Path dir, List<String> services)
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   356
        throws IOException
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   357
    {
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   358
        if (!services.isEmpty()) {
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   359
            Path path = dir.resolve(SERVICES);
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   360
            Files.createDirectories(path.getParent());
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   361
            Files.writeString(path, Library.cat_lines(services));
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   362
        }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   363
    }
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   364
f6862d5f4e7f clarified Isabelle meta-info within jar;
wenzelm
parents: 73964
diff changeset
   365
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   366
    /** create jar **/
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   367
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   368
    public static void create_jar(Path dir, String main, Path jar)
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   369
        throws IOException
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   370
    {
73949
714c267bb6fa more robust;
wenzelm
parents: 73948
diff changeset
   371
        Files.createDirectories(dir.resolve(jar).getParent());
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   372
        Files.deleteIfExists(jar);
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   373
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   374
        Manifest manifest = new Manifest();
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   375
        Attributes attributes = manifest.getMainAttributes();
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   376
        attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   377
        attributes.put(new Attributes.Name("Created-By"),
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   378
            System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")");
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   379
        if (!main.isEmpty()) { attributes.put(Attributes.Name.MAIN_CLASS, main); }
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   380
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   381
        try (JarOutputStream out =
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   382
            new JarOutputStream(new BufferedOutputStream(Files.newOutputStream(jar)), manifest))
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   383
        {
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   384
            for (Path path : Files.walk(dir).sorted().toArray(Path[]::new)) {
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   385
                boolean is_dir = Files.isDirectory(path);
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   386
                boolean is_file = Files.isRegularFile(path);
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   387
                if (is_dir || is_file) {
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   388
                    String name = Environment.slashes(dir.relativize(path).toString());
73950
cc49da3003aa more robust;
wenzelm
parents: 73949
diff changeset
   389
                    if (!name.isEmpty()) {
cc49da3003aa more robust;
wenzelm
parents: 73949
diff changeset
   390
                        JarEntry entry = new JarEntry(is_dir ? name + "/" : name);
cc49da3003aa more robust;
wenzelm
parents: 73949
diff changeset
   391
                        entry.setTime(path.toFile().lastModified());
cc49da3003aa more robust;
wenzelm
parents: 73949
diff changeset
   392
                        out.putNextEntry(entry);
cc49da3003aa more robust;
wenzelm
parents: 73949
diff changeset
   393
                        if (is_file) { out.write(Files.readAllBytes(path)); }
cc49da3003aa more robust;
wenzelm
parents: 73949
diff changeset
   394
                        out.closeEntry();
cc49da3003aa more robust;
wenzelm
parents: 73949
diff changeset
   395
                    }
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   396
                }
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   397
            }
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   398
        }
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   399
    }
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   400
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   401
73961
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   402
    /** classpath **/
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   403
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   404
    public static List<Path> classpath()
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   405
        throws IOException, InterruptedException
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   406
    {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   407
        List<Path> result = new LinkedList<Path>();
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   408
        for (Context context : component_contexts()) {
74057
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   409
            String module = context.module_result();
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   410
            if (!module.isEmpty()) { result.add(context.path(module)); }
73961
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   411
        }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   412
        return List.copyOf(result);
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   413
    }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   414
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   415
    public static List<String> services()
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   416
        throws IOException, InterruptedException
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   417
    {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   418
        List<String> result = new LinkedList<String>();
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   419
        for (Context context : component_contexts()) {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   420
            for (String s : context.services()) {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   421
                result.add(s);
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   422
            }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   423
        }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   424
        return List.copyOf(result);
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   425
    }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   426
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   427
73954
a3a64aab815a support mixed Scala/Java build;
wenzelm
parents: 73952
diff changeset
   428
    /** build **/
73922
3556303bd385 create jar in pure Java;
wenzelm
parents: 73921
diff changeset
   429
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   430
    public static void build(PrintStream output, Context context, boolean fresh)
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   431
        throws IOException, InterruptedException, NoSuchAlgorithmException
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   432
    {
74057
22ad3ac2152c clarified properties: "module" and "no_build";
wenzelm
parents: 74055
diff changeset
   433
        String module = context.module_result();
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   434
        if (!module.isEmpty()) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   435
            String title = context.title();
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   436
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   437
            Path jar_path = context.path(module);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   438
            String jar_name = jar_path.toString();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   439
            if (!jar_name.endsWith(".jar")) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   440
                throw new RuntimeException(
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   441
                    context.error_message("Bad jar module " + Library.quote(jar_name)));
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   442
            }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   443
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   444
            if (context.is_vacuous()) { Files.deleteIfExists(jar_path); }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   445
            else {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   446
                List<String> requirements = context.requirements();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   447
                List<String> resources = context.resources();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   448
                List<String> sources = context.sources();
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   449
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   450
                String shasum_old = get_shasum(jar_path);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   451
                String shasum;
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   452
                List<Path> compiler_deps = new LinkedList<Path>();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   453
                {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   454
                    StringBuilder _shasum = new StringBuilder();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   455
                    _shasum.append(context.shasum_props());
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   456
                    for (String s : requirements) {
74030
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   457
                        List<Path> paths = context.requirement_paths(s);
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   458
                        compiler_deps.addAll(paths);
39e05601faeb more accurate scala_project, based on build.props of components;
wenzelm
parents: 74029
diff changeset
   459
                        _shasum.append(context.shasum(s, paths));
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   460
                    }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   461
                    for (String s : resources) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   462
                        _shasum.append(context.shasum(context.item_name(s)));
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   463
                    }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   464
                    for (String s : sources) { _shasum.append(context.shasum(s)); }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   465
                    shasum = _shasum.toString();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   466
                }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   467
                if (fresh || !shasum_old.equals(shasum)) {
74059
55505e7bbfb3 clarified props: more permissive;
wenzelm
parents: 74058
diff changeset
   468
                    if (!title.isEmpty()) {
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   469
                        output.print("### Building " + title + " (" + jar_path + ") ...\n");
74059
55505e7bbfb3 clarified props: more permissive;
wenzelm
parents: 74058
diff changeset
   470
                    }
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   471
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   472
                    String isabelle_classpath = Environment.getenv("ISABELLE_CLASSPATH");
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   473
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   474
                    Path build_dir = Files.createTempDirectory("isabelle");
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   475
                    try {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   476
                        /* compile sources */
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   477
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   478
                        for (String s : isabelle_classpath.split(":", -1)) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   479
                            if (!s.isEmpty()) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   480
                              compiler_deps.add(Path.of(Environment.platform_path(s)));
73948
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   481
                            }
731ab64bae97 more compiler_deps via "requirements", notably jar list from settings;
wenzelm
parents: 73946
diff changeset
   482
                        }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   483
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   484
                        List<Path> compiler_sources = new LinkedList<Path>();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   485
                        for (String s : sources) { compiler_sources.add(context.path(s)); }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   486
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   487
                        compile_scala_sources(output, build_dir,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   488
                            context.scalac_options(), compiler_deps, compiler_sources);
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   489
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   490
                        compiler_deps.add(build_dir);
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   491
                        compile_java_sources(output, build_dir,
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   492
                            context.javac_options(), compiler_deps, compiler_sources);
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   493
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   494
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   495
                        /* copy resources */
73918
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   496
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   497
                        for (String s : context.resources()) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   498
                            String name = context.item_name(s);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   499
                            String target = context.item_target(s);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   500
                            Path file_name = Path.of(name).normalize().getFileName();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   501
                            Path target_path = Path.of(target).normalize();
73918
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   502
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   503
                            Path target_dir;
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   504
                            Path target_file;
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   505
                            {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   506
                                if (target.endsWith("/") || target.endsWith("/.")) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   507
                                    target_dir = build_dir.resolve(target_path);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   508
                                    target_file = target_dir.resolve(file_name);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   509
                                }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   510
                                else {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   511
                                    target_file = build_dir.resolve(target_path);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   512
                                    target_dir = target_file.getParent();
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   513
                                }
73918
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   514
                            }
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   515
                            Files.createDirectories(target_dir);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   516
                            Files.copy(context.path(name), target_file,
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   517
                                StandardCopyOption.COPY_ATTRIBUTES);
73918
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   518
                        }
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   519
07781cae0f71 support for jar resources;
wenzelm
parents: 73917
diff changeset
   520
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   521
                        /* packaging */
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   522
74029
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   523
                        create_shasum(build_dir, shasum);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   524
                        create_services(build_dir, context.services());
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   525
                        create_jar(build_dir, context.main(), jar_path);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   526
                    }
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   527
                    finally {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   528
                        try (Stream<Path> walk = Files.walk(build_dir)) {
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   529
                            walk.sorted(Comparator.reverseOrder())
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   530
                                .map(Path::toFile)
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   531
                                .forEach(File::delete);
0701ff55780d clarified build_props: empty module means no build;
wenzelm
parents: 74028
diff changeset
   532
                        }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   533
                    }
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   534
                }
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   535
            }
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   536
        }
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   537
    }
73961
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   538
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   539
    public static void build_components(PrintStream output, boolean fresh)
73961
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   540
        throws IOException, InterruptedException, NoSuchAlgorithmException
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   541
    {
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   542
        for (Context context : component_contexts()) {
74061
203dfa8bc0fc clarified compiler output: allow multithreaded execution;
wenzelm
parents: 74059
diff changeset
   543
            build(output, context, fresh);
73961
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   544
        }
f090787bb4c4 operations for all components;
wenzelm
parents: 73960
diff changeset
   545
    }
73914
4be1047576e6 support for Isabelle/Scala in pure Java;
wenzelm
parents:
diff changeset
   546
}