-
Notifications
You must be signed in to change notification settings - Fork 0
/
javagen.py
75 lines (69 loc) · 2.02 KB
/
javagen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import platform
import os
os.chdir("build")
is_jdk = 0
download = 0
filesnum = 0
chk_filesnum = 0
def start():
print("you need jdk added in the path to continue")
print("you can get jdk in https://www.oracle.com/java/technologies/downloads/#java17")
print("java 17 is recommended")
print("if you want the script will install jdk 17 for you")
os.system("pause")
def check_jdk():
global is_jdk
global download
global filesnum
global chk_filesnum
os.chdir("C:\\Program Files")
for chk in os.listdir():
filesnum = filesnum + 1
for e in os.listdir():
chk_filesnum = chk_filesnum + 1
if e == "Java":
os.chdir("Java")
for l in e:
if os.name == "nt" and e == "r":
is_jdk = False
break
elif os.name == "posix" and e == "r":
is_jdk = False
break
else:
print("you have jdk, you good!")
is_jdk = True
break
elif chk_filesnum == filesnum:
is_jdk = False
break
else:
break
if is_jdk == False:
while True:
yn = input("you want to download jdk 17? y/n")
if yn == "y" or yn == "Y":
download = True
break
elif yn == "n" or yn == "N":
download = False
break
if download == True:
if os.name == "nt" and int(platform.version()) >= 10:
os.system("curl -L https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.msi -o jdksetup.msi")
os.system("jdksetup.msi")
elif os.name == "posix" and platform.system() == "Darwin":
os.system("curl -L https://download.oracle.com/java/17/latest/jdk-17_macos-x64_bin.dmg -o jdksetup.dmg")
def generate_file(fn, inmain):
open(f"{fn}.java", "w").write(
f'class {fn} ' + '{\n public static void main(String[] args) {' + f'\n {inmain};' + '\n }\n}'
)
return fn
def compile(fn):
os.system(f"javac {fn}.java")
open("MANIFEST.MF", "w").write(f"Manifest-Version: 1.0\nMain-Class: {fn}\n\n")
os.chdir("output")
os.system(f"jar -cmvf ../MANIFEST.MF {fn}.jar ../{fn}.class")
return fn
def run_jar(fn):
os.system(f"java -jar {fn}.jar")