-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathbuild.gradle
More file actions
1643 lines (1483 loc) · 54.5 KB
/
Copy pathbuild.gradle
File metadata and controls
1643 lines (1483 loc) · 54.5 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
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import org.apache.tools.ant.filters.ReplaceTokens
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.text.SimpleDateFormat
import java.lang.management.ManagementFactory
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_packaging
plugins {
id "java"
// Apply the application plugin to add support for building a CLI application in Java.
// This produces the distributions and scripts for any OS
id "application"
id 'antlr'
// For source code formatting
id "com.diffplug.spotless" version "8.6.0"
// Shadow
id "com.gradleup.shadow" version "9.2.2"
// For dependency updates
id 'com.github.ben-manes.versions' version '0.54.0'
// For building service loader files
id "com.github.harbby.gradle.serviceloader" version "1.1.9"
// Maven Publisher
id 'maven-publish'
id 'signing'
id 'com.gradleup.nmcp.aggregation' version "1.4.4"
// Download task
id "de.undercouch.download" version "5.7.0"
}
/**
* Project Properties
*/
group = 'ortus.boxlang'
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".toString()
}
/**
* ANTLR Properties
*/
def antlrGeneratedParserPackage = "ortus.boxlang.parser.antlr"
def generatedSrcDir = "build/generated-src"
def antlrGeneratedParserBaseDir = "$generatedSrcDir/antlr/main"
def antlrGeneratedParserPackageDir = antlrGeneratedParserPackage.replaceAll("\\.", "/")
def antlrGrammarDir = "src/main/antlr"
java {
sourceCompatibility = JavaVersion.toVersion( jdkVersion )
targetCompatibility = JavaVersion.toVersion( jdkVersion )
withJavadocJar()
withSourcesJar()
}
sourceSets {
main {
java {
// Normal java sources + Antlr generated sources
srcDirs += [ "$antlrGeneratedParserBaseDir" ]
}
resources {
srcDirs = [ 'src/main/resources' ]
include '**/*.md'
include '**/*.xml'
include '**/*.properties'
include '**/*.class'
include '**/*.jar'
include '**/*.json'
include '**/*.bx*'
include '**/*.css'
include '**/*.js'
include '**/*.cf*'
include '**/META-INF/services/*'
}
}
test {
java {
srcDirs = [ 'src/test/java' ]
}
}
}
/**
* Repositories for dependencies in order
*/
repositories {
mavenLocal()
mavenCentral()
}
/**
* Project Dependencies
*/
dependencies {
// Testing Dependencies
testImplementation "org.junit.jupiter:junit-jupiter:6.0.3"
testImplementation "org.mockito:mockito-core:5.+"
testImplementation "com.google.truth:truth:1.+"
testImplementation "commons-cli:commons-cli:1.11.0"
testImplementation "org.wiremock:wiremock:3.13.2"
testImplementation 'org.apache.derby:derby:10.17.1.0'
testImplementation 'io.undertow:undertow-core:2.4.1.Final'
testImplementation 'org.bouncycastle:bcpkix-jdk18on:1.84'
// Explicitly declare the JUnit platform launcher (to avoid deprecation)
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
// Uncomment for MiniServer testing
//implementation files( '../boxlang-miniserver/build/distributions/boxlang-miniserver-1.10.0-snapshot.jar' )
// Antlr
antlr "org.antlr:antlr4:$antlrVersion"
// Uncomment if using ANTLR GUI debugger
//implementation "org.antlr:antlr4-runtime:$antlrVersion"
// Implementation Dependencies
// https://mvnrepository.com/artifact/commons-io/commons-io
implementation "commons-io:commons-io:2.22.0"
// https://mvnrepository.com/artifact/com.github.javaparser/javaparser-symbol-solver-core
implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.27.1'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation 'org.apache.commons:commons-lang3:3.20.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-text
// Many of these classes ( e.g. StringEscapeUtils ) are currently deprecated in commons-lang and others will be moved in the future
implementation 'org.apache.commons:commons-text:1.15.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-cli
implementation "commons-cli:commons-cli:1.11.0"
// https://mvnrepository.com/artifact/com.fasterxml.jackson.jr/jackson-jr-objects
implementation 'com.fasterxml.jackson.jr:jackson-jr-objects:2.21.4'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.jr/jackson-jr-extension-javatime
implementation 'com.fasterxml.jackson.jr:jackson-jr-extension-javatime:2.21.4'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.jr/jackson-jr-stree
implementation 'com.fasterxml.jackson.jr:jackson-jr-stree:2.21.4'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.jr/jackson-jr-annotation-support
implementation 'com.fasterxml.jackson.jr:jackson-jr-annotation-support:2.21.4'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
implementation 'org.slf4j:slf4j-api:2.0.18'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
implementation 'ch.qos.logback:logback-classic:1.5.32'
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
implementation 'com.zaxxer:HikariCP:6.3.0'
// https://mvnrepository.com/artifact/org.ow2.asm/asm-tree
implementation 'org.ow2.asm:asm-tree:9.9.1'
// https://mvnrepository.com/artifact/org.ow2.asm/asm-util
implementation 'org.ow2.asm:asm-util:9.9.1'
// https://mvnrepository.com/artifact/org.ow2.asm/asm-commons
implementation 'org.ow2.asm:asm-commons:9.9.1'
// https://mvnrepository.com/artifact/org.semver4j/semver4j
implementation 'org.semver4j:semver4j:6.0.0'
// Compile Only Dependencies
// Java Annotations Checks, this are for compile documentation only. It's not included in the final build
compileOnly 'org.checkerframework:checker-qual:3.54.0'
}
/**
* 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,
boolean beta = false,
boolean rc = false,
property = "version" ->
def propertiesFile = file( './gradle.properties' );
def properties = new Properties();
properties.load( propertiesFile.newDataInputStream() )
def versionTarget = major ? 0 : minor ? 1 : beta ? 2 : 3
def currentVersion = properties.getProperty( property )
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"
} else if( beta ){
// Get's the -betaX version.
def betaString = currentVersion.split( '-' )[ 1 ]
// Now we get the beta number
def betaNumber = betaString.split( 'beta' )[ 1 ].toInteger() + 1
newVersion = currentVersion.split( '-' )[ 0 ] + "-beta${betaNumber}"
} else if( rc ){
newVersion = "${versionParts[ 0 ]}.${versionParts[ 1 ]}.${versionParts[ 2 ]}.${newPathVersion}"
}
properties.setProperty( property, newVersion )
properties.store( propertiesFile.newWriter(), null )
println "Bumped version from ${currentVersion} to ${newVersion}"
}
/**
* Application Build
* https://docs.gradle.org/current/userguide/application_plugin.html
*/
application {
// We use full because it's not shadowed. It can be used for debugging or other packaging purposes
applicationName = "boxlang"
mainClass = "ortus.boxlang.runtime.BoxRunner"
}
/**
* This task processes resources to inject build metadata into version.properties
*/
processResources {
dependsOn compileJava
// Always run this task
outputs.upToDateWhen { false }
// Replace @build.date@ with the current date in META-INF/version.properties file
filter( ReplaceTokens, tokens: [ 'build.date': new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format( new Date() ) ] )
// Replace @build.version@ with the current version in META-INF/version.properties file
filter( ReplaceTokens, tokens: [ 'build.version': version + "+" + buildID ] )
doLast {
// Replace @build.bytecode.version@ after resources are copied
def versionFile = file("$buildDir/resources/main/META-INF/boxlang/version.properties")
if (versionFile.exists()) {
def loader = new URLClassLoader([file("$buildDir/classes/java/main").toURI().toURL()] as URL[])
def iBoxpilerClass = loader.loadClass('ortus.boxlang.compiler.IBoxpiler')
def bytecodeVersion = iBoxpilerClass.BYTECODE_VERSION.toString()
def content = versionFile.text
content = content.replace('@build.bytecode.version@', bytecodeVersion)
versionFile.text = content
}
}
}
/**
* ================================================================================
* JAR Build Configuration
* ================================================================================
*
* BoxLang produces 4 different JAR artifacts:
*
* 1. boxlang-{version}.jar (shadowJar)
* - Main distribution with Runtime + ASMBoxpiler + NoOpBoxpiler
* - Excludes: JavaBoxpiler and JavaParser dependencies
* - Service file: Lists ASMBoxpiler and NoOpBoxpiler
*
* 2. boxlang-noop-{version}.jar (shadowJarNoop)
* - Minimal runtime with NoOpBoxpiler ONLY
* - Excludes: Both ASMBoxpiler and JavaBoxpiler
* - Purpose: Pre-compiled deployments or custom classpath scenarios
* - Service file: Lists NoOpBoxpiler only
*
* 3. boxlang-compiler-java-{version}.jar (jarJavaCompiler)
* - JavaBoxpiler + JavaParser dependencies ONLY
* - Add-on JAR to combine with boxlang.jar or boxlang-noop.jar
* - Service file: Lists JavaBoxpiler only
*
* 4. boxlang-compiler-asm-{version}.jar (jarAsmCompiler)
* - ASMBoxpiler ONLY (ASM library remains in core runtime)
* - Add-on JAR to combine with boxlang-noop.jar if needed
* - Service file: Lists ASMBoxpiler only
*
* https://imperceptiblethoughts.com/shadow/configuration/
* ================================================================================
*/
jar {
archiveBaseName = 'boxlang'
archiveVersion = "${version}"
/**
* The manifest for the shadowJar task is configured to inherit from the manifest of the standard jar task.
*/
manifest {
attributes 'Main-Class': 'ortus.boxlang.runtime.BoxRunner'
attributes 'Description': 'This is the Ortus BoxLang OS Distribution'
attributes 'Implementation-Version': "${version}+${buildID}"
attributes 'Created-On': new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format( new Date() )
attributes 'Created-By': "Ortus Solutions, Corp"
}
// Exclude the following directories from the final built JAR
exclude '**/ortus/boxlang/tools/**'
}
// This is needed so gradle can find the shadowJar tasks
tasks.named( "startScripts" ) {
dependsOn tasks.named( "shadowJar" )
}
tasks.named( "startShadowScripts" ) {
dependsOn tasks.named( "jar" )
}
/**
* Customize BoxLang startup scripts to support .env file loading
*/
startShadowScripts {
doLast {
// Customize the Unix script
def unixScript = file("${buildDir}/scriptsShadow/boxlang")
customizeUnixScript(unixScript)
// Customize the Windows script
def windowsScript = file("${buildDir}/scriptsShadow/boxlang.bat")
customizeWindowsScript(windowsScript)
logger.info("+ BoxLang startup scripts customized with .env support")
}
}
/**
* Add .env file loading support to Unix script with --envfile argument support.
* Also injects AppCDS -Xshare:on flag when boxlang.jsa is present alongside the JAR.
*/
ext.customizeUnixScript = { File scriptFile ->
def content = scriptFile.text
def envLoaderScript = file('workbench/scripts/env-loader.sh').text
def envLoadingInvocation = """
######################################
# Load environment variables from .env file
######################################
# Source the env-loader script inline (to preserve environment variables)
${envLoaderScript}
# Update arguments to filtered args (without --envfile)
set -- \$FILTERED_ARGS
######################################
# End .env loading
######################################
"""
// AppCDS: auto-generate a class-data archive on first run into ~/.boxlang/cache/
// and activate it on subsequent runs. No .jsa is shipped in the distribution —
// it is created once per BoxLang version on the user's machine.
def appCdsSnippet = '''
######################################
# AppCDS: auto-generate and cache a class-data archive for faster startup
######################################
BL_JAR=$(ls "$APP_HOME/lib"/boxlang-[0-9]*.jar 2>/dev/null | head -1)
if [ -n "$BL_JAR" ]; then
BL_VER=$(basename "$BL_JAR" .jar | sed 's/^boxlang-//')
# Resolve BoxLang home: BOXLANG_HOME env > --bx-home arg > user home
if [ -n "$BOXLANG_HOME" ]; then
BL_HOME_DIR="$BOXLANG_HOME"
else
BL_HOME_DIR=""
_BL_PREV_HOME=0
for _bl_arg in "$@"; do
if [ "$_BL_PREV_HOME" = "1" ]; then
BL_HOME_DIR="$_bl_arg"
break
fi
if [ "$_bl_arg" = "--bx-home" ]; then
_BL_PREV_HOME=1
fi
done
if [ -z "$BL_HOME_DIR" ]; then
BL_HOME_DIR="$HOME/.boxlang"
fi
fi
BL_JSA_DIR="$BL_HOME_DIR/cache"
BL_JSA="$BL_JSA_DIR/boxlang-$BL_VER.jsa"
BL_JAVA="${JAVA_HOME:+$JAVA_HOME/bin/java}"
BL_JAVA="${BL_JAVA:-java}"
if [ ! -f "$BL_JSA" ] && command -v "$BL_JAVA" > /dev/null 2>&1; then
mkdir -p "$BL_JSA_DIR"
BL_CLASSLIST="$BL_JSA_DIR/boxlang-$BL_VER.classlist"
"$BL_JAVA" -XX:DumpLoadedClassList="$BL_CLASSLIST" -cp "$BL_JAR" ortus.boxlang.runtime.BoxRunner --version > /dev/null 2>&1
"$BL_JAVA" -Xshare:dump -XX:SharedClassListFile="$BL_CLASSLIST" -XX:SharedArchiveFile="$BL_JSA.tmp" -cp "$BL_JAR" ortus.boxlang.runtime.BoxRunner > /dev/null 2>&1 && mv "$BL_JSA.tmp" "$BL_JSA"
rm -f "$BL_CLASSLIST" "$BL_JSA.tmp"
fi
if [ -f "$BL_JSA" ]; then
JAVA_OPTS="$JAVA_OPTS -XX:TieredStopAtLevel=1 -Xshare:auto \"-XX:SharedArchiveFile=$BL_JSA\""
fi
fi
######################################
# End AppCDS
######################################
'''
// Insert env-loader and AppCDS together before the JVM detection line.
content = content.replace(
'# Determine the Java command to use to start the JVM.',
appCdsSnippet + envLoadingInvocation + '# Determine the Java command to use to start the JVM.'
)
scriptFile.text = content
scriptFile.setExecutable(true, false)
}
/**
* Add .env file loading support to Windows script with --envfile argument support.
* Also injects AppCDS -Xshare:on flag when boxlang.jsa is present alongside the JAR.
*/
ext.customizeWindowsScript = { File scriptFile ->
def content = scriptFile.text
def envLoaderScript = file('workbench/scripts/env-loader.bat').text
// Enable delayed expansion at the beginning of the script (needed for !variable! syntax)
if (!content.contains('@setlocal enabledelayedexpansion')) {
content = content.replaceFirst(
'(@echo off)',
'$1\r\n@setlocal enabledelayedexpansion'
)
}
// Inject AppCDS JVM flags for Windows: auto-generate into %USERPROFILE%\.boxlang\cache on first run.
def appCdsSnippet = '@rem ######################################\r\n' +
'@rem AppCDS: auto-generate and cache a class-data archive for faster startup\r\n' +
'@rem ######################################\r\n' +
'if defined BOXLANG_HOME (\r\n' +
' set "BL_HOME_DIR=%BOXLANG_HOME%"\r\n' +
') else (\r\n' +
' set "BL_HOME_DIR="\r\n' +
' set "_BL_PREV_HOME=0"\r\n' +
' for %%A in (%*) do (\r\n' +
' if "!_BL_PREV_HOME!"=="1" (\r\n' +
' set "BL_HOME_DIR=%%~A"\r\n' +
' set "_BL_PREV_HOME=0"\r\n' +
' ) else if "%%~A"=="--bx-home" (\r\n' +
' set "_BL_PREV_HOME=1"\r\n' +
' )\r\n' +
' )\r\n' +
' if not defined BL_HOME_DIR set "BL_HOME_DIR=%USERPROFILE%\\.boxlang"\r\n' +
')\r\n' +
'set "BL_JSA_DIR=!BL_HOME_DIR!\\cache"\r\n' +
'for %%F in ("%APP_HOME%\\lib\\boxlang-[0-9]*.jar") do set "BL_JAR=%%~fF" & set "BL_JARNAME=%%~nF"\r\n' +
'if defined BL_JAR (\r\n' +
' set "BL_VER=!BL_JARNAME:boxlang-=!"\r\n' +
' set "BL_JSA=!BL_JSA_DIR!\\boxlang-!BL_VER!.jsa"\r\n' +
' if defined JAVA_HOME (set "BL_JAVA=%JAVA_HOME%\\bin\\java.exe") else (set "BL_JAVA=java.exe")\r\n' +
' if not exist "!BL_JSA!" (\r\n' +
' if not exist "!BL_JSA_DIR!" mkdir "!BL_JSA_DIR!"\r\n' +
' set "BL_CLASSLIST=!BL_JSA_DIR!\\boxlang-!BL_VER!.classlist"\r\n' +
' "!BL_JAVA!" -XX:DumpLoadedClassList="!BL_CLASSLIST!" -cp "%BL_JAR%" ortus.boxlang.runtime.BoxRunner --version >nul 2>&1\r\n' +
' "!BL_JAVA!" -Xshare:dump -XX:SharedClassListFile="!BL_CLASSLIST!" -XX:SharedArchiveFile="!BL_JSA!" -cp "%BL_JAR%" ortus.boxlang.runtime.BoxRunner >nul 2>&1\r\n' +
' del "!BL_CLASSLIST!" >nul 2>&1\r\n' +
' )\r\n' +
' if exist "!BL_JSA!" (\r\n' +
' set JAVA_OPTS=!JAVA_OPTS! -XX:TieredStopAtLevel=1 -Xshare:auto "-XX:SharedArchiveFile=!BL_JSA!"\r\n' +
' )\r\n' +
')\r\n' +
'@rem ######################################\r\n' +
'@rem End AppCDS\r\n' +
'@rem ######################################\r\n\r\n'
// Insert the env loading code before "Setup the command line"
def envLoadingInvocation = """
@rem ######################################
@rem Load environment variables from .env file
@rem ######################################
${envLoaderScript}
@rem Update CMD_LINE_ARGS with filtered arguments
set "CMD_LINE_ARGS_TEMP=%FILTERED_ARGS%"
@rem ######################################
@rem End .env loading
@rem ######################################
"""
// Insert both blocks together: AppCDS first, then env-loader, both before "Setup the command line"
content = content.replace(
'@rem Setup the command line',
appCdsSnippet + envLoadingInvocation + '@rem Setup the command line'
)
// Replace CMD_LINE_ARGS with filtered arguments after it's set
content = content.replaceFirst(
/(set CMD_LINE_ARGS=%\*)/,
'$1\r\nif defined CMD_LINE_ARGS_TEMP set CMD_LINE_ARGS=%CMD_LINE_ARGS_TEMP%'
)
scriptFile.text = content
}
/**
* Main BoxLang Distribution JAR
* Includes: Runtime + ASMBoxpiler + NoOpBoxpiler
* Excludes: JavaBoxpiler and JavaParser dependencies
*/
shadowJar {
archiveBaseName = "boxlang"
archiveClassifier = ""
mergeServiceFiles()
// Antlr unnecessary files
exclude "com/ibm/icu/**"
exclude 'ortus/boxlang/tools/**'
exclude 'ortus/boxlang/runtime/testing/**'
// Exclude JavaBoxpiler and its dependencies
exclude 'ortus/boxlang/compiler/javaboxpiler/**'
exclude 'com/github/javaparser/**'
exclude 'org/javassist/**'
exclude 'com/google/**'
exclude 'org/checkerframework/**'
minimize{
exclude( dependency( "org.slf4j:.*:.*" ) )
exclude( dependency( "ch.qos.logback:.*:.*" ) )
exclude( dependency( "com.zaxxer:.*:.*" ) )
exclude( dependency( "com.fasterxml.jackson.jr:.*:.*" ) )
}
}
/**
* NoOp-Only BoxLang JAR
* Includes: Runtime + NoOpBoxpiler ONLY
* Excludes: ASMBoxpiler, JavaBoxpiler, ASM library (except what runtime needs), JavaParser
* Purpose: Minimal runtime for pre-compiled deployments
*/
task shadowJarNoop( type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar ) {
dependsOn classes
archiveBaseName = "boxlang-noop"
archiveClassifier = ""
archiveVersion = "${version}"
from sourceSets.main.output
configurations = [project.configurations.runtimeClasspath]
// Don't use mergeServiceFiles() - we'll provide a custom one
exclude 'META-INF/services/ortus.boxlang.compiler.IBoxpiler'
// Exclude unnecessary files
exclude "com/ibm/icu/**"
exclude 'ortus/boxlang/tools/**'
exclude 'ortus/boxlang/runtime/testing/**'
// Exclude both compiler implementations
exclude 'ortus/boxlang/compiler/asmboxpiler/**'
exclude 'ortus/boxlang/compiler/javaboxpiler/**'
// Exclude compiler dependencies
exclude 'com/github/javaparser/**'
exclude 'org/javassist/**'
exclude 'com/google/**'
exclude 'org/checkerframework/**'
// Note: We keep ASM in runtime as it's used for bytecode manipulation beyond compilation
manifest {
attributes 'Main-Class': 'ortus.boxlang.runtime.BoxRunner'
attributes 'Description': 'BoxLang NoOp Runtime (Pre-compiled Classes Only)'
attributes 'Implementation-Version': "${version}+${buildID}"
attributes 'Created-On': new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
attributes 'Created-By': "Ortus Solutions, Corp"
}
minimize{
exclude( dependency( "org.slf4j:.*:.*" ) )
exclude( dependency( "ch.qos.logback:.*:.*" ) )
exclude( dependency( "com.zaxxer:.*:.*" ) )
exclude( dependency( "com.fasterxml.jackson.jr:.*:.*" ) )
}
// Add custom service file with only NoOpBoxpiler
from(file("$buildDir/tmp/shadowJarNoop-services")) {
into('META-INF')
}
doFirst {
// Create custom service file before JAR is built
def servicesDir = file("$buildDir/tmp/shadowJarNoop-services/services")
servicesDir.mkdirs()
def serviceFile = file("$buildDir/tmp/shadowJarNoop-services/services/ortus.boxlang.compiler.IBoxpiler")
serviceFile.text = 'ortus.boxlang.compiler.NoOpBoxpiler\n'
}
}
/**
* Java Compiler Add-on JAR
* Includes: JavaBoxpiler + JavaParser dependencies ONLY
* Excludes: Runtime, ASMBoxpiler, NoOpBoxpiler
* Purpose: Add-on to combine with boxlang.jar or boxlang-noop.jar
*/
task jarJavaCompiler(type: Jar) {
dependsOn classes
archiveBaseName = "boxlang-compiler-java"
archiveClassifier = ""
archiveVersion = "${version}"
from(sourceSets.main.output) {
include 'ortus/boxlang/compiler/javaboxpiler/**'
}
// Include JavaParser dependencies
from {
configurations.runtimeClasspath.findAll {
it.name.contains('javaparser') ||
it.name.contains('javassist') ||
it.name.contains('checker-qual')
}.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes 'Description': 'BoxLang Java Compiler Add-on'
attributes 'Implementation-Version': "${version}+${buildID}"
attributes 'Created-On': new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
attributes 'Created-By': "Ortus Solutions, Corp"
}
doLast {
// Create service file for Java compiler
def servicesDir = file("$buildDir/tmp/jarJavaCompiler/META-INF/services")
servicesDir.mkdirs()
def serviceFile = file("$buildDir/tmp/jarJavaCompiler/META-INF/services/ortus.boxlang.compiler.IBoxpiler")
serviceFile.text = 'ortus.boxlang.compiler.javaboxpiler.JavaBoxpiler\n'
// Add service file to the JAR
ant.jar(update: true, destfile: archiveFile.get().asFile.absolutePath) {
zipfileset(dir: "$buildDir/tmp/jarJavaCompiler/META-INF", prefix: "META-INF")
}
}
}
/**
* ASM Compiler Add-on JAR
* Includes: ASMBoxpiler ONLY
* Excludes: Runtime, JavaBoxpiler, NoOpBoxpiler, ASM library (it's in core)
* Purpose: Add-on to combine with boxlang-noop.jar
*/
task jarAsmCompiler(type: Jar) {
dependsOn classes
archiveBaseName = "boxlang-compiler-asm"
archiveClassifier = ""
archiveVersion = "${version}"
from(sourceSets.main.output) {
include 'ortus/boxlang/compiler/asmboxpiler/**'
}
manifest {
attributes 'Description': 'BoxLang ASM Compiler Add-on'
attributes 'Implementation-Version': "${version}+${buildID}"
attributes 'Created-On': new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
attributes 'Created-By': "Ortus Solutions, Corp"
}
doLast {
// Create service file for ASM compiler
def servicesDir = file("$buildDir/tmp/jarAsmCompiler/META-INF/services")
servicesDir.mkdirs()
def serviceFile = file("$buildDir/tmp/jarAsmCompiler/META-INF/services/ortus.boxlang.compiler.IBoxpiler")
serviceFile.text = 'ortus.boxlang.compiler.asmboxpiler.ASMBoxpiler\n'
// Add service file to the JAR
ant.jar(update: true, destfile: archiveFile.get().asFile.absolutePath) {
zipfileset(dir: "$buildDir/tmp/jarAsmCompiler/META-INF", prefix: "META-INF")
}
}
}
/**
* ================================================================================
* Javadoc and Sources JARs for Compiler Artifacts
* These are required for Maven Central publication
* ================================================================================
*/
/**
* Javadoc JAR for Java Compiler
*/
task javadocJarJavaCompiler(type: Jar) {
dependsOn javadoc
archiveBaseName = "boxlang-compiler-java"
archiveClassifier = "javadoc"
archiveVersion = "${version}"
from javadoc.destinationDir
}
/**
* Sources JAR for Java Compiler
*/
task sourcesJarJavaCompiler(type: Jar) {
dependsOn generateGrammarSource, generateTestGrammarSource
archiveBaseName = "boxlang-compiler-java"
archiveClassifier = "sources"
archiveVersion = "${version}"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(sourceSets.main.allSource) {
include 'ortus/boxlang/compiler/javaboxpiler/**'
}
}
/**
* Javadoc JAR for ASM Compiler
*/
task javadocJarAsmCompiler(type: Jar) {
dependsOn javadoc
archiveBaseName = "boxlang-compiler-asm"
archiveClassifier = "javadoc"
archiveVersion = "${version}"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from javadoc.destinationDir
}
/**
* Sources JAR for ASM Compiler
*/
task sourcesJarAsmCompiler(type: Jar) {
dependsOn generateGrammarSource, generateTestGrammarSource
archiveBaseName = "boxlang-compiler-asm"
archiveClassifier = "sources"
archiveVersion = "${version}"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(sourceSets.main.allSource) {
include 'ortus/boxlang/compiler/asmboxpiler/**'
}
}
/**
* Javadoc JAR for NoOp Runtime
*/
task javadocJarNoop(type: Jar) {
dependsOn javadoc
archiveBaseName = "boxlang-noop"
archiveClassifier = "javadoc"
archiveVersion = "${version}"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from javadoc.destinationDir
}
/**
* Sources JAR for NoOp Runtime
*/
task sourcesJarNoop(type: Jar) {
dependsOn generateGrammarSource, generateTestGrammarSource
archiveBaseName = "boxlang-noop"
archiveClassifier = "sources"
archiveVersion = "${version}"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(sourceSets.main.allSource) {
// Include all sources except compiler-specific packages
exclude 'ortus/boxlang/compiler/javaboxpiler/**'
exclude 'ortus/boxlang/compiler/asmboxpiler/**'
}
}
/**
* Cleanup final artifacts, we only want the shadow artifacts
*/
tasks.distZip.setEnabled( false )
tasks.distTar.setEnabled( false )
tasks.shadowDistTar.setEnabled( false )
tasks.shadowDistZip.setEnabled( false )
/**
* ================================================================================
* AppCDS (Application Class-Data Sharing)
*
* Two tasks that together build a .jsa class-data archive:
*
* 1. generateCdsClassList — Runs BoxLang briefly with -XX:DumpLoadedClassList
* to record every class touched during startup.
*
* 2. generateCdsArchive — Consumes the class list and produces boxlang.jsa,
* a memory-mapped binary the JVM can share across processes at startup.
*
* The archive is included in the distribution ZIP and the launch scripts are
* updated to use -Xshare:on when the archive is present.
*
* To regenerate manually:
* ./gradlew generateCdsArchive
* ================================================================================
*/
def cdsDir = file( "${buildDir}/appcds" )
def cdsClassList = file( "${cdsDir}/boxlang.classlist" )
def cdsArchive = file( "${cdsDir}/boxlang.jsa" )
task generateCdsClassList( type: JavaExec ) {
dependsOn shadowJar
group = 'AppCDS'
description = 'Runs BoxLang with -XX:DumpLoadedClassList to record startup classes for AppCDS.'
inputs.file shadowJar.archiveFile
outputs.file cdsClassList
classpath = files( shadowJar.archiveFile )
mainClass = 'ortus.boxlang.runtime.BoxRunner'
args = [ '--version' ]
ignoreExitValue = true
doFirst {
cdsDir.mkdirs()
logger.lifecycle( "+ Generating AppCDS class list from ${shadowJar.archiveFile.get().asFile}" )
jvmArgs "-XX:DumpLoadedClassList=${cdsClassList.absolutePath}"
}
doLast {
if ( !cdsClassList.exists() || cdsClassList.length() == 0 ) {
throw new GradleException( "AppCDS class list was not generated at ${cdsClassList}" )
}
logger.lifecycle( "+ Class list written: ${cdsClassList} (${cdsClassList.length()} bytes)" )
}
}
task generateCdsArchive( type: JavaExec ) {
dependsOn generateCdsClassList
group = 'AppCDS'
description = 'Builds the boxlang.jsa AppCDS archive from the generated class list.'
inputs.file cdsClassList
outputs.file cdsArchive
classpath = files( shadowJar.archiveFile )
mainClass = 'ortus.boxlang.runtime.BoxRunner'
args = []
ignoreExitValue = true
doFirst {
logger.lifecycle( "+ Building AppCDS archive at ${cdsArchive}" )
jvmArgs '-Xshare:dump',
"-XX:SharedClassListFile=${cdsClassList.absolutePath}",
"-XX:SharedArchiveFile=${cdsArchive.absolutePath}"
}
doLast {
if ( !cdsArchive.exists() || cdsArchive.length() == 0 ) {
throw new GradleException( "AppCDS archive was not generated at ${cdsArchive}" )
}
logger.lifecycle( "+ AppCDS archive written: ${cdsArchive} (${cdsArchive.length()} bytes)" )
}
}
/**
* This is necessary to create a single level instead of what shadow does.
* Includes the AppCDS .jsa archive in the distribution when it has been generated.
*/
task createDistributionFile( type: Zip ){
dependsOn startShadowScripts
from( 'build/scriptsShadow' ) {
into 'bin'
}
from( 'build/libs' ) {
include 'boxlang-' + version + '.jar'
into 'lib'
}
// The AppCDS .jsa archive is NOT bundled in the distribution — it is generated
// automatically on first run into the user's ~/.boxlang/cache/ directory.
// This keeps the distribution ZIP at its original size (~7 MB).
archiveFileName = "boxlang-${version}.zip"
doLast {
println "+ Distribution file has been created"
}
}
/**
* Task moves the contents of the `libs` folder to the `distributions` folder
* Includes all BoxLang JAR variants: main, noop, java-compiler, and asm-compiler
*/
task libsToDistro( type: Copy ) {
dependsOn build, createDistributionFile, shadowJarNoop, jarJavaCompiler, jarAsmCompiler,
javadocJarJavaCompiler, sourcesJarJavaCompiler,
javadocJarAsmCompiler, sourcesJarAsmCompiler,
javadocJarNoop, sourcesJarNoop
from( 'build/libs' ) {
include 'boxlang-' + version + '.jar'
include 'boxlang-' + version + '-javadoc.jar'
include 'boxlang-' + version + '-sources.jar'
include 'boxlang-noop-' + version + '.jar'
include 'boxlang-noop-' + version + '-javadoc.jar'
include 'boxlang-noop-' + version + '-sources.jar'
include 'boxlang-compiler-java-' + version + '.jar'
include 'boxlang-compiler-java-' + version + '-javadoc.jar'
include 'boxlang-compiler-java-' + version + '-sources.jar'
include 'boxlang-compiler-asm-' + version + '.jar'
include 'boxlang-compiler-asm-' + version + '-javadoc.jar'
include 'boxlang-compiler-asm-' + version + '-sources.jar'
}
from( 'build/resources/main/META-INF/boxlang/version.properties' ){
}
destinationDir = file( "build/distributions" )
doLast {
// Generate checksums for all zip and jar files in distributions folder
file( "build/distributions" ).listFiles().each { file ->
if ( file.name.endsWith( '.zip' ) || file.name.endsWith( '.jar' ) ) {
generateChecksum( file, 'SHA-256' )
generateChecksum( file, 'MD5' )
}
}
// Move the distribution files to the evergreen folder
file( "build/evergreen" ).mkdirs()
if( branch == 'development' ){
Files.copy( file( "build/distributions/boxlang-${version}.zip" ).toPath(), file( "build/evergreen/boxlang-snapshot.zip" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/distributions/boxlang-${version}.jar" ).toPath(), file( "build/evergreen/boxlang-snapshot.jar" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/resources/main/META-INF/boxlang/version.properties" ).toPath(), file( "build/evergreen/version-snapshot.properties" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
// Copy checksums
Files.copy( file( "build/distributions/boxlang-${version}.zip.sha-256" ).toPath(), file( "build/evergreen/boxlang-snapshot.zip.sha-256" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/distributions/boxlang-${version}.zip.md5" ).toPath(), file( "build/evergreen/boxlang-snapshot.zip.md5" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/distributions/boxlang-${version}.jar.sha-256" ).toPath(), file( "build/evergreen/boxlang-snapshot.jar.sha-256" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/distributions/boxlang-${version}.jar.md5" ).toPath(), file( "build/evergreen/boxlang-snapshot.jar.md5" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
} else {
Files.copy( file( "build/distributions/boxlang-${version}.zip" ).toPath(), file( "build/evergreen/boxlang-latest.zip" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/distributions/boxlang-${version}.jar" ).toPath(), file( "build/evergreen/boxlang-latest.jar" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/resources/main/META-INF/boxlang/version.properties" ).toPath(), file( "build/evergreen/version-latest.properties" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
// Copy checksums
Files.copy( file( "build/distributions/boxlang-${version}.zip.sha-256" ).toPath(), file( "build/evergreen/boxlang-latest.zip.sha-256" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/distributions/boxlang-${version}.zip.md5" ).toPath(), file( "build/evergreen/boxlang-latest.zip.md5" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/distributions/boxlang-${version}.jar.sha-256" ).toPath(), file( "build/evergreen/boxlang-latest.jar.sha-256" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
Files.copy( file( "build/distributions/boxlang-${version}.jar.md5" ).toPath(), file( "build/evergreen/boxlang-latest.jar.md5" ).toPath(), StandardCopyOption.REPLACE_EXISTING )
}
println "+ Libs have been moved to the distribution and evergreen folders"
println "+ Checksums generated for all zip and jar files"
}
}
build.finalizedBy( libsToDistro )
/**
* Generate checksums for the given file using the specified algorithm
* @param file The file to generate the checksum for
* @param algorithm The algorithm to use (e.g., "SHA-256", "MD5")
*/
def generateChecksum( File file, String algorithm ) {
def digest = java.security.MessageDigest.getInstance( algorithm )
file.eachByte( 4096 ) { bytes, size ->
digest.update( bytes, 0, size )
}
def checksum = digest.digest().collect { String.format( '%02x', it ) }.join()
def checksumFile = new File( file.parent, "${file.name}.${algorithm.toLowerCase()}" )
checksumFile.text = "${checksum} ${file.name}\n"
}
/**
* Publish the artifacts to the local maven repository
*/
publishing {
publications {
shadow( MavenPublication ) { publication ->
artifact shadowJar
artifact javadocJar
artifact sourcesJar
// This is the only one sonatype accepts, not ortus.boxlang
// https://central.sonatype.com/
groupId = 'io.boxlang'
artifactId = 'boxlang'
pom {
name = "BoxLang"
description = "BoxLang is a dynamic multi-runtime JVM Language based on fluency and functional constructs. It can be deployed as a standalone language, embedded in your Java applications, web applications, serverless, android, etc."
url = "https://boxlang.io"
issueManagement {
system = "Jira"
url = "https://ortussolutions.atlassian.net/jira/software/c/projects/BL/issues"
}
mailingLists {
mailingList {
name = "BoxLang Community"
subscribe = "https://community.ortussolutions.com/c/boxlang/42"
unsubscribe = "https://community.ortussolutions.com/c/boxlang/42"
}
}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
scm {
connection = 'scm:git:https://github.com/ortus-boxlang/boxlang.git'
developerConnection = 'scm:git:ssh://github.com/ortus-boxlang/boxlang.git'
url = 'https://github.com/ortus-boxlang/boxlang'
}
developers{
developer {
id = "lmajano"
name = "Luis Majano"
email = "lmajano@ortussolutions.com"
organization = "Ortus Solutions, Corp"
organizationUrl = "https://www.ortussolutions.com"
}
developer {