Repository navigation
Expand file tree
/
Copy pathdev.py
More file actions
executable file
·167 lines (138 loc) · 5.65 KB
/
Copy pathdev.py
File metadata and controls
executable file
·167 lines (138 loc) · 5.65 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/python
# coding=utf-8
import sys, getopt
import os
import tarfile
import shutil
import subprocess
rootDir = sys.path[0]+os.sep
sys.path.append(rootDir + "script" + os.sep + "dev")
import scmProjectUtil
import scmCmdExecutor
import scmJdkInstaller
from scmCmdExecutor import ScmCmdExecutor
from scmProjectUtil import ScmProjectUtil
from scmJdkInstaller import ScmJdkInstaller
cmdExecutor = ScmCmdExecutor(False)
scmProjectUtil = ScmProjectUtil(rootDir + "script" + os.sep + "dev" + os.sep + "projectInfo.json", cmdExecutor)
jdkInstaller = ScmJdkInstaller(rootDir)
compileScmModule = None
needArchiveRelease = False
supportedCompileProfile = ["release", "original"]
def getScmVersion():
versionFile = rootDir + "script" + os.sep + "dev" + os.sep + "version"
with open(versionFile) as lines:
for line in lines:
line = line.strip()
if line.startswith("NewVersion="):
return line.replace("NewVersion=", "")
print ("Error:failed to get scm version from " + versionFile)
sys.exit(-1)
archiveReleasePath = rootDir + "archive-target" + os.sep + 'sequoiacm-' + getScmVersion() + '-release.tar.gz'
compileTestModule = None
runTestModule = None
compileRelease = False
compileProfile = "release"
skipInstallJDK = False
def display(exit_code):
print("config file: " + rootDir + "script" + os.sep + "dev" + os.sep + "projectInfo.json")
print("")
print(" --help | -h : print help message")
print(" --compile | -c : option value: all " + " ".join(scmProjectUtil.getScmModules()))
print(" --compileProfile : profile of maven compile configuration, default is release, supported: {}".format(supportedCompileProfile))
print(" --release : compile release sequoiacm")
print(" --compileTest : option value: all " + " ".join(scmProjectUtil.getTestModules()))
print(" --runTest : run test by testng.xml, test module: all " + " ".join(scmProjectUtil.getTestModules()))
print(" --archive | -a : archive scm project, package a tar.gz file")
print(" --tar-path | -t : specify package scm target file path, default " + archiveReleasePath)
print(" --skipInstallJDK : skip install JDK")
sys.exit(exit_code)
def parse_command():
global compileScmModule, needArchiveRelease, archiveReleasePath, compileTestModule, runTestModule, compileRelease, compileProfile, skipInstallJDK
try:
options, args = getopt.getopt(sys.argv[1:], "hc:at:",
["help", "compile=", "compileProfile=", "release", "archive", "tar-path=",
"compileTest=", "runTest=", "skipInstallJDK"])
except getopt.GetoptError, e:
print ("Error:", e)
sys.exit(-1)
for name, value in options:
if name in ("-h", "--help"):
display(0)
elif name in ("-c","--compile"):
compileScmModule = value
elif name in ("--compileProfile"):
if value not in supportedCompileProfile:
print('compileProfile {} is not supported, supported: {}\n'
.format(value, supportedCompileProfile))
display(1)
compileProfile = value
elif name in ("-a", "--archive"):
needArchiveRelease = True;
elif name in ("-t", "--tar-path"):
archiveReleasePath = value
elif name in ("--compileTest"):
compileTestModule = value
elif name in ("--runTest"):
runTestModule = value
elif name in ("--release"):
compileRelease = True
elif name in ("--skipInstallJDK"):
skipInstallJDK = True
def compileScm():
if not skipInstallJDK:
jdkInstaller.check_and_install_jdk()
compileArgs = ""
if compileRelease:
compileArgs = "-DpackageType=release"
if compileProfile:
compileArgs = compileArgs + " -P{} ".format(compileProfile)
projectRootDir = os.path.join(rootDir, 'src')
vulnerabilityFixerRootDir = os.path.join(rootDir, 'tools', 'scm-vulnerability-fixer')
if compileScmModule == "all":
scmProjectUtil.compileDoc(rootDir + "doc" + os.sep)
# cleanup local maven repository before compile
scmProjectUtil.cleanMavenLocalRepo()
scmProjectUtil.compileScm(compileArgs)
else:
scmProjectUtil.compileScmModule(compileScmModule, compileArgs)
if compileProfile == "release":
scmProjectUtil.verifyScm(projectRootDir,
os.path.join(vulnerabilityFixerRootDir, 'src', 'main', 'resources', 'artifacts.txt'),
os.path.join(vulnerabilityFixerRootDir, 'tmp'))
print("Success: no vulnerability jars have been detected in product archive.")
def compileTest():
if compileTestModule == "all":
scmProjectUtil.compileTest()
else:
scmProjectUtil.compileTestModule(compileTestModule)
def archive():
scmProjectUtil.packageScm(archiveReleasePath)
def untar(filePath,dir):
try:
t = tarfile.open(filePath)
t.extractall(dir)
except Exception as e:
print(e)
def runTest():
if runTestModule == "all":
scmProjectUtil.runAllTest()
else:
scmProjectUtil.runTest(runTestModule)
if __name__ == '__main__':
parse_command()
doSomething = False
if compileScmModule != None:
compileScm()
doSomething = True
if compileTestModule != None:
compileTest()
doSomething = True
if runTestModule != None:
runTest()
doSomething = True
if needArchiveRelease:
archive()
doSomething = True
if doSomething == False:
display(0)