Skip to content

Commit 7469e26

Browse files
committed
start of install jdk code
1 parent faf8b3f commit 7469e26

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

py5-resources/py5-module/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ py5-utils = "py5_tools.tools.py5utils:main"
6666
run_sketch = "py5_tools.tools.run_sketch:main"
6767
py5-run-sketch = "py5_tools.tools.run_sketch:main"
6868
py5-live-coding = "py5_tools.tools.live_coding:main"
69+
py5-install-jdk = "py5_tools.tools.install_jdk:main"
6970

7071
[project.urls]
7172
"Bug Tracker" = "https://github.com/py5coding/py5generator/issues"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# *****************************************************************************
2+
#
3+
# Part of the py5 library
4+
# Copyright (C) 2020-2026 Jim Schmitz
5+
#
6+
# This library is free software: you can redistribute it and/or modify it
7+
# under the terms of the GNU Lesser General Public License as published by
8+
# the Free Software Foundation, either version 2.1 of the License, or (at
9+
# your option) any later version.
10+
#
11+
# This library is distributed in the hope that it will be useful, but
12+
# WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
14+
# General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with this library. If not, see <https://www.gnu.org/licenses/>.
18+
#
19+
# *****************************************************************************
20+
import argparse
21+
import sys
22+
23+
parser = argparse.ArgumentParser(description="Install Java Development Environment")
24+
parser.add_argument(
25+
"-j",
26+
"--java-version",
27+
action="store",
28+
dest="java_version",
29+
default=21,
30+
type=int,
31+
help="Java Version (must be 17 or greater, defaults to 21)",
32+
)
33+
34+
35+
def main():
36+
args = parser.parse_args()
37+
38+
try:
39+
import jdk
40+
except ImportError:
41+
print(
42+
"Please first install the python library `install-jdk` using the command `pip install install-jdk`",
43+
file=sys.stderr,
44+
)
45+
return
46+
47+
java_version = args.java_version
48+
49+
if java_version < 17:
50+
print(
51+
f"Java version must be 17 or greater, please specify a different version using the -j option"
52+
)
53+
return
54+
55+
try:
56+
print(f"Installing Java Development Environment version {java_version}...")
57+
print(f"Java installed to {jdk.install(java_version)}")
58+
except jdk.JdkError as e:
59+
print(f"Failed to install Java: {e}", file=sys.stderr)
60+
61+
62+
if __name__ == "__main__":
63+
main()

0 commit comments

Comments
 (0)