forked from alfio-event/alf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
477 lines (408 loc) · 17 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
import ch.digitalfondue.jfiveparse.HtmlSerializer
import ch.digitalfondue.jfiveparse.NodeMatcher
import ch.digitalfondue.jfiveparse.Parser
import ch.digitalfondue.jfiveparse.Selector
import com.opentable.db.postgres.embedded.EmbeddedPostgres
import com.opentable.db.postgres.embedded.PgBinaryResolver
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import org.apache.commons.lang3.SystemUtils
import org.apache.tools.ant.filters.ReplaceTokens
import org.springframework.jdbc.core.JdbcTemplate
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
import java.time.Year
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import static java.lang.String.format
buildscript {
dependencies {
classpath 'com.opentable.components:otj-pg-embedded:0.13.3'
classpath 'org.postgresql:postgresql:42.2.9'
classpath "org.springframework:spring-jdbc:$springVersion"
//this is for processing the index.html at compile time
classpath "com.github.alfio-event:alf.io-public-frontend:$alfioPublicFrontendVersion"
classpath "ch.digitalfondue.jfiveparse:jfiveparse:0.7.1"
//
}
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
maven {
url "https://jitpack.io"
}
}
}
plugins {
id 'io.freefair.lombok' version '4.1.4'
id 'java'
id 'idea'
id 'org.kordamp.gradle.jacoco' version '0.32.0'
id 'org.kordamp.gradle.coveralls' version '0.32.0'
id 'com.github.ben-manes.versions' version '0.27.0'
id 'com.github.hierynomus.license' version '0.15.0'
id 'net.researchgate.release' version '2.8.1'
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'org.sonarqube' version '2.8'
id 'net.ltgt.errorprone' version '1.1.1'
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'project-report'
//as pointed out by @facundofarias, we should validate minimum javac version
task validate {
//check JDK version
def javaVersion = JavaVersion.current()
if (!javaVersion.isJava11Compatible()) {
throw new GradleException("A Java JDK 11+ is required to build the project.")
}
}
def profile = project.hasProperty('profile') ? project.profile : 'dev'
ext {
// default settings
jettyPort = 8080
jettyHost = '0.0.0.0'
datasourceUrl = 'jdbc:postgresql://localhost:5432/alfio'
datasourceUsername = 'postgres'
datasourcePassword = 'password'
datasourceValidationQuery = 'SELECT 1'
//springProfilesActive = 'dev
//springProfilesActive = 'dev,demo'
springProfilesActive = 'dev'
port = "8080"
switch (profile) {
case 'docker-test':
datasourceUrl = 'jdbc:postgresql://0.0.0.0:5432/postgres'
datasourceUsername = 'postgres'
datasourcePassword = 'postgres'
datasourceValidationQuery = 'SELECT 1'
break
case 'travis':
project.springProfilesActive = 'travis'
break
}
}
configurations {
compileOnly
testCompileOnly
providedRuntime
providedCompile
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url "https://jitpack.io"
}
}
dependencies {
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion"
compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
compile "org.springframework.boot:spring-boot-properties-migrator", {
exclude module : 'spring-boot-starter-logging'
}
compile 'org.springframework.session:spring-session:1.3.5.RELEASE'
compile "ch.digitalfondue.npjt-extra:npjt-extra:2.0.2"
compile "com.samskivert:jmustache:1.15"
compile "javax.mail:mail:1.5.0-b01"
compile 'com.moodysalem:LatLongToTimezoneMaven:1.2'
/**/
compile "com.openhtmltopdf:openhtmltopdf-core:1.0.1"
compile "com.openhtmltopdf:openhtmltopdf-pdfbox:1.0.1"
compile "ch.digitalfondue.jfiveparse:jfiveparse:0.7.1"
/**/
compile "com.google.zxing:core:3.4.0"
compile "com.google.zxing:javase:3.4.0"
compile "org.flywaydb:flyway-core:6.0.8"
compile "org.postgresql:postgresql:42.2.9"
compile "com.zaxxer:HikariCP:3.4.1"
compile "org.apache.logging.log4j:log4j-api:$log4jVersion"
compile "com.stripe:stripe-java:15.4.0"
implementation 'com.paypal.sdk:checkout-sdk:1.0.2'
implementation 'com.google.code.gson:gson:2.8.6'
compile "org.apache.commons:commons-lang3:3.9"
compile "org.apache.commons:commons-text:1.8"
compile "com.opencsv:opencsv:5.0"
compile 'commons-codec:commons-codec:1.13'
compile 'net.sf.biweekly:biweekly:0.6.3'
compile 'com.atlassian.commonmark:commonmark:0.13.1'
compile 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.13.1'
compile 'com.ryantenney.passkit4j:passkit4j:2.0.1'
compile 'com.github.ben-manes.caffeine:caffeine:2.8.0'
compile 'com.github.scribejava:scribejava-core:5.0.0'
compile 'ch.digitalfondue.vatchecker:vatchecker:1.2'
compile 'ch.digitalfondue.basicxlsx:basicxlsx:0.5.1'
compile 'org.imgscalr:imgscalr-lib:4.2'
compile 'org.aspectj:aspectjweaver:1.9.4'
compile "com.github.alfio-event:alf.io-public-frontend:$alfioPublicFrontendVersion"
testCompile 'com.opentable.components:otj-pg-embedded:0.13.3'
compileOnly "javax.servlet:javax.servlet-api:4.0.1"
testCompile "javax.servlet:javax.servlet-api:4.0.1"
testCompile "org.springframework.boot:spring-boot-starter-test", {
exclude module : 'spring-boot-starter-logging'
}
runtime "commons-fileupload:commons-fileupload:1.4"
compile "org.springframework.boot:spring-boot-starter-web", {
exclude module : 'spring-boot-starter-logging'
exclude group: "org.springframework.boot", module: 'spring-boot-starter-tomcat'
exclude group: "org.hibernate.validator"
}
compile "org.springframework.boot:spring-boot-starter-security", {
exclude module : 'spring-boot-starter-logging'
}
compile "org.springframework.boot:spring-boot-starter-mail", {
exclude module : 'spring-boot-starter-logging'
}
compile "org.springframework.boot:spring-boot@jar", {
exclude module : 'spring-boot-starter-logging'
}
compile "org.springframework.boot:spring-boot-autoconfigure@jar", {
exclude module : 'spring-boot-starter-logging'
}
compile "org.springframework.boot:spring-boot-starter-log4j2"
compile "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
}
testCompile "org.junit.jupiter:junit-jupiter-api"
testCompile "org.junit.jupiter:junit-jupiter-engine"
testCompile "org.junit.platform:junit-platform-engine"
testRuntime "org.junit.vintage:junit-vintage-engine:$junitVersion"
providedCompile "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
exclude module : 'spring-boot-starter-logging'
}
providedRuntime "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
exclude module : 'spring-boot-starter-logging'
}
implementation "org.joda:joda-money:1.0.1"
testCompile 'org.mock-server:mockserver-netty:5.8.1'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
errorprone('com.google.errorprone:error_prone_core:2.3.4')
}
// -- license configuration
license {
header = rootProject.file('config/HEADER')
strictCheck = true
ignoreFailures = false
mapping {
java = 'JAVADOC_STYLE'
sql = 'DOUBLEDASHES_STYLE'
}
ext.year = '2014-'+Year.now().toString()
include '**/*.java'
include '**/*.sql'
}
processResources {
doLast {
final gradleProperties = new File((File) it.destinationDir, 'application.properties')
final properties = new Properties()
assert gradleProperties.file
gradleProperties.withReader { properties.load(it) }
properties['alfio.version'] = project.version
properties['alfio.build-ts'] = ZonedDateTime.now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)
properties['alfio.frontend.version'] = alfioPublicFrontendVersion
gradleProperties.withWriter { properties.store(it, null) }
//
// alf.io public frontend: read index.html rewrite path for css/js
final resource = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/resources/webjars/alfio-public-frontend/$alfioPublicFrontendVersion/alfio-public-frontend/index.html")
final indexDoc = new Parser().parse(new InputStreamReader(resource, StandardCharsets.UTF_8))
final basePath = "webjars/alfio-public-frontend/$alfioPublicFrontendVersion/alfio-public-frontend/"
NodeMatcher scriptNodes = Selector.select().element("script").toMatcher()
indexDoc.getAllNodesMatching(scriptNodes).stream().forEach({
it.setAttribute("src", basePath + it.getAttribute("src"))
})
NodeMatcher cssNodes = Selector.select().element("link").attrValEq("rel", "stylesheet").toMatcher();
indexDoc.getAllNodesMatching(cssNodes).stream().forEach({
it.setAttribute("href", basePath + it.getAttribute("href"))
})
final alfioPublicIndex = new File((File) it.destinationDir, "alfio-public-frontend-index.html")
alfioPublicIndex.write(HtmlSerializer.serialize(indexDoc), "UTF-8", false)
}
}
compileJava {
options.compilerArgs = ['-Xlint:all,-serial,-processing']
// both checks are problematic with lombok code
options.errorprone.disable('UnusedVariable')
options.errorprone.disable('MixedMutabilityReturnType')
options.errorprone.disable('MissingOverride')
options.errorprone.disable('JavaTimeDefaultTimeZone') // a little bit too noisy
}
compileJava.dependsOn(processResources)
//propagate the system properties to the tests
test {
useJUnitPlatform()
systemProperties = System.properties
systemProperties.remove("java.endorsed.dirs")
jvmArgs("--illegal-access=warn")
testLogging {
events "failed"
exceptionFormat "full"
info.events = ["failed"]
}
}
bootRun {
def externalConfig = new File("./custom.jvmargs")
def opts = []
opts += [
"-Dspring.profiles.active=${project.springProfilesActive}",
"-Ddatasource.url=${project.datasourceUrl}",
"-Ddatasource.username=${project.datasourceUsername}",
"-Ddatasource.password=${project.datasourcePassword}",
"-Dalfio.version=${project.version}",
"-Dalfio.build-ts=${ZonedDateTime.now(ZoneId.of("UTC")).format(DateTimeFormatter.ISO_ZONED_DATE_TIME)}",
"-Dalfio.frontend.version=$alfioPublicFrontendVersion"
]
if(externalConfig.exists()) {
opts += externalConfig.readLines()
}
jvmArgs = opts
}
bootWar {
mainClassName = 'alfio.config.SpringBootLauncher'
classifier = 'boot'
def bowerDir = "resources/bower_components"
def excludesFile = new File("./lib_exclude")
if(excludesFile.exists()) {
exclude(excludesFile.readLines().collect({ bowerDir + it }))
}
}
// -- code-coverage
jacoco {
toolVersion = '0.8.2'
}
jacocoTestReport {
group = 'Reporting'
description = 'Generate Jacoco coverage reports after running tests.'
additionalSourceDirs.from(project.files(sourceSets.main.allSource.srcDirs))
sourceDirectories.from(project.files(sourceSets.main.allSource.srcDirs))
classDirectories.from(project.files(sourceSets.main.output))
reports {
xml.enabled = true
csv.enabled = false
html.enabled = true
}
}
task dockerize(type: Copy) {
from 'src/main/dist/Dockerfile'
into "${buildDir}/dockerize"
filter(ReplaceTokens, tokens: [ALFIO_VERSION: project.version])
}
task distribution(type: Copy) {
from zipTree("${project.buildDir}/libs/alfio-${project.version}-boot.war")
into "${buildDir}/dockerize"
dependsOn build, dockerize
}
task clever(type: Copy) {
from new File(project.buildDir, "libs/alfio-${project.version}-boot.war")
rename(new Transformer<String, String>() {
@Override
String transform(String s) {
return "alfio-boot.war"
}
})
into "${project.buildDir}/clevercloud"
dependsOn build
}
task startEmbeddedPgSQL {
doLast {
def pgsqlPath = Paths.get(System.getProperty("user.dir"), "alfio-itest")
Files.createDirectories(pgsqlPath)
def tmpDataDir = Files.createTempDirectory(pgsqlPath, "alfio-data")
def binDir = "alfio-pg-bin"+(UUID.randomUUID().toString())
def postgresBinariesDir = Files.createDirectories(pgsqlPath.resolve(binDir)).toAbsolutePath().toFile()
def postgres = EmbeddedPostgres.builder()
.setPort(5432)
.setDataDirectory(tmpDataDir)
.setOverrideWorkingDirectory(postgresBinariesDir)
// we are doing this because there is an unfortunate interplay with the persistence of the gradle daemon and
// EmbeddedPostgres.PREPARE_BINARIES (which is a static field)
// this cause to reuse a wrong directory
.setPgBinaryResolver(new PgBinaryResolver() {
@Override
InputStream getPgBinary(String system, String machineHardware) {
return EmbeddedPostgres.class.getResourceAsStream(format("/postgresql-%s-%s.txz", system, machineHardware));
}
})
.start()
// create a new admin, and then rename the user "postgres" as we don't want to have the superuser roles
def jdbc = new JdbcTemplate(postgres.getDatabase("postgres", "postgres"))
jdbc.execute("CREATE ROLE tmpadmin LOGIN PASSWORD 'password' SUPERUSER")
jdbc = new JdbcTemplate(postgres.getDatabase("tmpadmin", "postgres"))
jdbc.execute("ALTER USER postgres RENAME TO admin")
//
//todo: check if the following grants are necessary
jdbc.execute("CREATE ROLE postgres LOGIN PASSWORD 'password' NOSUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION")
jdbc.execute("GRANT pg_monitor TO postgres")
jdbc.execute("GRANT pg_read_all_settings TO postgres")
jdbc.execute("GRANT pg_read_all_stats TO postgres")
jdbc.execute("GRANT pg_signal_backend TO postgres")
jdbc.execute("GRANT pg_stat_scan_tables TO postgres")
jdbc.execute("CREATE DATABASE alfio WITH OWNER postgres")
//
Files.write(Paths.get(".", "alfio-itest", "pgsql-descriptor"), Arrays.asList(tmpDataDir.toAbsolutePath().toFile().toString(), postgresBinariesDir.toString()))
System.out.println("Launched pgsql")
}
}
// code imported from EmbeddedPostgres :D
String pgBin(File pgDirBase, String binaryName) {
final pgDir = pgDirBase.listFiles(new FileFilter() {
@Override
boolean accept(File file) {
return file.getName().startsWith("PG-") && file.isDirectory()
}
})[0]
final String extension = SystemUtils.IS_OS_WINDOWS ? ".exe" : ""
return new File(pgDir, "bin/" + binaryName + extension).getPath()
}
void system(String... command) {
final ProcessBuilder builder = new ProcessBuilder(command)
final Process process = builder.start()
if (0 != process.waitFor()) {
throw new IllegalStateException(String.format("Process %s failed%n%s", Arrays.asList(command), IOUtils.toString(process.getErrorStream())))
}
}
void pgCtl(File binDir, File dataDir, String action) {
system(pgBin(binDir, "pg_ctl"), "-D", dataDir.getPath(), action, "-m", "fast", "-t", "5", "-w")
}
//
task stopEmbeddedPgSQL {
doLast {
def descriptor = Paths.get(".", "alfio-itest", "pgsql-descriptor")
if (!Files.exists(descriptor)) {
System.out.println("No pid file, you may need to remove manually the alfio-itest folder")
return
}
def r = Files.readAllLines(descriptor)
def dataDir = new File(r.get(0))
def binariesDir = new File(r.get(1))
pgCtl(binariesDir, dataDir, "stop")
Files.deleteIfExists(descriptor)
FileUtils.deleteDirectory(dataDir)
FileUtils.deleteDirectory(binariesDir)
System.out.println("Stopped postgresql")
}
}
release {
buildTasks = ['distribution']
git {
requireBranch = ''
pushToRemote = 'origin'
signTag = true
}
}
// see https://github.com/freefair/gradle-plugins/issues/31#issuecomment-475355674
// since we have a custom lombok.config configuration file, we disable automatic override
generateLombokConfig.enabled = false