Skip to content

Commit 0e3ff02

Browse files
Add schema AST, refactor lib
1 parent 0f9d348 commit 0e3ff02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1331
-55
lines changed
File renamed without changes.

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1+
# IDE
12
.vscode
23
.idea
4+
5+
# Gradle
6+
**/.gradle
7+
**/.kotlin
8+
9+
# Build dirs
10+
rsvp/build
11+
rsvp/bin
12+
rsvp/app/build
13+
rsvp/app/bin
14+
rsvp/policy-ast/build
15+
rsvp/policy-ast/bin

rsvp/.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

rsvp/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@ Before building this project, you will need to build and deploy CedarJava locall
99
1. Clone CedarJava somewhere on your machine:
1010
```
1111
git clone git@github.com:rebecca-odonoghue/cedar-java.git
12+
cd cedar-java
1213
```
1314
2. Build CedarJava:
1415
```
15-
cd CedarJava
16-
./gradlew build
16+
./CedarJava/gradlew build -p ./CedarJava
1717
```
1818
3. Optionally, run the Rust test suite that is not executed as part of the Gradle build:
1919
```
20-
cd CedarJavaFFI
21-
cargo test
20+
cargo test --manifest-path CedarJavaFFI/Cargo.toml
2221
```
2322
4. Deploy CedarJava locally:
2423
```
25-
cd CedarJava
26-
./gradlew publishToMavenLocal
24+
./CedarJava/gradlew publishToMavenLocal -p ./CedarJava
2725
```
2826
2927
- Build:
@@ -32,13 +30,14 @@ Before building this project, you will need to build and deploy CedarJava locall
3230
./gradlew build
3331
```
3432
35-
- Run tests and output coverage to `app/build/reports/jacoco/test/html/index.html`:
33+
- Run tests and output coverage to `**/build/reports/jacoco/test/html/index.html`:
3634
3735
```
3836
./gradlew test
3937
```
4038
4139
- Run CLI application:
40+
4241
```
4342
./gradlew run --args="optional string of space separated args"
4443
```
@@ -48,15 +47,16 @@ Before building this project, you will need to build and deploy CedarJava locall
4847
./gradlew publishToMavenLocal
4948
```
5049
51-
## Implement a new visitor
50+
## Implement a new policy visitor
5251
53-
Visitor classes can be found in the `uq.pac.rsvp.ast.visitor` package. Visitors that don't need to visit every node but would still like to traverse the entire tree can extend the `PolicyVisitorImpl` class. Otherwise, interface `PolicyVisitor` can be implemented directly.
52+
Visitor classes can be found in the `uq.pac.rsvp.policy.ast.visitor` package. Visitors that don't need to visit every node type but would still like to traverse the entire tree can extend the `PolicyVisitorImpl` class. Otherwise, interface `PolicyVisitor` can be implemented directly.
5453
55-
The JSON schema for the serialised Java AST defined in `app/src/main/resources/ast.schema.json`.
54+
The JSON schema for the serialised Java AST is defined in `lib/src/main/resources/ast.schema.json`. A schema for the Cedar JSON
55+
Schema syntax can be found in the [Cedar VSCode Extension repository](https://raw.githubusercontent.com/cedar-policy/vscode-cedar/refs/heads/main/schemas/cedarschema.schema.json).
5656
57-
## Using the library in another project
57+
## Using the policy AST library in another project
5858
59-
In `build.gradle` in the project:
59+
Include in `build.gradle`:
6060
6161
```
6262
repositories {
@@ -65,7 +65,7 @@ repositories {
6565
}
6666

6767
dependencies {
68-
implementation 'uq.pac.rsvp.ast:rsvp-ast-lib:1.0.0'
68+
implementation 'uq.pac.rsvp:policy-ast:1.0.0'
6969
}
7070

7171
```

rsvp/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
dependencies {
6-
implementation project(':lib')
6+
implementation project(':policy-ast')
77
}
88

99
jar {

rsvp/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ allprojects {
88
}
99

1010
dependencies {
11+
// Custom cedar-java fork (https://github.com/rebecca-odonoghue/cedar-java)
12+
implementation 'com.cedarpolicy:cedar-java:3.1.2-rsvp:uber'
13+
1114
implementation 'com.google.code.gson:gson:2.13.2'
1215

16+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.20.0'
17+
1318
// Use JUnit Jupiter for testing.
1419
testImplementation libs.junit.jupiter
15-
1620
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
1721

18-
// This dependency is used by the application.
19-
implementation libs.guava
2022

21-
implementation 'com.cedarpolicy:cedar-java:3.1.2-rsvp:uber'
2223
}
2324

2425
// Apply a specific Java toolchain to ease working on different environments.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ plugins {
55
publishing {
66
publications {
77
mavenJava(MavenPublication) {
8-
groupId "uq.pac.rsvp.ast"
9-
artifactId "rsvp-ast-lib"
8+
groupId "uq.pac.rsvp"
9+
artifactId "policy-ast"
1010
version "1.0.0"
1111
from components.java
1212
}

rsvp/lib/src/main/java/uq/pac/rsvp/policy/ast/Policy.java renamed to rsvp/policy-ast/src/main/java/uq/pac/rsvp/policy/ast/Policy.java

File renamed without changes.

rsvp/lib/src/main/java/uq/pac/rsvp/policy/ast/PolicySet.java renamed to rsvp/policy-ast/src/main/java/uq/pac/rsvp/policy/ast/PolicySet.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@
88
import com.google.gson.Gson;
99
import com.google.gson.GsonBuilder;
1010

11+
import uq.pac.rsvp.policy.ast.expr.EntityExpression;
1112
import uq.pac.rsvp.policy.ast.expr.Expression;
13+
import uq.pac.rsvp.policy.ast.expr.EntityExpression.EntityExpressionDeserialiser;
1214
import uq.pac.rsvp.policy.ast.expr.Expression.ExpressionDeserialiser;
1315

1416
public class PolicySet extends LinkedHashSet<Policy> {
1517

18+
/**
19+
* Parse a Cedar policy file and return the corresponding AST.
20+
*
21+
* @param policyFile the path to the Cedar policy file
22+
* @return a new PolicySet instance corresponding to the parsed Cedar policy
23+
* file
24+
* @throws InternalException If an error occurs while parsing the Cedar policy
25+
* file
26+
* @throws IOException If an IO error occurs while reading the policy file
27+
*/
1628
public static PolicySet parseCedarPolicySet(Path policyFile) throws InternalException, IOException {
1729
String json = com.cedarpolicy.model.policy.PolicySet.parseToJsonAst(policyFile);
1830
Gson gson = new GsonBuilder().registerTypeAdapter(Expression.class, new ExpressionDeserialiser())
31+
.registerTypeAdapter(EntityExpression.class, new EntityExpressionDeserialiser())
1932
.create();
2033
return gson.fromJson(json, PolicySet.class);
2134
}

rsvp/lib/src/main/java/uq/pac/rsvp/policy/ast/SourceLoc.java renamed to rsvp/policy-ast/src/main/java/uq/pac/rsvp/policy/ast/SourceLoc.java

File renamed without changes.

0 commit comments

Comments
 (0)