Last active
June 18, 2024 12:10
-
-
Save iTrooz/3dbb8b3f3cb87f67bac8b8a17438d811 to your computer and use it in GitHub Desktop.
Simple script to map java versions and java bytecode versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
RESET='\033[0m' | |
COLOR='\033[0;36m' # Cyan | |
# List from https://javaalmanac.io/bytecode/versions/ | |
JAVA_TO_BYTECODE = { | |
1.0: 45.0, | |
1.1: 45.3, | |
1.2: 46.0, | |
1.3: 47.0, | |
1.4: 48.0, | |
5: 49.0, | |
6: 50.0, | |
7: 51.0, | |
8: 52.0, | |
9: 53.0, | |
10: 54.0, | |
11: 55.0, | |
12: 56.0, | |
13: 57.0, | |
14: 58.0, | |
15: 59.0, | |
16: 60.0, | |
17: 61.0, | |
18: 62.0, | |
19: 63.0, | |
20: 64.0, | |
21: 65.0, | |
22: 66.0, | |
23: 67.0, | |
24: 68.0 | |
} | |
BYTECODE_TO_JAVA = {v: k for k, v in JAVA_TO_BYTECODE.items()} | |
import sys | |
if len(sys.argv) == 1: | |
for version in JAVA_TO_BYTECODE: | |
print(f"{RESET}Java {COLOR}{version}{RESET}: bytecode version {COLOR}{JAVA_TO_BYTECODE[version]}") | |
else: | |
try: | |
arg = float(sys.argv[1]) | |
except ValueError: | |
print(f"{RESET}Invalid number {COLOR}{sys.argv[1]}") | |
exit(1) | |
if arg in JAVA_TO_BYTECODE: | |
print(f"{RESET}Java {COLOR}{arg}{RESET} bytecode version: {COLOR}{JAVA_TO_BYTECODE[arg]}") | |
else: | |
if arg in BYTECODE_TO_JAVA: | |
print(f"{RESET}Java {COLOR}{BYTECODE_TO_JAVA[arg]}{RESET} bytecode version: {COLOR}{arg}") | |
else: | |
print(f"{RESET}Java version or bytecode version {COLOR}{sys.argv[1]}{RESET} not found") | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment