Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ longer choose a generated protobuf runtime transitively. Add exactly one of thes
Do not put both generated protobuf artifacts on the same classpath; they provide the same generated
CEL protobuf classes for different protobuf runtime choices.

The generated protobuf classes check at runtime that `protobuf-java` is at least as new as the
protobuf version they were generated with. If your framework or platform BOM manages an older
`protobuf-java` (for example, Quarkus 4.0 manages 4.35.x), loading CEL-Java fails with a
`ProtobufRuntimeVersionException`. Either override the managed `protobuf-java` version, or use
[`cel-standalone`](#dependency-free-artifact), which relocates its protobuf dependencies.

## Usage

### Basic scripts
Expand Down
1 change: 1 addition & 0 deletions build-logic/src/main/kotlin/cel-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ val nonPublishedProjects =
"cel-conformance",
"cel-quarkus-smoke-standalone",
"cel-quarkus-smoke-core-pb3-jackson3",
"cel-quarkus-smoke-core-pb4-jackson3",
)

if (project.name !in nonPublishedProjects) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ nessieRunPlugin = "0.27.3"
protobuf = "4.36.2"
protobuf3 = { strictly = "[3.25.9, 3.26[", prefer = "3.25.9" }
protobufPlugin = "0.10.1"
quarkus = "3.40.1.2"
quarkus = "4.0.1"
shadowPlugin = "9.6.1"
slf4j = "1.7.36"
spotlessPlugin = "8.12.0"
Expand Down
2 changes: 1 addition & 1 deletion quarkus-smoke-core-pb3-jackson3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (testNativeRequested) {

dependencies {
// This smoke project deliberately verifies Protobuf 3, while the Quarkus BOM tracks Protobuf 4.
implementation(platform(libs.quarkus.bom)) {
implementation(enforcedPlatform(libs.quarkus.bom)) {
exclude(group = "com.google.protobuf", module = "protobuf-java")
}
implementation("io.quarkus:quarkus-arc")
Expand Down
60 changes: 60 additions & 0 deletions quarkus-smoke-core-pb4-jackson3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2026 The Authors of CEL-Java
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
alias(libs.plugins.quarkus)
id("cel-conventions")
`java-library`
}

description = "Quarkus native smoke test for cel-core, cel-generated-pb, and cel-jackson3"

val testNativeRequested =
gradle.startParameter.taskNames.any { taskName ->
taskName == "testNative" || taskName == "${project.path}:testNative"
}

if (testNativeRequested) {
quarkus {
set("native.enabled", "true")
set("native.container-build", "true")
set("package.jar.enabled", "false")
}
}

dependencies {
// cel-generated-pb requires a Protobuf runtime at least as new as its gencode, which can be newer
// than the Protobuf version managed by the Quarkus BOM.
implementation(enforcedPlatform(libs.quarkus.bom)) {
exclude(group = "com.google.protobuf", module = "protobuf-java")
}
implementation("io.quarkus:quarkus-arc")
implementation("io.quarkus:quarkus-rest-jackson")
implementation(project(":cel-core"))
implementation(project(":cel-generated-pb"))
implementation(testFixtures(project(":cel-generated-pb")))
implementation(project(":cel-jackson3"))

testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType<JavaCompile>().configureEach { options.release.set(21) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (C) 2026 The Authors of CEL-Java
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.projectnessie.cel.quarkus.smoke.corepb4jackson3;

import static java.util.Arrays.asList;
import static java.util.Map.of;
import static org.projectnessie.cel.Env.newCustomEnv;
import static org.projectnessie.cel.EnvOption.declarations;
import static org.projectnessie.cel.EnvOption.types;
import static org.projectnessie.cel.Library.StdLib;

import com.google.protobuf.Int32Value;
import dev.cel.expr.conformance.proto3.NestedTestAllTypes;
import dev.cel.expr.conformance.proto3.TestAllTypes;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.time.Instant;
import org.projectnessie.cel.Ast;
import org.projectnessie.cel.Env;
import org.projectnessie.cel.Env.AstIssuesTuple;
import org.projectnessie.cel.Program;
import org.projectnessie.cel.Program.EvalResult;
import org.projectnessie.cel.checker.Decls;
import org.projectnessie.cel.common.types.Err;
import org.projectnessie.cel.common.types.pb.ProtoTypeRegistry;
import org.projectnessie.cel.common.types.ref.Val;
import org.projectnessie.cel.types.jackson3.Jackson3Registry;

@Path("/cel/native-smoke")
public class SmokeResource {
private static final String JACKSON_EXPRESSION =
"input.name == \"reports\" && request.time < timestamp(\"2026-08-01T00:00:00Z\")";

private static final String PROTO_EXPRESSION = "proto.single_int32_wrapper == 123";

@GET
@Produces(MediaType.APPLICATION_JSON)
public SmokeResponse smoke() {
return new SmokeResponse(
"cel-core+cel-generated-pb+cel-jackson3", evaluateJackson(), evaluateProto());
}

private boolean evaluateJackson() {
Env env =
newCustomEnv(
Jackson3Registry.newRegistry(),
asList(
StdLib(),
types(Input.class),
declarations(
Decls.newVar("input", Decls.newObjectType(Input.class.getName())),
Decls.newVar("request.time", Decls.Timestamp))));

Program program = compile(env, JACKSON_EXPRESSION);
EvalResult result =
program.eval(
of(
"input",
new Input("reports"),
"request.time",
Instant.parse("2026-07-31T23:59:59Z")));
return booleanResult(result);
}

private boolean evaluateProto() {
Env env =
newCustomEnv(
ProtoTypeRegistry.newRegistry(),
asList(
StdLib(),
types(TestAllTypes.getDefaultInstance()),
declarations(
Decls.newVar(
"proto",
Decls.newObjectType(TestAllTypes.getDescriptor().getFullName())))));

Program program = compile(env, PROTO_EXPRESSION);
EvalResult result =
program.eval(
of(
"proto",
TestAllTypes.newBuilder().setSingleInt32Wrapper(Int32Value.of(123)).build()));
return booleanResult(result);
}

private static Program compile(Env env, String expression) {
AstIssuesTuple parsed = env.parse(expression);
if (parsed.hasIssues()) {
throw new IllegalStateException("parse failed: " + parsed.getIssues());
}

Ast ast = parsed.getAst();
AstIssuesTuple checked = env.check(ast);
if (checked.hasIssues()) {
throw new IllegalStateException("check failed: " + checked.getIssues());
}

return env.program(checked.getAst());
}

private static boolean booleanResult(EvalResult result) {
Val value = result.getVal();
if (Err.isError(value)) {
throw new IllegalStateException("evaluation failed: " + value);
}
return value.booleanValue();
}

public record SmokeResponse(String engine, boolean jackson, boolean protobuf) {}

@RegisterForReflection(targets = {TestAllTypes.class, NestedTestAllTypes.class})
static final class ProtobufReflection {}

@RegisterForReflection
public static final class Input {
private final String name;

public Input(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (C) 2026 The Authors of CEL-Java
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

quarkus.banner.enabled=false
quarkus.http.test-port=8183
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2026 The Authors of CEL-Java
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.projectnessie.cel.quarkus.smoke.corepb4jackson3;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
class SmokeResourceNativeIT extends SmokeResourceTest {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2026 The Authors of CEL-Java
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.projectnessie.cel.quarkus.smoke.corepb4jackson3;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

@QuarkusTest
class SmokeResourceTest {
@Test
void evaluatesCelExpressions() {
given()
.when()
.get("/cel/native-smoke")
.then()
.statusCode(200)
.body("engine", equalTo("cel-core+cel-generated-pb+cel-jackson3"))
.body("jackson", equalTo(true))
.body("protobuf", equalTo(true));
}
}
5 changes: 4 additions & 1 deletion quarkus-smoke-standalone/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ if (testNativeRequested) {
}

dependencies {
implementation(platform(libs.quarkus.bom))
implementation(enforcedPlatform(libs.quarkus.bom))
implementation("io.quarkus:quarkus-arc")
implementation("io.quarkus:quarkus-rest-jackson")
implementation(project(":cel-standalone")) { isTransitive = false }
// Quarkus 4 uses Jackson 3; this smoke test covers cel-standalone with Jackson 2.
implementation(platform(libs.jackson2.bom))
implementation("com.fasterxml.jackson.core:jackson-databind")

testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,6 @@ celProject("quarkus-smoke-standalone")

celProject("quarkus-smoke-core-pb3-jackson3")

celProject("quarkus-smoke-core-pb4-jackson3")

celProject("bom")