forked from aphex/SuperAnt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperAnt_exec.py
89 lines (68 loc) · 3.21 KB
/
SuperAnt_exec.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import sublime, sublime_plugin, sys,os
from xml.dom.minidom import parseString
DEFAULT_BUILD_CMD = "exec"
DEFAULT_BUILD_TASK = "build"
class SuperAntExecCommand(sublime_plugin.WindowCommand):
def run(self, **kwargs):
package_dir = os.path.join(sublime.packages_path(), "Super Ant");
self.working_dir = kwargs['working_dir'];
self.build = None;
s = sublime.load_settings("SuperAnt.sublime-settings");
build_file = s.get("build_file", "build.xml");
use_sorting = s.get("use_sorting", "true") == "true";
# buildfile by selection: search build file in project folder that file from active view is in
try:
active_file = self.window.active_view().file_name();
active_folder = os.path.dirname(active_file);
if os.path.exists(active_folder + os.sep + build_file):
self.build = active_folder + os.sep + build_file;
self.working_dir = active_folder
else:
raise Exception('not a build file');
except Exception as ex:
print 'No build file in base folder of currently viewed file';
# buildfile by default: build.xml found in first project folder
if self.build == None and os.path.exists(self.working_dir + os.sep + build_file):
self.build = self.working_dir + os.sep + build_file;
try:
f = open(self.build);
except Exception as ex:
print ex;
self.window.open_file(os.path.join(package_dir, 'SuperAnt.sublime-settings'));
return 'The file could not be opened';
self.working_dir = os.path.dirname(self.build);
data = f.read();
dom = parseString(data);
self.targets = dom.getElementsByTagName('target');
# get project name for target prefixing in quick panel
project_name = None;
try:
project_name = dom.firstChild.getAttributeNode('name').nodeValue;
except Exception, e:
# default to folder name if name attribute is not given in project tag
project_name = os.path.basename(self.working_dir);
self.targetsList = [];
list_prefix = project_name + ': ';
for target in self.targets:
targetName = target.getAttributeNode("name").nodeValue;
if targetName[0] != "_":
self.targetsList.append(list_prefix + targetName);
if use_sorting:
self.targetsList = sorted(self.targetsList);
def cleanName(n):
return n.replace(list_prefix, "");
self.targetLookup = map(cleanName, self.targetsList)
self.window.show_quick_panel(self.targetsList, self._quick_panel_callback);
def _quick_panel_callback(self, index):
if (index > -1):
targetName = self.targetLookup[index];
ant = "ant";
# Check for Windows Overrides and Merge
if sys.platform.startswith('win32'):
ant = "ant.bat";
cmd = {
'cmd': [ant, "-f", self.build, targetName],
'working_dir': self.working_dir
}
# run build
self.window.run_command("exec", cmd);