-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlauncher
executable file
·96 lines (82 loc) · 2.74 KB
/
launcher
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python
import copy
import os
import plistlib
import shlex
import string
import subprocess
import sys
import Tkinter
import tkMessageBox
def show_error(message):
window = Tkinter.Tk()
window.wm_withdraw()
tkMessageBox.showerror(title="Error", message=message, icon=tkMessageBox.ERROR)
def get_java_home(ver=None):
cmd = ["/usr/libexec/java_home"]
if ver is not None:
cmd.extend(["-v", ver])
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
s = p.communicate()
if 0 != p.returncode:
raise OSError("Requested version of java was not found")
return s[0].splitlines()[0]
def get_java_options(plist_root):
for key in ["Java", "JVMOptions"]:
plist_java = plist_root.get(key, None)
if plist_java is not None:
return plist_java
raise OSError("Not a java application")
def get_java_properties(plist_props):
props = []
for key in plist_props:
value = os.path.expandvars(plist_props[key])
props.append("-D%s=%s" % (key, value))
return props
def expand_path(path):
return os.path.expandvars(path)
def launch():
java_env = copy.copy(os.environ)
package_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
contents_dir = os.path.join(package_dir, "Contents")
resources_dir = os.path.join(contents_dir, "Resources")
bin_dir = os.path.join(package_dir, "bin")
os.environ["APP_PACKAGE"] = package_dir
plist_root = plistlib.readPlist(os.path.join(contents_dir, "Info.plist.original"))
plist_name = plist_root["CFBundleName"]
plist_icon = plist_root["CFBundleIconFile"]
plist_java = get_java_options(plist_root)
plist_ver = plist_java["JVMVersion"]
plist_classpath = plist_java["ClassPath"]
plist_workingdir = plist_java["WorkingDirectory"]
plist_vmoptions = plist_java["VMOptions"]
plist_properties = plist_java["Properties"]
plist_mainclass = plist_java["MainClass"]
java_home = get_java_home(plist_ver)
java_name = plist_name
java_icon = os.path.join(resources_dir, plist_icon)
java_classpath = expand_path(plist_classpath) + ":" + os.path.join(java_home, "lib/*")
java_workingdir = expand_path(plist_workingdir)
java_vmoptions = shlex.split(plist_vmoptions)
java_properties = get_java_properties(plist_properties)
java_mainclass = plist_mainclass
java = os.path.join(java_home, "bin/java")
java_env["JAVA_HOME"] = java_home
java_args = [java]
java_args.append("-Xdock:name=" + java_name)
java_args.append("-Xdock:icon=" + java_icon)
java_args.extend(java_vmoptions)
java_args.extend(java_properties)
java_args.extend(["-classpath", java_classpath])
java_args.append(java_mainclass)
os.chdir(java_workingdir)
os.execve(java, java_args, java_env)
# must not get here
def main(argv):
try:
return launch()
except Exception, e:
show_error(str(e))
return 1
if __name__ == "__main__":
sys.exit(main(sys.argv))