|
| 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