10
10
11
11
_logger = _logging .getLogger (__name__ )
12
12
13
+ # Constraints on the Java installation to be used.
14
+ _fetch_java : str = "auto"
15
+ _java_vendor : str = "zulu-jre"
16
+ _java_version : str = "11"
17
+ _maven_url : str = "tgz+https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz" # noqa: E501
18
+ _maven_sha : str = "a555254d6b53d267965a3404ecb14e53c3827c09c3b94b5678835887ab404556bfaf78dcfe03ba76fa2508649dca8531c74bca4d5846513522404d48e8c4ac8b" # noqa: E501
19
+
13
20
endpoints : list [str ] = []
14
21
15
22
_repositories = {"scijava.public" : _scijava_public ()}
@@ -35,6 +42,109 @@ class Mode(_enum.Enum):
35
42
mode = Mode .JPYPE
36
43
37
44
45
+ def set_java_constraints (
46
+ fetch : str | bool | None = None ,
47
+ vendor : str | None = None ,
48
+ version : str | None = None ,
49
+ maven_url : str | None = None ,
50
+ maven_sha : str | None = None ,
51
+ ) -> None :
52
+ """
53
+ Set constraints on the version of Java to be used.
54
+
55
+ :param fetch:
56
+ If "auto" (default), when a JVM/or maven cannot be located on the system,
57
+ [`cjdk`](https://github.com/cachedjdk/cjdk) will be used to download
58
+ a JDK/JRE distribution and set up the JVM.
59
+ If "always", cjdk will always be used; if "never", cjdk will never be used.
60
+ :param vendor:
61
+ The vendor of the JDK/JRE distribution for cjdk to download and cache.
62
+ Defaults to "zulu-jre". See the cjdk documentation for details.
63
+ :param version:
64
+ Expression defining the Java version for cjdk to download and cache.
65
+ Defaults to "11". See the cjdk documentation for details.
66
+ :param maven_url:
67
+ URL of the Maven distribution for cjdk to download and cache.
68
+ Defaults to the Maven 3.9.9 binary distribution from dlcdn.apache.org.
69
+ :param maven_sha:
70
+ The SHA512 (or SHA256 or SHA1) hash of the Maven distribution to download,
71
+ if providing a custom maven_url.
72
+ """
73
+ global _fetch_java , _java_vendor , _java_version , _maven_url , _maven_sha
74
+ if fetch is not None :
75
+ if isinstance (fetch , bool ):
76
+ # Be nice and allow boolean values as a convenience.
77
+ fetch = "always" if fetch else "never"
78
+ expected = ["auto" , "always" , "never" ]
79
+ if fetch not in expected :
80
+ raise ValueError (f"Fetch mode { fetch } is not one of { expected } " )
81
+ _fetch_java = fetch
82
+ if vendor is not None :
83
+ _java_vendor = vendor
84
+ if version is not None :
85
+ _java_version = version
86
+ if maven_url is not None :
87
+ _maven_url = maven_url
88
+ _maven_sha = ""
89
+ if maven_sha is not None :
90
+ _maven_sha = maven_sha
91
+
92
+
93
+ def get_fetch_java () -> str :
94
+ """
95
+ Get whether [`cjdk`](https://github.com/cachedjdk/cjdk)
96
+ will be used to download a JDK/JRE distribution and set up the JVM.
97
+ To set this value, see set_java_constraints.
98
+
99
+ :return:
100
+ "always" for cjdk to obtain the JDK/JRE;
101
+ "never" for cjdk *not* to obtain a JDK/JRE;
102
+ "auto" for cjdk to be used only when a JVM/or Maven is not on the system path.
103
+ """
104
+ return _fetch_java
105
+
106
+
107
+ def get_java_vendor () -> str :
108
+ """
109
+ Get the vendor of the JDK/JRE distribution to download.
110
+ Vendor of the Java installation for cjdk to download and cache.
111
+ To set this value, see set_java_constraints.
112
+
113
+ :return: String defining the desired JDK/JRE vendor for downloaded JDK/JREs.
114
+ """
115
+ return _java_vendor
116
+
117
+
118
+ def get_java_version () -> str :
119
+ """
120
+ Expression defining the Java version for cjdk to download and cache.
121
+ To set this value, see set_java_constraints.
122
+
123
+ :return: String defining the desired JDK/JRE version for downloaded JDK/JREs.
124
+ """
125
+ return _java_version
126
+
127
+
128
+ def get_maven_url () -> str :
129
+ """
130
+ The URL of the Maven distribution to download.
131
+ To set this value, see set_java_constraints.
132
+
133
+ :return: URL pointing to the Maven distribution.
134
+ """
135
+ return _maven_url
136
+
137
+
138
+ def get_maven_sha () -> str :
139
+ """
140
+ The SHA512 (or SHA256 or SHA1) hash of the Maven distribution to download,
141
+ if providing a custom maven_url. To set this value, see set_java_constraints.
142
+
143
+ :return: Hash value of the Maven distribution, or empty string to skip hash check.
144
+ """
145
+ return _maven_sha
146
+
147
+
38
148
def add_repositories (* args , ** kwargs ) -> None :
39
149
"""
40
150
Add one or more Maven repositories to be used by jgo for downloading dependencies.
0 commit comments