-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathbuild.gradle
More file actions
309 lines (259 loc) · 8.7 KB
/
build.gradle
File metadata and controls
309 lines (259 loc) · 8.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
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.27"
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.9"
}
}
/*
Applies core Gradle plugins, which are ones built into Gradle itself.
*/
plugins {
// Java for compile and unit test of Java source files. Read more at:
// https://docs.gradle.org/current/userguide/java_plugin.html
id 'java'
// JaCoCo for coverage metrics and reports of Java source files. Read more at:
// https://docs.gradle.org/current/userguide/jacoco_plugin.html
id 'jacoco'
// Maven Publish for publishing artifacts to an Apache Maven repository
id 'maven-publish'
id 'signing'
// Download Task for integration tests
id 'de.undercouch.download' version '5.6.0'
// Quality checks on Java source files
// https://docs.gradle.org/current/userguide/checkstyle_plugin.html
id 'checkstyle'
}
/*
Applies community Gradle plugins, usually added as build-tools in Config.
*/
// SpotBugs for quality checks and reports of source files. Read more at:
// https://spotbugs.readthedocs.io/en/stable/gradle.html
apply plugin: 'com.github.spotbugs'
/*
Configures the JaCoCo "jacoco" plugin. Remove this if you want to skip
these checks and report generation.
Set minimum code coverage to fail build, where 0.01 = 1%.
*/
check.dependsOn jacocoTestCoverageVerification
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.2
}
}
}
}
/*
Configures the SpotBugs "com.github.spotbugs" plugin. Remove this and the
plugin to skip these checks and report generation.
*/
spotbugs {
ignoreFailures.set(false)
}
repositories {
mavenCentral()
}
configurations {
testCompileOnly.extendsFrom compileOnly
}
dependencies {
// Do not upgrade to Jackson 3.x without addressing stack overflow issues in ValueDeserializer
// The upgrade should be reviewed by AppSec
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2'
implementation 'com.fizzed:jne:4.3.0'
implementation 'com.google.guava:guava:33.4.0-jre'
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.9.0'
testImplementation 'net.jqwik:jqwik:1.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.4'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.4'
}
def ffiDir = '../CedarJavaFFI'
def compiledLibDir = 'resources/compiled'
def rustLibraryTargets = [
'aarch64-apple-darwin' : 'libcedar_java_ffi.dylib',
'aarch64-unknown-linux-gnu' : 'libcedar_java_ffi.so',
'x86_64-apple-darwin' : 'libcedar_java_ffi.dylib',
'x86_64-pc-windows-gnu' : 'cedar_java_ffi.dll',
'x86_64-unknown-linux-gnu' : 'libcedar_java_ffi.so'
]
def rustJavaTargets = [
'aarch64-apple-darwin' : 'macos/aarch64',
'aarch64-unknown-linux-gnu' : 'linux/aarch64',
'x86_64-apple-darwin' : 'macos/x86_64',
'x86_64-pc-windows-gnu' : 'windows/x86_64',
'x86_64-unknown-linux-gnu' : 'linux/x86_64'
]
def RustVersion = '1.83'
tasks.register('installRequiredRustVersion', Exec) {
group 'Build'
description 'Install required Rust version.'
commandLine 'rustup', 'install', RustVersion
}
tasks.register('installCargoZigbuild', Exec) {
dependsOn('installRequiredRustVersion')
group 'Build'
description 'Installs Cargo Zigbuild for Rust compilation.'
commandLine 'cargo', '+' + RustVersion, 'install', 'cargo-zigbuild@0.19.7'
}
tasks.register('compileFFI') {
dependsOn('installCargoZigbuild')
group 'Build'
description 'Compiles Foreign Function Interface libraries.'
exec {
workingDir = ffiDir
commandLine 'rustup', 'override', 'set', RustVersion
}
doLast {
rustLibraryTargets.forEach { rustTarget, libraryFile ->
exec {
commandLine 'rustup', 'target', 'add', rustTarget, '--toolchain', RustVersion
}
exec {
workingDir = ffiDir
commandLine 'cargo', '+' + RustVersion, 'zigbuild', '--features', 'partial-eval', '--release', '--target', rustTarget
}
def sourcePath = "${ffiDir}/target/${rustTarget}/release/${libraryFile}"
def javaTargetPath = rustJavaTargets.get(rustTarget)
copy {
from(sourcePath)
into layout.buildDirectory.dir("${compiledLibDir}/jne/${javaTargetPath}")
}
}
}
}
tasks.register('testFFI') {
dependsOn('compileFFI')
group 'Build'
description 'Tests Foreign Function Interface libraries.'
doLast {
exec {
workingDir = ffiDir
commandLine 'cargo', 'test'
}
}
}
tasks.register('cleanFFI', Exec) {
group 'Build'
description 'Deletes the build directory for Foreign Function Interface libraries.'
workingDir ffiDir
commandLine 'cargo', 'clean'
}
tasks.register('uberJar', Jar) {
dependsOn('compileFFI')
group 'Build'
description 'Assembles a jar archive containing standard classes and native libraries.'
archiveClassifier = 'uber'
with jar
from(layout.buildDirectory.dir(compiledLibDir))
}
tasks.register('downloadIntegrationTests', Download) {
group 'Build'
description 'Downloads Cedar repository with integration tests.'
src 'https://codeload.github.com/cedar-policy/cedar-integration-tests/zip/main'
dest layout.buildDirectory.file('cedar-integration-tests-main.zip')
overwrite false
}
tasks.register('extractIntegrationTests', Copy) {
group 'Build'
description 'Extracts Cedar integration tests.'
dependsOn('checkstyleTest')
dependsOn('downloadIntegrationTests')
from zipTree(layout.buildDirectory.file('cedar-integration-tests-main.zip'))
into layout.buildDirectory.dir('resources/test')
}
tasks.register('extractCorpusTests', Copy) {
group 'Build'
description 'Extracts Cedar corpus tests.'
dependsOn('extractIntegrationTests')
dependsOn('processTestResources')
from tarTree(layout.buildDirectory.file('resources/test/cedar-integration-tests-main/corpus-tests.tar.gz'))
into layout.buildDirectory.dir('resources/test/cedar-integration-tests-main')
}
tasks.named('test') {
useJUnitPlatform()
dependsOn('compileFFI')
dependsOn('extractCorpusTests')
classpath += files(layout.buildDirectory.dir(compiledLibDir))
}
test {
testLogging {
events "skipped", "failed", "standardOut", "standardError"
showStandardStreams false
exceptionFormat 'full'
}
}
compileTestJava {
sourceCompatibility = "17"
targetCompatibility = "17"
}
compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.named('build') {
dependsOn('uberJar')
}
java {
withSourcesJar()
withJavadocJar()
}
/*
Configures Maven publishing
*/
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
groupId = 'com.cedarpolicy'
artifactId = 'cedar-java'
version = '3.1.2'
artifacts {
jar
artifact tasks.named('uberJar')
}
pom {
name = 'cedar-java'
description = 'Java bindings for Cedar policy language.'
url = 'http://www.cedarpolicy.com'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'cedar'
name = 'Cedar Team'
email = 'cedar-sonatype-team@amazon.com'
}
}
scm {
connection = 'scm:git:https://github.com/cedar-policy/cedar-java.git'
developerConnection = 'scm:git:https://github.com/cedar-policy/cedar-java.git'
url = 'https://github.com/cedar-policy/cedar-java'
}
}
}
}
repositories {
maven {
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
// To publish, uncomment these lines and ensure you have them set in `gradle.properties`
// credentials {
// username ossrhUsername
// password ossrhPassword
// }
}
}
}
signing {
sign publishing.publications.mavenJava
}