-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathbuild.gradle
More file actions
452 lines (377 loc) · 15.9 KB
/
build.gradle
File metadata and controls
452 lines (377 loc) · 15.9 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
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
plugins {
id 'java-library'
id "com.diffplug.spotless" version "6.13.0"
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "org.cyclonedx.bom" version "1.8.2"
id 'com.github.jk1.dependency-license-report' version '1.17'
}
import com.github.jk1.license.render.TextReportRenderer
if (project.hasProperty('isRelease')) {
version = getAbbreviatedGitVersion()
} else {
version = getGitVersion() + "-SNAPSHOT"
}
def thirdpartyNoticeDir = "$buildDir/" + thirdpartyNoticeDir
ext {
println("Driver version = " + version)
releaseVersion = getReleaseVersion()
println("Artifacts version = " + releaseVersion)
javaDataLoader = "com.mongodb.jdbc.integration.testharness.DataLoader"
javaTestGenerator = "com.mongodb.jdbc.integration.testharness.TestGenerator"
aspectjVersion = '1.9.7'
}
spotless {
java {
googleJavaFormat('1.1').aosp()
licenseHeaderFile('resources/license_header.txt')
}
}
licenseReport {
outputDir = (thirdpartyNoticeDir as File).toPath().toString()
renderers = [new TextReportRenderer(thirdpartyNoticeName) ]
}
generateLicenseReport {
def tempFile = new File("$buildDir", "temp-third-party-notice.txt")
def header = new File("$projectDir/resources", "third_party_header.txt")
doLast {
// Replace original file with temp file content
def inputFile = new File((thirdpartyNoticeDir as File).toPath().toString(), thirdpartyNoticeName)
tempFile.setText(header.getText() + inputFile.getText())
inputFile.text = tempFile.text
tempFile.delete() // Clean up the temporary file
}
}
cyclonedxBom {
// includeConfigs is the list of configuration names to include when generating the BOM (leave empty to include every configuration), regex is supported
includeConfigs = ["runtimeClasspath"]
// skipConfigs is a list of configuration names to exclude when generating the BOM, regex is supported
skipConfigs = ["testCompileClasspath", "testRuntimeClass", "testRuntimeOnly"]
// skipProjects is a list of project names to exclude when generating the BOM
skipProjects = ["integration-test", "demo", "smoketest"]
// Specified the type of project being built. Defaults to 'library'
projectType = "library"
// Specified the version of the CycloneDX specification to use. Defaults to '1.5'
schemaVersion = "1.5"
// Boms destination directory. Defaults to 'build/reports'
destination = file(cyclonedxBomDestination)
// The file name for the generated BOMs (before the file format suffix). Defaults to 'bom'
outputName = cyclonedxBomName
// The file format generated, can be xml, json or all for generating both. Defaults to 'all'
outputFormat = "json"
// Exclude BOM Serial Number. Defaults to 'true'
includeBomSerialNumber = false
// Exclude License Text. Defaults to 'true'
includeLicenseText = false
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
allprojects {
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = sourceCompatibility
repositories {
mavenCentral()
}
configurations {
ajc
aspects
compile {
extendsFrom aspects
}
sbom
}
dependencies {
// MongoDB
ajc "org.aspectj:aspectjtools:$aspectjVersion"
implementation "org.aspectj:aspectjrt:$aspectjVersion"
implementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: mongodbDriverVersion
implementation group: 'com.google.guava', name: 'guava', version: guavaVersion
implementation group: 'org.apache.commons', name: 'commons-lang3', version: lang3Version
implementation group: 'org.apache.commons', name: 'commons-text', version: commonsTextVersion
ajc "org.aspectj:aspectjtools:$aspectjVersion"
implementation group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: bouncyCastleVersion
implementation group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: bouncyCastleVersion
// Test
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitJupiterVersion
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: mockitoVersion
}
compileJava {
doLast {
ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties",
classpath: configurations.ajc.asPath)
ant.iajc(
maxmem: "1024m", fork: "true", Xlint: "ignore",
destDir: project.sourceSets.main.output.classesDirs[0].absolutePath,
sourceroots: project.sourceSets.main.java.srcDirs[0].absolutePath,
classpath: project.sourceSets.main.runtimeClasspath.asPath,
source: project.sourceCompatibility,
target: project.targetCompatibility,
showWeaveInfo: true
)
}
}
test {
useJUnitPlatform()
failFast = true
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
classifier "sources"
}
task testJar(type: Jar) {
from sourceSets.test.allJava
classifier "test"
}
task javadocJar(type: Jar) {
from javadoc
classifier 'javadoc'
}
artifacts {
sourceJar
testJar
javadocJar
}
}
configurations {
integrationTestImplementation.extendsFrom implementation
integrationTestRuntimeOnly.extendsFrom runtimeOnly
// Use the release version instead of gitVersion for the produced jar
jar.archiveVersion = releaseVersion
shadowJar.archiveVersion = releaseVersion
}
shadowJar {
archiveClassifier = 'all'
relocate 'com.google', 'shadow.com.google'
relocate 'com.nimbusds', 'shadow.com.nimbusds'
relocate 'net.jcip', 'shadow.net.jcip'
relocate 'ognl', 'shadow.ognl'
relocate('org', 'shadow.org') {
exclude 'org.ow2.asm:.*'
exclude 'org.javassist:.*'
}
// Exclude Java 21 compiled classes and multi-release JAR versions
exclude 'META-INF/versions/**'
exclude '**/module-info.class'
// Exclude specific dependencies that contain Java 21 bytecode
dependencies {
exclude(dependency('org.ow2.asm:.*'))
exclude(dependency('org.javassist:.*'))
}
// Configure ASM to skip problematic class files
transform(com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer)
}
task integrationTest(type: Test) {
useJUnitPlatform()
description = 'Runs integration tests.'
group = 'verification'
dependsOn tasks.named('jar')
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath + files(tasks.jar.archiveFile.get()) - sourceSets.main.output
shouldRunAfter test
}
check.dependsOn integrationTest
task runTestGenerator(type: JavaExec) {
group = "Execution"
description = "Run the integration test baseline file generator."
classpath = sourceSets.integrationTest.runtimeClasspath
main = javaTestGenerator
}
task runDataLoader(type: JavaExec) {
group = "Execution"
description = "Run the data loader."
classpath = sourceSets.integrationTest.runtimeClasspath
main = javaDataLoader
}
task runServer(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.mongodb.jdbc.oidc.manualtests.TestRFC8252Server'
}
task runAuthFlow(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.mongodb.jdbc.oidc.manualtests.TestOidcAuthFlow'
}
task runAuthFlowAndRefresh(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.mongodb.jdbc.oidc.manualtests.TestOidcAuthFlowAndRefresh'
}
task runCallback(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.mongodb.jdbc.oidc.manualtests.TestOidcCallback'
}
task runCallbackWithShortTimeout(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.mongodb.jdbc.oidc.manualtests.TestOidcCallbackWithShortTimeout'
}
task runCallbackWithBadRefreshToken(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.mongodb.jdbc.oidc.manualtests.TestOidcCallbackWithBadRefreshToken'
}
jar {
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version)
}
}
dependencies {
integrationTestImplementation "org.yaml:snakeyaml:$snakeYamlVersion"
api "org.mongodb:mongodb-driver-sync:$mongodbDriverVersion"
integrationTestImplementation "org.junit.jupiter:junit-jupiter:$junitJupiterVersion"
integrationTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion
implementation group: 'org.thymeleaf', name: 'thymeleaf', version: thymeLeafVersion
implementation group: 'com.nimbusds', name: 'oauth2-oidc-sdk', version: oauth2OIDCVersion
}
def getReleaseVersion() {
String baseVersion = getAbbreviatedGitVersion()
boolean isSnapshot = !project.hasProperty('isRelease')
String suffix = ""
if (isSnapshot) {
suffix += "-SNAPSHOT"
}
return baseVersion + suffix
}
def getGitVersion() {
def out = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--always', '--dirty'
standardOutput = out
}
out.toString().substring(1).trim()
}
def getAbbreviatedGitVersion() {
def out = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--abbrev=0'
standardOutput = out
}
// Remove the leading 'v'
out = out.toString().substring(1).trim()
println "Untrimmed git version : $out"
// Remove the libv portion
String[] parts = out.split("-libv")
if (parts.length > 1) {
out = parts[0]
}
println "Trimmed git version : $out"
return out
}
// Determines the version of libmongosqltranslate to use based on the following priority:
// Command line property 'libVersion' ie -PlibmongosqltranslateVersion=1.2.3 for manual testing
// If build is triggered by a tag, check that LIBMONGOSQLTRANSLATE_VER environment variable is set and use that value
// Otherwise default to "snapshot" version
def getLibMongosqlTranslateVersion() {
if (project.hasProperty('libmongosqltranslateVersion')) {
logger.lifecycle("Using manually specified libVersion: ${project.property('libmongosqltranslateVersion')}")
return project.property('libmongosqltranslateVersion')
}
if (project.hasProperty('isRelease')) {
if (System.getenv('LIBMONGOSQLTRANSLATE_VER')) {
logger.lifecycle("Using version from environment: ${System.getenv('LIBMONGOSQLTRANSLATE_VER')}")
return System.getenv('LIBMONGOSQLTRANSLATE_VER')
} else {
throw new GradleException("Build is tag-triggered but LIBMONGOSQLTRANSLATE_VER " +
"environment variable is not set. This is required for tag-triggered builds.")
}
}
logger.lifecycle("Using snapshot version")
return "snapshot"
}
def libraryCache = new File("${project.rootDir}/.library_cache")
task downloadLibMongosqlTranslate {
def libraryPlatforms = [
[platform: 'linux', arch: 'arm', libPrefix: 'lib', ext: 'so'],
[platform: 'linux', arch: 'x86_64', libPrefix: 'lib', ext: 'so'],
[platform: 'macos', arch: 'arm', libPrefix: 'lib', ext: 'dylib'],
[platform: 'macos', arch: 'x86_64', libPrefix: 'lib', ext: 'dylib'],
[platform: 'win', arch: 'x86_64', libPrefix: '', ext: 'dll']
]
description = 'Downloads mongosqltranslate libraries for all platforms'
group = 'Build Setup'
// Read the force-update flag from the command line `-PupdateLibs=true`
def updateLibs = project.hasProperty('updateLibs') ? project.property('updateLibs').toBoolean() : false
doLast {
def libVersion = getLibMongosqlTranslateVersion()
logger.lifecycle("Using libmongosqltranslate version: ${libVersion}")
libraryCache.mkdirs()
libraryPlatforms.each { platform ->
def libraryFileName = "${platform.libPrefix}mongosqltranslate.${platform.ext}"
def s3FileName =
"${platform.libPrefix}mongosqltranslate-v${libVersion}-${platform.platform}-${platform.arch}.${platform.ext}"
def s3Url = "https://translators-connectors-releases.s3.amazonaws.com/mongosqltranslate/${s3FileName}"
def cacheFile = new File(libraryCache, s3FileName)
def resourceDir = new File("${project.rootDir}/src/main/resources/${platform.arch}/${platform.platform}")
resourceDir.mkdirs()
def destinationFile = new File(resourceDir, libraryFileName)
// Skip the download if the force-update flag is not set and the library already exists in library cache
if (!updateLibs && cacheFile.exists() && cacheFile.length() > 0) {
logger.lifecycle("Using cached version of ${s3FileName} for ${platform.platform}-${platform.arch}")
destinationFile.bytes = cacheFile.bytes
return
}
try {
logger.lifecycle("Downloading ${s3Url}...")
def connection = new URL(s3Url).openConnection()
connection.connectTimeout = 30000
connection.readTimeout = 30000
cacheFile.withOutputStream { outputStream ->
connection.getInputStream().withCloseable { inputStream ->
outputStream << inputStream
}
}
// Verify we downloaded actual content
if (cacheFile.length() == 0) {
throw new IOException("Downloaded file is empty")
}
destinationFile.bytes = cacheFile.bytes
logger.lifecycle("Successfully downloaded ${s3FileName} for ${platform.platform}-${platform.arch}")
} catch (Exception e) {
logger.warn("Could not download ${s3FileName}: ${e.message}")
if (cacheFile.exists() && cacheFile.length() > 0) {
logger.lifecycle("Using cached version from ${cacheFile.path}")
destinationFile.bytes = cacheFile.bytes
} else {
logger.error("ERROR: Could not download ${s3FileName} and no valid cached version available.")
logger.error("S3 URL attempted: ${s3Url}")
throw new GradleException("Failed to download " + s3FileName +
" and no valid cached version exists. Build cannot continue.")
}
}
}
}
}
tasks.named('compileJava').configure {
dependsOn tasks.named('downloadLibMongosqlTranslate')
}
tasks.register('runMongoSQLTranslateLibTest', Test) {
description = 'Runs MongoSQLTranslateLibTest'
group = 'verification'
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
useJUnitPlatform()
filter {
if (project.hasProperty('testMethod')) {
includeTestsMatching "*MongoSQLTranslateLibTest.$testMethod"
} else {
includeTestsMatching "*MongoSQLTranslateLibTest"
}
}
}
tasks.test {
filter {
excludeTestsMatching "*MongoSQLTranslateLibTest"
}
}
apply from: 'gradle/publish.gradle'
apply from: 'gradle/deploy.gradle'