Skip to content

Commit 3a3199e

Browse files
l46kokcopybara-github
authored andcommitted
Add planner test coverage for policy compilation
PiperOrigin-RevId: 901483162
1 parent 5667bd8 commit 3a3199e

File tree

50 files changed

+1156
-1249
lines changed

Some content is hidden

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

50 files changed

+1156
-1249
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ TRUTH_VERSION = "1.4.4"
4646

4747
PROTOBUF_JAVA_VERSION = "4.33.5"
4848

49-
CEL_VERSION = "0.12.0"
49+
CEL_VERSION = "0.13.0"
5050

5151
# Compile only artifacts
5252
[

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ CEL-Java is available in Maven Central Repository. [Download the JARs here][8] o
5555
<dependency>
5656
<groupId>dev.cel</groupId>
5757
<artifactId>cel</artifactId>
58-
<version>0.12.0</version>
58+
<version>0.13.0</version>
5959
</dependency>
6060
```
6161

6262
**Gradle**
6363

6464
```gradle
65-
implementation 'dev.cel:cel:0.12.0'
65+
implementation 'dev.cel:cel:0.13.0'
6666
```
6767

6868
Then run this example:

common/src/main/java/dev/cel/common/values/CelValueConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected Object normalizePrimitive(Object value) {
117117
}
118118

119119
/** Adapts a {@link CelValue} to a plain old Java Object. */
120-
private static Object unwrap(CelValue celValue) {
120+
private Object unwrap(CelValue celValue) {
121121
Preconditions.checkNotNull(celValue);
122122

123123
if (celValue instanceof OptionalValue) {
@@ -126,7 +126,7 @@ private static Object unwrap(CelValue celValue) {
126126
return Optional.empty();
127127
}
128128

129-
return Optional.of(optionalValue.value());
129+
return Optional.of(maybeUnwrap(optionalValue.value()));
130130
}
131131

132132
if (celValue instanceof ErrorValue) {

extensions/src/main/java/dev/cel/extensions/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ java_library(
4242
":strings",
4343
"//common:options",
4444
"//extensions:extension_library",
45+
"@maven//:com_google_errorprone_error_prone_annotations",
4546
"@maven//:com_google_guava_guava",
4647
],
4748
)
@@ -121,7 +122,6 @@ java_library(
121122
":extension_library",
122123
"//checker:checker_builder",
123124
"//common:compiler_common",
124-
"//common:options",
125125
"//common/ast",
126126
"//common/exceptions:numeric_overflow",
127127
"//common/internal:comparison_functions",

extensions/src/main/java/dev/cel/extensions/CelEncoderExtensions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
135135
functions.forEach(
136136
function -> {
137137
if (celOptions.evaluateCanonicalTypesToNativeValues()) {
138-
runtimeBuilder.addFunctionBindings(function.nativeBytesFunctionBinding);
138+
runtimeBuilder.addFunctionBindings(
139+
CelFunctionBinding.fromOverloads(
140+
function.getFunction(), function.nativeBytesFunctionBinding));
139141
} else {
140-
runtimeBuilder.addFunctionBindings(function.protoBytesFunctionBinding);
142+
runtimeBuilder.addFunctionBindings(
143+
CelFunctionBinding.fromOverloads(
144+
function.getFunction(), function.protoBytesFunctionBinding));
141145
}
142146
});
143147
}

extensions/src/main/java/dev/cel/extensions/CelExtensions.java

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import com.google.common.collect.ImmutableSet;
2121
import com.google.common.collect.Streams;
22+
import com.google.errorprone.annotations.InlineMe;
2223
import dev.cel.common.CelOptions;
24+
import dev.cel.extensions.CelMathExtensions.Function;
2325
import java.util.Set;
2426

2527
/**
@@ -121,21 +123,18 @@ public static CelProtoExtensions protos() {
121123
* <p>This will include all functions denoted in {@link CelMathExtensions.Function}, including any
122124
* future additions. To expose only a subset of these, use {@link #math(CelOptions,
123125
* CelMathExtensions.Function...)} or {@link #math(CelOptions,int)} instead.
124-
*
125-
* @param celOptions CelOptions to configure CelMathExtension with. This should be the same
126-
* options object used to configure the compilation/runtime environments.
127126
*/
128-
public static CelMathExtensions math(CelOptions celOptions) {
129-
return CelMathExtensions.library(celOptions).latest();
127+
public static CelMathExtensions math() {
128+
return CelMathExtensions.library().latest();
130129
}
131130

132131
/**
133132
* Returns the specified version of the 'math' extension.
134133
*
135134
* <p>Refer to README.md for functions available in each version.
136135
*/
137-
public static CelMathExtensions math(CelOptions celOptions, int version) {
138-
return CelMathExtensions.library(celOptions).version(version);
136+
public static CelMathExtensions math(int version) {
137+
return CelMathExtensions.library().version(version);
139138
}
140139

141140
/**
@@ -150,13 +149,9 @@ public static CelMathExtensions math(CelOptions celOptions, int version) {
150149
* collision.
151150
*
152151
* <p>This will include only the specific functions denoted by {@link CelMathExtensions.Function}.
153-
*
154-
* @param celOptions CelOptions to configure CelMathExtension with. This should be the same
155-
* options object used to configure the compilation/runtime environments.
156152
*/
157-
public static CelMathExtensions math(
158-
CelOptions celOptions, CelMathExtensions.Function... functions) {
159-
return math(celOptions, ImmutableSet.copyOf(functions));
153+
public static CelMathExtensions math(CelMathExtensions.Function... functions) {
154+
return math(ImmutableSet.copyOf(functions));
160155
}
161156

162157
/**
@@ -171,13 +166,49 @@ public static CelMathExtensions math(
171166
* collision.
172167
*
173168
* <p>This will include only the specific functions denoted by {@link CelMathExtensions.Function}.
174-
*
175-
* @param celOptions CelOptions to configure CelMathExtension with. This should be the same
176-
* options object used to configure the compilation/runtime environments.
177169
*/
170+
public static CelMathExtensions math(Set<CelMathExtensions.Function> functions) {
171+
return new CelMathExtensions(functions);
172+
}
173+
174+
/**
175+
* @deprecated Use {@link #math()} instead.
176+
*/
177+
@Deprecated
178+
@InlineMe(replacement = "CelExtensions.math()", imports = "dev.cel.extensions.CelExtensions")
179+
public static CelMathExtensions math(CelOptions unused) {
180+
return math();
181+
}
182+
183+
/**
184+
* @deprecated Use {@link #math(int)} instead.
185+
*/
186+
@Deprecated
187+
@InlineMe(
188+
replacement = "CelExtensions.math(version)",
189+
imports = "dev.cel.extensions.CelExtensions")
190+
public static CelMathExtensions math(CelOptions unused, int version) {
191+
return math(version);
192+
}
193+
194+
/**
195+
* @deprecated Use {@link #math(Function...)} instead.
196+
*/
197+
@Deprecated
198+
public static CelMathExtensions math(CelOptions unused, CelMathExtensions.Function... functions) {
199+
return math(ImmutableSet.copyOf(functions));
200+
}
201+
202+
/**
203+
* @deprecated Use {@link #math(Set)} instead.
204+
*/
205+
@Deprecated
206+
@InlineMe(
207+
replacement = "CelExtensions.math(functions)",
208+
imports = "dev.cel.extensions.CelExtensions")
178209
public static CelMathExtensions math(
179-
CelOptions celOptions, Set<CelMathExtensions.Function> functions) {
180-
return new CelMathExtensions(celOptions, functions);
210+
CelOptions unused, Set<CelMathExtensions.Function> functions) {
211+
return math(functions);
181212
}
182213

183214
/**
@@ -354,7 +385,7 @@ public static CelExtensionLibrary<? extends CelExtensionLibrary.FeatureSet> getE
354385
case "lists":
355386
return CelListsExtensions.library();
356387
case "math":
357-
return CelMathExtensions.library(options);
388+
return CelMathExtensions.library();
358389
case "optional":
359390
return CelOptionalLibrary.library();
360391
case "protos":

0 commit comments

Comments
 (0)