├── .github ├── renovate.json5 └── workflows │ ├── main.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── .idea ├── codeStyles │ └── codeStyleConfig.xml └── google-java-format.xml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── bom └── build.gradle.kts ├── build-tool-integ-tests ├── .gradle ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── build.gradle ├── gradlew ├── gradlew.bat ├── mvnw ├── mvnw.cmd ├── pom.xml ├── settings.gradle └── src │ └── main │ └── java │ └── MyClass.java ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── CodeCoverage.kt │ ├── Ide.kt │ ├── Java.kt │ ├── ProtobufHelperPlugin.kt │ ├── PublishingHelperExtension.kt │ ├── PublishingHelperPlugin.kt │ ├── Spotless.kt │ ├── Testing.kt │ ├── Utilities.kt │ └── cel-conventions.gradle.kts ├── codestyle ├── copyright-header-java.txt ├── copyright-header.txt └── org.eclipse.wst.xml.core.prefs ├── conformance ├── README.md ├── build.gradle.kts ├── conformance-server.sh ├── run-conformance-tests.sh └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── projectnessie │ │ │ └── cel │ │ │ └── server │ │ │ ├── ConformanceServer.java │ │ │ └── ConformanceServiceImpl.java │ └── proto │ │ └── google │ │ ├── api │ │ └── expr │ │ │ └── conformance │ │ └── rpc │ └── test │ └── java │ └── org │ └── projectnessie │ └── cel │ └── server │ └── ConformanceServerTest.java ├── core ├── build.gradle.kts └── src │ ├── jmh │ └── java │ │ └── org │ │ └── projectnessie │ │ └── cel │ │ ├── CELBench.java │ │ ├── common │ │ └── types │ │ │ ├── ProviderBench.java │ │ │ ├── ProviderBenchNativeToValue.java │ │ │ └── pb │ │ │ └── PbTypeDescriptionBench.java │ │ └── interpreter │ │ ├── AttributesBench.java │ │ └── InterpreterBench.java │ ├── main │ ├── java │ │ └── org │ │ │ └── projectnessie │ │ │ └── cel │ │ │ ├── Ast.java │ │ │ ├── CEL.java │ │ │ ├── Env.java │ │ │ ├── EnvOption.java │ │ │ ├── EvalDetails.java │ │ │ ├── EvalOption.java │ │ │ ├── Issues.java │ │ │ ├── Library.java │ │ │ ├── Prog.java │ │ │ ├── ProgFactory.java │ │ │ ├── ProgGen.java │ │ │ ├── Program.java │ │ │ ├── ProgramOption.java │ │ │ ├── checker │ │ │ ├── Checker.java │ │ │ ├── CheckerEnv.java │ │ │ ├── Decls.java │ │ │ ├── Mapping.java │ │ │ ├── Printer.java │ │ │ ├── Scopes.java │ │ │ ├── Standard.java │ │ │ ├── TypeErrors.java │ │ │ └── Types.java │ │ │ ├── common │ │ │ ├── CELError.java │ │ │ ├── ErrorWithLocation.java │ │ │ ├── Errors.java │ │ │ ├── Location.java │ │ │ ├── Source.java │ │ │ ├── ULong.java │ │ │ ├── containers │ │ │ │ └── Container.java │ │ │ ├── debug │ │ │ │ └── Debug.java │ │ │ ├── operators │ │ │ │ └── Operator.java │ │ │ └── types │ │ │ │ ├── BoolT.java │ │ │ │ ├── BytesT.java │ │ │ │ ├── DoubleT.java │ │ │ │ ├── DurationT.java │ │ │ │ ├── Err.java │ │ │ │ ├── IntT.java │ │ │ │ ├── IterableT.java │ │ │ │ ├── IteratorT.java │ │ │ │ ├── ListT.java │ │ │ │ ├── MapT.java │ │ │ │ ├── NullT.java │ │ │ │ ├── ObjectT.java │ │ │ │ ├── Overflow.java │ │ │ │ ├── Overloads.java │ │ │ │ ├── StringT.java │ │ │ │ ├── TimestampT.java │ │ │ │ ├── TypeT.java │ │ │ │ ├── Types.java │ │ │ │ ├── UintT.java │ │ │ │ ├── UnknownT.java │ │ │ │ ├── Util.java │ │ │ │ ├── pb │ │ │ │ ├── Checked.java │ │ │ │ ├── Db.java │ │ │ │ ├── DefaultTypeAdapter.java │ │ │ │ ├── Description.java │ │ │ │ ├── EnumValueDescription.java │ │ │ │ ├── FieldDescription.java │ │ │ │ ├── FileDescription.java │ │ │ │ ├── PbObjectT.java │ │ │ │ ├── PbTypeDescription.java │ │ │ │ └── ProtoTypeRegistry.java │ │ │ │ ├── ref │ │ │ │ ├── BaseVal.java │ │ │ │ ├── FieldGetter.java │ │ │ │ ├── FieldTester.java │ │ │ │ ├── FieldType.java │ │ │ │ ├── Type.java │ │ │ │ ├── TypeAdapter.java │ │ │ │ ├── TypeAdapterSupport.java │ │ │ │ ├── TypeDescription.java │ │ │ │ ├── TypeEnum.java │ │ │ │ ├── TypeProvider.java │ │ │ │ ├── TypeRegistry.java │ │ │ │ └── Val.java │ │ │ │ └── traits │ │ │ │ ├── Adder.java │ │ │ │ ├── Comparer.java │ │ │ │ ├── Container.java │ │ │ │ ├── Divider.java │ │ │ │ ├── FieldTester.java │ │ │ │ ├── Indexer.java │ │ │ │ ├── Lister.java │ │ │ │ ├── Mapper.java │ │ │ │ ├── Matcher.java │ │ │ │ ├── Modder.java │ │ │ │ ├── Multiplier.java │ │ │ │ ├── Negater.java │ │ │ │ ├── Receiver.java │ │ │ │ ├── Sizer.java │ │ │ │ ├── Subtractor.java │ │ │ │ └── Trait.java │ │ │ ├── extension │ │ │ ├── Guards.java │ │ │ ├── QuadFunction.java │ │ │ ├── StringsLib.java │ │ │ └── TriFunction.java │ │ │ ├── interpreter │ │ │ ├── Activation.java │ │ │ ├── AstPruner.java │ │ │ ├── AttributeFactory.java │ │ │ ├── AttributePattern.java │ │ │ ├── Coster.java │ │ │ ├── Dispatcher.java │ │ │ ├── EvalState.java │ │ │ ├── Interpretable.java │ │ │ ├── InterpretableDecorator.java │ │ │ ├── InterpretablePlanner.java │ │ │ ├── Interpreter.java │ │ │ ├── ResolvedValue.java │ │ │ └── functions │ │ │ │ ├── BinaryOp.java │ │ │ │ ├── FunctionOp.java │ │ │ │ ├── Overload.java │ │ │ │ └── UnaryOp.java │ │ │ └── parser │ │ │ ├── ExprHelper.java │ │ │ ├── ExprHelperImpl.java │ │ │ ├── Helper.java │ │ │ ├── Macro.java │ │ │ ├── MacroExpander.java │ │ │ ├── Options.java │ │ │ ├── ParseError.java │ │ │ ├── Parser.java │ │ │ ├── StringCharStream.java │ │ │ ├── Unescape.java │ │ │ └── Unparser.java │ └── resources │ │ └── META-INF │ │ └── native-image │ │ └── org.projectnessie.cel │ │ └── cel-core │ │ └── main │ │ ├── native-image.properties │ │ └── reflection-config.json │ ├── test │ └── java │ │ └── org │ │ └── projectnessie │ │ ├── ListContainsTest.java │ │ └── cel │ │ ├── CELTest.java │ │ ├── checker │ │ ├── CheckerEnvTest.java │ │ └── CheckerTest.java │ │ ├── common │ │ ├── ErrorsTest.java │ │ ├── SourceTest.java │ │ ├── containers │ │ │ └── ContainerTest.java │ │ └── types │ │ │ ├── BoolTest.java │ │ │ ├── BytesTest.java │ │ │ ├── DoubleTest.java │ │ │ ├── DurationTest.java │ │ │ ├── IntTest.java │ │ │ ├── JsonListTest.java │ │ │ ├── JsonStructTest.java │ │ │ ├── ListTest.java │ │ │ ├── MapTest.java │ │ │ ├── NullTest.java │ │ │ ├── ProviderTest.java │ │ │ ├── StringTest.java │ │ │ ├── TimestampTest.java │ │ │ ├── TypeTest.java │ │ │ ├── UintTest.java │ │ │ └── pb │ │ │ ├── FieldDescriptionTest.java │ │ │ ├── PbObjectTest.java │ │ │ ├── PbTypeDescriptionTest.java │ │ │ ├── UnwrapContext.java │ │ │ └── UnwrapTestCase.java │ │ ├── extension │ │ └── StringsTest.java │ │ ├── interpreter │ │ ├── ActivationTest.java │ │ ├── AttributePatternsTest.java │ │ ├── AttributesTest.java │ │ ├── InterpreterTest.java │ │ ├── InterpreterTestCase.java │ │ └── PruneTest.java │ │ ├── parser │ │ ├── ParserTest.java │ │ ├── UnescapeTest.java │ │ └── UnparserTest.java │ │ └── proto │ │ └── ProtoTest.java │ └── testFixtures │ └── java │ └── org │ └── projectnessie │ └── cel │ ├── TestExpr.java │ └── Util.java ├── generated-antlr ├── build.gradle.kts └── src │ └── main │ └── antlr │ └── org.projectnessie.cel.parser.gen │ ├── CEL.g4 │ ├── CEL.tokens │ └── CELLexer.tokens ├── generated-pb ├── build.gradle.kts └── src │ ├── main │ └── proto │ │ └── google │ │ ├── api │ │ └── expr │ │ │ └── v1alpha1 │ │ └── rpc │ └── testFixtures │ └── proto │ ├── out_of_order_enum.proto │ ├── proto-map.proto │ └── proto │ └── test │ └── v1 │ ├── proto2 │ └── proto3 ├── generated-pb3 ├── build.gradle.kts └── src ├── gradle.properties ├── gradle ├── contributors.csv ├── developers.csv ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── ide-name.txt ├── jackson ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── org │ │ └── projectnessie │ │ └── cel │ │ └── types │ │ └── jackson │ │ ├── JacksonEnumDescription.java │ │ ├── JacksonEnumValue.java │ │ ├── JacksonFieldType.java │ │ ├── JacksonObjectT.java │ │ ├── JacksonRegistry.java │ │ └── JacksonTypeDescription.java │ └── test │ └── java │ └── org │ └── projectnessie │ └── cel │ └── types │ └── jackson │ ├── JacksonRegistryTest.java │ ├── JacksonScriptHostTest.java │ ├── JacksonTypeDescriptionTest.java │ └── types │ ├── AnEnum.java │ ├── ClassWithEnum.java │ ├── CollectionsObject.java │ ├── InnerType.java │ ├── MetaTest.java │ ├── MyPojo.java │ ├── ObjectListEnum.java │ ├── RefBase.java │ ├── RefVariantA.java │ ├── RefVariantB.java │ └── RefVariantC.java ├── settings.gradle.kts ├── standalone └── build.gradle.kts ├── tools ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── org │ │ └── projectnessie │ │ └── cel │ │ └── tools │ │ ├── Script.java │ │ ├── ScriptCreateException.java │ │ ├── ScriptException.java │ │ ├── ScriptExecutionException.java │ │ └── ScriptHost.java │ └── test │ ├── java │ └── org │ │ └── projectnessie │ │ └── cel │ │ └── tools │ │ └── ScriptHostTest.java │ └── proto │ └── dummy.proto └── version.txt /.github/renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | extends: ["config:base"], 4 | 5 | "labels": ["dependencies"], 6 | 7 | packageRules: [ 8 | // Check for updates, merge automatically 9 | { 10 | matchManagers: ["maven", "gradle", "gradle-wrapper"], 11 | matchUpdateTypes: ["minor", "patch"], 12 | automerge: true, 13 | platformAutomerge: true 14 | }, 15 | 16 | // Check for major updates, but do not merge automatically 17 | { 18 | matchManagers: ["maven", "gradle", "gradle-wrapper"], 19 | matchUpdateTypes: ["major"], 20 | automerge: false 21 | } 22 | ], 23 | 24 | // Max 50 PRs in total, 10 per hour 25 | prConcurrentLimit: 50, 26 | prHourlyLimit: 10 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 The Authors of CEL-Java 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: CI 16 | 17 | on: 18 | push: 19 | branches: [ main ] 20 | pull_request: 21 | 22 | jobs: 23 | java: 24 | name: Java/Gradle 25 | runs-on: ubuntu-latest 26 | strategy: 27 | max-parallel: 4 28 | matrix: 29 | java-version: [17, 21, 24] 30 | steps: 31 | - uses: actions/checkout@v4 32 | with: 33 | submodules: 'true' 34 | 35 | - name: Set up JDK ${{ matrix.java-version }} 36 | uses: actions/setup-java@v4 37 | with: 38 | distribution: 'temurin' 39 | java-version: ${{ matrix.java-version }} 40 | 41 | - name: Setup Gradle 42 | uses: gradle/actions/setup-gradle@v4 43 | with: 44 | cache-read-only: ${{ github.event_name != 'push' || github.ref != 'refs/heads/main' }} 45 | 46 | - name: Spotless Check 47 | # Spotless must run in a different invocation, because 48 | # it has some weird Gradle configuration/variant issue 49 | if: ${{ matrix.java-version == '17' }} 50 | run: ./gradlew spotlessCheck --scan 51 | 52 | - name: Build 53 | run: ./gradlew --rerun-tasks assemble ${{ env.ADDITIONAL_GRADLE_OPTS }} check publishToMavenLocal -x jmh -x spotlessCheck --scan 54 | 55 | - name: Build tool integrations 56 | # The buildToolIntegration* tasks require publishToMavenLocal, run it as a separate step, 57 | # because these tasks intentionally do not depend on the publishToMavenLocal tasks. 58 | run: ./gradlew buildToolIntegrations 59 | 60 | - name: Microbenchmarks 61 | run: ./gradlew jmh 62 | 63 | - name: Cache Bazel stuff 64 | if: ${{ matrix.java-version == '17' }} 65 | uses: actions/cache@v4 66 | with: 67 | path: | 68 | ~/.cache/bazel 69 | key: bazel-${{ hashFiles('**/.gitmodules') }} 70 | restore-keys: bazel- 71 | 72 | - name: Conformance tests 73 | if: ${{ matrix.java-version == '17' }} 74 | run: conformance/run-conformance-tests.sh 75 | 76 | - name: Capture test results 77 | uses: actions/upload-artifact@v4 78 | if: failure() 79 | with: 80 | name: test-results 81 | path: | 82 | **/build/reports/* 83 | **/build/test-results/* 84 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Gradle 3 | build/ 4 | .gradle/ 5 | 6 | # Maven 7 | **/.mvn/wrapper/maven-wrapper.jar 8 | target/ 9 | 10 | # IDE 11 | /.idea 12 | out/ 13 | 14 | conformance/conformance-server.pid 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "submodules/googleapis"] 2 | path = submodules/googleapis 3 | url = https://github.com/googleapis/googleapis/ 4 | [submodule "submodules/cel-spec"] 5 | path = submodules/cel-spec 6 | url = https://github.com/google/cel-spec 7 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/google-java-format.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Nessie 2 | ## How to contribute 3 | Everyone is encouraged to contribute to the CEL-Java project. We welcome of course code changes, 4 | but we are also grateful for bug reports, feature suggestions, helping with testing and 5 | documentation, or simply spreading the word about CEL-Java and [projectnessie](https://github.com/projectnessie/). 6 | 7 | Please use [GitHub issues](https://github.com/projectnessie/cel-java/issues) for bug reports and 8 | feature requests and [GitHub Pull Requests](https://github.com/projectnessie/cel-java/pulls) for code 9 | contributions. 10 | 11 | More information are available at https://projectnessie.org/develop/ 12 | 13 | ## Code of conduct 14 | You must agree to abide by the Project Nessie [Code of Conduct](CODE_OF_CONDUCT.md). 15 | 16 | ## Reporting issues 17 | Issues can be filed on GitHub. Please add as much detail as possible. Including the 18 | version and a reproducer. The more the community knows the more it can help :-) 19 | 20 | ### Feature Requests 21 | 22 | If you have a feature request or questions about the direction of the project please as via a 23 | GitHub issue. 24 | 25 | ### Large changes or improvements 26 | 27 | We are excited to accept new contributors and larger changes. Please post a proposal 28 | before submitting a large change. This helps avoid double work and allows the community to arrive at a consensus 29 | on the new feature or improvement. 30 | 31 | ## Code changes 32 | 33 | ### Development process 34 | 35 | The development process doesn't contain many surprises. As most projects on github anyone can contribute by 36 | forking the repo and posting a pull request. See 37 | [GitHub's documentation](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork) 38 | for more information. Small changes don't require an issue. However, it is good practice to open up an issue for 39 | larger changes. 40 | The [good first issue](https://github.com/projectnessie/cel-java/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label marks issues 41 | that are particularly good for people new to the codebase. 42 | 43 | ### Style guide 44 | 45 | Changes must adhere to the style guide and this will be verified by the continuous integration build. 46 | 47 | * Java code style is [Google style](https://google.github.io/styleguide/javaguide.html). 48 | 49 | Java code style is checked by [Spotless](https://github.com/diffplug/spotless) 50 | with [google-java-format](https://github.com/google/google-java-format) during build. 51 | 52 | #### Configuring the Code Formatter for Intellij IDEA and Eclipse 53 | 54 | Follow the instructions for [Eclipse](https://github.com/google/google-java-format#eclipse) or 55 | [IntelliJ](https://github.com/google/google-java-format#intellij-android-studio-and-other-jetbrains-ides), 56 | note the required manual actions for IntelliJ. 57 | 58 | #### Automatically fixing code style issues 59 | 60 | Java and Scala code style issues can be fixed from the command line using 61 | `./gradlew spotlessApply`. 62 | 63 | ### Submitting a pull request 64 | 65 | Anyone can take part in the review process and once the community is happy and the build actions are passing a 66 | Pull Request will be merged. Support must be unanimous for a change to be merged. 67 | 68 | ### Reporting security issues 69 | 70 | Please see our [Security Policy](SECURITY.md) 71 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | The project is in a very early stage. 4 | 5 | ## Supported Versions 6 | 7 | None, yet. 8 | 9 | ## Reporting a Vulnerability 10 | 11 | Any security issues should be reported to security@projectnessie.org, please refrain from posting publicly until the team can investigate and patch the code. 12 | -------------------------------------------------------------------------------- /bom/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-platform` 19 | `maven-publish` 20 | signing 21 | `cel-conventions` 22 | } 23 | 24 | dependencies { 25 | constraints { 26 | api(project(":cel-core")) 27 | api(project(":cel-generated-antlr", "shadow")) 28 | api(project(":cel-generated-pb")) 29 | api(project(":cel-generated-pb3")) 30 | api(project(":cel-conformance")) 31 | api(project(":cel-jackson")) 32 | api(project(":cel-tools")) 33 | api(project(":cel-standalone")) 34 | } 35 | } 36 | 37 | javaPlatform { allowDependencies() } 38 | -------------------------------------------------------------------------------- /build-tool-integ-tests/.gradle: -------------------------------------------------------------------------------- 1 | ../.gradle -------------------------------------------------------------------------------- /build-tool-integ-tests/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 18 | -------------------------------------------------------------------------------- /build-tool-integ-tests/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 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 | id 'java-library' 19 | } 20 | 21 | group 'org.projectnessie.cel.build-tool-integration-tests' 22 | version '0.0.2-SNAPSHOT' 23 | 24 | repositories { 25 | mavenLocal() 26 | mavenCentral() 27 | } 28 | 29 | dependencies { 30 | implementation(enforcedPlatform("org.projectnessie.cel:cel-bom:${System.getProperty("cel.version")}")) 31 | implementation("org.projectnessie.cel:cel-tools") 32 | implementation("org.projectnessie.cel:cel-jackson") 33 | } 34 | -------------------------------------------------------------------------------- /build-tool-integ-tests/gradlew: -------------------------------------------------------------------------------- 1 | ../gradlew -------------------------------------------------------------------------------- /build-tool-integ-tests/gradlew.bat: -------------------------------------------------------------------------------- 1 | ../gradlew.bat -------------------------------------------------------------------------------- /build-tool-integ-tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 4.0.0 21 | 22 | org.projectnessie.cel.build-tool-integration-tests 23 | maven-integ-test 24 | 0.0.1-SNAPSHOT 25 | 26 | 27 | UTF-8 28 | 8 29 | 0.5.3 30 | 31 | 32 | 33 | 34 | 35 | org.projectnessie.cel 36 | cel-bom 37 | ${cel.version} 38 | pom 39 | import 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.projectnessie.cel 47 | cel-tools 48 | 49 | 50 | org.projectnessie.cel 51 | cel-jackson 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.apache.maven.plugins 60 | maven-compiler-plugin 61 | 3.14.0 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /build-tool-integ-tests/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 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 | rootProject.name = 'gradle-integ-test' 18 | -------------------------------------------------------------------------------- /build-tool-integ-tests/src/main/java/MyClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 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.api.expr.v1alpha1.Decl; 18 | import org.projectnessie.cel.checker.Decls; 19 | import org.projectnessie.cel.tools.ScriptHost; 20 | import org.projectnessie.cel.types.jackson.JacksonRegistry; 21 | 22 | public class MyClass {} -------------------------------------------------------------------------------- /buildSrc/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 { `kotlin-dsl` } 18 | 19 | repositories { 20 | mavenCentral() 21 | gradlePluginPortal() 22 | if (System.getProperty("withMavenLocal").toBoolean()) { 23 | mavenLocal() 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation(gradleKotlinDsl()) 29 | implementation(libs.spotless.plugin) 30 | implementation(libs.jandex.plugin) 31 | implementation(libs.idea.ext) 32 | implementation(libs.shadow.plugin) 33 | implementation(libs.protobuf.plugin) 34 | implementation(libs.errorprone.plugin) 35 | } 36 | 37 | java { toolchain { languageVersion.set(JavaLanguageVersion.of(11)) } } 38 | -------------------------------------------------------------------------------- /buildSrc/settings.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 | dependencyResolutionManagement { 18 | versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } } 19 | } 20 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/CodeCoverage.kt: -------------------------------------------------------------------------------- 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 org.gradle.api.Plugin 18 | import org.gradle.api.Project 19 | import org.gradle.api.tasks.testing.Test 20 | import org.gradle.kotlin.dsl.apply 21 | import org.gradle.kotlin.dsl.configure 22 | import org.gradle.kotlin.dsl.withType 23 | import org.gradle.testing.jacoco.plugins.JacocoPlugin 24 | import org.gradle.testing.jacoco.plugins.JacocoPluginExtension 25 | import org.gradle.testing.jacoco.plugins.JacocoReportAggregationPlugin 26 | import org.gradle.testing.jacoco.plugins.JacocoTaskExtension 27 | import org.gradle.testing.jacoco.tasks.JacocoReport 28 | 29 | class CelCodeCoveragePlugin : Plugin { 30 | override fun apply(project: Project): Unit = 31 | project.run { 32 | apply() 33 | apply() 34 | 35 | tasks.withType().configureEach { 36 | reports { 37 | html.required.set(true) 38 | xml.required.set(true) 39 | } 40 | } 41 | 42 | configure { toolVersion = libsRequiredVersion("jacoco") } 43 | 44 | if (plugins.hasPlugin("io.quarkus")) { 45 | tasks.named("classes") { dependsOn(tasks.named("compileQuarkusGeneratedSourcesJava")) } 46 | 47 | tasks.withType().configureEach { 48 | extensions.configure(JacocoTaskExtension::class.java) { 49 | val excluded = excludeClassLoaders 50 | excludeClassLoaders = 51 | listOf("*QuarkusClassLoader") + (if (excluded != null) excluded else emptyList()) 52 | } 53 | systemProperty("quarkus.jacoco.report", "false") 54 | systemProperty("quarkus.jacoco.reuse-data-file", "true") 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Ide.kt: -------------------------------------------------------------------------------- 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 org.gradle.api.Project 18 | import org.gradle.kotlin.dsl.apply 19 | import org.gradle.kotlin.dsl.configure 20 | import org.gradle.plugins.ide.eclipse.EclipsePlugin 21 | import org.gradle.plugins.ide.eclipse.model.EclipseModel 22 | import org.gradle.plugins.ide.idea.model.IdeaModel 23 | import org.jetbrains.gradle.ext.ActionDelegationConfig 24 | import org.jetbrains.gradle.ext.IdeaExtPlugin 25 | import org.jetbrains.gradle.ext.copyright 26 | import org.jetbrains.gradle.ext.delegateActions 27 | import org.jetbrains.gradle.ext.encodings 28 | import org.jetbrains.gradle.ext.runConfigurations 29 | import org.jetbrains.gradle.ext.settings 30 | 31 | fun Project.nessieIde() { 32 | apply() 33 | 34 | if (this == rootProject) { 35 | 36 | val projectName = rootProject.file("ide-name.txt").readText().trim() 37 | val ideName = 38 | "$projectName ${rootProject.version.toString().replace(Regex("^([0-9.]+).*"), "$1")}" 39 | 40 | apply() 41 | configure { 42 | module { 43 | name = ideName 44 | isDownloadSources = true // this is the default BTW 45 | inheritOutputDirs = true 46 | } 47 | 48 | project.settings { 49 | copyright { 50 | useDefault = "Nessie-ASF" 51 | profiles.create("Nessie-ASF") { 52 | // strip trailing LF 53 | val copyrightText = 54 | rootProject.file("codestyle/copyright-header.txt").readLines().joinToString("\n") 55 | notice = copyrightText 56 | } 57 | } 58 | 59 | encodings.encoding = "UTF-8" 60 | encodings.properties.encoding = "UTF-8" 61 | 62 | runConfigurations.register("Gradle", org.jetbrains.gradle.ext.Gradle::class.java) { 63 | defaults = true 64 | 65 | jvmArgs = 66 | rootProject.projectDir 67 | .resolve("gradle.properties") 68 | .reader() 69 | .use { 70 | val rules = java.util.Properties() 71 | rules.load(it) 72 | rules 73 | } 74 | .map { e -> "-D${e.key}=${e.value}" } 75 | .joinToString(" ") 76 | } 77 | 78 | delegateActions.testRunner = ActionDelegationConfig.TestRunner.CHOOSE_PER_TEST 79 | } 80 | } 81 | 82 | // There's no proper way to set the name of the IDEA project (when "just importing" or syncing 83 | // the Gradle project) 84 | val ideaDir = projectDir.resolve(".idea") 85 | 86 | if (ideaDir.isDirectory) { 87 | ideaDir.resolve(".name").writeText(ideName) 88 | } 89 | 90 | configure { project { name = ideName } } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Java.kt: -------------------------------------------------------------------------------- 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 org.gradle.api.JavaVersion 18 | import org.gradle.api.Project 19 | import org.gradle.api.file.DuplicatesStrategy 20 | import org.gradle.api.plugins.JavaPlugin 21 | import org.gradle.api.plugins.JavaPluginExtension 22 | import org.gradle.api.tasks.bundling.Jar 23 | import org.gradle.api.tasks.compile.JavaCompile 24 | import org.gradle.api.tasks.javadoc.Javadoc 25 | import org.gradle.external.javadoc.CoreJavadocOptions 26 | import org.gradle.kotlin.dsl.configure 27 | import org.gradle.kotlin.dsl.repositories 28 | import org.gradle.kotlin.dsl.withType 29 | 30 | fun Project.nessieConfigureJava() { 31 | 32 | repositories { 33 | mavenCentral { content { excludeVersionByRegex("io[.]delta", ".*", ".*-nessie") } } 34 | if (System.getProperty("withMavenLocal").toBoolean()) { 35 | mavenLocal() 36 | } 37 | } 38 | 39 | tasks.withType().configureEach { 40 | manifest { 41 | attributes["Implementation-Title"] = "CEL-Java" 42 | attributes["Implementation-Version"] = project.version 43 | attributes["Implementation-Vendor"] = "Authors of CEL-Java" 44 | } 45 | } 46 | 47 | tasks.withType().configureEach { 48 | options.encoding = "UTF-8" 49 | options.release.set(8) 50 | } 51 | 52 | tasks.withType().configureEach { 53 | val opt = options as CoreJavadocOptions 54 | // don't spam log w/ "warning: no @param/@return" 55 | opt.addStringOption("Xdoclint:-reference", "-quiet") 56 | } 57 | 58 | plugins.withType().configureEach { 59 | configure { 60 | withJavadocJar() 61 | withSourcesJar() 62 | sourceCompatibility = JavaVersion.VERSION_1_8 63 | targetCompatibility = JavaVersion.VERSION_1_8 64 | modularity.inferModulePath.set(true) 65 | } 66 | } 67 | 68 | if (project != rootProject) { 69 | tasks.withType().configureEach { duplicatesStrategy = DuplicatesStrategy.WARN } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/ProtobufHelperPlugin.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 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.ProtobufExtract 18 | import com.google.protobuf.gradle.ProtobufPlugin 19 | import org.gradle.api.Plugin 20 | import org.gradle.api.Project 21 | import org.gradle.kotlin.dsl.apply 22 | import org.gradle.kotlin.dsl.withType 23 | 24 | /** Makes the generated sources available to IDEs, disables Checkstyle on generated code. */ 25 | @Suppress("unused") 26 | class ProtobufHelperPlugin : Plugin { 27 | override fun apply(project: Project): Unit = 28 | project.run { 29 | apply() 30 | 31 | tasks.withType(ProtobufExtract::class.java).configureEach { 32 | dependsOn(tasks.named("processJandexIndex")) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/PublishingHelperExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 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 org.gradle.api.Project 18 | 19 | open class PublishingHelperExtension(project: Project) { 20 | val nessieRepoName = project.objects.property(String::class.java) 21 | val inceptionYear = project.objects.property(String::class.java) 22 | } 23 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Testing.kt: -------------------------------------------------------------------------------- 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 org.gradle.api.Project 18 | import org.gradle.api.tasks.testing.Test 19 | import org.gradle.kotlin.dsl.withType 20 | 21 | fun Project.nessieConfigureTestTasks() { 22 | tasks.withType().configureEach { 23 | useJUnitPlatform {} 24 | maxParallelForks = Runtime.getRuntime().availableProcessors() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Utilities.kt: -------------------------------------------------------------------------------- 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 org.gradle.api.Project 18 | import org.gradle.api.artifacts.VersionCatalogsExtension 19 | import org.gradle.kotlin.dsl.getByType 20 | 21 | fun Project.libsRequiredVersion(name: String): String { 22 | val libVer = 23 | extensions.getByType().named("libs").findVersion(name).get() 24 | val reqVer = libVer.requiredVersion 25 | check(reqVer.isNotEmpty()) { 26 | "libs-version for '$name' is empty, but must not be empty, version. strict: ${libVer.strictVersion}, required: ${libVer.requiredVersion}, preferred: ${libVer.preferredVersion}" 27 | } 28 | return reqVer 29 | } 30 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/cel-conventions.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 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 | if (project.name != "conformance" && project.name != "jacoco") { 18 | apply() 19 | } 20 | 21 | nessieConfigureSpotless() 22 | 23 | nessieConfigureJava() 24 | 25 | nessieIde() 26 | 27 | apply() 28 | 29 | if (projectDir.resolve("src/test/java").exists()) { 30 | nessieConfigureTestTasks() 31 | } 32 | -------------------------------------------------------------------------------- /codestyle/copyright-header-java.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) $YEAR 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 | -------------------------------------------------------------------------------- /codestyle/copyright-header.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) $today.year The Authors of CEL-Java 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /codestyle/org.eclipse.wst.xml.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | formatCommentJoinLines=false 3 | formatCommentText=false 4 | indentationChar=space 5 | indentationSize=2 6 | lineWidth=100 7 | spaceBeforeEmptyCloseTag=false 8 | -------------------------------------------------------------------------------- /conformance/README.md: -------------------------------------------------------------------------------- 1 | # Running CEL-spec conformance tests against CEL-Java 2 | 3 | If your environment is already setup, just run the shell script 4 | ```shell 5 | ./run-conformance-tests.sh 6 | ``` 7 | 8 | ## Requirements & Setup 9 | 10 | The CEL-spec conformance test suite is written in Go and uses the bazel build tool. 11 | 12 | Required tools: 13 | * [Bazel build tool](https://bazel.build/) 14 | 15 | See [Bazel web site](https://bazel.build/install) for installation instructions. 16 | Do **not** use the `bazel-bootstrap` package on Ubuntu, because it comes with 17 | pre-compiled classes that are built with Java 17 or newer, preventing it from 18 | running bazel using older Java versions. 19 | * gcc 20 | 21 | On Ubuntu run `apt-get install gcc` 22 | 23 | Other required dependencies like "Go" will be managed by bazel. 24 | 25 | ## FAQ 26 | 27 | ### Bazel build hangs 28 | 29 | If the bazel build does not start, i.e. it gets stuck with messages like 30 | ``` 31 | Starting local Bazel server and connecting to it... 32 | ... still trying to connect to local Bazel server after 10 seconds ... 33 | ... still trying to connect to local Bazel server after 20 seconds ... 34 | ... still trying to connect to local Bazel server after 30 seconds ... 35 | ``` 36 | then kill all bazel processes make sure that Java 11 is the current one. It seems, that the 37 | above *may* happen when with Java 8. 38 | 39 | ### Bazel build fails from `./run-conformance-tests.sh` 40 | 41 | If the bazel build fails with an error like this (note the `Failed to create temporary file`), 42 | run the bazel build once from the console: 43 | 44 | ```shell 45 | cd submodules/cel-spec 46 | 47 | bazel build ... 48 | ``` 49 | 50 | If the build still fails, try the following options: 51 | 52 | ```shell 53 | bazel build ... --sandbox_writable_path="${HOME}/.ccache" --strategy=CppCompile=standalone 54 | ``` 55 | 56 | After the build succeeds once from that directory, you can use the `./run-conformance-tests.sh` 57 | script. 58 | -------------------------------------------------------------------------------- /conformance/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 | id("com.github.johnrengelman.shadow") 23 | id("org.caffinitas.gradle.testsummary") 24 | id("org.caffinitas.gradle.testrerun") 25 | `cel-conventions` 26 | } 27 | 28 | apply() 29 | 30 | sourceSets.main { 31 | java.srcDir(layout.buildDirectory.dir("generated/source/proto/main/java")) 32 | java.srcDir(layout.buildDirectory.dir("generated/source/proto/main/grpc")) 33 | } 34 | 35 | configurations.all { exclude(group = "org.projectnessie.cel", module = "cel-generated-pb") } 36 | 37 | dependencies { 38 | implementation(project(":cel-core")) 39 | implementation(testFixtures(project(":cel-core"))) 40 | implementation(testFixtures(project(":cel-generated-pb3"))) 41 | 42 | implementation(libs.protobuf.java) { version { strictly(libs.versions.protobuf3.get()) } } 43 | 44 | implementation(libs.grpc.protobuf) 45 | implementation(libs.grpc.stub) 46 | runtimeOnly(libs.grpc.netty.shaded) 47 | compileOnly(libs.tomcat.annotations.api) 48 | 49 | testImplementation(platform(libs.junit.bom)) 50 | testImplementation(libs.bundles.junit.testing) 51 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") 52 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 53 | } 54 | 55 | tasks.named("shadowJar") { 56 | manifest { attributes("Main-Class" to "org.projectnessie.cel.server.ConformanceServer") } 57 | } 58 | 59 | // *.proto files taken from https://github.com/google/cel-spec/ repo, available as a git submodule 60 | configure { 61 | // Configure the protoc executable 62 | protoc { 63 | // Download from repositories 64 | artifact = "com.google.protobuf:protoc:${libs.versions.protobuf3.get()}" 65 | } 66 | plugins { 67 | this.create("grpc") { artifact = "io.grpc:protoc-gen-grpc-java:${libs.versions.grpc.get()}" } 68 | } 69 | generateProtoTasks { all().configureEach { this.plugins.create("grpc") {} } } 70 | } 71 | 72 | // The protobuf-plugin should ideally do this 73 | tasks.named("sourcesJar") { dependsOn(tasks.named("generateProto")) } 74 | -------------------------------------------------------------------------------- /conformance/conformance-server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (C) 2021 The Authors of CEL-Java 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | wd="$(dirname "$0")" 19 | 20 | pid_file="${wd}/conformance-server.pid" 21 | 22 | function kill_server() { 23 | if [[ -f ${pid_file} ]] ; then 24 | kill "$(cat "${pid_file}")" && rm "${pid_file}" 25 | fi 26 | } 27 | 28 | trap kill_server SIGINT SIGTERM 29 | 30 | java -Djava.net.preferIPv4Stack=true -jar "${wd}"/build/libs/cel-conformance-*-all.jar "${@}" & 31 | java_pid=$! 32 | echo "${java_pid}" > "${pid_file}" 33 | wait 34 | -------------------------------------------------------------------------------- /conformance/src/main/java/org/projectnessie/cel/server/ConformanceServer.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.server; 17 | 18 | import io.grpc.Server; 19 | import io.grpc.ServerBuilder; 20 | import java.net.Inet6Address; 21 | import java.net.InetAddress; 22 | import java.net.InetSocketAddress; 23 | import java.net.SocketAddress; 24 | import java.util.List; 25 | 26 | public class ConformanceServer implements AutoCloseable { 27 | 28 | private final Server server; 29 | 30 | public ConformanceServer(Server server) { 31 | this.server = server; 32 | } 33 | 34 | public static String getListenHost(Server server) { 35 | List addrs = server.getListenSockets(); 36 | SocketAddress addr = addrs.get(0); 37 | InetSocketAddress ia = (InetSocketAddress) addr; 38 | InetAddress a = ia.getAddress(); 39 | 40 | String host; 41 | if (a instanceof Inet6Address) { 42 | if (a.isAnyLocalAddress()) { 43 | host = "::1"; 44 | } else { 45 | host = a.getCanonicalHostName(); 46 | } 47 | } else { 48 | if (a.isAnyLocalAddress()) { 49 | host = "127.0.0.1"; 50 | } else { 51 | host = a.getCanonicalHostName(); 52 | } 53 | } 54 | 55 | return host; 56 | } 57 | 58 | public void blockUntilShutdown() throws InterruptedException { 59 | server.awaitTermination(); 60 | } 61 | 62 | @Override 63 | public void close() throws Exception { 64 | server.shutdown().awaitTermination(); 65 | } 66 | 67 | public static void main(String[] args) throws Exception { 68 | ConformanceServiceImpl service = new ConformanceServiceImpl(); 69 | 70 | for (String arg : args) { 71 | if ("--verbose".equals(arg) || "-v".equals(arg)) { 72 | service.setVerboseEvalErrors(true); 73 | } 74 | } 75 | 76 | Server c = ServerBuilder.forPort(0).addService(service).build(); 77 | 78 | Thread hook = new Thread(c::shutdown); 79 | 80 | try (ConformanceServer cs = new ConformanceServer(c.start())) { 81 | System.out.printf("Listening on %s:%d%n", getListenHost(cs.server), cs.server.getPort()); 82 | 83 | Runtime.getRuntime().addShutdownHook(hook); 84 | cs.blockUntilShutdown(); 85 | } finally { 86 | try { 87 | Runtime.getRuntime().removeShutdownHook(hook); 88 | } catch (IllegalStateException e) { 89 | // ignore (might happen, when a JVM shutdown is already in progress) 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /conformance/src/main/proto/google/api/expr/conformance: -------------------------------------------------------------------------------- 1 | ../../../../../../../submodules/googleapis/google/api/expr/conformance -------------------------------------------------------------------------------- /conformance/src/main/proto/google/rpc: -------------------------------------------------------------------------------- 1 | ../../../../../submodules/googleapis/google/rpc/ -------------------------------------------------------------------------------- /core/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 | signing 20 | `maven-publish` 21 | id("com.diffplug.spotless") 22 | alias(libs.plugins.jmh) 23 | alias(libs.plugins.testsummary) 24 | alias(libs.plugins.testrerun) 25 | `cel-conventions` 26 | `java-test-fixtures` 27 | } 28 | 29 | configurations.named("jmhImplementation") { extendsFrom(configurations.testFixturesApi.get()) } 30 | 31 | dependencies { 32 | implementation(project(":cel-generated-antlr", "shadow")) 33 | api(project(":cel-generated-pb")) 34 | 35 | implementation(libs.agrona) 36 | 37 | testFixturesApi(platform(libs.junit.bom)) 38 | testFixturesApi(libs.bundles.junit.testing) 39 | testFixturesApi(libs.protobuf.java) 40 | testFixturesApi(libs.guava) 41 | testFixturesApi(testFixtures(project(":cel-generated-pb"))) 42 | testFixturesApi(project(":cel-tools")) 43 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") 44 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 45 | 46 | jmhImplementation(libs.jmh.core) 47 | jmhAnnotationProcessor(libs.jmh.generator.annprocess) 48 | } 49 | 50 | jmh { jmhVersion.set(libs.versions.jmh.get()) } 51 | 52 | sourceSets.test { 53 | java.srcDir(layout.buildDirectory.dir("generated/source/proto/test/java")) 54 | java.destinationDirectory.set(layout.buildDirectory.dir("classes/java/generatedTest")) 55 | } 56 | 57 | tasks.named("check") { dependsOn(tasks.named("jmh")) } 58 | 59 | tasks.named("assemble") { dependsOn(tasks.named("jmhJar")) } 60 | -------------------------------------------------------------------------------- /core/src/jmh/java/org/projectnessie/cel/CELBench.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; 17 | 18 | import static org.projectnessie.cel.Env.newEnv; 19 | import static org.projectnessie.cel.EnvOption.declarations; 20 | import static org.projectnessie.cel.ProgramOption.evalOptions; 21 | import static org.projectnessie.cel.Util.mapOf; 22 | 23 | import java.util.Map; 24 | import java.util.concurrent.TimeUnit; 25 | import org.openjdk.jmh.annotations.Benchmark; 26 | import org.openjdk.jmh.annotations.BenchmarkMode; 27 | import org.openjdk.jmh.annotations.Fork; 28 | import org.openjdk.jmh.annotations.Measurement; 29 | import org.openjdk.jmh.annotations.Mode; 30 | import org.openjdk.jmh.annotations.OutputTimeUnit; 31 | import org.openjdk.jmh.annotations.Param; 32 | import org.openjdk.jmh.annotations.Scope; 33 | import org.openjdk.jmh.annotations.Setup; 34 | import org.openjdk.jmh.annotations.State; 35 | import org.openjdk.jmh.annotations.Threads; 36 | import org.openjdk.jmh.annotations.Warmup; 37 | import org.projectnessie.cel.Env.AstIssuesTuple; 38 | import org.projectnessie.cel.checker.Decls; 39 | 40 | @Warmup(iterations = 1, time = 1500, timeUnit = TimeUnit.MILLISECONDS) 41 | @Measurement(iterations = 5, time = 300, timeUnit = TimeUnit.MILLISECONDS) 42 | @Fork(1) 43 | @Threads(2) 44 | @BenchmarkMode(Mode.AverageTime) 45 | @OutputTimeUnit(TimeUnit.MICROSECONDS) 46 | public class CELBench { 47 | 48 | @State(Scope.Benchmark) 49 | public static class Prg { 50 | 51 | @Param({"OptExhaustiveEval", "OptOptimize", "OptPartialEval"}) 52 | public EvalOption evalOption; 53 | 54 | private Program prg; 55 | private Map vars; 56 | 57 | @Setup 58 | public void init() { 59 | Env e = 60 | newEnv( 61 | declarations( 62 | Decls.newVar("ai", Decls.Int), 63 | Decls.newVar("ar", Decls.newMapType(Decls.String, Decls.String)))); 64 | AstIssuesTuple astIss = e.compile("ai == 20 || ar['foo'] == 'bar'"); 65 | vars = mapOf("ai", 2, "ar", mapOf("foo", "bar")); 66 | 67 | prg = e.program(astIss.getAst(), evalOptions(evalOption)); 68 | } 69 | } 70 | 71 | @Benchmark 72 | public void eval(Prg prg) { 73 | prg.prg.eval(prg.vars); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /core/src/jmh/java/org/projectnessie/cel/common/types/ProviderBench.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.projectnessie.cel.Util.mapOf; 19 | import static org.projectnessie.cel.common.types.ListT.newGenericArrayList; 20 | import static org.projectnessie.cel.common.types.MapT.newMaybeWrappedMap; 21 | import static org.projectnessie.cel.common.types.StringT.stringOf; 22 | import static org.projectnessie.cel.common.types.pb.ProtoTypeRegistry.newRegistry; 23 | 24 | import com.google.api.expr.v1alpha1.ParsedExpr; 25 | import java.util.concurrent.TimeUnit; 26 | import org.openjdk.jmh.annotations.Benchmark; 27 | import org.openjdk.jmh.annotations.BenchmarkMode; 28 | import org.openjdk.jmh.annotations.Fork; 29 | import org.openjdk.jmh.annotations.Measurement; 30 | import org.openjdk.jmh.annotations.Mode; 31 | import org.openjdk.jmh.annotations.OutputTimeUnit; 32 | import org.openjdk.jmh.annotations.Param; 33 | import org.openjdk.jmh.annotations.Scope; 34 | import org.openjdk.jmh.annotations.Setup; 35 | import org.openjdk.jmh.annotations.State; 36 | import org.openjdk.jmh.annotations.Threads; 37 | import org.openjdk.jmh.annotations.Warmup; 38 | import org.projectnessie.cel.common.types.ref.TypeRegistry; 39 | 40 | @Warmup(iterations = 1, time = 1500, timeUnit = TimeUnit.MILLISECONDS) 41 | @Measurement(iterations = 5, time = 300, timeUnit = TimeUnit.MILLISECONDS) 42 | @Fork(1) 43 | @Threads(2) 44 | @BenchmarkMode(Mode.AverageTime) 45 | @OutputTimeUnit(TimeUnit.MICROSECONDS) 46 | public class ProviderBench { 47 | 48 | @State(Scope.Benchmark) 49 | public static class NativeToValueState { 50 | @Param({"v_true", "v_int64", "v_stringT"}) 51 | public ProviderBenchNativeToValue value; 52 | 53 | TypeRegistry reg; 54 | 55 | @Setup 56 | public void init() { 57 | reg = newRegistry(); 58 | } 59 | } 60 | 61 | @Benchmark 62 | public void nativeToValue(NativeToValueState val) { 63 | TypeRegistry reg = newRegistry(); 64 | 65 | Object in = val.value.value(); 66 | 67 | reg.nativeToValue(in); 68 | } 69 | 70 | @State(Scope.Benchmark) 71 | public static class NewValueState { 72 | TypeRegistry reg = newRegistry(ParsedExpr.getDefaultInstance()); 73 | } 74 | 75 | @Benchmark 76 | public void newValue(NewValueState state) { 77 | TypeRegistry reg = state.reg; 78 | reg.newValue( 79 | "google.api.expr.v1.SourceInfo", 80 | mapOf( 81 | "Location", stringOf("BenchmarkTypeProvider_NewValue"), 82 | "LineOffsets", newGenericArrayList(reg, new Object[] {0L, 2L}), 83 | "Positions", newMaybeWrappedMap(reg, mapOf(1L, 2L, 2L, 4L)))); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /core/src/jmh/java/org/projectnessie/cel/common/types/ProviderBenchNativeToValue.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.projectnessie.cel.common.types.StringT.stringOf; 19 | 20 | @SuppressWarnings("unused") 21 | public enum ProviderBenchNativeToValue { 22 | v_true(true), 23 | v_false(false), 24 | v_float32(-1.2f), 25 | v_float64(-2.4d), 26 | v_int32(2), 27 | v_int64(3L), 28 | v_emptyString(""), 29 | v_hello("hello"), 30 | v_stringT(stringOf("hello world")); 31 | 32 | private final Object value; 33 | 34 | ProviderBenchNativeToValue(Object value) { 35 | this.value = value; 36 | } 37 | 38 | public Object value() { 39 | return value; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/jmh/java/org/projectnessie/cel/common/types/pb/PbTypeDescriptionBench.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 | 20 | import com.google.protobuf.Message; 21 | import java.util.concurrent.TimeUnit; 22 | import org.openjdk.jmh.annotations.Benchmark; 23 | import org.openjdk.jmh.annotations.BenchmarkMode; 24 | import org.openjdk.jmh.annotations.Fork; 25 | import org.openjdk.jmh.annotations.Measurement; 26 | import org.openjdk.jmh.annotations.Mode; 27 | import org.openjdk.jmh.annotations.OutputTimeUnit; 28 | import org.openjdk.jmh.annotations.Param; 29 | import org.openjdk.jmh.annotations.Scope; 30 | import org.openjdk.jmh.annotations.Setup; 31 | import org.openjdk.jmh.annotations.State; 32 | import org.openjdk.jmh.annotations.Threads; 33 | import org.openjdk.jmh.annotations.Warmup; 34 | 35 | @Warmup(iterations = 1, time = 1500, timeUnit = TimeUnit.MILLISECONDS) 36 | @Measurement(iterations = 5, time = 300, timeUnit = TimeUnit.MILLISECONDS) 37 | @Fork(1) 38 | @Threads(2) 39 | @BenchmarkMode(Mode.AverageTime) 40 | @OutputTimeUnit(TimeUnit.NANOSECONDS) 41 | public class PbTypeDescriptionBench { 42 | 43 | @State(Scope.Benchmark) 44 | public static class Case { 45 | 46 | @Param({ 47 | "msgDesc_zero", 48 | "structpb_NewBoolValue_false", 49 | "structpb_NewStringValue", 50 | "wrapperspb_Int64", 51 | "wrapperspb_UInt64", 52 | "timestamp", 53 | "proto3pb_TestAllTypes" 54 | }) 55 | public UnwrapTestCase testCase; 56 | 57 | PbTypeDescription td; 58 | Message msg; 59 | UnwrapContext ctx; 60 | 61 | @Setup 62 | public void init() { 63 | ctx = UnwrapContext.get(); 64 | 65 | msg = testCase.message(); 66 | 67 | String typeName = msg.getDescriptorForType().getFullName(); 68 | td = ctx.pbdb.describeType(typeName); 69 | assertThat(td).isNotNull(); 70 | } 71 | } 72 | 73 | @Benchmark 74 | public void maybeUnwrap(Case c) { 75 | c.td.maybeUnwrap(c.ctx.pbdb, c.msg); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /core/src/jmh/java/org/projectnessie/cel/interpreter/InterpreterBench.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; 17 | 18 | import static org.projectnessie.cel.interpreter.Interpreter.optimize; 19 | 20 | import java.util.Arrays; 21 | import java.util.concurrent.TimeUnit; 22 | import org.openjdk.jmh.annotations.Benchmark; 23 | import org.openjdk.jmh.annotations.BenchmarkMode; 24 | import org.openjdk.jmh.annotations.Fork; 25 | import org.openjdk.jmh.annotations.Measurement; 26 | import org.openjdk.jmh.annotations.Mode; 27 | import org.openjdk.jmh.annotations.OutputTimeUnit; 28 | import org.openjdk.jmh.annotations.Param; 29 | import org.openjdk.jmh.annotations.Scope; 30 | import org.openjdk.jmh.annotations.Setup; 31 | import org.openjdk.jmh.annotations.State; 32 | import org.openjdk.jmh.annotations.Threads; 33 | import org.openjdk.jmh.annotations.Warmup; 34 | import org.projectnessie.cel.interpreter.InterpreterTest.Program; 35 | import org.projectnessie.cel.interpreter.InterpreterTest.TestCase; 36 | 37 | @Warmup(iterations = 1, time = 1500, timeUnit = TimeUnit.MILLISECONDS) 38 | @Measurement(iterations = 5, time = 300, timeUnit = TimeUnit.MILLISECONDS) 39 | @Fork(1) 40 | @BenchmarkMode(Mode.AverageTime) 41 | @OutputTimeUnit(TimeUnit.MICROSECONDS) 42 | public class InterpreterBench { 43 | 44 | @State(Scope.Benchmark) 45 | public static class Case { 46 | Program program; 47 | 48 | @Param({ 49 | "and_false_2nd", 50 | "call_no_args", 51 | "call_one_arg", 52 | "call_two_arg", 53 | "call_varargs", 54 | "call_ns_func", 55 | "call_ns_func_unchecked", 56 | "call_ns_func_in_pkg", 57 | "call_ns_func_unchecked_in_pkg", 58 | "timestamp_eq_timestamp", 59 | "timestamp_le_timestamp", 60 | "macro_has_pb3_field", 61 | "nested_proto_field_with_index", 62 | "parse_nest_message_literal", 63 | "select_pb3_wrapper_fields", 64 | "select_pb3_compare", 65 | "select_custom_pb3_compare" 66 | }) 67 | public InterpreterTestCase testCase; 68 | 69 | @Setup 70 | public void init() { 71 | TestCase test = 72 | Arrays.stream(InterpreterTest.testCases()) 73 | .filter(tc -> tc.name == testCase) 74 | .findFirst() 75 | .orElseThrow(() -> new RuntimeException("No test case named '" + testCase + '\'')); 76 | this.program = InterpreterTest.program(test, optimize()); 77 | } 78 | } 79 | 80 | @Benchmark 81 | @Threads(1) 82 | public void interpreterSingle(Case state) { 83 | state.program.interpretable.eval(state.program.activation); 84 | } 85 | 86 | @Benchmark 87 | public void interpreterParallel(Case state) { 88 | state.program.interpretable.eval(state.program.activation); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/Ast.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; 17 | 18 | import com.google.api.expr.v1alpha1.Expr; 19 | import com.google.api.expr.v1alpha1.Reference; 20 | import com.google.api.expr.v1alpha1.SourceInfo; 21 | import com.google.api.expr.v1alpha1.Type; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | import org.projectnessie.cel.checker.Decls; 25 | import org.projectnessie.cel.common.Source; 26 | 27 | /** 28 | * Ast representing the checked or unchecked expression, its source, and related metadata such as 29 | * source position information. 30 | */ 31 | public final class Ast { 32 | private final Expr expr; 33 | private final SourceInfo info; 34 | private final Source source; 35 | final Map refMap; 36 | final Map typeMap; 37 | 38 | public Ast(Expr expr, SourceInfo info, Source source) { 39 | this(expr, info, source, new HashMap<>(), new HashMap<>()); 40 | } 41 | 42 | public Ast( 43 | Expr expr, 44 | SourceInfo info, 45 | Source source, 46 | Map refMap, 47 | Map typeMap) { 48 | this.expr = expr; 49 | this.info = info; 50 | this.source = source; 51 | this.refMap = refMap; 52 | this.typeMap = typeMap; 53 | } 54 | 55 | /** Expr returns the proto serializable instance of the parsed/checked expression. */ 56 | public Expr getExpr() { 57 | return expr; 58 | } 59 | 60 | /** IsChecked returns whether the Ast value has been successfully type-checked. */ 61 | public boolean isChecked() { 62 | return typeMap != null && !typeMap.isEmpty(); 63 | } 64 | 65 | public Source getSource() { 66 | return source; 67 | } 68 | 69 | /** 70 | * SourceInfo returns character offset and newling position information about expression elements. 71 | */ 72 | public SourceInfo getSourceInfo() { 73 | return info; 74 | } 75 | 76 | /** 77 | * ResultType returns the output type of the expression if the Ast has been type-checked, else 78 | * returns decls.Dyn as the parse step cannot infer the type. 79 | */ 80 | public Type getResultType() { 81 | if (!isChecked()) { 82 | return Decls.Dyn; 83 | } 84 | return typeMap.get(expr.getId()); 85 | } 86 | 87 | /** 88 | * Source returns a view of the input used to create the Ast. This source may be complete or 89 | * constructed from the SourceInfo. 90 | */ 91 | @Override 92 | public String toString() { 93 | return source.content(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/EvalDetails.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; 17 | 18 | import org.projectnessie.cel.interpreter.EvalState; 19 | 20 | /** EvalDetails holds additional information observed during the Eval() call. */ 21 | public final class EvalDetails { 22 | private final EvalState state; 23 | 24 | public EvalDetails(EvalState state) { 25 | this.state = state; 26 | } 27 | 28 | /** 29 | * State of the evaluation, non-nil if the OptTrackState or OptExhaustiveEval is specified within 30 | * EvalOptions. 31 | */ 32 | public EvalState getState() { 33 | return state; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/EvalOption.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; 17 | 18 | /** 19 | * EvalOption indicates an evaluation option that may affect the evaluation behavior or information 20 | * in the output result. 21 | */ 22 | public enum EvalOption { 23 | 24 | /** OptTrackState will cause the runtime to return an immutable EvalState value in the Result. */ 25 | OptTrackState(1), 26 | 27 | /** OptExhaustiveEval causes the runtime to disable short-circuits and track state. */ 28 | OptExhaustiveEval(2 | OptTrackState.mask), 29 | 30 | /** 31 | * OptOptimize precomputes functions and operators with constants as arguments at program creation 32 | * time. This flag is useful when the expression will be evaluated repeatedly against a series of 33 | * different inputs. 34 | */ 35 | OptOptimize(4), 36 | 37 | /** 38 | * OptPartialEval enables the evaluation of a partial state where the input data that may be known 39 | * to be missing, either as top-level variables, or somewhere within a variable's object member 40 | * graph. 41 | * 42 | *

By itself, OptPartialEval does not change evaluation behavior unless the input to the 43 | * Program Eval is an PartialVars. 44 | */ 45 | OptPartialEval(8); 46 | 47 | private final int mask; 48 | 49 | EvalOption(int mask) { 50 | this.mask = mask; 51 | } 52 | 53 | public int getMask() { 54 | return mask; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/Issues.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; 17 | 18 | import java.util.List; 19 | import org.projectnessie.cel.common.CELError; 20 | import org.projectnessie.cel.common.Errors; 21 | import org.projectnessie.cel.common.Source; 22 | 23 | /** 24 | * Issues defines methods for inspecting the error details of parse and check calls. 25 | * 26 | *

Note: in the future, non-fatal warnings and notices may be inspectable via the Issues struct. 27 | */ 28 | public final class Issues { 29 | 30 | private final Errors errs; 31 | 32 | private Issues(Errors errs) { 33 | this.errs = errs; 34 | } 35 | 36 | /** NewIssues returns an Issues struct from a common.Errors object. */ 37 | public static Issues newIssues(Errors errs) { 38 | return new Issues(errs); 39 | } 40 | 41 | /** NewIssues returns an Issues struct from a common.Errors object. */ 42 | public static Issues noIssues(Source source) { 43 | return new Issues(new Errors(source)); 44 | } 45 | 46 | /** Err returns an error value if the issues list contains one or more errors. */ 47 | public RuntimeException err() { 48 | if (!errs.hasErrors()) { 49 | return null; 50 | } 51 | return new RuntimeException(toString()); 52 | } 53 | 54 | public boolean hasIssues() { 55 | return errs.hasErrors(); 56 | } 57 | 58 | /** Errors returns the collection of errors encountered in more granular detail. */ 59 | public List getErrors() { 60 | return errs.getErrors(); 61 | } 62 | 63 | /** Append collects the issues from another Issues struct into a new Issues object. */ 64 | public Issues append(Issues other) { 65 | return newIssues(errs.append(other.getErrors())); 66 | } 67 | 68 | /** String converts the issues to a suitable display string. */ 69 | @Override 70 | public String toString() { 71 | return errs.toDisplayString(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/ProgFactory.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; 17 | 18 | import org.projectnessie.cel.interpreter.EvalState; 19 | 20 | /** progFactory is a helper alias for marking a program creation factory function. */ 21 | @FunctionalInterface 22 | interface ProgFactory { 23 | Program apply(EvalState evalState); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/ProgGen.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; 17 | 18 | import static org.projectnessie.cel.CEL.estimateCost; 19 | import static org.projectnessie.cel.Prog.emptyEvalState; 20 | import static org.projectnessie.cel.interpreter.EvalState.newEvalState; 21 | 22 | import org.projectnessie.cel.interpreter.Coster; 23 | import org.projectnessie.cel.interpreter.EvalState; 24 | 25 | final class ProgGen implements Program, Coster { 26 | private final ProgFactory factory; 27 | 28 | ProgGen(ProgFactory factory) { 29 | this.factory = factory; 30 | } 31 | 32 | /** Eval implements the Program interface method. */ 33 | @Override 34 | public EvalResult eval(Object input) { 35 | // The factory based Eval() differs from the standard evaluation model in that it generates a 36 | // new EvalState instance for each call to ensure that unique evaluations yield unique stateful 37 | // results. 38 | EvalState state = newEvalState(); 39 | 40 | // Generate a new instance of the interpretable using the factory configured during the call to 41 | // newProgram(). It is incredibly unlikely that the factory call will generate an error given 42 | // the factory test performed within the Program() call. 43 | Program p = factory.apply(state); 44 | 45 | // Evaluate the input, returning the result and the 'state' within EvalDetails. 46 | return p.eval(input); 47 | } 48 | 49 | /** Cost implements the Coster interface method. */ 50 | @Override 51 | public Cost cost() { 52 | // Use an empty state value since no evaluation is performed. 53 | Program p = factory.apply(emptyEvalState); 54 | return estimateCost(p); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/Program.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; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Program is an evaluable view of an Ast. */ 21 | public interface Program { 22 | 23 | static EvalResult newEvalResult(Val val, EvalDetails evalDetails) { 24 | return new EvalResult(val, evalDetails); 25 | } 26 | 27 | /** 28 | * Eval returns the result of an evaluation of the Ast and environment against the input vars. 29 | * 30 | *

The vars value may either be an `interpreter.Activation` or a `map[string]interface{}`. 31 | * 32 | *

If the `OptTrackState` or `OptExhaustiveEval` flags are used, the `details` response will be 33 | * non-nil. Given this caveat on `details`, the return state from evaluation will be: 34 | * 35 | *

    36 | *
  • `val`, `details`, `nil` - Successful evaluation of a non-error result. 37 | *
  • `val`, `details`, `err` - Successful evaluation to an error result. 38 | *
  • `nil`, `details`, `err` - Unsuccessful evaluation. 39 | *
40 | * 41 | *

An unsuccessful evaluation is typically the result of a series of incompatible `EnvOption` 42 | * or `ProgramOption` values used in the creation of the evaluation environment or executable 43 | * program. 44 | */ 45 | EvalResult eval(Object vars); 46 | 47 | final class EvalResult { 48 | private final Val val; 49 | private final EvalDetails evalDetails; 50 | 51 | private EvalResult(Val val, EvalDetails evalDetails) { 52 | this.val = val; 53 | this.evalDetails = evalDetails; 54 | } 55 | 56 | public Val getVal() { 57 | return val; 58 | } 59 | 60 | public EvalDetails getEvalDetails() { 61 | return evalDetails; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/ProgramOption.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; 17 | 18 | import static org.projectnessie.cel.interpreter.Activation.newActivation; 19 | 20 | import java.util.Collections; 21 | import org.projectnessie.cel.interpreter.InterpretableDecorator; 22 | import org.projectnessie.cel.interpreter.functions.Overload; 23 | 24 | @FunctionalInterface 25 | public interface ProgramOption { 26 | Prog apply(Prog prog); 27 | 28 | /** 29 | * CustomDecorator appends an InterpreterDecorator to the program. 30 | * 31 | *

InterpretableDecorators can be used to inspect, alter, or replace the Program plan. 32 | */ 33 | static ProgramOption customDecorator(InterpretableDecorator dec) { 34 | return p -> { 35 | p.decorators.add(dec); 36 | return p; 37 | }; 38 | } 39 | 40 | /** Functions adds function overloads that extend or override the set of CEL built-ins. */ 41 | static ProgramOption functions(Overload... funcs) { 42 | return p -> { 43 | p.dispatcher.add(funcs); 44 | return p; 45 | }; 46 | } 47 | 48 | /** 49 | * Globals sets the global variable values for a given program. These values may be shadowed by 50 | * variables with the same name provided to the Eval() call. 51 | * 52 | *

The vars value may either be an `interpreter.Activation` instance or a 53 | * `map[string]interface{}`. 54 | */ 55 | static ProgramOption globals(Object vars) { 56 | return p -> { 57 | p.defaultVars = newActivation(vars); 58 | return p; 59 | }; 60 | } 61 | 62 | /** EvalOptions sets one or more evaluation options which may affect the evaluation or Result. */ 63 | static ProgramOption evalOptions(EvalOption... opts) { 64 | return p -> { 65 | Collections.addAll(p.evalOpts, opts); 66 | return p; 67 | }; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/checker/Mapping.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.emptyMap; 19 | 20 | import com.google.api.expr.v1alpha1.Type; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | public final class Mapping { 25 | 26 | private final Map mapping; 27 | private final Map typeKeys; 28 | 29 | private Mapping(Map srcMapping, Map srcTypeKeys) { 30 | // Looks overly complicated, but prevents a bunch of j.u.HashMap.resize() operations. 31 | // The copy() operation is called very often when a script's being checked, so this saves 32 | // quite a lot. 33 | // The formula "* 4 / 3 + 1" prevents the HashMap from resizing, assuming the 34 | // default-load-factor of .75 (-> 3/4). 35 | this.mapping = new HashMap<>(srcMapping.size() * 4 / 3 + 1); 36 | this.mapping.putAll(srcMapping); 37 | this.typeKeys = new HashMap<>(srcTypeKeys.size() * 4 / 3 + 1); 38 | this.typeKeys.putAll(srcTypeKeys); 39 | } 40 | 41 | static Mapping newMapping() { 42 | return new Mapping(emptyMap(), emptyMap()); 43 | } 44 | 45 | private String keyForType(Type t) { 46 | // The lookup by `Type` called very often when a script's being checked, so this saves 47 | // quite a lot. 48 | return typeKeys.computeIfAbsent(t, Types::typeKey); 49 | } 50 | 51 | void add(Type from, Type to) { 52 | mapping.put(keyForType(from), to); 53 | } 54 | 55 | Type find(Type from) { 56 | return mapping.get(keyForType(from)); 57 | } 58 | 59 | Mapping copy() { 60 | return new Mapping(mapping, typeKeys); 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | StringBuilder result = new StringBuilder("{"); 66 | 67 | mapping.forEach((k, v) -> result.append(k).append(" => ").append(v)); 68 | 69 | result.append("}"); 70 | return result.toString(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/checker/Printer.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 org.projectnessie.cel.checker.Types.formatCheckedType; 19 | 20 | import com.google.api.expr.v1alpha1.CheckedExpr; 21 | import com.google.api.expr.v1alpha1.Expr; 22 | import com.google.api.expr.v1alpha1.Reference; 23 | import com.google.api.expr.v1alpha1.Type; 24 | import org.projectnessie.cel.common.debug.Debug; 25 | import org.projectnessie.cel.common.debug.Debug.Adorner; 26 | 27 | public final class Printer { 28 | 29 | static final class SemanticAdorner implements Adorner { 30 | private final CheckedExpr checks; 31 | 32 | SemanticAdorner(CheckedExpr checks) { 33 | this.checks = checks; 34 | } 35 | 36 | @Override 37 | public String getMetadata(Object elem) { 38 | if (!(elem instanceof Expr)) { 39 | return ""; 40 | } 41 | StringBuilder result = new StringBuilder(); 42 | Expr e = (Expr) elem; 43 | Type t = checks.getTypeMapMap().get(e.getId()); 44 | if (t != null) { 45 | result.append("~"); 46 | result.append(formatCheckedType(t)); 47 | } 48 | 49 | switch (e.getExprKindCase()) { 50 | case IDENT_EXPR: 51 | case CALL_EXPR: 52 | case STRUCT_EXPR: 53 | case SELECT_EXPR: 54 | Reference ref = checks.getReferenceMapMap().get(e.getId()); 55 | if (ref != null) { 56 | if (ref.getOverloadIdCount() == 0) { 57 | result.append("^").append(ref.getName()); 58 | } else { 59 | for (int i = 0; i < ref.getOverloadIdCount(); i++) { 60 | if (i == 0) { 61 | result.append("^"); 62 | } else { 63 | result.append("|"); 64 | } 65 | result.append(ref.getOverloadId(i)); 66 | } 67 | } 68 | } 69 | } 70 | 71 | return result.toString(); 72 | } 73 | } 74 | 75 | /** 76 | * Print returns a string representation of the Expr message, annotated with types from the 77 | * CheckedExpr. The Expr must be a sub-expression embedded in the CheckedExpr. 78 | */ 79 | public static String print(Expr e, CheckedExpr checks) { 80 | SemanticAdorner a = new SemanticAdorner(checks); 81 | return Debug.toAdornedDebugString(e, a); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/ErrorWithLocation.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; 17 | 18 | public final class ErrorWithLocation extends RuntimeException { 19 | private final Location location; 20 | 21 | public ErrorWithLocation(Location location, String message) { 22 | super(message); 23 | this.location = location; 24 | } 25 | 26 | public Location getLocation() { 27 | return location; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/Errors.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; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | 22 | public class Errors { 23 | private final List errors = new ArrayList<>(); 24 | private final Source source; 25 | 26 | public Errors(Source source) { 27 | this.source = source; 28 | } 29 | 30 | /** ReportError records an error at a source location. */ 31 | public void reportError(Location l, String format, Object... args) { 32 | reportError(null, l, format, args); 33 | } 34 | 35 | public void reportError(Exception e, Location l, String format, Object... args) { 36 | CELError err = new CELError(e, l, String.format(format, args)); 37 | errors.add(err); 38 | } 39 | 40 | /** GetErrors returns the list of observed errors. */ 41 | public List getErrors() { 42 | return errors; 43 | } 44 | 45 | public boolean hasErrors() { 46 | return !errors.isEmpty(); 47 | } 48 | 49 | /** 50 | * Append takes an Errors object as input creates a new Errors object with the current and input 51 | * errors. 52 | */ 53 | public Errors append(List errors) { 54 | Errors errs = new Errors(source); 55 | errs.errors.addAll(this.errors); 56 | errs.errors.addAll(errors); 57 | return errs; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return toDisplayString(); 63 | } 64 | 65 | /** ToDisplayString returns the error set to a newline delimited string. */ 66 | public String toDisplayString() { 67 | return errors.stream() 68 | .sorted() 69 | .map(e -> e.toDisplayString(source)) 70 | .collect(Collectors.joining("\n")); 71 | } 72 | 73 | public void syntaxError(Location l, String msg) { 74 | reportError(l, "Syntax error: %s", msg); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/Location.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; 17 | 18 | import java.util.Objects; 19 | 20 | public interface Location extends Comparable { 21 | Location NoLocation = newLocation(-1, -1); 22 | 23 | // NewLocation creates a new location. 24 | static Location newLocation(int line, int column) { 25 | return new SourceLocation(line, column); 26 | } 27 | 28 | /** 1-based line number within source. */ 29 | int line(); 30 | 31 | /** 0-based column number within source. */ 32 | int column(); 33 | } 34 | 35 | final class SourceLocation implements Location { 36 | private final int line; 37 | private final int column; 38 | 39 | public SourceLocation(int line, int column) { 40 | this.line = line; 41 | this.column = column; 42 | } 43 | 44 | @Override 45 | public int compareTo(Location o) { 46 | int r = Integer.compare(line, o.line()); 47 | if (r == 0) { 48 | r = Integer.compare(column, o.column()); 49 | } 50 | return r; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object o) { 55 | if (this == o) { 56 | return true; 57 | } 58 | if (o == null || getClass() != o.getClass()) { 59 | return false; 60 | } 61 | SourceLocation that = (SourceLocation) o; 62 | return line == that.line && column == that.column; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | return Objects.hash(line, column); 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "line=" + line + ", column=" + column; 73 | } 74 | 75 | @Override 76 | public int line() { 77 | return line; 78 | } 79 | 80 | @Override 81 | public int column() { 82 | return column; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/ULong.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; 17 | 18 | import java.math.BigInteger; 19 | 20 | /** 21 | * Represents a 64 bit unsigned long for the CEL {@code uint} type. 22 | * 23 | *

According to the CEL spec, the {@code uint} and {@code int} types are, loosely speaking, 24 | * "incompatible. This means, that these two types are not comparable in operators (for example 25 | * _equal_, _less-than_, etc) not do function overloads match across both types. 26 | * 27 | *

This class is mostly there to let the unit tests ported from CEL-Go pass. 28 | */ 29 | public final class ULong extends Number implements Comparable { 30 | private final long ulong; 31 | 32 | private ULong(long ulong) { 33 | this.ulong = ulong; 34 | } 35 | 36 | public static ULong valueOf(long ulong) { 37 | return new ULong(ulong); 38 | } 39 | 40 | @Override 41 | public int compareTo(ULong o) { 42 | return Long.compareUnsigned(ulong, o.ulong); 43 | } 44 | 45 | @Override 46 | public int hashCode() { 47 | return (int) ulong; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object obj) { 52 | if (!(obj instanceof ULong)) { 53 | return false; 54 | } 55 | return ((ULong) obj).ulong == ulong; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return Long.toUnsignedString(ulong); 61 | } 62 | 63 | @Override 64 | public int intValue() { 65 | return (int) ulong; 66 | } 67 | 68 | @Override 69 | public long longValue() { 70 | return ulong; 71 | } 72 | 73 | @Override 74 | public float floatValue() { 75 | return new BigInteger(toString()).floatValue(); 76 | } 77 | 78 | @Override 79 | public double doubleValue() { 80 | return new BigInteger(toString()).doubleValue(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/IterableT.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 | public interface IterableT { 19 | 20 | /** Iterator returns a new iterator view of the struct. */ 21 | IteratorT iterator(); 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/IteratorT.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.projectnessie.cel.common.types.Err.noMoreElements; 19 | import static org.projectnessie.cel.common.types.Types.boolOf; 20 | 21 | import java.util.Iterator; 22 | import java.util.NoSuchElementException; 23 | import org.projectnessie.cel.common.types.ref.BaseVal; 24 | import org.projectnessie.cel.common.types.ref.Type; 25 | import org.projectnessie.cel.common.types.ref.TypeAdapter; 26 | import org.projectnessie.cel.common.types.ref.Val; 27 | 28 | /** Iterator permits safe traversal over the contents of an aggregate type. */ 29 | public interface IteratorT extends Val { 30 | 31 | static IteratorT javaIterator(TypeAdapter adapter, Iterator iterator) { 32 | return new JavaIteratorT(adapter, iterator); 33 | } 34 | 35 | /** HasNext returns true if there are unvisited elements in the Iterator. */ 36 | Val hasNext(); 37 | 38 | /** Next returns the next element. */ 39 | Val next(); 40 | 41 | final class JavaIteratorT extends BaseVal implements IteratorT { 42 | private final TypeAdapter adapter; 43 | private final Iterator iterator; 44 | 45 | JavaIteratorT(TypeAdapter adapter, Iterator iterator) { 46 | this.adapter = adapter; 47 | this.iterator = iterator; 48 | } 49 | 50 | @Override 51 | public Val hasNext() { 52 | return boolOf(iterator.hasNext()); 53 | } 54 | 55 | @Override 56 | public Val next() { 57 | Object n; 58 | try { 59 | n = iterator.next(); 60 | } catch (NoSuchElementException e) { 61 | return noMoreElements(); 62 | } 63 | if (n instanceof Val) { 64 | return (Val) n; 65 | } 66 | return adapter.nativeToValue(n); 67 | } 68 | 69 | @Override 70 | public T convertToNative(Class typeDesc) { 71 | throw new UnsupportedOperationException(); 72 | } 73 | 74 | @Override 75 | public Val convertToType(Type typeValue) { 76 | throw new UnsupportedOperationException(); 77 | } 78 | 79 | @Override 80 | public Val equal(Val other) { 81 | throw new UnsupportedOperationException(); 82 | } 83 | 84 | @Override 85 | public Type type() { 86 | throw new UnsupportedOperationException(); 87 | } 88 | 89 | @Override 90 | public Object value() { 91 | throw new UnsupportedOperationException(); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/Types.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.projectnessie.cel.common.types.BytesT.BytesType; 19 | import static org.projectnessie.cel.common.types.DoubleT.DoubleType; 20 | import static org.projectnessie.cel.common.types.IntT.IntType; 21 | import static org.projectnessie.cel.common.types.ListT.ListType; 22 | import static org.projectnessie.cel.common.types.MapT.MapType; 23 | import static org.projectnessie.cel.common.types.NullT.NullType; 24 | import static org.projectnessie.cel.common.types.StringT.StringType; 25 | import static org.projectnessie.cel.common.types.TypeT.TypeType; 26 | import static org.projectnessie.cel.common.types.UintT.UintType; 27 | 28 | import java.util.HashMap; 29 | import java.util.Map; 30 | import org.projectnessie.cel.common.types.ref.Type; 31 | 32 | public final class Types { 33 | 34 | private Types() {} 35 | 36 | private static final Map typeNameToTypeValue = new HashMap<>(); 37 | 38 | static { 39 | typeNameToTypeValue.put(BoolT.BoolType.typeName(), BoolT.BoolType); 40 | typeNameToTypeValue.put(BytesType.typeName(), BytesType); 41 | typeNameToTypeValue.put(DoubleType.typeName(), DoubleType); 42 | typeNameToTypeValue.put(NullType.typeName(), NullType); 43 | typeNameToTypeValue.put(IntType.typeName(), IntType); 44 | typeNameToTypeValue.put(ListType.typeName(), ListType); 45 | typeNameToTypeValue.put(MapType.typeName(), MapType); 46 | typeNameToTypeValue.put(StringType.typeName(), StringType); 47 | typeNameToTypeValue.put(TypeType.typeName(), TypeType); 48 | typeNameToTypeValue.put(UintType.typeName(), UintType); 49 | } 50 | 51 | public static Type getTypeByName(String typeName) { 52 | return null; 53 | } 54 | 55 | public static BoolT boolOf(boolean b) { 56 | return b ? BoolT.True : BoolT.False; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/Util.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 org.projectnessie.cel.common.types.ref.Val; 19 | 20 | public final class Util { 21 | 22 | /** IsUnknownOrError returns whether the input element ref.Val is an ErrType or UnknonwType. */ 23 | public static boolean isUnknownOrError(Val val) { 24 | switch (val.type().typeEnum()) { 25 | case Unknown: 26 | case Err: 27 | return true; 28 | } 29 | return false; 30 | } 31 | 32 | /** 33 | * IsPrimitiveType returns whether the input element ref.Val is a primitive type. Note, primitive 34 | * types do not include well-known types such as Duration and Timestamp. 35 | */ 36 | public static boolean isPrimitiveType(Val val) { 37 | switch (val.type().typeEnum()) { 38 | case Bool: 39 | case Bytes: 40 | case Double: 41 | case Int: 42 | case String: 43 | case Uint: 44 | return true; 45 | } 46 | return false; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/pb/Description.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 com.google.protobuf.Message; 19 | 20 | /** 21 | * description is a private interface used to make it convenient to perform type unwrapping at the 22 | * TypeDescription or FieldDescription level. 23 | */ 24 | abstract class Description { 25 | /** 26 | * Zero returns an empty immutable protobuf message when the description is a protobuf message 27 | * type. 28 | */ 29 | abstract Message zero(); 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/pb/EnumValueDescription.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 com.google.protobuf.Descriptors.EnumValueDescriptor; 19 | import java.util.Objects; 20 | 21 | /** EnumValueDescription maps a fully-qualified enum value name to its numeric value. */ 22 | public final class EnumValueDescription { 23 | 24 | private final String enumValueName; 25 | private final EnumValueDescriptor desc; 26 | 27 | private EnumValueDescription(String enumValueName, EnumValueDescriptor desc) { 28 | this.enumValueName = enumValueName; 29 | this.desc = desc; 30 | } 31 | 32 | /** 33 | * NewEnumValueDescription produces an enum value description with the fully qualified enum value 34 | * name and the enum value descriptor. 35 | */ 36 | public static EnumValueDescription newEnumValueDescription( 37 | String name, EnumValueDescriptor desc) { 38 | return new EnumValueDescription(name, desc); 39 | } 40 | 41 | /** Name returns the fully-qualified identifier name for the enum value. */ 42 | public String name() { 43 | return enumValueName; 44 | } 45 | 46 | /** Value returns the (numeric) value of the enum. */ 47 | public int value() { 48 | return desc.getNumber(); 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (this == o) { 54 | return true; 55 | } 56 | if (o == null || getClass() != o.getClass()) { 57 | return false; 58 | } 59 | EnumValueDescription that = (EnumValueDescription) o; 60 | return Objects.equals(enumValueName, that.enumValueName) && Objects.equals(desc, that.desc); 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return Objects.hash(enumValueName, desc); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/BaseVal.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.ref; 17 | 18 | import static org.projectnessie.cel.common.types.BoolT.BoolType; 19 | import static org.projectnessie.cel.common.types.BoolT.True; 20 | import static org.projectnessie.cel.common.types.DoubleT.DoubleType; 21 | import static org.projectnessie.cel.common.types.IntT.IntType; 22 | 23 | public abstract class BaseVal implements Val { 24 | 25 | @Override 26 | public int hashCode() { 27 | return value().hashCode(); 28 | } 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | if (obj instanceof Val) { 33 | return equal((Val) obj) == True; 34 | } 35 | return value().equals(obj); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return String.format("%s{%s}", type().typeName(), value()); 41 | } 42 | 43 | @Override 44 | public boolean booleanValue() { 45 | return convertToType(BoolType).booleanValue(); 46 | } 47 | 48 | @Override 49 | public long intValue() { 50 | return convertToType(IntType).intValue(); 51 | } 52 | 53 | @Override 54 | public double doubleValue() { 55 | return convertToType(DoubleType).doubleValue(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/FieldGetter.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.ref; 17 | 18 | /** FieldGetter is used to get the field value from an input object, if set. */ 19 | @FunctionalInterface 20 | public interface FieldGetter { 21 | Object getFrom(Object target); 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/FieldTester.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.ref; 17 | 18 | /** FieldTester is used to test field presence on an input object. */ 19 | @FunctionalInterface 20 | public interface FieldTester { 21 | boolean isSet(Object target); 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/FieldType.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.ref; 17 | 18 | /** FieldType represents a field's type value and whether that field supports presence detection. */ 19 | public class FieldType { 20 | /** Type of the field. */ 21 | public final com.google.api.expr.v1alpha1.Type type; 22 | 23 | /** IsSet indicates whether the field is set on an input object. */ 24 | public final FieldTester isSet; 25 | 26 | /** GetFrom retrieves the field value on the input object, if set. */ 27 | public final FieldGetter getFrom; 28 | 29 | public FieldType(com.google.api.expr.v1alpha1.Type type, FieldTester isSet, FieldGetter getFrom) { 30 | this.type = type; 31 | this.isSet = isSet; 32 | this.getFrom = getFrom; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/Type.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.ref; 17 | 18 | import org.projectnessie.cel.common.types.traits.Trait; 19 | 20 | /** Type interface indicate the name of a given type. */ 21 | public interface Type extends Val { 22 | 23 | /** 24 | * HasTrait returns whether the type has a given trait associated with it. 25 | * 26 | *

See common/types/traits/traits.go for a list of supported traits. 27 | */ 28 | boolean hasTrait(Trait trait); 29 | 30 | /** 31 | * TypeName returns the qualified type name of the type. 32 | * 33 | *

The type name is also used as the type's identifier name at type-check and interpretation 34 | * time. 35 | */ 36 | String typeName(); 37 | 38 | /** Get the type enum. */ 39 | TypeEnum typeEnum(); 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/TypeAdapter.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.ref; 17 | 18 | /** 19 | * TypeAdapter converts native Go values of varying type and complexity to equivalent CEL values. 20 | */ 21 | public interface TypeAdapter { 22 | /** NativeToValue converts the input `value` to a CEL `ref.Val`. */ 23 | Val nativeToValue(Object value); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/TypeDescription.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.ref; 17 | 18 | /** 19 | * TypeDescription is a collection of type metadata relevant to expression checking and evaluation. 20 | */ 21 | public interface TypeDescription { 22 | 23 | /** Name returns the fully-qualified name of the type. */ 24 | String name(); 25 | 26 | /** ReflectType returns the Golang reflect.Type for this type. */ 27 | Class reflectType(); 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/TypeEnum.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.ref; 17 | 18 | public enum TypeEnum { 19 | Bool("bool"), 20 | Bytes("bytes"), 21 | Double("double"), 22 | Duration("google.protobuf.Duration"), 23 | Err("error"), 24 | Int("int"), 25 | List("list"), 26 | Map("map"), 27 | Null("null_type"), 28 | Object("object"), 29 | String("string"), 30 | Timestamp("google.protobuf.Timestamp"), 31 | Type("type"), 32 | Uint("uint"), 33 | Unknown("unknown"); 34 | 35 | private final String name; 36 | 37 | TypeEnum(java.lang.String name) { 38 | this.name = name; 39 | } 40 | 41 | public java.lang.String getName() { 42 | return name; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/TypeProvider.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.ref; 17 | 18 | import com.google.api.expr.v1alpha1.Type; 19 | import java.util.Map; 20 | 21 | /** 22 | * TypeProvider specifies functions for creating new object instances and for resolving enum values 23 | * by name. 24 | */ 25 | public interface TypeProvider { 26 | /** EnumValue returns the numeric value of the given enum value name. */ 27 | Val enumValue(String enumName); 28 | 29 | /** FindIdent takes a qualified identifier name and returns a Value if one exists. */ 30 | Val findIdent(String identName); 31 | 32 | /** 33 | * FindType looks up the Type given a qualified typeName. Returns false if not found. 34 | * 35 | *

Used during type-checking only. 36 | */ 37 | Type findType(String typeName); 38 | 39 | /** 40 | * FieldFieldType returns the field type for a checked type value. Returns false if the field 41 | * could not be found. 42 | * 43 | *

Used during type-checking only. 44 | */ 45 | FieldType findFieldType(String messageType, String fieldName); 46 | 47 | /** 48 | * NewValue creates a new type value from a qualified name and map of field name to value. 49 | * 50 | *

Note, for each value, the Val.ConvertToNative function will be invoked to convert the Val to 51 | * the field's native type. If an error occurs during conversion, the NewValue will be a 52 | * types.Err. 53 | */ 54 | Val newValue(String typeName, Map fields); 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/TypeRegistry.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.ref; 17 | 18 | /** 19 | * TypeRegistry allows third-parties to add custom types to CEL. Not all `TypeProvider` 20 | * implementations support type-customization, so these features are optional. However, a 21 | * `TypeRegistry` should be a `TypeProvider` and a `TypeAdapter` to ensure that types which are 22 | * registered can be converted to CEL representations. 23 | */ 24 | public interface TypeRegistry extends TypeAdapter, TypeProvider { 25 | 26 | /** Copy the TypeRegistry and return a new registry whose mutable state is isolated. */ 27 | TypeRegistry copy(); 28 | 29 | /** Register a type via a materialized object, which the provider can turn into a type. */ 30 | void register(Object t); 31 | 32 | /** 33 | * RegisterType registers a type value with the provider which ensures the provider is aware of 34 | * how to map the type to an identifier. 35 | * 36 | *

If a type is provided more than once with an alternative definition, the call will result in 37 | * an error. 38 | */ 39 | void registerType(Type... types); 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/ref/Val.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.ref; 17 | 18 | /** 19 | * Val interface defines the functions supported by all expression values. Val implementations may 20 | * specialize the behavior of the value through the addition of traits. 21 | */ 22 | public interface Val { 23 | /** 24 | * ConvertToNative converts the Value to a native Go struct according to the reflected type 25 | * description, or error if the conversion is not feasible. 26 | */ 27 | T convertToNative(Class typeDesc); 28 | 29 | /** 30 | * ConvertToType supports type conversions between value types supported by the expression 31 | * language. 32 | */ 33 | Val convertToType(Type typeValue); 34 | 35 | /** 36 | * Equal returns true if the `other` value has the same type and content as the implementing 37 | * struct. 38 | */ 39 | Val equal(Val other); 40 | 41 | /** Type returns the TypeValue of the value. */ 42 | Type type(); 43 | 44 | /** 45 | * Value returns the raw value of the instance which may not be directly compatible with the 46 | * expression language types. 47 | */ 48 | Object value(); 49 | 50 | boolean booleanValue(); 51 | 52 | long intValue(); 53 | 54 | double doubleValue(); 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Adder.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Adder interface to support '+' operator overloads. */ 21 | public interface Adder { 22 | /** 23 | * Add returns a combination of the current value and other value. 24 | * 25 | *

If the other value is an unsupported type, an error is returned. 26 | */ 27 | Val add(Val other); 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Comparer.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** 21 | * Comparer interface for ordering comparisons between values in order to support '<', '<=', 22 | * '>=', '>' overloads. 23 | */ 24 | public interface Comparer { 25 | /** 26 | * Compare this value to the input other value, returning an Int: 27 | * 28 | *

{@code this < other -> Int(-1)
this == other -> Int(0)
this > other 29 | * -> Int(1) } 30 | * 31 | *

If the comparison cannot be made or is not supported, an error should be returned. 32 | */ 33 | Val compare(Val other); 34 | } 35 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Container.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Container interface which permits containment tests such as 'a in b'. */ 21 | public interface Container { 22 | /** Contains returns true if the value exists within the object. */ 23 | Val contains(Val value); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Divider.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Divider interface to support '/' operator overloads. */ 21 | public interface Divider { 22 | /** 23 | * Divide returns the result of dividing the current value by the input denominator. 24 | * 25 | *

A denominator value of zero results in an error. 26 | */ 27 | Val divide(Val denominator); 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/FieldTester.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** 21 | * FieldTester indicates if a defined field on an object type is set to a non-default value. 22 | * 23 | *

For use with the `has()` macro. 24 | */ 25 | public interface FieldTester { 26 | /** 27 | * IsSet returns true if the field is defined and set to a non-default value. The method will 28 | * return false if defined and not set, and an error if the field is not defined. 29 | */ 30 | Val isSet(Val field); 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Indexer.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Indexer permits random access of elements by index 'a[b()]'. */ 21 | public interface Indexer { 22 | /** Get the value at the specified index or error. */ 23 | Val get(Val index); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Lister.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.IterableT; 19 | import org.projectnessie.cel.common.types.ref.Val; 20 | 21 | /** Lister interface which aggregates the traits of a list. */ 22 | public interface Lister extends Val, Adder, Container, Indexer, IterableT, Sizer {} 23 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Mapper.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.IterableT; 19 | import org.projectnessie.cel.common.types.ref.Val; 20 | 21 | /** Mapper interface which aggregates the traits of a maps. */ 22 | public interface Mapper extends Val, Container, Indexer, IterableT, Sizer { 23 | 24 | /** 25 | * Find returns a value, if one exists, for the input key. 26 | * 27 | *

If the key is not found the function returns (nil, false). If the input key is not valid for 28 | * the map, or is Err or Unknown the function returns (Unknown|Err, false). 29 | */ 30 | Val find(Val key); 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Matcher.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Matcher interface for supporting 'matches()' overloads. */ 21 | public interface Matcher { 22 | /** Match returns true if the pattern matches the current value. */ 23 | Val match(Val pattern); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Modder.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Modder interface to support '%' operator overloads. */ 21 | public interface Modder { 22 | /** 23 | * Modulo returns the result of taking the modulus of the current value by the denominator. 24 | * 25 | *

A denominator value of zero results in an error. 26 | */ 27 | Val modulo(Val denominator); 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Multiplier.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Multiplier interface to support '*' operator overloads. */ 21 | public interface Multiplier { 22 | /** Multiply returns the result of multiplying the current and input value. */ 23 | Val multiply(Val other); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Negater.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Negater interface to support unary '-' and '!' operator overloads. */ 21 | public interface Negater { 22 | /** Negate returns the complement of the current value. */ 23 | Val negate(); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Receiver.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Receiver interface for routing instance method calls within a value. */ 21 | public interface Receiver { 22 | /** Receive accepts a function name, overload id, and arguments and returns a value. */ 23 | Val receive(String function, String overload, Val... args); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Sizer.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Sizer interface for supporting 'size()' overloads. */ 21 | public interface Sizer { 22 | /** Size returns the number of elements or length of the value. */ 23 | Val size(); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Subtractor.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.traits; 17 | 18 | import org.projectnessie.cel.common.types.ref.Val; 19 | 20 | /** Subtractor interface to support binary '-' operator overloads. */ 21 | public interface Subtractor { 22 | /** Subtract returns the result of subtracting the input from the current value. */ 23 | Val subtract(Val subtrahend); 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/common/types/traits/Trait.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.traits; 17 | 18 | public enum Trait { 19 | /** AdderType types provide a '+' operator overload. */ 20 | AdderType, 21 | 22 | /** ComparerType types support ordering comparisons '<', '<=', '<', '<='. */ 23 | ComparerType, 24 | 25 | /** ContainerType types support 'in' operations. */ 26 | ContainerType, 27 | 28 | /** DividerType types support '/' operations. */ 29 | DividerType, 30 | 31 | /** FieldTesterType types support the detection of field value presence. */ 32 | FieldTesterType, 33 | 34 | /** IndexerType types support index access with dynamic values. */ 35 | IndexerType, 36 | 37 | /** IterableType types can be iterated over in comprehensions. */ 38 | IterableType, 39 | 40 | /** IteratorType types support iterator semantics. */ 41 | IteratorType, 42 | 43 | /** MatcherType types support pattern matching via 'matches' method. */ 44 | MatcherType, 45 | 46 | /** ModderType types support modulus operations '%' */ 47 | ModderType, 48 | 49 | /** MultiplierType types support '*' operations. */ 50 | MultiplierType, 51 | 52 | /** NegatorType types support either negation via '!' or '-' */ 53 | NegatorType, 54 | 55 | /** ReceiverType types support dynamic dispatch to instance methods. */ 56 | ReceiverType, 57 | 58 | /** SizerType types support the size() method. */ 59 | SizerType, 60 | 61 | /** SubtractorType type support '-' operations. */ 62 | SubtractorType 63 | } 64 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/extension/QuadFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 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.extension; 17 | 18 | @FunctionalInterface 19 | public interface QuadFunction { 20 | R apply(A a, B b, C c, D d); 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/extension/TriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 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.extension; 17 | 18 | import java.util.Objects; 19 | import java.util.function.Function; 20 | 21 | @FunctionalInterface 22 | interface TriFunction { 23 | 24 | R apply(A a, B b, C c); 25 | 26 | default TriFunction andThen(Function after) { 27 | Objects.requireNonNull(after); 28 | return (A a, B b, C c) -> after.apply(apply(a, b, c)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/interpreter/Coster.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; 17 | 18 | import java.util.Objects; 19 | 20 | /** Coster calculates the heuristic cost incurred during evaluation. */ 21 | public interface Coster { 22 | Cost cost(); 23 | 24 | static Cost costOf(long min, long max) { 25 | return new Cost(min, max); 26 | } 27 | 28 | final class Cost { 29 | public static final Cost Unknown = costOf(0, Long.MAX_VALUE); 30 | public static final Cost None = costOf(0, 0); 31 | public static final Cost OneOne = costOf(1, 1); 32 | public final long min; 33 | public final long max; 34 | 35 | private Cost(long min, long max) { 36 | this.min = min; 37 | this.max = max; 38 | } 39 | 40 | /** estimateCost returns the heuristic cost interval for the program. */ 41 | public static Cost estimateCost(Object i) { 42 | if (i instanceof Coster) { 43 | return ((Coster) i).cost(); 44 | } 45 | return Unknown; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object o) { 50 | if (this == o) { 51 | return true; 52 | } 53 | if (o == null || getClass() != o.getClass()) { 54 | return false; 55 | } 56 | Cost cost = (Cost) o; 57 | return min == cost.min && max == cost.max; 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return Objects.hash(min, max); 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "Cost{" + "min=" + min + ", max=" + max + '}'; 68 | } 69 | 70 | public Cost add(Cost c) { 71 | return new Cost(min + c.min, max + c.max); 72 | } 73 | 74 | public Cost multiply(long multiplier) { 75 | return new Cost(min * multiplier, max * multiplier); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /core/src/main/java/org/projectnessie/cel/interpreter/EvalState.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; 17 | 18 | import org.agrona.collections.Long2ObjectHashMap; 19 | import org.projectnessie.cel.common.types.ref.Val; 20 | 21 | /** EvalState tracks the values associated with expression ids during execution. */ 22 | public interface EvalState { 23 | /** IDs returns the list of ids with recorded values. */ 24 | long[] ids(); 25 | 26 | /** 27 | * Value returns the observed value of the given expression id if found, and a nil false result if 28 | * not. 29 | */ 30 | Val value(long id); 31 | 32 | /** SetValue sets the observed value of the expression id. */ 33 | void setValue(long id, Val v); 34 | 35 | /** Reset clears the previously recorded expression values. */ 36 | void reset(); 37 | 38 | /** 39 | * NewEvalState returns an EvalState instanced used to observe the intermediate evaluations of an 40 | * expression. 41 | */ 42 | static EvalState newEvalState() { 43 | return new EvalStateImpl(); 44 | } 45 | 46 | /** evalState permits the mutation of evaluation state for a given expression id. */ 47 | final class EvalStateImpl implements EvalState { 48 | private final Long2ObjectHashMap 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 | --------------------------------------------------------------------------------