Skip to content

Commit e8e4cb3

Browse files
Kesha Hietaladependabot[bot]sarahcecshaobo-he-awsexceptionfactory
authored
Backport changes to the release/3.1.x branch (#100)
Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Sarah Cecchetti <sarahcec@amazon.com> Signed-off-by: Shaobo He <shaobohe@amazon.com> Signed-off-by: David Handermann <exceptionfactory@apache.org> Signed-off-by: Andrew Wells <anmwells@amazon.com> Signed-off-by: Kesha Hietala <khieta@amazon.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sarah Cecchetti <sarah@engageidentity.com> Co-authored-by: shaobo-he-aws <130499339+shaobo-he-aws@users.noreply.github.com> Co-authored-by: David Handermann <exceptionfactory@apache.org> Co-authored-by: Andrew Wells <130512013+andrewmwells-amazon@users.noreply.github.com>
1 parent 9046fa4 commit e8e4cb3

21 files changed

Lines changed: 331 additions & 158 deletions

File tree

.github/workflows/ci.yml

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
1-
name: Build & Test (CedarJava & CedarJavaFFI)
1+
name: Continuous Integration Build
22

33
on:
44
pull_request:
5+
workflow_dispatch:
56

67
env:
78
CARGO_TERM_COLOR: always
89

910
jobs:
10-
build_and_test_cedar_java_ffi:
11-
name: Rust project - latest
12-
runs-on: ubuntu-latest
11+
build:
1312
strategy:
1413
matrix:
15-
toolchain:
16-
- stable
14+
os: [ubuntu-latest, macos-14]
15+
include:
16+
- os: ubuntu-latest
17+
name: Build on Linux
18+
zigInstall: sudo snap install zig --beta --classic
19+
- os: macos-14
20+
name: Build on macOS
21+
zigInstall: brew install zig
22+
runs-on: ${{ matrix.os }}
23+
name: ${{ matrix.name }}
1724
steps:
18-
- name: Checkout CedarJava
19-
uses: actions/checkout@v3
20-
- name: Checkout cedar
21-
uses: actions/checkout@v3
22-
with:
23-
repository: cedar-policy/cedar
24-
ref: main
25-
path: ./cedar
26-
- name: rustup
27-
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
28-
- name: cargo fmt
29-
working-directory: ./CedarJavaFFI
25+
- name: Checkout cedar-java
26+
uses: actions/checkout@v4
27+
- name: Prepare Rust Build
28+
run: rustup update stable && rustup default stable
29+
- name: Check FFI Formatting
30+
working-directory: CedarJavaFFI
3031
run: cargo fmt --all --check
31-
- name: configure
32-
working-directory: ./CedarJava
33-
shell: bash
34-
run: bash config.sh run_int_tests
35-
- name: cargo build
36-
working-directory: ./CedarJavaFFI
37-
run: RUSTFLAGS="-D warnings -F unsafe-code" cargo build --verbose
38-
- name: cargo test
39-
working-directory: ./CedarJavaFFI
40-
run: RUSTFLAGS="-D warnings -F unsafe-code" cargo test --verbose
41-
- name: Build and Test CedarJava
42-
working-directory: ./CedarJava
43-
shell: bash
44-
run: export MUST_RUN_CEDAR_INTEGRATION_TESTS=1 && ./gradlew build
45-
- name: JavaDoc Cedarjava
46-
working-directory: ./CedarJava
47-
shell: bash
32+
- name: Install Zig
33+
run: ${{ matrix.zigInstall }}
34+
- name: Setup Java JDK
35+
uses: actions/setup-java@v4
36+
with:
37+
java-version: '17'
38+
distribution: 'corretto'
39+
cache: 'gradle'
40+
- name: Build FFI and Java Libraries
41+
working-directory: CedarJava
42+
run: ./gradlew build
43+
- name: Generate Java Documentation
44+
working-directory: CedarJava
4845
run: ./gradlew javadoc

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.gradle/
2+
.idea/
3+
/build
4+
/buildSrc/build/
5+
/gradle/
6+
/gradlew
7+
/gradlew.bat
8+
/wrapper/
9+
.DS_Store
10+
.jqwik-database
11+
*.iml
12+
.classpath
13+
.factorypath
14+
.project
15+
.settings/
16+
target/
17+
18+
# Ignore changes to gradle.properties because we enter passwords here for releases
19+
/gradle.properties

CedarJava/README.md

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,25 @@ This package provides the Java interface for the Cedar language. You can use the
44

55
For more information about Cedar, please see: https://www.cedarpolicy.com/
66

7-
## Usage
8-
This package depends on [Cedar](https://www.cedarpolicy.com/), a library
9-
that needs to be compiled so that it can be run on the used platform.
10-
You need JDK 17 or later to run the code.
7+
## Prerequisites
118

12-
You need to ensure the `CEDAR_JAVA_FFI_LIB` variable is set correctly. Typically ./config.sh will set this for you.
9+
- [JDK 17](https://openjdk.org/projects/jdk/17/) or later
10+
- [Rust](https://rustup.rs/) with `rustup`
11+
- [Zig](https://ziglang.org/learn/getting-started/) for cross compiling with [cargo-zigbuild](https://github.com/rust-cross/cargo-zigbuild)
1312

14-
### Building
15-
- Ensure Rust, Gradle and a JDK are installed.
16-
- then:
17-
```shell
18-
cd CedarJavaFFI
19-
cargo build
20-
cargo test
21-
cd ../CedarJava
22-
bash config.sh
23-
./gradlew build
24-
```
25-
This will run the tests as well (but not the integration tests).
13+
## Building
2614

27-
If you want to run the integration tests, you'll also need:
28-
```shell
29-
export CEDAR_INTEGRATION_TESTS_ROOT=`path_to_cedar/cedar-integration-tests`
30-
```
15+
Run the [Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper_basics.html)
16+
with the `build` task to compile both the Cedar Java Foreign Function Interface and the Cedar Java library.
3117

32-
Otherwise you can do (done for you in `config.sh`):
3318
```shell
34-
export CEDAR_INTEGRATION_TESTS_ROOT=`/tmp`
19+
./gradlew build
3520
```
36-
And the tests won't be found (and hence won't be run).
37-
3821

3922
## Debugging
4023

4124
If you're encountering unexpected errors, a good first step in debugging can be to enable TRACE-level logging for
42-
`cedarpolicy`, which will then show the exact messages being passed to Cedar. You can do this for
43-
the unit tests by modifying the `test/resources/log4j2.xml` file; this file also gives an example for what to do in
44-
other Log4j2-based packages.
25+
`com.cedarpolicy`, which will then show the exact messages being passed to Cedar.
4526

4627
Debugging calls across the JNI boundary is a bit tricky (as ever a bit more so on a Mac), but can be done by attaching
4728
both a Java and native debugger (such as GDB/LLDB) to the program.

CedarJava/build.gradle

Lines changed: 185 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
6773
dependencies {
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

Comments
 (0)