This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvn-release.py
executable file
·149 lines (128 loc) · 4.4 KB
/
mvn-release.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
142
143
144
145
146
147
148
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import argparse
import subprocess
import configparser
MAVENSARLIO_URL = os.environ.get("MAVENSARLIO_URL", None)
UPDATESSARLIO_URL = os.environ.get("UPDATESSARLIO_URL", None)
MAVENSARLIO_USER = os.environ.get("MAVENSARLIO_USER", None)
DEPENDENCIESSARLIO_URL = os.environ.get("DEPENDENCIESSARLIO_URL", None)
##########################################"
##
def read_user_configuration():
global MAVENSARLIO_URL
global UPDATESSARLIO_URL
global MAVENSARLIO_USER
global DEPENDENCIESSARLIO_URL
sarlrc_file = os.path.join(os.environ['HOME'], '.sarlrc')
if os.path.exists(sarlrc_file):
config = configparser.SafeConfigParser()
config.read(sarlrc_file)
MAVENSARLIO_URL = config.get('servers', 'MAVENSARLIO_URL')
UPDATESSARLIO_URL = config.get('servers', 'UPDATESSARLIO_URL')
MAVENSARLIO_USER = config.get('servers', 'MAVENSARLIO_USER')
DEPENDENCIESSARLIO_URL = config.get('servers', 'DEPENDENCIESSARLIO_URL')
##############################
##
def ask_pass():
pass_phrase = subprocess.check_output(['ssh-askpass', 'Please enter your passphrase for connection to the server:'])
if pass_phrase:
pass_phrase = pass_phrase.decode("utf-8")
pass_phrase = str(pass_phrase).strip()
if pass_phrase:
return pass_phrase
return None
##############################
##
def check_configuration():
global MAVENSARLIO_URL
global UPDATESSARLIO_URL
global MAVENSARLIO_USER
global DEPENDENCIESSARLIO_URL
if not MAVENSARLIO_URL:
raise Exception("You must define the MAVENSARLIO_URL environment variable to the URL of the Maven upload server , e.g. dav:https://myhost/dav")
if not UPDATESSARLIO_URL:
raise Exception("You must define the UPDATESSARLIO_URL environment variable to the URL of the P2 upload server , e.g. dav:https://myhost/dav")
if not MAVENSARLIO_USER:
raise Exception("You must define the MAVENSARLIO_USER environment variable with the login to the upload servers.")
if not DEPENDENCIESSARLIO_URL:
raise Exception("You must define the DEPENDENCIESSARLIO_URL environment variable with the login to the upload servers.")
##############################
## pass_phrase: password
def print_configuration(pass_phrase):
global MAVENSARLIO_URL
global UPDATESSARLIO_URL
global MAVENSARLIO_USER
global DEPENDENCIESSARLIO_URL
print("MAVENSARLIO_URL = " + str(MAVENSARLIO_URL))
print("UPDATESSARLIO_URL = " + str(UPDATESSARLIO_URL))
print("DEPENDENCIESSARLIO_URL = " + str(DEPENDENCIESSARLIO_URL))
print("MAVENSARLIO_USER = " + str(MAVENSARLIO_USER))
print("MAVENSARLIO_PWD = " + str(pass_phrase))
##############################
##
def filterArgs(args):
l = []
if args:
if isinstance(args, list):
l = args
if len(args) > 0:
if isinstance(args, list):
l = args[0]
r = []
for e in l:
if e != '--':
r.append(e)
return r
##############################
## pass_phrase: the password
## args: command-line arguments
def execute_maven(pass_phrase, args):
global MAVENSARLIO_URL
global UPDATESSARLIO_URL
global MAVENSARLIO_USER
global DEPENDENCIESSARLIO_URL
maven_cmd = os.environ.get('MAVEN_CMD')
if maven_cmd is None:
maven_cmd = 'mvn'
os.environ["MAVENSARLIO_USER"] = MAVENSARLIO_USER
os.environ["MAVENSARLIO_PWD"] = pass_phrase
os.environ["MAVENSARLIO_URL"] = MAVENSARLIO_URL
os.environ["UPDATESSARLIO_URL"] = UPDATESSARLIO_URL
os.environ["DEPENDENCIESSARLIO_URL"] = DEPENDENCIESSARLIO_URL
cmd = [ maven_cmd,
"-Dmaven.test.skip=true",
"-DskipTests=true",
"-Dcheckstyle.skip=true",
"-DMAVENSARLIO_USER=\"" + MAVENSARLIO_USER + "\"",
"-DMAVENSARLIO_PWD=\"" + pass_phrase + "\"",
"-DMAVENSARLIO_URL=\"" + MAVENSARLIO_URL + "\"",
"-DUPDATESSARLIO_URL=\"" + UPDATESSARLIO_URL + "\"",
"-DDEPENDENCIESSARLIO_URL=\"" + DEPENDENCIESSARLIO_URL + "\"",
"-PuploadP2Repo",
]
for arg in args:
cmd.append(arg)
cmd.append("clean")
cmd.append("deploy")
shell_cmd = ' '.join(cmd)
print(shell_cmd)
r = os.system(shell_cmd)
return r
##############################
##
parser = argparse.ArgumentParser(description="Release SARL P2 on the server")
parser.add_argument('args', nargs=argparse.REMAINDER, action="append")
args = parser.parse_args()
rargs = filterArgs(args.args)
read_user_configuration()
check_configuration()
pass_phrase = ask_pass()
if pass_phrase:
print_configuration(pass_phrase)
r = execute_maven(pass_phrase, rargs)
sys.exit(r)
else:
sys.exit(255)