-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathbuild.gradle
More file actions
243 lines (204 loc) · 6.78 KB
/
build.gradle
File metadata and controls
243 lines (204 loc) · 6.78 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
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.8"
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'
}
/*
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 ValueCedarDeserializer
// The upgrade should be reviewed by AppSec
implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.16.2'
implementation 'org.slf4j:slf4j-api:2.0.12'
implementation 'com.fizzed:jne:4.1.1'
implementation 'com.google.guava:guava:33.1.0-jre'
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.8.3'
testImplementation 'org.slf4j:slf4j-simple:2.0.12'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testImplementation 'net.jqwik:jqwik:1.8.3'
}
test {
useJUnitPlatform()
//environment "CEDAR_INTEGRATION_TESTS_ROOT", ''set to absolute path of `cedar-integration-tests`'
//environment 'CEDAR_JAVA_FFI_LIB', 'set to absolute path of cedar_java_ffi native library (including file extension)'
testLogging {
showStandardStreams false
exceptionFormat 'full'
}
}
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'
]
tasks.register('installCargoZigbuild', Exec) {
group 'Build'
description 'Installs Cargo Zigbuild for Rust compilation.'
commandLine 'cargo', 'install', 'cargo-zigbuild'
}
tasks.register('installRustTargets') {
dependsOn('installCargoZigbuild')
group 'Build'
description 'Installs Rust platform build targets.'
doLast {
rustLibraryTargets.keySet().forEach { rustTarget ->
exec {
commandLine 'rustup', 'target', 'add', rustTarget
}
}
}
}
tasks.register('compileFFI') {
dependsOn('installRustTargets')
group 'Build'
description 'Compiles Foreign Function Interface libraries.'
doLast {
rustLibraryTargets.forEach { rustTarget, libraryFile ->
exec {
workingDir = ffiDir
commandLine 'cargo', 'zigbuild', '--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.named('test') {
dependsOn('compileFFI')
classpath += files(layout.buildDirectory.dir(compiledLibDir))
}
tasks.named('build') {
dependsOn('uberJar')
}
/*
Configures Maven publishing
*/
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.cedarpolicy'
artifactId = 'cedar-java'
version = '3.1.0-SNAPSHOT'
from components.java
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'
}
}
}
}
}