@@ -5,7 +5,7 @@ buildscript {
55 }
66 }
77 dependencies {
8- classpath " com.github.spotbugs.snom:spotbugs-gradle-plugin:5 .0.14 "
8+ classpath " com.github.spotbugs.snom:spotbugs-gradle-plugin:6 .0.8 "
99 classpath " gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.9"
1010 }
1111}
@@ -21,6 +21,12 @@ plugins {
2121 // JaCoCo for coverage metrics and reports of Java source files. Read more at:
2222 // https://docs.gradle.org/current/userguide/jacoco_plugin.html
2323 id ' jacoco'
24+
25+ // Maven Publish for publishing artifacts to an Apache Maven repository
26+ id ' maven-publish'
27+
28+ // Download Task for integration tests
29+ id ' de.undercouch.download' version ' 5.6.0'
2430}
2531
2632/*
@@ -67,22 +73,194 @@ configurations {
6773dependencies {
6874 // Do not upgrade to Jackson 3.x without addressing stack overflow issues in ValueCedarDeserializer
6975 // The upgrade should be reviewed by AppSec
70- implementation ' com.fasterxml.jackson.core:jackson-databind:2.16.1 '
71- implementation ' com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.16.1 '
76+ implementation ' com.fasterxml.jackson.core:jackson-databind:2.16.2 '
77+ implementation ' com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.16.2 '
7278 implementation ' org.slf4j:slf4j-api:2.0.12'
73- implementation ' com.google.guava:guava:33.0.0-jre'
79+ implementation ' com.fizzed:jne:4.1.1'
80+ implementation ' com.google.guava:guava:33.1.0-jre'
7481 compileOnly ' com.github.spotbugs:spotbugs-annotations:4.8.3'
7582 testImplementation ' org.slf4j:slf4j-simple:2.0.12'
83+ testImplementation ' net.jqwik:jqwik:1.8.4'
7684 testImplementation ' org.junit.jupiter:junit-jupiter-api:5.10.2'
77- testImplementation ' net.jqwik:jqwik:1.8.3 '
85+ testRuntimeOnly ' org.junit.jupiter:junit-jupiter-engine:5.10.2 '
7886}
7987
80- test {
88+ def ffiDir = ' ../CedarJavaFFI'
89+ def compiledLibDir = ' resources/compiled'
90+
91+ def rustLibraryTargets = [
92+ ' aarch64-apple-darwin' : ' libcedar_java_ffi.dylib' ,
93+ ' aarch64-unknown-linux-gnu' : ' libcedar_java_ffi.so' ,
94+ ' x86_64-apple-darwin' : ' libcedar_java_ffi.dylib' ,
95+ ' x86_64-pc-windows-gnu' : ' cedar_java_ffi.dll' ,
96+ ' x86_64-unknown-linux-gnu' : ' libcedar_java_ffi.so'
97+ ]
98+
99+ def rustJavaTargets = [
100+ ' aarch64-apple-darwin' : ' macos/aarch64' ,
101+ ' aarch64-unknown-linux-gnu' : ' linux/aarch64' ,
102+ ' x86_64-apple-darwin' : ' macos/x86_64' ,
103+ ' x86_64-pc-windows-gnu' : ' windows/x86_64' ,
104+ ' x86_64-unknown-linux-gnu' : ' linux/x86_64'
105+ ]
106+
107+ tasks. register(' installCargoZigbuild' , Exec ) {
108+ group ' Build'
109+ description ' Installs Cargo Zigbuild for Rust compilation.'
110+
111+ commandLine ' cargo' , ' install' , ' cargo-zigbuild'
112+ }
113+
114+ tasks. register(' installRustTargets' ) {
115+ dependsOn(' installCargoZigbuild' )
116+ group ' Build'
117+ description ' Installs Rust platform build targets.'
118+
119+ doLast {
120+ rustLibraryTargets. keySet(). forEach { rustTarget ->
121+ exec {
122+ commandLine ' rustup' , ' target' , ' add' , rustTarget
123+ }
124+ }
125+ }
126+ }
127+
128+ tasks. register(' compileFFI' ) {
129+ dependsOn(' installRustTargets' )
130+ group ' Build'
131+ description ' Compiles Foreign Function Interface libraries.'
132+
133+ doLast {
134+ rustLibraryTargets. forEach { rustTarget , libraryFile ->
135+ exec {
136+ workingDir = ffiDir
137+ commandLine ' cargo' , ' zigbuild' , ' --features' , ' partial-eval' , ' --release' , ' --target' , rustTarget
138+ }
139+
140+ def sourcePath = " ${ ffiDir} /target/${ rustTarget} /release/${ libraryFile} "
141+ def javaTargetPath = rustJavaTargets. get(rustTarget)
142+
143+ copy {
144+ from(sourcePath)
145+ into layout. buildDirectory. dir(" ${ compiledLibDir} /jne/${ javaTargetPath} " )
146+ }
147+ }
148+ }
149+ }
150+
151+ tasks. register(' testFFI' ) {
152+ dependsOn(' compileFFI' )
153+ group ' Build'
154+ description ' Tests Foreign Function Interface libraries.'
155+
156+ doLast {
157+ exec {
158+ workingDir = ffiDir
159+ commandLine ' cargo' , ' test'
160+ }
161+ }
162+ }
163+
164+ tasks. register(' cleanFFI' , Exec ) {
165+ group ' Build'
166+ description ' Deletes the build directory for Foreign Function Interface libraries.'
167+
168+ workingDir ffiDir
169+ commandLine ' cargo' , ' clean'
170+ }
171+
172+ tasks. register(' uberJar' , Jar ) {
173+ dependsOn(' compileFFI' )
174+ group ' Build'
175+ description ' Assembles a jar archive containing standard classes and native libraries.'
176+
177+ archiveClassifier = ' uber'
178+ with jar
179+
180+ from(layout. buildDirectory. dir(compiledLibDir))
181+ }
182+
183+ tasks. register(' downloadIntegrationTests' , Download ) {
184+ group ' Build'
185+ description ' Downloads Cedar repository with integration tests.'
186+
187+ src ' https://codeload.github.com/cedar-policy/cedar/zip/main'
188+ dest layout. buildDirectory. file(' cedar-main.zip' )
189+ overwrite false
190+ }
191+
192+ tasks. register(' extractIntegrationTests' , Copy ) {
193+ group ' Build'
194+ description ' Extracts Cedar integration tests.'
195+
196+ dependsOn(' downloadIntegrationTests' )
197+ from zipTree(layout. buildDirectory. file(' cedar-main.zip' ))
198+ into layout. buildDirectory. dir(' resources/test' )
199+ }
200+
201+ tasks. named(' test' ) {
81202 useJUnitPlatform()
203+ dependsOn(' compileFFI' )
204+ dependsOn(' extractIntegrationTests' )
205+ classpath + = files(layout. buildDirectory. dir(compiledLibDir))
206+ }
207+
208+ test {
82209 // environment "CEDAR_INTEGRATION_TESTS_ROOT", ''set to absolute path of `cedar-integration-tests`'
83- // environment 'CEDAR_JAVA_FFI_LIB', 'set to absolute path of cedar_java_ffi native library (including file extension)'
84210 testLogging {
211+ events " skipped" , " failed" , " standardOut" , " standardError"
85212 showStandardStreams false
86213 exceptionFormat ' full'
87214 }
88215}
216+
217+ tasks. named(' build' ) {
218+ dependsOn(' uberJar' )
219+ }
220+
221+ /*
222+ Configures Maven publishing
223+ */
224+ publishing {
225+ publications {
226+ maven(MavenPublication ) {
227+ groupId = ' com.cedarpolicy'
228+ artifactId = ' cedar-java'
229+ version = ' 3.1.0-SNAPSHOT'
230+
231+ from components. java
232+
233+ artifacts {
234+ jar
235+ artifact tasks. named(' uberJar' )
236+ }
237+
238+ pom {
239+ name = ' cedar-java'
240+ description = ' Java bindings for Cedar policy language.'
241+ url = ' http://www.cedarpolicy.com'
242+
243+ licenses {
244+ license {
245+ name = ' The Apache License, Version 2.0'
246+ url = ' http://www.apache.org/licenses/LICENSE-2.0.txt'
247+ }
248+ }
249+
250+ developers {
251+ developer {
252+ id = ' cedar'
253+ name = ' Cedar Team'
254+ email = ' cedar-sonatype-team@amazon.com'
255+ }
256+ }
257+
258+ scm {
259+ connection = ' scm:git:https://github.com/cedar-policy/cedar-java.git'
260+ developerConnection = ' scm:git:https://github.com/cedar-policy/cedar-java.git'
261+ url = ' https://github.com/cedar-policy/cedar-java'
262+ }
263+ }
264+ }
265+ }
266+ }
0 commit comments