-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jar.py
67 lines (51 loc) · 1.75 KB
/
Jar.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
import sublime, sublime_plugin, subprocess, platform, urllib, os
class JarCommand(sublime_plugin.TextCommand):
def run(self, edit):
filename = self.view.file_name()
print filename
decompiled, errormessages = self.decompile(filename)
print errormessages
self.edit_window(edit, decompiled, filename)
def decompile(self, filename):
executable = self.get_jar_exec()
filepath, extension = os.path.splitext(filename)
print 'Detected extension:'
print extension
basename = os.path.basename(filepath)
dirname = os.path.dirname(filepath)
command = [executable, 'tfv', filename]
print 'Executing:'
print command
return self.exec_command(command)
def exec_command(self, command):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo)
out, err = p.communicate()
return (out, err)
def edit_window(self, edit, contents, filename):
view = self.view
view.erase(edit, sublime.Region(0, view.size()))
view.insert(edit, 0, contents)
view.set_scratch(1)
#view.set_syntax_file('Packages/Java/Java.tmLanguage')
def get_new_filename(self, filename):
return filename.replace("class", "java")
def get_jar_exec(self):
os_alias = platform.system().lower()
print os_alias
if 'windows' in os_alias:
return 'jar.exe'
elif 'linux' in os_alias:
return 'jar'
elif 'darwin' in os_alias:
return 'jar'
class OpenClassFileCommand(sublime_plugin.EventListener):
def on_load(self, view):
filename = view.file_name()
if filename is not None:
extension = os.path.splitext(filename)[1]
if extension == ".jar":
view.run_command("jar")
def on_activated(self, view):
self.on_load(view)