This repository has been archived by the owner on Apr 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mvn-push.py
executable file
·141 lines (119 loc) · 3.27 KB
/
mvn-push.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
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import getopt
from os.path import realpath
from os.path import join
from os.path import basename
import subprocess
help_message = \
'mvn-push.py --group package --id package --version version --file file [--javadoc file|path] [--sources file]'
mvn_repo = os.getcwd()
cleanup = ''
def subprocess_cmd(command):
process = subprocess.Popen(command, stdout=subprocess.PIPE,
shell=True)
proc_stdout = process.communicate()[0].strip()
if proc_stdout:
print proc_stdout
def check_required(arg_value_name_pairs):
for pair in arg_value_name_pairs:
if not pair[0]:
print pair[1], 'is empty or invalid'
sys.exit(1)
def detect_packaging(file_path):
file_extension = file_path[-4:]
if file_extension == '.aar':
return 'aar'
elif file_extension == '.jar':
return 'jar'
else:
print 'wrong file extension'
sys.exit(1)
def pack_javadoc(file_path, javadoc):
if not javadoc:
return javadoc
else:
global cleanup
temp_jar = basename('%s-javadoc.jar' % file_path[:-4])
subprocess_cmd('cd {0}; jar cf {1} *'.format(javadoc, temp_jar))
cleanup = cleanup + ' ' + join(javadoc, temp_jar)
return join(javadoc, temp_jar)
def deploy(
group_id,
artifact_id,
version,
file_path,
javadoc,
sources,
packaging,
):
mvn_deploy = \
'mvn deploy:deploy-file -Durl=file://{0} -DgroupId={1} -DartifactId={2} -Dversion={3} -Dpackaging={4} -Dfile={5}'.format(
mvn_repo,
group_id,
artifact_id,
version,
packaging,
file_path,
)
if sources:
mvn_deploy += ' -Dsources=%s' % sources
if javadoc:
mvn_deploy += ' -Djavadoc=%s' % javadoc
subprocess_cmd(mvn_deploy)
def main(argv):
group_id = ''
artifact_id = ''
version = ''
file_path = ''
javadoc = ''
sources = ''
try:
(opts, args) = getopt.getopt(argv, 'h:', [
'group=',
'id=',
'version=',
'file=',
'javadoc=',
'sources=',
])
except getopt.GetoptError:
print help_message
sys.exit(1)
if len(opts) == 0:
print help_message
sys.exit(1)
for (opt, arg) in opts:
if opt == '-h':
print help_message
sys.exit()
elif opt == '--group':
group_id = arg
elif opt == '--id':
artifact_id = arg
elif opt == '--version':
version = arg
elif opt == '--file':
file_path = realpath(arg)
elif opt == '--javadoc':
javadoc = realpath(arg)
elif opt == '--sources':
sources = realpath(arg)
check_required(((group_id, 'group'), (artifact_id, 'id'), (version,
'version'), (file_path, 'file')))
packaging = detect_packaging(file_path)
javadoc = pack_javadoc(file_path, javadoc)
deploy(
group_id,
artifact_id,
version,
file_path,
javadoc,
sources,
packaging,
)
subprocess_cmd('rm %s' % cleanup)
if __name__ == '__main__':
main(sys.argv[1:])