forked from PlatONnetwork/browser-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
344 lines (309 loc) · 14.6 KB
/
build.gradle
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://mvnrepository.com/artifact/" }
}
dependencies {
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1")
classpath 'org.yaml:snakeyaml:1.27'
classpath 'cn.hutool:hutool-all:5.5.7'
classpath 'javax.mail:mail:1.4.7'
}
}
plugins {
id 'org.hidetake.ssh' version '2.10.1'
id "github.com.sakamotodesu.jcifs" version "0.2.2"
}
import github.com.sakamotodesu.JcifsCopy
import groovy.json.JsonBuilder
import org.yaml.snakeyaml.Yaml
import static java.nio.file.Files.copy
import static java.nio.file.Paths.get
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
group = 'com.platon.browser'
version = "${projectVersion}"
def shortCommitId = 'git log -1 --pretty=%h'.execute([], project.rootDir).text.trim()
apply plugin: "org.sonarqube"
sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
}
}
def recursiveCopy(startDir, replaceDir) {
file(startDir).listFiles().each { conf ->
if (conf.isDirectory()) {
recursiveCopy(conf.path, replaceDir)
} else {
def classPathFile = file(conf.path.replace(replaceDir, 'scan-api/build/resources/main/public'))
def ss = conf.path.replace(replaceDir, 'scan-api/build/package/public')
def packagePathFile = file(ss)
def outPathFile = file(conf.path.replace(replaceDir, 'scan-api/build/distributions/public'))
if (!classPathFile.exists()) classPathFile.parentFile.mkdirs()
if (!packagePathFile.exists()) packagePathFile.parentFile.mkdirs()
if (!outPathFile.exists()) outPathFile.parentFile.mkdirs()
copy(get(conf.path), get(classPathFile.path), REPLACE_EXISTING)
copy(get(conf.path), get(packagePathFile.path), REPLACE_EXISTING)
copy(get(conf.path), get(outPathFile.path), REPLACE_EXISTING)
}
}
}
subprojects {
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
apply plugin: 'java'
apply plugin: 'jacoco'
group 'com.platon.browser'
version "$projectVersion-$shortCommitId"
sourceCompatibility = '1.8'
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
maven { url "https://sdk.platon.network/nexus/content/groups/public/" }
mavenCentral()
}
// configurations {
// all {
//// exclude module: "junit"
//// 默认24小时 这样配置jar包会直接去配置的仓库拿
// resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
// }
// }
// 配置文件更新&生成
def bootApps = ['scan-agent', 'scan-api', 'scan-export', 'scan-press', 'scan-sync']
if (project.name in bootApps) {
file("${projectDir.path}/conftpl").listFiles().each { tpl ->
def txt = tpl.text
.replace('_VERSION_', "$projectVersion")
.replace('_DESCRIPTION_', "$description")
.replace('_DB_HOST_', "$dbHost")
.replace('_DB_PORT_', "$dbPort")
.replace('_DB_NAME_', "$dbName")
.replace('_DB_USER_', "$dbUser")
.replace('_DB_PASS_', "$dbPass")
.replace('_REDIS_IPS_', "$redisIps")
.replace('_REDIS_PWD_', "$redisPwd")
.replace('_REDIS_DB_', "$redisDb")
.replace('_ES_IPS_', "$esIps")
.replace('_ES_PORT_', "$esPort")
.replace('_ES_USER_', "$esUser")
.replace('_ES_PWD_', "$esPwd")
file(tpl.absolutePath.replace('conftpl', 'src/main/resources')).write(txt, "utf-8")
file(tpl.absolutePath.replace('conftpl', 'src/test/resources')).write(txt, "utf-8")
}
}
if (project.name in ['scan-agent', 'scan-api']) {
apply plugin: 'distribution' //打包tar包用到的插件
def packageName = "${project.name}-${version}"
// 复制配置文件
task copyConf(type: Copy) {
from('src/main/resources/application-appchain.yml')
from('src/main/resources/application-apollo.yml')
from('../jasypt.properties')
from('status.hook')
from("build/libs/${packageName}.jar")
into('build/package')
}
build {
doFirst {
def yamlFilter = new FilenameFilter() {
boolean accept(File dir, String name) {
return name.endsWith(".yml")
}
}
file("${rootDir}/estpl").listFiles(yamlFilter).each { tpl ->
copy(get(tpl.path), get("${rootDir}/scan-agent/src/main/resources/estpl").resolve(tpl.name), REPLACE_EXISTING)
copy(get(tpl.path), get("${rootDir}/scan-service/src/test/resources/estpl").resolve(tpl.name), REPLACE_EXISTING)
}
file("${rootDir}/scripts/").listFiles(new FilenameFilter() {
@Override
boolean accept(File dir, String name) {
return name.endsWith(".sql") && name.contains(projectVersion)
}
}).each { srcFile ->
def desFile = file("${rootDir}/scan-agent/build/package/${srcFile.name}")
if (!desFile.exists()) desFile.parentFile.mkdirs()
copy(get(srcFile.path), get(desFile.path), REPLACE_EXISTING)
}
file("${rootDir}/docs/apidef").listFiles(yamlFilter).each { api ->
file("${rootDir}/docs/apidef/${api.name}.json").write(
new JsonBuilder(
new Yaml().load(api.text
.replace("_VERSION_", "$projectVersion")
.replace("_COMMIT_ID_", shortCommitId)
.replace("_BASE_PATH_", "/browser-server")
)
).toString(), "utf-8"
)
}
recursiveCopy("scan-api/webconfig", "scan-api" + File.separator + "webconfig")
recursiveCopy('docs', 'docs')
file("${rootDir}/scripts").listFiles(new FilenameFilter() {
boolean accept(File dir, String name) {
return name.endsWith("tpl.sh")
}
}).each { tpl ->
def desFile = file(tpl.path.replace('scripts', "scan-api/build/package").replace("tpl.sh", "sh"))
if (!desFile.exists()) desFile.parentFile.mkdirs()
desFile.write(tpl.text
.replace('_PROJECT_NAME_', "scan-api")
.replace('_VERSION_', "$projectVersion")
.replace('_PROFILE_', "platon")
.replace('_DB_HOST_', "$dbHost")
.replace('_DB_USER_', "$dbUser")
.replace('_DB_PASS_', "$dbPass")
.replace('_JAVA_PATH_', "$deployJavaAbsPath")
, "utf-8")
desFile = file(tpl.path.replace('scripts', "scan-agent/build/package").replace("tpl.sh", "sh"))
if (!desFile.exists()) desFile.parentFile.mkdirs()
desFile.write(tpl.text
.replace('_PROJECT_NAME_', "scan-agent")
.replace('_VERSION_', "$projectVersion")
.replace('_PROFILE_', "platon")
.replace('_DB_HOST_', "$dbHost")
.replace('_DB_USER_', "$dbUser")
.replace('_DB_PASS_', "$dbPass")
.replace('_JAVA_PATH_', "$deployJavaAbsPath")
, "utf-8")
}
file("${buildDir}/package").listFiles(new FilenameFilter() {
@Override
boolean accept(File dir, String name) {
return name.endsWith('.jar') && !name.contains(packageName)
}
}).each { file -> file.delete() }
file("${buildDir}/distributions").listFiles(new FilenameFilter() {
@Override
boolean accept(File dir, String name) {
return !name.contains(packageName)
}
}).each { file -> file.delete() }
file("${buildDir}/libs").listFiles(new FilenameFilter() {
@Override
boolean accept(File dir, String name) {
return !name.contains(packageName)
}
}).each { file -> file.delete() }
}
}
task buildTar(dependsOn: [
'build',
copyConf
]) {}
distributions {
monitor {
baseName = project.name
contents {
from { 'build/package' }
}
}
}
monitorDistTar.dependsOn 'copyConf'
monitorDistTar.compression = Compression.GZIP
monitorDistTar.archiveExtension.set('tar.gz')
remotes {
webServer {
host = "$deployServerHost"
user = "$deployServerUser"
port = Integer.parseInt("$deployServerPort")
password = "$deployServerPassword"
}
}
// 拷包到测试环境
def deployDir = "$deployRootDir/${project.name}"
def activeProfile = "$deployProfile"
task deployToTestEnv(dependsOn: ['buildTar'], group: 'deploy') {
doLast {
ssh.settings {
knownHosts = allowAnyHosts
pty = true
}
ssh.run {
session(remotes.webServer) {
execute "mkdir -p $deployDir && rm -rf $deployDir/${project.name}*.jar"
put from: "${buildDir}/libs/${packageName}.jar", into: "$deployDir"
execute "cd $deployDir && $deployFixScript && chmod a+x *.sh && ./start.sh $activeProfile"
}
}
}
}
def parentDir = project.name.contains('agent') ? 'scan-agent' : 'scan-api'
def desDir = "${projectVersion}-" + new Date().format("yyyy.MM.dd.HHmm")
// 请在系统环境变量配置自己的NAS发布账户
def publishServerUser = System.getenv('publishServerUser')
def publishServerPassword = System.getenv('publishServerPassword')
task releaseToCifs(type: JcifsCopy, dependsOn: ['buildTar'], group: 'release') {
from "${projectDir.path}/build/distributions/${packageName}.tar.gz"
into "smb://${publishServerUser}:${publishServerPassword}@${publishServerHost}/${publishServerPath}/${parentDir}/${desDir}/"
}
}
//sonar扫描的路径
sonarqube {
properties {
property "sonar.sources", "src/main/java"
}
}
//jacoco测试报表的功能
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.7
}
}
}
}
check.dependsOn jacocoTestReport
dependencies {
// testCompile "junit:junit:$junitVersion"
testCompile "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
compile "com.alibaba:fastjson:$fastJsonVersion"
compile "org.apache.commons:commons-lang3:$commonLang3Version"
compile "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
compile "commons-io:commons-io:$commonIoVersion"
compile "redis.clients:jedis:$jedisVersion"
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.2'
testCompile group: 'org.powermock', name: 'powermock-api-easymock', version: '2.0.2'
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.2'
testCompile group: 'org.powermock', name: 'powermock-core', version: '2.0.2'
compile("org.elasticsearch.client:elasticsearch-rest-high-level-client:$elasticSearchVersion") {
exclude module: 'elasticsearch'
exclude module: 'elasticsearch-rest-client'
}
compile "org.elasticsearch:elasticsearch:$elasticSearchVersion"
compile("org.elasticsearch.client:elasticsearch-rest-client:$elasticSearchVersion") {
exclude module: 'httpclient'
exclude module: 'httpcore'
exclude module: 'httpasyncclient'
exclude module: 'httcore-nio'
}
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.10'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.12'
compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.4'
compile group: 'org.apache.httpcomponents', name: 'httpcore-nio', version: '4.4.12'
implementation "org.springframework.boot:spring-boot-starter-cache:$springbootVersion"
implementation group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.9.0'
compile group: 'org.springframework.retry', name: 'spring-retry', version: '1.2.4.RELEASE'
testCompile group: 'org.hsqldb', name: 'hsqldb', version: '2.5.0'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.27'
compile 'cn.hutool:hutool-all:5.5.7'
implementation 'javax.mail:mail:1.4.7'
implementation group: 'p6spy', name: 'p6spy', version: '3.9.0'
implementation group: 'com.xuxueli', name: 'xxl-job-core', version: '2.3.0'
implementation group: 'com.ctrip.framework.apollo', name: 'apollo-client', version: '1.9.1'
// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
// https://mvnrepository.com/artifact/commons-codec/commons-codec
implementation group: 'commons-codec', name: 'commons-codec', version: '1.15'
}
tasks.named('test') {
useJUnitPlatform()
}
}