-
Notifications
You must be signed in to change notification settings - Fork 10
/
commands.py
129 lines (109 loc) · 4.09 KB
/
commands.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Here you can create play commands that are specific to the module, and extend existing commands
import os, inspect, shutil
import getopt
import sys
import subprocess
MODULE = 'maven'
# Commands that are specific to your module
COMMANDS = ['new','mvn:init','mvn:install','mvn:update','mvn:up','mvn:refresh','mvn:re','mvn:sources','mvn:src','mvn:play-dependency-sources','mvn:play-src']
HELP = {
'update': "Updates libraries in the /lib folder",
'refresh': "Deletes all *.jar and *.zip in /lib folder and updates libraries in the /lib folder",
}
##################################################
### execute
##################################################
def execute(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")
# Definition of Module path
module_dir = inspect.getfile(inspect.currentframe()).replace("commands.py","")
kargs["module_dir"]=module_dir
# Definition of Application path
kargs["app_path"]=app.path
if command == "mvn:install":
callInstall(kargs)
if command == 'new' or command == "mvn:init":
callInit(kargs)
if command == 'mvn:update' or command == 'mvn:up':
checkPomXML(app.path)
callUpdate(kargs)
if command == 'mvn:refresh' or command == 'mvn:re':
checkPomXML(app.path)
callRefresh(kargs)
if command == 'mvn:sources' or command == 'mvn:src':
checkPomXML(app.path)
callSources(kargs)
if command == 'mvn:play-dependency-sources' or command == 'mvn:play-src':
checkPomXML(app.path)
callPlaySources(kargs)
##################################################
### mvn:install
##################################################
def callInstall(args):
module_dir = args.get("module_dir")
save_cwd = os.getcwd()
print "~ Installing parent pom ..."
print "~ "
os.chdir(os.path.join(module_dir, 'resources/play-parent'))
os.system('mvn clean install')
os.chdir(save_cwd)
##################################################
### mvn:init OR new
##################################################
def callInit(args):
module_dir = args.get("module_dir")
app_path=args.get("app_path")
print "~ Executing mvn:init"
print "~ "
callInstall(args)
if os.path.exists('pom.xml'):
print "~ "
print "~ Existing pom.xml will be backed up to pom.xml.bak"
print "~ "
shutil.copyfile('pom.xml', 'pom.xml.bak')
print "~ "
print "~ Copying pom.xml from module to project ..."
print "~ "
shutil.copyfile(os.path.join(module_dir,'resources/pom.xml'), os.path.join(app_path, 'pom.xml'))
##################################################
### mvn:update OR mvn:up
##################################################
def callUpdate(args):
print "~"
print "~ Retrieving dependencies..."
print "~"
os.system('mvn dependency:copy-dependencies')
# callSources(args)
##################################################
### mvn:refresh OR mvn:re
##################################################
def callRefresh(args):
print "~"
print "~ Refresh dependencies..."
print "~"
os.system('mvn clean')
callUpdate(args)
##################################################
### mvn:sources OR mvn:src
##################################################
def callSources(args):
print "~"
print "~ Retrieving dependencies sources..."
print "~"
os.system('mvn dependency:copy-dependencies -Dclassifier=sources')
##################################################
### mvn:play-dependency-sources OR mvn:play-src
##################################################
def callPlaySources(args):
print "~"
print "~ Retrieving Play's dependencies sources ..."
print "~"
os.system('mvn dependency:copy-dependencies -Pplay-src')
def checkPomXML(path):
if not os.path.exists('pom.xml'):
print "~ ERROR : pom.xml does not exist in your project."
print "~ You can initialize a pom.xml with the command play mvn:init."
sys.exit(-1)