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