-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
486 lines (415 loc) · 13.3 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
478
479
480
481
482
483
484
import se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask
plugins {
id 'java'
id 'application'
id 'com.gradleup.shadow' version 'latest.release'
id 'maven-publish'
id 'signing'
id 'pmd'
id 'checkstyle'
id 'jacoco'
id 'com.github.kt3k.coveralls' version "latest.release"
id "com.github.spotbugs" version "latest.release"
id "com.diffplug.spotless" version "latest.release"
id "de.undercouch.download" version "latest.release"
id 'org.hidetake.ssh' version "latest.release"
id "com.github.hierynomus.license" version "latest.release"
id "se.bjurr.gitchangelog.git-changelog-gradle-plugin" version "2.0.0" //later depends on JDK 17
id 'biz.aQute.bnd.builder' version '6.4.0' //later depends on JDK 17
}
repositories {
mavenLocal()
mavenCentral()
//Sonatype OSSRH
maven {
url = uri('https://s01.oss.sonatype.org/content/repositories/snapshots/')
}
maven {
url = uri('https://oss.sonatype.org/content/repositories/snapshots/')
}
maven {
url = uri('https://oss.sonatype.org/content/groups/public/')
}
}
configurations {
xmlDoclet
}
dependencies {
implementation('com.github.jsqlparser:jsqlparser:+'){ changing = true }
//for JSON (de)serialization
implementation 'org.json:json:+'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.11.3'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.3'
testImplementation 'org.duckdb:duckdb_jdbc:1.1.3'
testImplementation 'org.apache.commons:commons-compress:+'
testImplementation 'com.opencsv:opencsv:+'
// we do need better matchers
testImplementation("org.assertj:assertj-core:+")
// for the ASCII Trees
testImplementation 'hu.webarticum:tree-printer:+'
//calling external python
testImplementation 'org.apache.commons:commons-exec:+'
// Java Doc in XML Format
xmlDoclet 'com.manticore-projects.tools:xml-doclet:+'
}
configurations.configureEach {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.github.jsqlparser') {
// Check for updates every build
resolutionStrategy.cacheChangingModulesFor 30, 'seconds'
}
}
}
def getVersion = { boolean considerSnapshot ->
Integer major = 0
Integer minor = 0
Integer patch = null
Integer build = null
def commit = null
def snapshot = ""
new ByteArrayOutputStream().withStream { os ->
exec {
args = [
"--no-pager"
, "describe"
, "--tags"
, "--always"
, "--dirty=-SNAPSHOT"
]
executable "git"
standardOutput = os
}
def versionStr = os.toString().trim()
def pattern = /(?<major>\d*)\.(?<minor>\d*)(\.(?<patch>\d*))?(-(?<build>\d*)-(?<commit>[a-zA-Z\d]*))?/
def matcher = versionStr =~ pattern
if (matcher.find()) {
major = matcher.group('major') as Integer
minor = matcher.group('minor') as Integer
patch = matcher.group('patch') as Integer
build = matcher.group('build') as Integer
commit = matcher.group('commit')
}
if (considerSnapshot && ( versionStr.endsWith('SNAPSHOT') || build!=null) ) {
minor++
if (patch!=null) patch = 0
snapshot = "-SNAPSHOT"
}
}
return patch!=null
? "${major}.${minor}.${patch}${snapshot}"
: "${major}.${minor}${snapshot}"
}
version = getVersion(true)
group = 'ai.starlake.jsqltranspiler'
description = 'JSQLTranspiler'
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility(JavaVersion.VERSION_11)
targetCompatibility(JavaVersion.VERSION_11)
// needed for XML-Doclet to work (since Doclet changed again with Java 13)
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
application {
mainClass.set("ai.starlake.transpiler.JSQLTranspiler")
}
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
options.addBooleanOption("Xdoclint:none", true)
}
tasks.register('xmldoc', Javadoc) {
source = sourceSets.main.allJava
destinationDir = reporting.file("xmlDoclet")
options.docletpath = configurations.xmlDoclet.files as List
options.doclet = "com.github.markusbernhardt.xmldoclet.XmlDoclet"
options.addBooleanOption("rst", true)
options.addBooleanOption("withFloatingToc", true)
options.addStringOption("basePackage", "ai.starlake.jsqltranspiler")
dependsOn(compileJava)
doLast {
copy {
from reporting.file("xmlDoclet/javadoc.rst")
into "${projectDir}/src/site/sphinx/"
}
}
}
jar {
bnd("Created-By": System.properties.get('user.name'),
"Main-Class": "ai.starlake.transpiler.JSQLTranspiler",
"Bundle-SymbolicName": "ai.starlake.transpiler",
"Import-Package": "*",
"Export-Package": "ai.starlake.transpiler.*"
)
}
shadowJar {
minimize()
}
test {
useJUnitPlatform()
// set heap size for the test JVM(s)
minHeapSize = "128m"
maxHeapSize = "1G"
jacoco {
excludes = ['net/sf/jsqlparser/parser/CCJSqlParserTokenManager']
}
doFirst {
// Download Amazon Redshift `TickitDB` example
// Use the Gradle task in order to allow caching
download.run {
src 'https://docs.aws.amazon.com/redshift/latest/gsg/samples/tickitdb.zip'
dest "build/resources/test/ai/starlake/transpiler/tickitdb.zip"
overwrite false
onlyIfModified true
tempAndMove true
}
// Download Amazong Redshift geo-spatial example
// public datasets that correlate location data of rental accommodations with postal codes in Berlin, Germany.
download.run {
src 'https://s3.amazonaws.com/redshift-downloads/spatial-data/accommodations.csv'
dest "build/resources/test/ai/starlake/transpiler/accommodations.csv"
overwrite false
onlyIfModified true
tempAndMove true
}
download.run {
src 'https://s3.amazonaws.com/redshift-downloads/spatial-data/zipcode.csv'
dest "build/resources/test/ai/starlake/transpiler/zipcode.csv"
overwrite false
onlyIfModified true
tempAndMove true
}
}
}
license {
excludes(["**/*.txt", "**/*.conf", "**/*.sql",])
includes(["**/*.properties", "**/*.java", "**/*.xml"])
ext.year = Calendar.getInstance().get(Calendar.YEAR)
ext.name = 'Starlake.AI'
ext.email = '[email protected]'
strictCheck = false
ignoreFailures = true
}
coveralls {
jacocoReportPath layout.buildDirectory.file('reports/jacoco/test/jacocoTestReport.xml')
}
jacocoTestReport {
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
"net/sf/jsqlparser/parser/**"
])
}))
}
dependsOn test // tests are required to run before generating the report
reports {
xml.required = true
csv.required = false
html.outputLocation = layout.buildDirectory.dir('reports/jacoco')
}
}
jacocoTestCoverageVerification {
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
"net/sf/jsqlparser/parser/**"
])
}))
}
violationRules {
rule {
//element = 'CLASS'
limit {
minimum = 0.10
}
excludes = [
]
}
rule {
//element = 'CLASS'
limit {
counter = 'LINE'
value = 'MISSEDCOUNT'
maximum = 2048
}
excludes = [
]
}
}
}
spotbugsMain {
reports {
html {
enabled = true
destination = file("build/reports/spotbugs/main/spotbugs.html")
stylesheet = 'fancy-hist.xsl'
}
}
}
spotbugs {
// fail only on P1 and without the net.sf.jsqlparser.parser.*
excludeFilter = file("config/spotbugs/spotBugsExcludeFilter.xml")
// do not run over the test, although we should do that eventually
spotbugsTest.enabled = false
}
pmd {
toolVersion = "7.6.0"
consoleOutput = true
sourceSets = [ sourceSets.main, sourceSets.test]
// clear the ruleset in order to use configured rules only
ruleSets = []
//rulesMinimumPriority = 1
ruleSetFiles = files("config/pmd/ruleset.xml")
pmdMain {
excludes = [
"build/generated/*"
]
}
}
checkstyle {
sourceSets = [sourceSets.main, sourceSets.test]
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
}
spotless {
// optional: limit format enforcement to just the files changed by this feature branch
ratchetFrom 'origin/main'
format 'misc', {
// define the files to apply `misc` to
target '*.rst', '*.md', '.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces(4) // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
java {
indentWithSpaces(4)
eclipse().configFile('config/formatter/eclipse-java-google-style.xml')
}
}
tasks.withType(Checkstyle).configureEach {
reports {
xml.required = false
html.required = true
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifactId 'jsqltranspiler'
from(components.java)
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = 'JSQLTranspiler library'
description = 'Rewrite Big RDBMS queries into DuckDB compatible queries'
url = 'https://github.com/starlake-ai/jsqltranspiler'
licenses {
license {
name = 'Apache License'
url = 'https://www.apache.org/licenses/LICENSE-2.0'
}
}
developers {
developer {
id = 'are'
name = 'Andreas Reichel'
email = '[email protected]'
}
}
}
}
}
repositories {
maven {
// Username and Password are defined in ~/.gradle/gradle.properties
name "ossrh"
url version.toString().endsWith('-SNAPSHOT')
? "https://s01.oss.sonatype.org/content/repositories/snapshots/"
: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials(PasswordCredentials)
}
}
}
signing {
required { !version.endsWith("SNAPSHOT") && gradle.taskGraph.hasTask("publish") }
sign publishing.publications.mavenJava
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release = 11
}
tasks.withType(Test).configureEach {
maxParallelForks = 10
}
tasks.register('gitChangelogTask', GitChangelogTask) {
fromRepo = file("$projectDir")
file = new File("${projectDir}/src/site/sphinx/changelog.rst")
//fromRef = "4.0";
//toRef = "1.1";
templateContent = """
************************
Changelog
************************
{{#tags}}
{{#ifMatches name "^Unreleased.*"}}
Latest Changes since |JSQLTRANSPILER_VERSION|
{{/ifMatches}}
{{#ifMatches name "^(?!Unreleased).*"}}
Version {{name}}
{{/ifMatches}}
=============================================================
{{#issues}}
{{#commits}}
{{#ifMatches messageTitle "^(?!Merge).*"}}
* **{{{messageTitle}}}**
{{authorName}}, {{commitDate}}
{{/ifMatches}}
{{/commits}}
{{/issues}}
{{/tags}}
"""
}
remotes {
webServer {
host = findProperty("${project.name}.host")
user = findProperty("${project.name}.username")
identity = new File("${System.properties['user.home']}/.ssh/id_rsa")
}
}
ssh.settings {
timeoutSec = 60000
}
tasks.register('upload') {
dependsOn(jar, gitChangelogTask, xmldoc)
doFirst {
if (findProperty("${project.name}.host") == null) {
println(
"""
Property \"${project.name}.host\' not found.
Please define \"${project.name}.host\" in the Gradle configuration (e. g. \$HOME/.gradle/gradle.properties.
"""
)
}
}
doLast {
ssh.run {
session(remotes.webServer) {
def versionStable = getVersion(false)
execute "mkdir -p download/${project.name}-${versionStable}"
for (File file: fileTree(include:['*.jar'], dir:"${project.buildDir}/libs").collect()) {
put from: file, into: "download/${project.name}-${versionStable}"
}
}
}
}
}