values = new Long2ObjectHashMap<>();
49 |
50 | /** IDs implements the EvalState interface method. */
51 | @Override
52 | public long[] ids() {
53 | return values.keySet().stream().mapToLong(l -> l).toArray();
54 | }
55 |
56 | /** Value is an implementation of the EvalState interface method. */
57 | @Override
58 | public Val value(long id) {
59 | return values.get(id);
60 | }
61 |
62 | /** SetValue is an implementation of the EvalState interface method. */
63 | @Override
64 | public void setValue(long id, Val v) {
65 | values.put(id, v);
66 | }
67 |
68 | /** Reset implements the EvalState interface method. */
69 | @Override
70 | public void reset() {
71 | values.clear();
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/core/src/main/java/org/projectnessie/cel/interpreter/ResolvedValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.interpreter;
17 |
18 | import java.util.Objects;
19 |
20 | public final class ResolvedValue {
21 | public static final ResolvedValue NULL_VALUE = new ResolvedValue(null, true);
22 | public static final ResolvedValue ABSENT = new ResolvedValue(null, false);
23 |
24 | public static ResolvedValue resolvedValue(Object value) {
25 | return new ResolvedValue(Objects.requireNonNull(value), true);
26 | }
27 |
28 | private final Object value;
29 | private final boolean present;
30 |
31 | private ResolvedValue(Object value, boolean present) {
32 | this.value = value;
33 | this.present = present;
34 | }
35 |
36 | public Object value() {
37 | return value;
38 | }
39 |
40 | public boolean present() {
41 | return present;
42 | }
43 |
44 | @Override
45 | public boolean equals(Object o) {
46 | if (this == o) return true;
47 | if (o == null || getClass() != o.getClass()) return false;
48 |
49 | ResolvedValue that = (ResolvedValue) o;
50 |
51 | if (present != that.present) return false;
52 | return Objects.equals(value, that.value);
53 | }
54 |
55 | @Override
56 | public int hashCode() {
57 | int result = value != null ? value.hashCode() : 0;
58 | result = 31 * result + (present ? 1 : 0);
59 | return result;
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return "ResolvedValue{present=" + present + ", value=" + value + '}';
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/core/src/main/java/org/projectnessie/cel/interpreter/functions/BinaryOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.interpreter.functions;
17 |
18 | import org.projectnessie.cel.common.types.ref.Val;
19 |
20 | /** BinaryOp is a function that takes two values and produces an output. */
21 | @FunctionalInterface
22 | public interface BinaryOp {
23 | Val invoke(Val lhs, Val rhs);
24 | }
25 |
--------------------------------------------------------------------------------
/core/src/main/java/org/projectnessie/cel/interpreter/functions/FunctionOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.interpreter.functions;
17 |
18 | import org.projectnessie.cel.common.types.ref.Val;
19 |
20 | /**
21 | * FunctionOp is a function with accepts zero or more arguments and produces an value (as
22 | * interface{}) or error as a result.
23 | */
24 | @FunctionalInterface
25 | public interface FunctionOp {
26 | Val invoke(Val... values);
27 | }
28 |
--------------------------------------------------------------------------------
/core/src/main/java/org/projectnessie/cel/interpreter/functions/UnaryOp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.interpreter.functions;
17 |
18 | import org.projectnessie.cel.common.types.ref.Val;
19 |
20 | /** UnaryOp is a function that takes a single value and produces an output. */
21 | @FunctionalInterface
22 | public interface UnaryOp {
23 | Val invoke(Val val);
24 | }
25 |
--------------------------------------------------------------------------------
/core/src/main/java/org/projectnessie/cel/parser/MacroExpander.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.parser;
17 |
18 | import com.google.api.expr.v1alpha1.Expr;
19 | import java.util.List;
20 | import org.projectnessie.cel.common.ErrorWithLocation;
21 |
22 | /**
23 | * MacroExpander converts the target and args of a function call that matches a Macro.
24 | *
25 | * Note: when the Macros.IsReceiverStyle() is true, the target argument will be nil.
26 | */
27 | @FunctionalInterface
28 | public interface MacroExpander {
29 | Expr expand(ExprHelper eh, Expr target, List args) throws ErrorWithLocation;
30 | }
31 |
--------------------------------------------------------------------------------
/core/src/main/java/org/projectnessie/cel/parser/ParseError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.parser;
17 |
18 | import org.projectnessie.cel.common.Location;
19 |
20 | public final class ParseError extends RuntimeException {
21 | private final Location location;
22 |
23 | public ParseError(Location location, String message) {
24 | super(message);
25 | this.location = location;
26 | }
27 |
28 | public Location getLocation() {
29 | return location;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.parser;
17 |
18 | import org.projectnessie.cel.shaded.org.antlr.v4.runtime.CharStream;
19 | import org.projectnessie.cel.shaded.org.antlr.v4.runtime.IntStream;
20 | import org.projectnessie.cel.shaded.org.antlr.v4.runtime.misc.Interval;
21 |
22 | public final class StringCharStream implements CharStream {
23 |
24 | private final String buf;
25 | private final String src;
26 | private int pos;
27 |
28 | public StringCharStream(String buf, String src) {
29 | this.buf = buf;
30 | this.src = src;
31 | }
32 |
33 | @Override
34 | public void consume() {
35 | if (pos >= buf.length()) {
36 | throw new RuntimeException("cannot consume EOF");
37 | }
38 | pos++;
39 | }
40 |
41 | @Override
42 | public int LA(int offset) {
43 | if (offset == 0) {
44 | return 0;
45 | }
46 | if (offset < 0) {
47 | offset++;
48 | }
49 | pos = pos + offset - 1;
50 | if (pos < 0 || pos >= buf.length()) {
51 | return IntStream.EOF;
52 | }
53 | return buf.charAt(pos);
54 | }
55 |
56 | @Override
57 | public int mark() {
58 | return -1;
59 | }
60 |
61 | @Override
62 | public void release(int marker) {}
63 |
64 | @Override
65 | public int index() {
66 | return pos;
67 | }
68 |
69 | @Override
70 | public void seek(int index) {
71 | if (index <= pos) {
72 | pos = index;
73 | return;
74 | }
75 | pos = Math.min(index, buf.length());
76 | }
77 |
78 | @Override
79 | public int size() {
80 | return buf.length();
81 | }
82 |
83 | @Override
84 | public String getSourceName() {
85 | return src;
86 | }
87 |
88 | @Override
89 | public String getText(Interval interval) {
90 | int start = interval.a;
91 | int stop = interval.b;
92 | if (stop >= buf.length()) {
93 | stop = buf.length() - 1;
94 | }
95 | if (start >= buf.length()) {
96 | return "";
97 | }
98 | return buf.substring(start, stop + 1);
99 | }
100 |
101 | @Override
102 | public String toString() {
103 | return buf;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/core/src/main/resources/META-INF/native-image/org.projectnessie.cel/cel-core/main/native-image.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2023 The Authors of CEL-Java
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | Args = -H:ReflectionConfigurationResources=${.}/reflection-config.json
18 |
--------------------------------------------------------------------------------
/core/src/main/resources/META-INF/native-image/org.projectnessie.cel/cel-core/main/reflection-config.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name" : "com.google.protobuf.NullValue",
4 | "allDeclaredConstructors" : true,
5 | "allPublicConstructors" : true,
6 | "allDeclaredMethods" : true,
7 | "allPublicMethods" : true,
8 | "allDeclaredFields" : true,
9 | "allPublicFields" : true
10 | }
11 | ]
12 |
--------------------------------------------------------------------------------
/core/src/test/java/org/projectnessie/cel/checker/CheckerEnvTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.checker;
17 |
18 | import static java.util.Collections.singletonList;
19 | import static org.projectnessie.cel.checker.CheckerEnv.newStandardCheckerEnv;
20 | import static org.projectnessie.cel.common.types.pb.ProtoTypeRegistry.newRegistry;
21 |
22 | import com.google.api.expr.v1alpha1.Type;
23 | import java.util.List;
24 | import org.assertj.core.api.Assertions;
25 | import org.junit.jupiter.api.Test;
26 | import org.projectnessie.cel.common.containers.Container;
27 | import org.projectnessie.cel.common.types.Overloads;
28 |
29 | public class CheckerEnvTest {
30 |
31 | @Test
32 | void overlappingIdentifier() {
33 | CheckerEnv env = newStandardCheckerEnv(Container.defaultContainer, newRegistry());
34 | Assertions.assertThatThrownBy(() -> env.add(Decls.newVar("int", Decls.newTypeType(null))))
35 | .hasMessage("overlapping identifier for name 'int'");
36 | }
37 |
38 | @Test
39 | void overlappingMacro() {
40 | CheckerEnv env = newStandardCheckerEnv(Container.defaultContainer, newRegistry());
41 | Assertions.assertThatThrownBy(
42 | () ->
43 | env.add(
44 | Decls.newFunction(
45 | "has", Decls.newOverload("has", singletonList(Decls.String), Decls.Bool))))
46 | .hasMessage("overlapping macro for name 'has' with 1 args");
47 | }
48 |
49 | @Test
50 | void overlappingOverload() {
51 | CheckerEnv env = newStandardCheckerEnv(Container.defaultContainer, newRegistry());
52 | Type paramA = Decls.newTypeParamType("A");
53 | List typeParamAList = singletonList("A");
54 | Assertions.assertThatThrownBy(
55 | () ->
56 | env.add(
57 | Decls.newFunction(
58 | Overloads.TypeConvertDyn,
59 | Decls.newParameterizedOverload(
60 | Overloads.ToDyn, singletonList(paramA), Decls.Dyn, typeParamAList))))
61 | .hasMessage(
62 | "overlapping overload for name 'dyn' (type '(type_param: \"A\") -> dyn' with overloadId: 'to_dyn' cannot be distinguished from '(type_param: \"A\") -> dyn' with overloadId: 'to_dyn')");
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/core/src/test/java/org/projectnessie/cel/common/types/NullTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.common.types;
17 |
18 | import static org.assertj.core.api.Assertions.assertThat;
19 | import static org.projectnessie.cel.common.types.BoolT.True;
20 | import static org.projectnessie.cel.common.types.NullT.NullType;
21 | import static org.projectnessie.cel.common.types.StringT.StringType;
22 | import static org.projectnessie.cel.common.types.StringT.stringOf;
23 | import static org.projectnessie.cel.common.types.TypeT.TypeType;
24 |
25 | import com.google.protobuf.Any;
26 | import com.google.protobuf.NullValue;
27 | import com.google.protobuf.Value;
28 | import org.junit.jupiter.api.Test;
29 |
30 | public class NullTest {
31 |
32 | @Test
33 | void nullConvertToNative_Json() {
34 | Value expected = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
35 |
36 | // Json Value
37 | Value val = NullT.NullValue.convertToNative(Value.class);
38 | assertThat(expected).isEqualTo(val);
39 | }
40 |
41 | @Test
42 | void nullConvertToNative() throws Exception {
43 | Value expected = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
44 |
45 | // google.protobuf.Any
46 | Any val = NullT.NullValue.convertToNative(Any.class);
47 |
48 | Value data = val.unpack(Value.class);
49 | assertThat(expected).isEqualTo(data);
50 |
51 | // NullValue
52 | NullValue val2 = NullT.NullValue.convertToNative(NullValue.class);
53 | assertThat(val2).isEqualTo(NullValue.NULL_VALUE);
54 | }
55 |
56 | @Test
57 | void nullConvertToType() {
58 | assertThat(NullT.NullValue.convertToType(NullType).equal(NullT.NullValue)).isSameAs(True);
59 |
60 | assertThat(NullT.NullValue.convertToType(StringType).equal(stringOf("null"))).isSameAs(True);
61 | assertThat(NullT.NullValue.convertToType(TypeType).equal(NullType)).isSameAs(True);
62 | }
63 |
64 | @Test
65 | void nullEqual() {
66 | assertThat(NullT.NullValue.equal(NullT.NullValue)).isSameAs(True);
67 | }
68 |
69 | @Test
70 | void nullType() {
71 | assertThat(NullT.NullValue.type()).isSameAs(NullType);
72 | }
73 |
74 | @Test
75 | void nullValue() {
76 | assertThat(NullT.NullValue.value()).isSameAs(NullValue.NULL_VALUE);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/core/src/test/java/org/projectnessie/cel/common/types/TypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.common.types;
17 |
18 | import static org.assertj.core.api.Assertions.assertThat;
19 | import static org.projectnessie.cel.common.types.BoolT.BoolType;
20 | import static org.projectnessie.cel.common.types.BytesT.BytesType;
21 | import static org.projectnessie.cel.common.types.DoubleT.DoubleType;
22 | import static org.projectnessie.cel.common.types.DurationT.DurationType;
23 | import static org.projectnessie.cel.common.types.IntT.IntType;
24 | import static org.projectnessie.cel.common.types.ListT.ListType;
25 | import static org.projectnessie.cel.common.types.MapT.MapType;
26 | import static org.projectnessie.cel.common.types.NullT.NullType;
27 | import static org.projectnessie.cel.common.types.StringT.StringType;
28 | import static org.projectnessie.cel.common.types.TimestampT.TimestampType;
29 | import static org.projectnessie.cel.common.types.TypeT.TypeType;
30 | import static org.projectnessie.cel.common.types.UintT.UintType;
31 |
32 | import org.junit.jupiter.api.Test;
33 | import org.projectnessie.cel.common.types.ref.Type;
34 | import org.projectnessie.cel.common.types.ref.Val;
35 |
36 | public class TypeTest {
37 |
38 | @Test
39 | void typeConvertToType() {
40 | Type[] stdTypes =
41 | new Type[] {
42 | BoolType,
43 | BytesType,
44 | DoubleType,
45 | DurationType,
46 | IntType,
47 | ListType,
48 | MapType,
49 | NullType,
50 | StringType,
51 | TimestampType,
52 | TypeType,
53 | UintType,
54 | };
55 | for (Type stdType : stdTypes) {
56 | Val cnv = stdType.convertToType(TypeType);
57 | assertThat(cnv).isEqualTo(TypeType);
58 | }
59 | }
60 |
61 | @Test
62 | void typeType() {
63 | assertThat(TypeType.type()).isSameAs(TypeType);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/core/src/test/java/org/projectnessie/cel/common/types/pb/UnwrapContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.common.types.pb;
17 |
18 | import static org.assertj.core.api.Assertions.assertThat;
19 | import static org.projectnessie.cel.common.types.pb.Db.newDb;
20 |
21 | import com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes;
22 |
23 | /** Required by {@link UnwrapTestCase} et al. */
24 | class UnwrapContext {
25 |
26 | final Db pbdb;
27 | final PbTypeDescription msgDesc;
28 |
29 | UnwrapContext() {
30 | pbdb = newDb();
31 | pbdb.registerMessage(TestAllTypes.getDefaultInstance());
32 | String msgType = "google.protobuf.Value";
33 | msgDesc = pbdb.describeType(msgType);
34 | assertThat(msgDesc).isNotNull();
35 | }
36 |
37 | private static UnwrapContext instance;
38 |
39 | static synchronized UnwrapContext get() {
40 | if (instance == null) {
41 | instance = new UnwrapContext();
42 | }
43 | return instance;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/generated-antlr/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
18 |
19 | plugins {
20 | `java-library`
21 | antlr
22 | `maven-publish`
23 | signing
24 | id("com.github.johnrengelman.shadow")
25 | `cel-conventions`
26 | }
27 |
28 | dependencies {
29 | antlr(libs.antlr.antlr4) // TODO remove from runtime-classpath *sigh*
30 | implementation(libs.antlr.antlr4.runtime)
31 | }
32 |
33 | // The antlr-plugin should ideally do this
34 | tasks.named("sourcesJar") { dependsOn(tasks.named("generateGrammarSource")) }
35 |
36 | tasks.named("jar") { archiveClassifier.set("raw") }
37 |
38 | tasks.named("shadowJar") {
39 | // The antlr-plugin should ideally do this
40 | dependsOn(tasks.named("generateGrammarSource"))
41 |
42 | dependencies { include(dependency("org.antlr:antlr4-runtime")) }
43 | relocate("org.antlr.v4.runtime", "org.projectnessie.cel.shaded.org.antlr.v4.runtime")
44 | archiveClassifier.set("")
45 | }
46 |
--------------------------------------------------------------------------------
/generated-antlr/src/main/antlr/org.projectnessie.cel.parser.gen/CEL.tokens:
--------------------------------------------------------------------------------
1 | EQUALS=1
2 | NOT_EQUALS=2
3 | IN=3
4 | LESS=4
5 | LESS_EQUALS=5
6 | GREATER_EQUALS=6
7 | GREATER=7
8 | LOGICAL_AND=8
9 | LOGICAL_OR=9
10 | LBRACKET=10
11 | RPRACKET=11
12 | LBRACE=12
13 | RBRACE=13
14 | LPAREN=14
15 | RPAREN=15
16 | DOT=16
17 | COMMA=17
18 | MINUS=18
19 | EXCLAM=19
20 | QUESTIONMARK=20
21 | COLON=21
22 | PLUS=22
23 | STAR=23
24 | SLASH=24
25 | PERCENT=25
26 | TRUE=26
27 | FALSE=27
28 | NULL=28
29 | WHITESPACE=29
30 | COMMENT=30
31 | NUM_FLOAT=31
32 | NUM_INT=32
33 | NUM_UINT=33
34 | STRING=34
35 | BYTES=35
36 | IDENTIFIER=36
37 | '=='=1
38 | '!='=2
39 | 'in'=3
40 | '<'=4
41 | '<='=5
42 | '>='=6
43 | '>'=7
44 | '&&'=8
45 | '||'=9
46 | '['=10
47 | ']'=11
48 | '{'=12
49 | '}'=13
50 | '('=14
51 | ')'=15
52 | '.'=16
53 | ','=17
54 | '-'=18
55 | '!'=19
56 | '?'=20
57 | ':'=21
58 | '+'=22
59 | '*'=23
60 | '/'=24
61 | '%'=25
62 | 'true'=26
63 | 'false'=27
64 | 'null'=28
65 |
--------------------------------------------------------------------------------
/generated-antlr/src/main/antlr/org.projectnessie.cel.parser.gen/CELLexer.tokens:
--------------------------------------------------------------------------------
1 | EQUALS=1
2 | NOT_EQUALS=2
3 | IN=3
4 | LESS=4
5 | LESS_EQUALS=5
6 | GREATER_EQUALS=6
7 | GREATER=7
8 | LOGICAL_AND=8
9 | LOGICAL_OR=9
10 | LBRACKET=10
11 | RPRACKET=11
12 | LBRACE=12
13 | RBRACE=13
14 | LPAREN=14
15 | RPAREN=15
16 | DOT=16
17 | COMMA=17
18 | MINUS=18
19 | EXCLAM=19
20 | QUESTIONMARK=20
21 | COLON=21
22 | PLUS=22
23 | STAR=23
24 | SLASH=24
25 | PERCENT=25
26 | TRUE=26
27 | FALSE=27
28 | NULL=28
29 | WHITESPACE=29
30 | COMMENT=30
31 | NUM_FLOAT=31
32 | NUM_INT=32
33 | NUM_UINT=33
34 | STRING=34
35 | BYTES=35
36 | IDENTIFIER=36
37 | '=='=1
38 | '!='=2
39 | 'in'=3
40 | '<'=4
41 | '<='=5
42 | '>='=6
43 | '>'=7
44 | '&&'=8
45 | '||'=9
46 | '['=10
47 | ']'=11
48 | '{'=12
49 | '}'=13
50 | '('=14
51 | ')'=15
52 | '.'=16
53 | ','=17
54 | '-'=18
55 | '!'=19
56 | '?'=20
57 | ':'=21
58 | '+'=22
59 | '*'=23
60 | '/'=24
61 | '%'=25
62 | 'true'=26
63 | 'false'=27
64 | 'null'=28
65 |
--------------------------------------------------------------------------------
/generated-pb/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import com.google.protobuf.gradle.ProtobufExtension
18 | import com.google.protobuf.gradle.ProtobufPlugin
19 |
20 | plugins {
21 | `java-library`
22 | `maven-publish`
23 | signing
24 | `cel-conventions`
25 | `java-test-fixtures`
26 | }
27 |
28 | apply()
29 |
30 | sourceSets.main {
31 | java.srcDir(layout.buildDirectory.dir("generated/source/proto/main/java"))
32 | java.destinationDirectory.set(layout.buildDirectory.dir("classes/java/generated"))
33 | }
34 |
35 | sourceSets.test {
36 | java.srcDir(layout.buildDirectory.dir("generated/source/proto/test/java"))
37 | java.destinationDirectory.set(layout.buildDirectory.dir("classes/java/generatedTest"))
38 | }
39 |
40 | dependencies {
41 | api(libs.protobuf.java)
42 |
43 | // Since we need the protobuf stuff in this cel-core module, it's easy to generate the
44 | // gRPC code as well. But do not expose the gRPC dependencies "publicly".
45 | compileOnly(libs.grpc.protobuf)
46 | compileOnly(libs.grpc.stub)
47 | compileOnly(libs.tomcat.annotations.api)
48 | }
49 |
50 | // *.proto files taken from https://github.com/googleapis/googleapis/ repo, available as a git
51 | // submodule
52 | configure {
53 | // Configure the protoc executable
54 | protoc {
55 | // Download from repositories
56 | artifact = "com.google.protobuf:protoc:${libs.versions.protobuf.get()}"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/generated-pb/src/main/proto/google/api/expr/v1alpha1:
--------------------------------------------------------------------------------
1 | ../../../../../../../submodules/googleapis/google/api/expr/v1alpha1
--------------------------------------------------------------------------------
/generated-pb/src/main/proto/google/rpc:
--------------------------------------------------------------------------------
1 | ../../../../../submodules/googleapis/google/rpc
--------------------------------------------------------------------------------
/generated-pb/src/testFixtures/proto/out_of_order_enum.proto:
--------------------------------------------------------------------------------
1 | package org.projectnessie.cel.test.proto3;
2 |
3 | // Enum intended to provide test values where the ordinal/index of the
4 | // enum variant differs from the actual enum value.
5 | enum OutOfOrderEnum {
6 | ZERO = 0;
7 | // TWO is set to have a value of 2, but it's in the 1-indexed position
8 | // because it is out of order.
9 | TWO = 2;
10 | ONE = 1;
11 | // FIVE is set to have a value of 5, but it's in the 3-indexed position
12 | // because there is a gap in the sequence of enum values.
13 | FIVE = 5;
14 | }
15 |
--------------------------------------------------------------------------------
/generated-pb/src/testFixtures/proto/proto-map.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | option java_package = "org.projectnessie.cel.proto.tests";
4 | option java_outer_classname = "ProtoTestTypes";
5 | option java_generate_equals_and_hash = true;
6 |
7 | message EventA {
8 | bool property_bool = 5;
9 | map map_str = 11;
10 | }
11 |
--------------------------------------------------------------------------------
/generated-pb/src/testFixtures/proto/proto/test/v1/proto2:
--------------------------------------------------------------------------------
1 | ../../../../../../../submodules/cel-spec/proto/test/v1/proto2
--------------------------------------------------------------------------------
/generated-pb/src/testFixtures/proto/proto/test/v1/proto3:
--------------------------------------------------------------------------------
1 | ../../../../../../../submodules/cel-spec/proto/test/v1/proto3
--------------------------------------------------------------------------------
/generated-pb3/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import com.google.protobuf.gradle.ProtobufExtension
18 | import com.google.protobuf.gradle.ProtobufPlugin
19 |
20 | plugins {
21 | `java-library`
22 | `maven-publish`
23 | signing
24 | `cel-conventions`
25 | `java-test-fixtures`
26 | }
27 |
28 | apply()
29 |
30 | sourceSets.main {
31 | java.srcDir(layout.buildDirectory.dir("generated/source/proto/main/java"))
32 | java.destinationDirectory.set(layout.buildDirectory.dir("classes/java/generated"))
33 | }
34 |
35 | sourceSets.test {
36 | java.srcDir(layout.buildDirectory.dir("generated/source/proto/test/java"))
37 | java.destinationDirectory.set(layout.buildDirectory.dir("classes/java/generatedTest"))
38 | }
39 |
40 | dependencies {
41 | api(libs.protobuf.java) { version { strictly(libs.versions.protobuf3.get()) } }
42 |
43 | // Since we need the protobuf stuff in this cel-core module, it's easy to generate the
44 | // gRPC code as well. But do not expose the gRPC dependencies "publicly".
45 | compileOnly(libs.grpc.protobuf)
46 | compileOnly(libs.grpc.stub)
47 | compileOnly(libs.tomcat.annotations.api)
48 | }
49 |
50 | // *.proto files taken from https://github.com/googleapis/googleapis/ repo, available as a git
51 | // submodule
52 | configure {
53 | // Configure the protoc executable
54 | protoc {
55 | // Download from repositories
56 | artifact = "com.google.protobuf:protoc:${libs.versions.protobuf3.get()}"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/generated-pb3/src:
--------------------------------------------------------------------------------
1 | ../generated-pb/src
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # enable the Gradle build cache
2 | org.gradle.caching=true
3 | # enable Gradle parallel builds
4 | org.gradle.parallel=true
5 | # configure only necessary Gradle tasks
6 | org.gradle.configureondemand=true\
7 | #
8 | org.gradle.jvmargs=\
9 | --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
10 | --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
11 | --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
12 | --add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \
13 | --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
14 | --add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
15 | --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
16 | --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
17 | --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
18 | --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
19 |
--------------------------------------------------------------------------------
/gradle/contributors.csv:
--------------------------------------------------------------------------------
1 | alancao-uber,https://github.com/alancao-uber
2 |
--------------------------------------------------------------------------------
/gradle/developers.csv:
--------------------------------------------------------------------------------
1 | snazy,Robert Stupp,https://github.com/snazy
2 | nastra,Eduard Tudenhoefner,https://github.com/nastra
3 | rymurr,Ryan Murray,https://github.com/rymurr
4 | laurentgo,Laurent Goujon,https://github.com/laurentgo
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/projectnessie/cel-java/62013f1910e1455f7439683ab4cadee982a2e2b7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionSha256Sum=443c9c8ee2ac1ee0e11881a40f2376d79c66386264a44b24a9f8ca67e633375f
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-all.zip
5 | networkTimeout=10000
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/ide-name.txt:
--------------------------------------------------------------------------------
1 | CEL-Java
--------------------------------------------------------------------------------
/jackson/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | plugins {
18 | `java-library`
19 | `maven-publish`
20 | signing
21 | id("org.caffinitas.gradle.testsummary")
22 | id("org.caffinitas.gradle.testrerun")
23 | `cel-conventions`
24 | }
25 |
26 | dependencies {
27 | api(project(":cel-core"))
28 |
29 | implementation(platform(libs.jackson.bom))
30 | implementation("com.fasterxml.jackson.core:jackson-databind")
31 | implementation("com.fasterxml.jackson.core:jackson-core")
32 | implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-protobuf")
33 | implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
34 |
35 | testImplementation(project(":cel-tools"))
36 | testAnnotationProcessor(libs.immutables.value.processor)
37 | testCompileOnly(libs.immutables.value.annotations)
38 | testImplementation(libs.findbugs.jsr305)
39 |
40 | testImplementation(platform(libs.junit.bom))
41 | testImplementation(libs.bundles.junit.testing)
42 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
43 | testRuntimeOnly("org.junit.platform:junit-platform-launcher")
44 | }
45 |
--------------------------------------------------------------------------------
/jackson/src/main/java/org/projectnessie/cel/types/jackson/JacksonEnumDescription.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson;
17 |
18 | import com.fasterxml.jackson.databind.JavaType;
19 | import com.fasterxml.jackson.databind.ser.std.EnumSerializer;
20 | import java.util.List;
21 | import java.util.stream.Stream;
22 | import org.projectnessie.cel.common.types.pb.Checked;
23 |
24 | final class JacksonEnumDescription {
25 |
26 | private final String name;
27 | private final com.google.api.expr.v1alpha1.Type pbType;
28 | private final List> enumValues;
29 |
30 | JacksonEnumDescription(JavaType javaType, EnumSerializer ser) {
31 | this.name = javaType.getRawClass().getName().replace('$', '.');
32 | this.enumValues = ser.getEnumValues().enums();
33 | this.pbType = Checked.checkedInt;
34 | }
35 |
36 | com.google.api.expr.v1alpha1.Type pbType() {
37 | return pbType;
38 | }
39 |
40 | Stream buildValues() {
41 | return enumValues.stream().map(JacksonEnumValue::new);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/jackson/src/main/java/org/projectnessie/cel/types/jackson/JacksonEnumValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson;
17 |
18 | import static org.projectnessie.cel.common.types.IntT.intOf;
19 |
20 | import org.projectnessie.cel.common.types.ref.Val;
21 |
22 | final class JacksonEnumValue {
23 |
24 | private final Val ordinalValue;
25 | private final Enum> enumValue;
26 |
27 | JacksonEnumValue(Enum> enumValue) {
28 | this.ordinalValue = intOf(enumValue.ordinal());
29 | this.enumValue = enumValue;
30 | }
31 |
32 | static String fullyQualifiedName(Enum> value) {
33 | return value.getClass().getName().replace('$', '.') + '.' + value.name();
34 | }
35 |
36 | String fullyQualifiedName() {
37 | return fullyQualifiedName(enumValue);
38 | }
39 |
40 | Val ordinalValue() {
41 | return ordinalValue;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/jackson/src/main/java/org/projectnessie/cel/types/jackson/JacksonFieldType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson;
17 |
18 | import com.fasterxml.jackson.databind.ser.PropertyWriter;
19 | import com.google.api.expr.v1alpha1.Type;
20 | import org.projectnessie.cel.common.types.ref.FieldGetter;
21 | import org.projectnessie.cel.common.types.ref.FieldTester;
22 | import org.projectnessie.cel.common.types.ref.FieldType;
23 |
24 | final class JacksonFieldType extends FieldType {
25 |
26 | private final PropertyWriter propertyWriter;
27 |
28 | JacksonFieldType(
29 | Type type, FieldTester isSet, FieldGetter getFrom, PropertyWriter propertyWriter) {
30 | super(type, isSet, getFrom);
31 | this.propertyWriter = propertyWriter;
32 | }
33 |
34 | PropertyWriter propertyWriter() {
35 | return propertyWriter;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/jackson/src/main/java/org/projectnessie/cel/types/jackson/JacksonObjectT.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson;
17 |
18 | import static org.projectnessie.cel.common.types.Err.newTypeConversionError;
19 | import static org.projectnessie.cel.common.types.Err.noSuchField;
20 | import static org.projectnessie.cel.common.types.Err.noSuchOverload;
21 | import static org.projectnessie.cel.common.types.Types.boolOf;
22 |
23 | import org.projectnessie.cel.common.types.ObjectT;
24 | import org.projectnessie.cel.common.types.StringT;
25 | import org.projectnessie.cel.common.types.ref.Val;
26 |
27 | final class JacksonObjectT extends ObjectT {
28 |
29 | private JacksonObjectT(JacksonRegistry registry, Object value, JacksonTypeDescription typeDesc) {
30 | super(registry, value, typeDesc, typeDesc.type());
31 | }
32 |
33 | static JacksonObjectT newObject(
34 | JacksonRegistry registry, Object value, JacksonTypeDescription typeDesc) {
35 | return new JacksonObjectT(registry, value, typeDesc);
36 | }
37 |
38 | JacksonTypeDescription typeDesc() {
39 | return (JacksonTypeDescription) typeDesc;
40 | }
41 |
42 | JacksonRegistry registry() {
43 | return (JacksonRegistry) adapter;
44 | }
45 |
46 | @Override
47 | public Val isSet(Val field) {
48 | if (!(field instanceof StringT)) {
49 | return noSuchOverload(this, "isSet", field);
50 | }
51 | String fieldName = (String) field.value();
52 |
53 | if (!typeDesc().hasProperty(fieldName)) {
54 | return noSuchField(fieldName);
55 | }
56 |
57 | Object value = typeDesc().fromObject(value(), fieldName);
58 |
59 | return boolOf(value != null);
60 | }
61 |
62 | @Override
63 | public Val get(Val index) {
64 | if (!(index instanceof StringT)) {
65 | return noSuchOverload(this, "get", index);
66 | }
67 | String fieldName = (String) index.value();
68 |
69 | if (!typeDesc().hasProperty(fieldName)) {
70 | return noSuchField(fieldName);
71 | }
72 |
73 | Object v = typeDesc().fromObject(value(), fieldName);
74 |
75 | return registry().nativeToValue(v);
76 | }
77 |
78 | @Override
79 | public T convertToNative(Class typeDesc) {
80 | if (typeDesc.isAssignableFrom(value.getClass())) {
81 | return (T) value;
82 | }
83 | if (typeDesc.isAssignableFrom(getClass())) {
84 | return (T) this;
85 | }
86 | throw new IllegalArgumentException(
87 | newTypeConversionError(value.getClass().getName(), typeDesc).toString());
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/AnEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | public enum AnEnum {
19 | ENUM_VALUE_1,
20 | ENUM_VALUE_2,
21 | ENUM_VALUE_3
22 | }
23 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/ClassWithEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | public class ClassWithEnum {
19 | public enum ClassEnum {
20 | VAL_1,
21 | VAL_2,
22 | VAL_3,
23 | VAL_4
24 | }
25 |
26 | public String value;
27 |
28 | public ClassWithEnum() {}
29 |
30 | public ClassWithEnum(String value) {
31 | this.value = value;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/CollectionsObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | import static java.util.Arrays.asList;
19 |
20 | import com.google.protobuf.ByteString;
21 | import com.google.protobuf.Duration;
22 | import com.google.protobuf.Timestamp;
23 | import java.time.ZonedDateTime;
24 | import java.util.List;
25 | import java.util.Map;
26 | import org.projectnessie.cel.common.ULong;
27 |
28 | public class CollectionsObject {
29 | public Map stringBooleanMap;
30 | public Map byteShortMap;
31 | public Map intLongMap;
32 | public Map ulongTimestampMap;
33 | public Map ulongZonedDateTimeMap;
34 | public Map stringProtoDurationMap;
35 | public Map stringJavaDurationMap;
36 | public Map stringBytesMap;
37 | public Map floatDoubleMap;
38 |
39 | public List stringList;
40 | public List booleanList;
41 | public List byteList;
42 | public List shortList;
43 | public List intList;
44 | public List longList;
45 | public List ulongList;
46 | public List timestampList;
47 | public List zonedDateTimeList;
48 | public List durationList;
49 | public List javaDurationList;
50 | public List bytesList;
51 | public List floatList;
52 | public List doubleList;
53 |
54 | public Map stringInnerMap;
55 | public List innerTypes;
56 |
57 | public AnEnum anEnum;
58 | public List anEnumList;
59 | public Map anEnumStringMap;
60 | public Map stringAnEnumMap;
61 |
62 | public static final List ALL_PROPERTIES =
63 | asList(
64 | "stringBooleanMap",
65 | "byteShortMap",
66 | "intLongMap",
67 | "ulongTimestampMap",
68 | "ulongZonedDateTimeMap",
69 | "stringProtoDurationMap",
70 | "stringJavaDurationMap",
71 | "stringBytesMap",
72 | "floatDoubleMap",
73 | "stringList",
74 | "booleanList",
75 | "byteList",
76 | "shortList",
77 | "intList",
78 | "longList",
79 | "ulongList",
80 | "timestampList",
81 | "zonedDateTimeList",
82 | "durationList",
83 | "javaDurationList",
84 | "bytesList",
85 | "floatList",
86 | "doubleList",
87 | "stringInnerMap",
88 | "innerTypes",
89 | "anEnum",
90 | "anEnumList",
91 | "anEnumStringMap",
92 | "stringAnEnumMap");
93 | }
94 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/InnerType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | public class InnerType {
19 | public int intProp;
20 | public Integer wrappedIntProp;
21 | }
22 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/MyPojo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | public class MyPojo {
19 | private String property;
20 |
21 | public String getProperty() {
22 | return property;
23 | }
24 |
25 | public void setProperty(String property) {
26 | this.property = property;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/ObjectListEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | import java.util.List;
19 | import org.immutables.value.Value;
20 |
21 | @Value.Immutable(prehash = true)
22 | public interface ObjectListEnum {
23 |
24 | static ImmutableObjectListEnum.Builder builder() {
25 | return ImmutableObjectListEnum.builder();
26 | }
27 |
28 | List getEntries();
29 |
30 | @Value.Immutable(prehash = true)
31 | interface Entry {
32 |
33 | static ImmutableEntry.Builder builder() {
34 | return ImmutableEntry.builder();
35 | }
36 |
37 | ClassWithEnum.ClassEnum getType();
38 |
39 | ClassWithEnum getHolder();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/RefBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | import com.fasterxml.jackson.annotation.JsonSubTypes;
19 | import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
20 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
21 | import javax.annotation.Nullable;
22 |
23 | @JsonSubTypes({@Type(RefVariantB.class), @Type(RefVariantA.class), @Type(RefVariantC.class)})
24 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
25 | public interface RefBase {
26 | String getName();
27 |
28 | @Nullable
29 | String getHash();
30 | }
31 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/RefVariantA.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | import com.fasterxml.jackson.annotation.JsonTypeName;
19 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
21 | import org.immutables.value.Value;
22 |
23 | @Value.Immutable(prehash = true)
24 | @JsonSerialize(as = ImmutableRefVariantA.class)
25 | @JsonDeserialize(as = ImmutableRefVariantA.class)
26 | @JsonTypeName("A")
27 | public interface RefVariantA extends RefBase {
28 |
29 | static ImmutableRefVariantA.Builder builder() {
30 | return ImmutableRefVariantA.builder();
31 | }
32 |
33 | static RefVariantA of(String name, String hash) {
34 | return builder().name(name).hash(hash).build();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/RefVariantB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | import com.fasterxml.jackson.annotation.JsonTypeName;
19 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
21 | import org.immutables.value.Value;
22 |
23 | /** Api representation of an Nessie Tag/Branch. This object is akin to a Ref in Git terminology. */
24 | @Value.Immutable(prehash = true)
25 | @JsonSerialize(as = ImmutableRefVariantB.class)
26 | @JsonDeserialize(as = ImmutableRefVariantB.class)
27 | @JsonTypeName("B")
28 | public interface RefVariantB extends RefBase {
29 |
30 | static ImmutableRefVariantB.Builder builder() {
31 | return ImmutableRefVariantB.builder();
32 | }
33 |
34 | static RefVariantB of(String name, String hash) {
35 | return builder().name(name).hash(hash).build();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/jackson/src/test/java/org/projectnessie/cel/types/jackson/types/RefVariantC.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.types.jackson.types;
17 |
18 | import com.fasterxml.jackson.annotation.JsonTypeName;
19 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
21 | import org.immutables.value.Value;
22 | import org.immutables.value.Value.Derived;
23 |
24 | @Value.Immutable(prehash = true)
25 | @JsonSerialize(as = ImmutableRefVariantC.class)
26 | @JsonDeserialize(as = ImmutableRefVariantC.class)
27 | @JsonTypeName("C")
28 | public abstract class RefVariantC implements RefBase {
29 |
30 | @Override
31 | @Derived
32 | public String getHash() {
33 | return getName();
34 | }
35 |
36 | public static RefVariantC of(String hash) {
37 | return ImmutableRefVariantC.builder().name(hash).build();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/standalone/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
18 |
19 | plugins {
20 | `java-library`
21 | `maven-publish`
22 | signing
23 | id("com.github.johnrengelman.shadow")
24 | `cel-conventions`
25 | }
26 |
27 | dependencies {
28 | api(project(":cel-tools"))
29 | api(project(":cel-jackson"))
30 | api(project(":cel-generated-antlr", configuration = "shadow"))
31 |
32 | compileOnly(libs.protobuf.java)
33 | compileOnly(libs.agrona)
34 | }
35 |
36 | val shadowJar = tasks.named("shadowJar")
37 |
38 | shadowJar.configure {
39 | // relocate com.google.api/protobuf/rpc classes
40 | relocate("com.google", "org.projectnessie.cel.relocated.com.google")
41 | relocate("org.agrona", "org.projectnessie.cel.relocated.org.agrona")
42 | manifest {
43 | attributes["Specification-Title"] = "Common-Expression-Language - dependency-free CEL"
44 | attributes["Specification-Version"] = libs.protobuf.java.get().version
45 | }
46 | configurations = listOf(project.configurations.getByName("compileClasspath"))
47 | dependencies {
48 | include(project(":cel-tools"))
49 | include(project(":cel-core"))
50 | include(project(":cel-jackson"))
51 | include(project(":cel-generated-pb"))
52 | include(project(":cel-generated-antlr"))
53 |
54 | include(dependency(libs.protobuf.java.get()))
55 | include(dependency(libs.agrona.get()))
56 | }
57 | }
58 |
59 | tasks.named("compileJava").configure { finalizedBy(shadowJar) }
60 |
61 | tasks.named("processResources").configure { finalizedBy(shadowJar) }
62 |
63 | tasks.named("jar").configure { dependsOn("shadowJar") }
64 |
65 | shadowJar.configure {
66 | outputs.cacheIf { false } // do not cache uber/shaded jars
67 | archiveClassifier.set("")
68 | mergeServiceFiles()
69 | }
70 |
71 | tasks.named("jar").configure {
72 | dependsOn(shadowJar)
73 | archiveClassifier.set("raw")
74 | }
75 |
76 | tasks.withType().configureEach { exclude("META-INF/jandex.idx") }
77 |
--------------------------------------------------------------------------------
/tools/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import com.google.protobuf.gradle.ProtobufExtension
18 | import com.google.protobuf.gradle.ProtobufPlugin
19 |
20 | plugins {
21 | `java-library`
22 | `maven-publish`
23 | signing
24 | id("org.caffinitas.gradle.testsummary")
25 | id("org.caffinitas.gradle.testrerun")
26 | `cel-conventions`
27 | }
28 |
29 | apply()
30 |
31 | dependencies {
32 | api(project(":cel-core"))
33 |
34 | testImplementation(platform(libs.junit.bom))
35 | testImplementation(libs.bundles.junit.testing)
36 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
37 | testRuntimeOnly("org.junit.platform:junit-platform-launcher")
38 | }
39 |
40 | configure {
41 | // Configure the protoc executable
42 | protoc {
43 | // Download from repositories
44 | artifact = "com.google.protobuf:protoc:${libs.versions.protobuf.get()}"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tools/src/main/java/org/projectnessie/cel/tools/Script.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.tools;
17 |
18 | import static org.projectnessie.cel.common.types.Err.isError;
19 | import static org.projectnessie.cel.common.types.UnknownT.isUnknown;
20 |
21 | import java.util.Map;
22 | import java.util.Objects;
23 | import java.util.function.Function;
24 | import org.projectnessie.cel.Env;
25 | import org.projectnessie.cel.Program;
26 | import org.projectnessie.cel.Program.EvalResult;
27 | import org.projectnessie.cel.common.types.Err;
28 | import org.projectnessie.cel.common.types.ref.Val;
29 |
30 | public final class Script {
31 | private final Env env;
32 | private final Program prg;
33 |
34 | Script(Env env, Program prg) {
35 | this.env = env;
36 | this.prg = prg;
37 | }
38 |
39 | public T execute(Class resultType, Function arguments)
40 | throws ScriptException {
41 | return evaluate(resultType, arguments);
42 | }
43 |
44 | public T execute(Class resultType, Map arguments) throws ScriptException {
45 | return evaluate(resultType, arguments);
46 | }
47 |
48 | @SuppressWarnings("unchecked")
49 | private T evaluate(Class resultType, Object arguments) throws ScriptExecutionException {
50 | Objects.requireNonNull(resultType, "resultType missing");
51 | Objects.requireNonNull(arguments, "arguments missing");
52 |
53 | EvalResult evalResult = prg.eval(arguments);
54 |
55 | Val result = evalResult.getVal();
56 |
57 | if (isError(result)) {
58 | Err err = (Err) result;
59 | throw new ScriptExecutionException(err.toString(), err.getCause());
60 | }
61 | if (isUnknown(result)) {
62 | if (resultType == Val.class || resultType == Object.class) {
63 | return (T) result;
64 | }
65 | throw new ScriptExecutionException(
66 | String.format(
67 | "script returned unknown %s, but expected result type is %s",
68 | result, resultType.getName()));
69 | }
70 |
71 | return result.convertToNative(resultType);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/tools/src/main/java/org/projectnessie/cel/tools/ScriptCreateException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.tools;
17 |
18 | import java.util.Objects;
19 | import org.projectnessie.cel.Issues;
20 | import org.projectnessie.cel.common.CELError;
21 |
22 | public final class ScriptCreateException extends ScriptException {
23 |
24 | private final Issues issues;
25 |
26 | public ScriptCreateException(String message, Issues issues) {
27 | super(String.format("%s: %s", message, issues));
28 | this.issues = issues;
29 | issues.getErrors().stream()
30 | .map(CELError::getException)
31 | .filter(Objects::nonNull)
32 | .forEach(this::addSuppressed);
33 | }
34 |
35 | public Issues getIssues() {
36 | return issues;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tools/src/main/java/org/projectnessie/cel/tools/ScriptException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.tools;
17 |
18 | public abstract class ScriptException extends Exception {
19 |
20 | protected ScriptException(String message) {
21 | super(message);
22 | }
23 |
24 | protected ScriptException(String message, Throwable cause) {
25 | super(message, cause);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tools/src/main/java/org/projectnessie/cel/tools/ScriptExecutionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Authors of CEL-Java
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.projectnessie.cel.tools;
17 |
18 | public final class ScriptExecutionException extends ScriptException {
19 |
20 | public ScriptExecutionException(String message) {
21 | super(message);
22 | }
23 |
24 | public ScriptExecutionException(String message, Throwable cause) {
25 | super(message, cause);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tools/src/test/proto/dummy.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package org.projectnessie.cel.toolstests;
3 |
4 | message MyPojo {
5 | string Property1 = 1;
6 | }
7 |
--------------------------------------------------------------------------------
/version.txt:
--------------------------------------------------------------------------------
1 | 0.5.4-SNAPSHOT
2 |
--------------------------------------------------------------------------------