forked from ortus-boxlang/bx-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
373 lines (339 loc) · 11.6 KB
/
build.gradle
File metadata and controls
373 lines (339 loc) · 11.6 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
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_packaging
plugins {
id 'java'
// For source code formatting
id "com.diffplug.spotless" version "8.4.0"
// https://github.com/harbby/gradle-serviceloader
id "com.github.harbby.gradle.serviceloader" version "1.1.9"
// Shadow
id "com.gradleup.shadow" version "9.4.1"
// Download task
id "de.undercouch.download" version "5.7.0"
}
/**
* Project Properties
*/
ext {
buildID = System.getenv( 'BUILD_ID' ) ?: '0'
branch = System.getenv( 'BRANCH' ) ?: 'development'
}
if ( branch == 'development' ) {
// If the branch is 'development', ensure the version ends with '-snapshot'
// This replaces any existing prerelease identifier with '-snapshot'
version = version.contains('-') ? version.replaceAll(/-.*/, '-snapshot') : "${version}-snapshot"
boxlangVersion = boxlangVersion.contains('-') ? boxlangVersion.replaceAll(/-.*/, '-snapshot') : "${boxlangVersion}-snapshot"
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// Until BoxLang is published to Maven Central
// Look for it in the local build directory
// You must run `./gradle build -x test` in the BoxLang project
// if ( file( '../../boxlang/build/libs/boxlang-' + boxlangVersion + '.jar' ).exists() ) {
// compileOnly files( '../../boxlang/build/libs/boxlang-' + boxlangVersion + '.jar' )
// testImplementation files( '../../boxlang/build/libs/boxlang-' + boxlangVersion + '.jar' )
// } else {
compileOnly files( 'src/test/resources/libs/boxlang-' + boxlangVersion + '.jar' )
testImplementation files( 'src/test/resources/libs/boxlang-' + boxlangVersion + '.jar' )
//}
// PDF Extraction
implementation 'org.apache.pdfbox:pdfbox:3.0.7'
// JSoup for HTML parsing and web scraping
implementation 'org.jsoup:jsoup:1.22.1'
// RSS Reader for feed parsing
implementation 'com.apptasticsoftware:rssreader:3.12.0'
// Testing Frameworks
testImplementation 'io.github.cdimascio:dotenv-java:3.2.0'
testImplementation "org.junit.jupiter:junit-jupiter:6.+"
testImplementation "org.mockito:mockito-core:5.+"
testImplementation "com.google.truth:truth:1.+"
// Explicitly declare the JUnit platform launcher (to avoid deprecation)
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
}
java {
// Replaces sourceCompatibility, targetCompatibility
toolchain {
languageVersion.set( JavaLanguageVersion.of( jdkVersion ) )
}
// Produces a javadocs jar
withJavadocJar()
}
// Exclude main resources from IDE classpath to avoid class loading conflicts
// Resources are still included in the JAR/build outputs
sourceSets {
main {
resources {
// Empty the resources to exclude from IDE classpath
srcDirs = []
}
}
}
compileJava {
// Compiler Options
options.incremental = true
options.encoding = 'UTF-8'
options.debugOptions.debugLevel = "source,lines,vars"
}
compileTestJava{
// Make sure the service loaders are created before testing
dependsOn compileJava, serviceLoaderBuild
}
compileTestJava.finalizedBy( shadowJar )
/**
* Clean up
*/
clean {
doLast{
var userDir = file( "${System.getProperty('user.home')}/.boxlang/classes" )
if ( userDir.exists() ) {
userDir.deleteDir()
println "+ Cleared user home classes " + userDir.toString()
}
println "+ Clean finalized!"
}
}
javadoc {
// To avoid our own doclet issues
options.addBooleanOption( "Xdoclint:none", true )
//exclude '**/boxlang/parser/**'
options.addBooleanOption( 'html5', true )
}
task zipJavadocs( type: Zip ) {
group = "documentation"
from javadoc.destinationDir
archiveFileName = "${project.name}-javadocs-${version}.zip"
destinationDirectory = file( "$buildDir/distributions" )
// Output that the docs have been zippped
doLast {
println "+ Javadocs have been zipped to the distribution folder"
}
}
javadoc.finalizedBy( zipJavadocs )
/**
* Docs are here:
* - https://github.com/harbby/gradle-serviceloader,
* - https://plugins.gradle.org/plugin/com.github.harbby.gradle.serviceloader
* This generates the META-INF/services files for the ServiceLoader as part of the `build` task
*/
serviceLoader {
serviceInterface 'ortus.boxlang.runtime.jdbc.drivers.IJDBCDriver'
serviceInterface 'ortus.boxlang.runtime.bifs.BIF'
serviceInterface 'ortus.boxlang.runtime.components.Component'
serviceInterface 'ortus.boxlang.runtime.async.tasks.IScheduler'
serviceInterface 'ortus.boxlang.runtime.cache.providers.ICacheProvider'
serviceInterface 'ortus.boxlang.runtime.events.IInterceptor'
serviceInterface 'ortus.boxlang.runtime.services.IService'
}
jar {
archiveVersion = "${version}"
manifest {
attributes 'Description': 'ExampleBoxLangModule'
}
}
shadowJar {
archiveClassifier = ''
mergeServiceFiles()
destinationDirectory = file( "build/libs" )
// Minimize the JAR by only including classes that are actually used
// This significantly reduces the size by excluding unused PDFBox classes
minimize {
// Keep JSoup classes (used by WebCrawlerLoader)
exclude( dependency( 'org.jsoup:.*' ) )
// Keep RSS Reader classes (used by FeedLoader)
exclude( dependency( 'com.apptasticsoftware:.*' ) )
// Keep PDFBox classes (used by PDFLoader.bx - BoxLang files aren't analyzed by bytecode scanner)
exclude( dependency( 'org.apache.pdfbox:.*' ) )
// Keep FontBox classes (required by PDFBox for text extraction)
exclude( dependency( 'org.apache.fontbox:.*' ) )
}
}
/**
* Source Code Formatting
*/
spotless {
java {
target fileTree( "." ) {
include "**/*.java"
exclude "**/build/**", "bin/**", "examples/**"
}
eclipse().configFile( "./.ortus-java-style.xml" )
toggleOffOn()
}
}
/**
* Custom task that creates a build/module folders
* - Copies the build/libs/BoxLangModuleTemplate-1.0.0.jar to build/module/libs/BoxLangModuleTemplate-1.0.0.jar
* - Copies the src/main/bx/** to build/module/ folder.
*/
task createModuleStructure(type: Copy) {
mustRunAfter shadowJar, jar
from( 'build/libs' ) {
include "${project.name}-${version}.jar"
into 'libs'
}
from( 'src/main/bx' ) {
include '**/*.bx'
include '**/*.bxm'
include '**/*.bxs'
// Token Replacements Go Here
filter{ line -> line.replaceAll( '@build.version@', project.version ) }
if( project.branch == "development" ){
filter{ line -> line.replaceAll( '\\+@build.number@', '' ) }
} else {
filter{ line -> line.replaceAll( '@build.number@', project.buildID ) }
}
}
from( '.' ) {
include 'box.json'
include 'readme.md'
include 'changelog.md'
// Token Replacements Go Here
filter{ line -> line.replaceAll( '@build.version@', project.version ) }
if( project.branch == "development" ){
filter{ line -> line.replaceAll( '\\+@build.number@', '' ) }
} else {
filter{ line -> line.replaceAll( '@build.number@', project.buildID ) }
}
}
from( 'docs' ) {
include '**/*.md'
into 'docs'
}
destinationDir = file( 'build/module' )
}
task zipModuleStructure( type: Zip ) {
group = "distribution"
from createModuleStructure.destinationDir
archiveFileName = "${project.name}-${version}.zip"
destinationDirectory = file( "$buildDir/distributions" )
// Output that the module has been zippped
doLast {
println "+ Module has been zipped to the distribution folder"
}
}
createModuleStructure.finalizedBy( zipModuleStructure )
shadowJar.finalizedBy( createModuleStructure )
test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
events "passed", "skipped", "failed"
exceptionFormat "full"
showExceptions true
showCauses true
}
classpath = classpath.filter { !it.path.contains( "build${File.separator}resources" ) }
}
/**
* Task to download the latest jar from https://ortus-temp.s3.amazonaws.com/jericho/libs/boxlang-1.0.0.jar
*/
task downloadBoxLang( type: Download ) {
// Create the destination directory
doFirst {
file( "src/test/resources/libs" ).mkdirs()
}
// Configure the URL of the file to download
src "https://downloads.ortussolutions.com/ortussolutions/boxlang/${boxlangVersion}/boxlang-${boxlangVersion}.jar"
// Specify the destination directory for the downloaded file
dest "src/test/resources/libs/boxlang-${boxlangVersion}.jar"
overwrite true
onlyIfModified false
}
/**
* Task to download and extract the needed boxlang modules for testing.
*/
task downloadBoxLangModules( type: Download ) {
// Create the destination directory
doFirst {
def modulesDir = file( "src/test/resources/modules" )
// Delete the directory recursively first if it exists
if ( modulesDir.exists() ) {
modulesDir.deleteDir()
}
// Recreate it
modulesDir.mkdirs()
}
// Download the test dependencies
src( [
"https://downloads.ortussolutions.com/ortussolutions/boxlang-modules/bx-derby/${derbyModuleVersion}/bx-derby-${derbyModuleVersion}.zip",
"https://downloads.ortussolutions.com/ortussolutions/boxlang-modules/bx-postgresql/${postgresqlModuleVersion}/bx-postgresql-${postgresqlModuleVersion}.zip",
"https://downloads.ortussolutions.com/ortussolutions/boxlang-modules/bx-sqlite/${sqliteModuleVersion}/bx-sqlite-${sqliteModuleVersion}.zip",
"https://downloads.ortussolutions.com/ortussolutions/boxlang-modules/bx-mysql/${mysqlModuleVersion}/bx-mysql-${mysqlModuleVersion}.zip",
"https://downloads.ortussolutions.com/ortussolutions/boxlang-modules/bx-web-support/${webSupportVersion}/bx-web-support-${webSupportVersion}.zip"
] )
// Specify the destination for the downloaded file
dest "src/test/resources/modules/"
overwrite true
onlyIfModified false
}
task extractBoxLangModules( type: Copy ) {
dependsOn downloadBoxLangModules
from( zipTree( "src/test/resources/modules/bx-derby-${derbyModuleVersion}.zip" ) ) {
into "bx-derby"
}
from( zipTree( "src/test/resources/modules/bx-postgresql-${postgresqlModuleVersion}.zip" ) ) {
into "bx-postgresql"
}
from( zipTree( "src/test/resources/modules/bx-sqlite-${sqliteModuleVersion}.zip" ) ) {
into "bx-sqlite"
}
from( zipTree( "src/test/resources/modules/bx-mysql-${mysqlModuleVersion}.zip" ) ) {
into "bx-mysql"
}
from( zipTree( "src/test/resources/modules/bx-web-support-${webSupportVersion}.zip" ) ) {
into "bx-web-support"
}
destinationDir = file( "src/test/resources/modules" )
}
// Make sure test depends on Derby module extraction
downloadBoxLang.finalizedBy( extractBoxLangModules )
/**
* Project Wide Helper function
* This is not a task, but a reusable UDF
*/
project.ext.bumpVersion = { boolean major = false, boolean minor = false, boolean patch = false ->
def propertiesFile = file( './gradle.properties' );
def properties = new Properties();
properties.load( propertiesFile.newDataInputStream() )
def versionTarget = major ? 0 : minor ? 1 : 2
def currentVersion = properties.getProperty( 'version' )
def versionParts = currentVersion.split( '\\.' )
def newPathVersion = versionParts[ versionTarget ].toInteger() + 1
def newVersion = '';
if( patch ){
newVersion = "${versionParts[ 0 ]}.${versionParts[ 1 ]}.${newPathVersion}"
} else if( minor ){
newVersion = "${versionParts[ 0 ]}.${newPathVersion}.0"
} else if( major ){
newVersion = "${newPathVersion}.0.0"
}
properties.setProperty( 'version', newVersion )
properties.store( propertiesFile.newWriter(), null )
println "Bumped version from ${currentVersion} to ${newVersion}"
}
/**
* Bump the major version number
*/
task bumpMajorVersion {
doLast{
bumpVersion( true )
}
}
/**
* Bump the minor version number
*/
task bumpMinorVersion {
doLast{
bumpVersion( false, true )
}
}
/**
* Bump the patch version number
*/
task bumpPatchVersion {
doLast{
bumpVersion( false, false, true )
}
}