* bindings/java: Add prefix to native methods * bindings/java: Add javadocs and missing methods to Engine * Setup publishing uber-JAR via GitHub workflow * bindings/java: Update README * bindings/java: Improve native library loading from JAR * bindings/java: Fix usage of `working-directory` * bindings/java: Pass required `distribution` parameter to `actions/setup-java@v4` * bindings/java: Use Corretto distribution This is because Microsoft doesn't provide JDK8, see https://learn.microsoft.com/en-us/java/openjdk/download#openjdk-8. * bindings/java: Install GCC toolchain for `aarch64-unknown-linux-gnu` * bindings/java: Upload artifacts with different names from each step * bindings/java: Upload built JARs to GitHub
2.8 KiB
Regorus Java
Regorus is
- Rego-Rus(t) - A fast, light-weight Rego interpreter written in Rust.
- Rigorous - A rigorous enforcer of well-defined Rego semantics.
See main Regorus page for more details about the project.
Usage
Regorus Java is published to Maven Central with native libraries for the following:
- 64-bit Linux (kernel 3.2+, glibc 2.17+)
- ARM64 Linux (kernel 4.1, glibc 2.17+)
- 64-bit macOS (10.12+, Sierra+)
- ARM64 macOS (11.0+, Big Sur+)
- 64-bit MSVC (Windows 7+)
If you need to run it in a different OS or an architecture you need to manually build it.
If you're on one of the supported platforms, you can just pull prebuilt JAR from Maven Central by declaring a dependency on com.microsoft.regorus:regorus-java.
With Maven:
<dependencies>
<dependency>
<groupId>com.microsoft.regorus</groupId>
<artifactId>regorus-java</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
With Gradle:
// build.gradle.kts
implementation("com.microsoft.regorus:regorus-java:0.0.1")
Afterwards you can use it as follows:
import com.microsoft.regorus.Engine;
public class Test {
public static void main(String[] args) {
try (Engine engine = new Engine()) {
engine.addPolicy(
"hello.rego",
"package test\nmessage = concat(\", \", [input.message, data.message])"
);
engine.addDataJson("{\"message\":\"World!\"}");
engine.setInputJson("{\"message\":\"Hello\"}");
String resJson = engine.evalQuery("data.test.message");
System.out.println(resJson);
}
}
}
And you can see the following output once you run it:
{"result":[{"expressions":[{"value":"Hello, World!","text":"data.test.message","location":{"row":1,"col":1}}]}]}
Building
In order to build Regorus Java for a target platform, you need to install Rust target for that target platform first:
$ rustup target add aarch64-apple-darwin
Afterwards, you can build native library for that target using:
$ cargo build --release --target aarch64-apple-darwin
You will then have a native library at ../../target/aarch64-apple-darwin/release/libregorus_java.dylib depending on your target.
You can then build a JAR from source using:
$ mvn package
And you will have a JAR at ./target/regorus-java-0.0.1.jar.
You need to make sure both of the artifacts in Java's classpath.
For example with java CLI:
$ java -Djava.library.path=../../target/aarch64-apple-darwin/release/ -cp target/regorus-java-0.0.1.jar Test.java