-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathbuild.gradle
More file actions
433 lines (374 loc) · 16.7 KB
/
build.gradle
File metadata and controls
433 lines (374 loc) · 16.7 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
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
plugins {
id "com.github.spotbugs-base" version "${spotbugsPluginVersion}"
id "com.github.johnrengelman.shadow" version "${shadowJarPluginVersion}"
id "de.undercouch.download" version "${downloadPluginVersion}"
id "net.researchgate.release" version "${releasePluginVersion}"
id "org.cyclonedx.bom" version "${cyclonedxBomPluginVersion}"
id "java"
}
apply plugin: 'maven-publish'
allprojects {
group = project.group
version = project.version
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
repositories {
mavenLocal()
maven {
url = 'https://repo.maven.apache.org/maven2'
}
// Commented out due to package corruption
// maven {
// url = 'https://maven.wso2.org/nexus/content/repositories/releases/'
// }
//
// maven {
// url = 'https://maven.wso2.org/nexus/content/groups/wso2-public/'
// }
maven {
url = 'https://maven.pkg.github.com/ballerina-platform/*'
credentials {
username System.getenv("packageUser")
password System.getenv("packagePAT")
}
}
}
ext {
snapshotVersion = '-SNAPSHOT'
timestampedVersionRegex = '.*-\\d{8}-\\d{6}-\\w.*\$'
}
}
subprojects {
apply plugin: "java"
configurations {
ballerinaStdLibs
jbalTools
}
dependencies {
jbalTools("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") {
transitive = false
}
/* Standard libraries */
ballerinaStdLibs "io.ballerina.stdlib:constraint-ballerina:${stdlibConstraintVersion}"
ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}"
ballerinaStdLibs "io.ballerina.stdlib:random-ballerina:${stdlibRandomVersion}"
ballerinaStdLibs "io.ballerina.stdlib:time-ballerina:${stdlibTimeVersion}"
ballerinaStdLibs "io.ballerina.stdlib:url-ballerina:${stdlibUrlVersion}"
ballerinaStdLibs "io.ballerina.stdlib:crypto-ballerina:${stdlibCryptoVersion}"
ballerinaStdLibs "io.ballerina.stdlib:log-ballerina:${stdlibLogVersion}"
ballerinaStdLibs "io.ballerina.stdlib:os-ballerina:${stdlibOsVersion}"
ballerinaStdLibs "io.ballerina.stdlib:uuid-ballerina:${stdlibUuidVersion}"
ballerinaStdLibs "io.ballerina.stdlib:auth-ballerina:${stdlibAuthVersion}"
ballerinaStdLibs "io.ballerina.stdlib:oauth2-ballerina:${stdlibOAuth2Version}"
ballerinaStdLibs "io.ballerina.lib:data.jsondata-ballerina:${stdlibJsonDataVersion}"
ballerinaStdLibs "io.ballerina.stdlib:http-ballerina:${stdlibHttpVersion}"
ballerinaStdLibs "io.ballerina.stdlib:graphql-ballerina:${stdlibGraphqlVersion}"
ballerinaStdLibs "io.ballerina.stdlib:sql-ballerina:${stdLibSqlVersion}"
ballerinaStdLibs "io.ballerina.stdlib:grpc-ballerina:${stdlibGrpcVersion}"
ballerinaStdLibs "io.ballerina:observe-ballerina:${observeInternalVersion}"
ballerinaStdLibs "io.ballerina.stdlib:observe-ballerina:${observeVersion}"
ballerinaStdLibs "io.ballerina.stdlib:tcp-ballerina:${stdlibTcpVersion}"
/* Ballerina Persist Tool */
ballerinaStdLibs "io.ballerina:persist-tools:${persistToolVersion}"
}
}
def moduleVersion = project.version
if (moduleVersion.indexOf('-') != -1) {
moduleVersion = moduleVersion.substring(0, moduleVersion.indexOf('-'))
}
// TODO: Remove this once the workspace manager is refactored to import modules where necessary.
def pullBallerinaModule(String packageName, String version = null, String orgName = "ballerinax") {
def taskName = "pull${orgName.capitalize()}Module_${packageName.replace('/', '_')}"
if (tasks.findByName(taskName) != null) {
return tasks.named(taskName)
}
tasks.register(taskName) {
doLast {
def errOutput = new ByteArrayOutputStream()
def result = exec {
ignoreExitValue = true
// Check if the package exists in the ballerina user home
def centralRepoDir = new File(System.getProperty("user.home"), ".ballerina/repositories/central.ballerina.io/bala/${orgName}")
if (centralRepoDir.exists()) {
def pkgDir = new File(centralRepoDir, packageName)
if (pkgDir.exists()) {
if (version != null) {
// Check if the specific version exists
def versionDir = new File(pkgDir, version)
if (versionDir.exists()) {
commandLine 'echo', "Package ${packageName} version ${version} exists"
return
}
} else {
// If no version is specified, check for any version
commandLine 'echo', "Package ${packageName} exists"
return
}
}
}
def balPullCommand = "bal pull ${orgName}/${packageName}${version ? ':' + version : ''} --sticky=false"
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
commandLine 'cmd', '/c', balPullCommand
} else {
commandLine '/bin/sh', '-c', balPullCommand
}
errorOutput = errOutput
}
if (result.exitValue != 0) {
println errOutput
throw new GradleException("Failed to pull Ballerina module: ${packageName}")
}
}
}
}
// Building a custom Ballerina distribution for testing
ext.configureBallerinaDistribution = { Project targetProject ->
targetProject.with {
def balDistribution = file("$targetProject.buildDir/jballerina-tools-${ballerinaLangVersion}")
tasks.register('unpackJballerinaTools') {
project.configurations.each { configuration ->
if (configuration.name == "externalJars") {
dependsOn(project.copyToLib)
}
}
doLast {
project.configurations.jbalTools.resolvedConfiguration.resolvedArtifacts.each { artifact ->
project.copy {
from project.zipTree(artifact.getFile())
into new File("${project.buildDir}/")
}
}
}
}
tasks.register('buildAndCopyLangserverStdlib') {
dependsOn ':langserver-stdlib:build'
doLast {
// Get all .bala files from the source directory
fileTree("${rootProject.project(':langserver-stdlib').buildDir}/ballerina-src/target/bala").include("**/*.bala").each { balaFile ->
// Parse the bala filename to extract organization, package, jdk, and version
// Format: <org>-<package>-<jdk>-<version>.bala
def fileName = balaFile.name.replace('.bala', '')
def parts = fileName.split('-')
if (parts.length >= 4) {
def org = parts[0]
def version = parts[parts.length - 1]
def jdk = parts[parts.length - 2]
// Package name could be multiple parts joined with hyphens
def packageParts = parts[1..(parts.length - 3)]
def packageName = packageParts.join('-')
// Create directory structure: <org>/<package>/<version>/<jdk>
def targetDir = "${project.buildDir}/jballerina-tools-${project.ballerinaLangVersion}/repo/bala/${org}/${packageName}/${version}/${jdk}"
// Extract the .bala file to the destination directory
// .bala files are ZIP archives, so we can use zipTree to extract them
copy {
from zipTree(balaFile)
into targetDir
}
println "Extracted ${balaFile.name} to ${targetDir}"
} else {
println "Warning: Bala file ${balaFile.name} does not match the expected format <org>-<package>-<jdk>-<version>.bala"
}
}
}
}
// Configure test task to use the common dependencies and system properties
test {
dependsOn unpackJballerinaTools
dependsOn buildAndCopyLangserverStdlib
systemProperty "ballerina.home", balDistribution
systemProperty "responseTimeThreshold", 2000
}
}
}
configurations {
externalJarDeps
}
// Defines the third party dependencies to be included in the final JAR
dependencies {
externalJarDeps "org.eclipse.lsp4j:org.eclipse.lsp4j:${eclipseLsp4jVersion}"
externalJarDeps "com.google.code.gson:gson:${gsonVersion}"
externalJarDeps "org.eclipse.lsp4j:org.eclipse.lsp4j:${eclipseLsp4jVersion}"
externalJarDeps "com.fasterxml.jackson.core:jackson-databind:${jacksonDatabindVersion}"
externalJarDeps "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonDataformatYamlVersion}"
externalJarDeps "io.netty:netty-buffer:${nettyBufferVersion}"
externalJarDeps "org.slf4j:slf4j-jdk14:${slf4jJdk14Version}"
externalJarDeps "com.google.code.findbugs:jsr305:${findbugsJsr305Version}"
externalJarDeps "org.apache.commons:commons-lang3:${apacheCommonsLang3Version}"
externalJarDeps "commons-io:commons-io:${commonsIoVersion}"
externalJarDeps "com.google.guava:guava:${guavaVersion}"
externalJarDeps "com.moandjiezana.toml:toml4j:${moandjiezanaToml4jVersion}"
externalJarDeps "com.github.zafarkhaja:java-semver:${javaSemverVersion}"
externalJarDeps "org.xerial:sqlite-jdbc:${sqliteJdbcVersion}"
}
// Task to generate POM file for inclusion in JAR
task generatePackPom {
description 'Generates POM file for inclusion in the pack JAR'
group 'build'
def outputDir = file("$buildDir/generated-pack-pom")
outputs.dir outputDir
doLast {
// Create processed POM from template
def pomTemplate = file('build-config/maven-template/pom-template.xml')
if (!pomTemplate.exists()) {
throw new GradleException("POM template file not found: ${pomTemplate.absolutePath}")
}
def pomContent = pomTemplate.text
.replace('{{version}}', project.version)
.replace('{{groupId}}', project.group)
.replace('{{artifactId}}', project.name)
.replace('{{ballerinaLangVersion}}', ballerinaLangVersion ?: 'unknown')
// Create META-INF/maven directory structure
def metaInfDir = file("$outputDir/META-INF/maven/${project.group}/${project.name}")
metaInfDir.mkdirs()
// Write processed POM
def pomFile = new File(metaInfDir, 'pom.xml')
pomFile.text = pomContent
// Create pom.properties file
def pomPropsTemplate = file('build-config/maven-template/pom-properties-template.properties')
if (!pomPropsTemplate.exists()) {
throw new GradleException("POM properties template file not found: ${pomPropsTemplate.absolutePath}")
}
def pomPropsContent = pomPropsTemplate.text
.replace('{{version}}', project.version)
.replace('{{groupId}}', project.group)
.replace('{{artifactId}}', project.name)
def pomPropsFile = new File(metaInfDir, 'pom.properties')
pomPropsFile.text = pomPropsContent
}
}
task pack(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
description 'Creates a single JAR containing all submodules'
group 'build'
// Depend on each subproject's build task and POM generation
dependsOn subprojects.collect { it.path + ':build' }
dependsOn generatePackPom
archiveBaseName = project.name
archiveClassifier = ''
archiveVersion = project.version
destinationDirectory = file("$project.buildDir")
configurations = [project.configurations.externalJarDeps]
// Include the compiled classes and resources from all submodules
subprojects.each { subproject ->
if (subproject.tasks.findByName('jar')) {
from subproject.tasks.jar.outputs
}
}
// Include the generated POM file at the standard Maven location
from(generatePackPom.outputs.files) {
include 'META-INF/maven/**'
}
// Set the main class for the executable JAR
manifest {
attributes(
'Main-Class': 'org.ballerinalang.langserver.launchers.stdio.Main',
'Implementation-Title': 'Ballerina Language Server',
'Implementation-Version': project.version
)
}
// Manage dependencies to avoid duplicates
mergeServiceFiles()
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
// Exclude all dependency Maven metadata but keep our main project's POM
exclude { details ->
def path = details.path
return !path.contains("META-INF/maven/${project.group}/${project.name}/") &&
(path.startsWith('META-INF/maven/') && (path.contains('/pom.xml') || path.contains('/pom.properties')))
}
}
task pullBallerinaModules {
dependsOn pullBallerinaModule('ai', ballerinaxAiAgent)
dependsOn pullBallerinaModule('kafka', ballerinaxKafkaVersion)
dependsOn pullBallerinaModule('rabbitmq', ballerinaxRabbitmqVersion)
dependsOn pullBallerinaModule('solace', ballerinaxSolaceVersion)
dependsOn pullBallerinaModule('cdc', ballerinaxCdcVersion)
dependsOn pullBallerinaModule('mssql', ballerinaxMSSQLVersion)
dependsOn pullBallerinaModule('mssql.cdc.driver', ballerinaxMSSQLCDCDriverVersion)
dependsOn pullBallerinaModule('trigger.github', ballerinaxGithubTriggerVersion)
dependsOn pullBallerinaModule('trigger.shopify', ballerinaxShopifyTriggerVersion)
dependsOn pullBallerinaModule('np', ballerinaxNp)
dependsOn pullBallerinaModule('workflow', ballerinaWorkflowVersion, "ballerina")
}
test {
dependsOn pullBallerinaModules
}
task buildFlow {
dependsOn(":flow-model-generator:flow-model-generator-core:build")
dependsOn(":flow-model-generator:flow-model-generator-ls-extension:build")
}
task buildService {
dependsOn(":service-model-generator:service-model-generator-ls-extension:build")
}
task buildDesign {
dependsOn(":architecture-model-generator:architecture-model-generator-core:build")
dependsOn(":architecture-model-generator:architecture-model-generator-ls-extension:build")
}
task buildSequence {
dependsOn(":sequence-model-generator:sequence-model-generator-core:build")
dependsOn(":sequence-model-generator:sequence-model-generator-ls-extension:build")
}
task buildTestService {
dependsOn(":test-manager-service:test-manager-service-ls-extension:build")
}
task buildCommons {
dependsOn(":model-generator-commons:build")
}
publishing {
publications {
mavenJava(MavenPublication) { publication ->
publication.artifact(tasks.pack) {
classifier = ''
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/ballerina-platform/ballerina-language-server")
credentials {
username = System.getenv("packageUser")
password = System.getenv("packagePAT")
}
}
}
}
release {
failOnPublishNeeded = false
buildTasks = ['build']
versionPropertyFile = 'gradle.properties'
tagTemplate = 'v${version}'
git {
requireBranch = "release-${moduleVersion}"
pushToRemote = 'origin'
}
}
// Configure CycloneDX SBOM generation
cyclonedxBom {
includeConfigs = ["externalJarDeps"]
schemaVersion = "1.4"
destination = file("$buildDir")
outputName = "sbom"
outputFormat = "json"
includeBomSerialNumber = true
}
build.dependsOn test
build.doNotTrackState("build needs to run every time")
publishToMavenLocal.dependsOn build
publish.dependsOn build