Class EvaluatorBuilder
Evaluator. Can be reused to build multiple evaluators.-
Method Summary
Modifier and TypeMethodDescriptionaddEnvironmentVariable(String name, String value) Adds the given environment variable, overriding any environment variable previously added under the same name.addEnvironmentVariables(Map<String, String> envVars) Adds the given environment variables, overriding any environment variables previously added under the same name.addExternalProperties(Map<String, String> properties) Adds the given external properties, overriding any properties previously set under the same name.addExternalProperty(String name, String value) Adds the given external property, overriding any property previously set under the same name.addModuleKeyFactories(Collection<ModuleKeyFactory> factories) Adds the given module key factories.addModuleKeyFactory(ModuleKeyFactory factory) Adds the given module key factory.addResourceReader(ResourceReader reader) addResourceReaders(Collection<ResourceReader> readers) applyFromProject(Project project) Given a project, sets its dependencies, and also applies any evaluator settings if set.build()Returns the set of patterns to be allowed when importing modules.Returns the set of patterns to be allowed when reading resources.booleangetColor()Returns the current setting of the option to render errors in ANSI color.Returns the currently set environment variables.Returns the currently set external properties.Returns the currently set HTTP client.Returns the currently set logger.Returns the directory where `package:` modules are cached.Returns the currently set module key factories.Returns the currently set output format, if any.Returns the currently set resource readers.Returns the currently set root directory, if set.Returns the currently set security manager.Returns the currently set stack frame transformer.Returns the currently set evaluation timeout.Returns whether calls to trace() produce indented, multi-line output.static EvaluatorBuilderCreates a builder preconfigured with:SecurityManagers.defaultAllowedModulesSecurityManagers.defaultAllowedResourcesLoggers.noop()ModuleKeyFactories.standardLibraryModuleKeyFactories.classPath(java.lang.ClassLoader)ModuleKeyFactories.fromServiceProviders()ModuleKeyFactories.fileModuleKeyFactories.pkgModuleKeyFactories.projectpackageModuleKeyFactories.genericUrlResourceReaders.environmentVariable()ResourceReaders.externalProperty()ResourceReaders.classPath(java.lang.ClassLoader)ResourceReaders.file()ResourceReaders.http()ResourceReaders.https()ResourceReaders.pkg()ResourceReaders.projectpackage()ResourceReaders.fromServiceProviders()System.getProperties()setAllowedModules(Collection<Pattern> patterns) Sets the set of URI patterns to be allowed when importing modules.setAllowedResources(Collection<Pattern> patterns) Sets the set of URI patterns to be allowed when reading resources.setColor(boolean color) Sets the option to render errors in ANSI color.setEnvironmentVariables(Map<String, String> envVars) Removes any existing environment variables, then adds the given environment variables.setExternalProperties(Map<String, String> properties) Removes any existing external properties, then adds the given properties.setHttpClient(HttpClient httpClient) Sets the HTTP client to be used.Sets the given logger, replacing any previously set logger.setModuleCacheDir(@Nullable Path moduleCacheDir) Sets the directory where `package:` modules are cached.setModuleKeyFactories(Collection<ModuleKeyFactory> factories) Removes any existing module key factories, then adds the given factories.setOutputFormat(@Nullable String outputFormat) Sets the desired output format, if any.setOutputFormat(@Nullable OutputFormat outputFormat) Sets the desired output format, if any.setProjectDependencies(DeclaredDependencies dependencies) Sets the project dependencies for the evaluator.setResourceReaders(Collection<ResourceReader> readers) setRootDir(@Nullable Path rootDir) Sets the root directory, which restricts access to file-based modules and resources located under this directory.setSecurityManager(@Nullable SecurityManager manager) Sets the given security manager, replacing any previously set security manager.setStackFrameTransformer(StackFrameTransformer stackFrameTransformer) Sets the given stack frame transformer, replacing any previously set transformer.setTimeout(Duration timeout) Sets an evaluation timeout to be enforced by theEvaluator'sevaluatemethods.setTraceMode(TraceMode traceMode) Sets whether calls to trace() produce indented, multi-line output.static EvaluatorBuilderCreates a builder that is unconfigured.
-
Method Details
-
preconfigured
Creates a builder preconfigured with:SecurityManagers.defaultAllowedModulesSecurityManagers.defaultAllowedResourcesLoggers.noop()ModuleKeyFactories.standardLibraryModuleKeyFactories.classPath(java.lang.ClassLoader)ModuleKeyFactories.fromServiceProviders()ModuleKeyFactories.fileModuleKeyFactories.pkgModuleKeyFactories.projectpackageModuleKeyFactories.genericUrlResourceReaders.environmentVariable()ResourceReaders.externalProperty()ResourceReaders.classPath(java.lang.ClassLoader)ResourceReaders.file()ResourceReaders.http()ResourceReaders.https()ResourceReaders.pkg()ResourceReaders.projectpackage()ResourceReaders.fromServiceProviders()System.getProperties()
-
unconfigured
Creates a builder that is unconfigured. At a minimum, a security manager will need to be set before building an instance. -
setColor
Sets the option to render errors in ANSI color. -
getColor
public boolean getColor()Returns the current setting of the option to render errors in ANSI color. -
setStackFrameTransformer
Sets the given stack frame transformer, replacing any previously set transformer. -
getStackFrameTransformer
Returns the currently set stack frame transformer. -
setSecurityManager
Sets the given security manager, replacing any previously set security manager. -
unsetSecurityManager
-
getSecurityManager
Returns the currently set security manager. -
setAllowedModules
Sets the set of URI patterns to be allowed when importing modules.- Throws:
IllegalStateException- ifsetSecurityManager(SecurityManager)was also called.
-
getAllowedModules
Returns the set of patterns to be allowed when importing modules. -
setAllowedResources
Sets the set of URI patterns to be allowed when reading resources.- Throws:
IllegalStateException- ifsetSecurityManager(SecurityManager)was also called.
-
getAllowedResources
Returns the set of patterns to be allowed when reading resources. -
setRootDir
Sets the root directory, which restricts access to file-based modules and resources located under this directory. -
getRootDir
Returns the currently set root directory, if set. -
setLogger
Sets the given logger, replacing any previously set logger. -
getLogger
Returns the currently set logger. -
setHttpClient
Sets the HTTP client to be used.Defaults to
HttpClient.builder().buildLazily(). -
getHttpClient
Returns the currently set HTTP client. -
addModuleKeyFactory
Adds the given module key factory. Factories will be asked to resolve module keys in the order they have been added to this builder. -
addModuleKeyFactories
Adds the given module key factories. Factories will be asked to resolve module keys in the order they have been added to this builder. -
setModuleKeyFactories
Removes any existing module key factories, then adds the given factories. -
getModuleKeyFactories
Returns the currently set module key factories. -
addResourceReader
-
addResourceReaders
-
setResourceReaders
-
getResourceReaders
Returns the currently set resource readers. -
addEnvironmentVariable
Adds the given environment variable, overriding any environment variable previously added under the same name.Pkl code can read environment variables with
read("env:<NAME>"). -
addEnvironmentVariables
Adds the given environment variables, overriding any environment variables previously added under the same name.Pkl code can read environment variables with
read("env:<NAME>"). -
setEnvironmentVariables
Removes any existing environment variables, then adds the given environment variables. -
getEnvironmentVariables
Returns the currently set environment variables. -
addExternalProperty
Adds the given external property, overriding any property previously set under the same name.Pkl code can read external properties with
read("prop:<name>"). -
addExternalProperties
Adds the given external properties, overriding any properties previously set under the same name.Pkl code can read external properties with
read("prop:<name>"). -
setExternalProperties
Removes any existing external properties, then adds the given properties. -
getExternalProperties
Returns the currently set external properties. -
setTimeout
Sets an evaluation timeout to be enforced by theEvaluator'sevaluatemethods. -
getTimeout
Returns the currently set evaluation timeout. -
setModuleCacheDir
Sets the directory where `package:` modules are cached.If
null, the module cache is disabled. -
getModuleCacheDir
Returns the directory where `package:` modules are cached. Ifnull, the module cache is disabled. -
setOutputFormat
Sets the desired output format, if any.By default, modules support the formats described by
OutputFormat. and fall back toOutputFormat.PCFif no format is specified.Modules that override
output.rendererin their source code may ignore this option or may support formats other than those described byOutputFormat. In particular, most templates ignore this option and always render the same format. -
setOutputFormat
Sets the desired output format, if any.By default, modules support the formats described by
OutputFormat. and fall back toOutputFormat.PCFif no format is specified.Modules that override
output.rendererin their source code may ignore this option or may support formats other than those described byOutputFormat. In particular, most templates ignore this option and always render the same format. -
getOutputFormat
Returns the currently set output format, if any. -
setProjectDependencies
Sets the project dependencies for the evaluator. -
getProjectDependencies
-
setTraceMode
Sets whether calls to trace() produce indented, multi-line output. -
getTraceMode
Returns whether calls to trace() produce indented, multi-line output. -
applyFromProject
Given a project, sets its dependencies, and also applies any evaluator settings if set.- Throws:
IllegalStateException- ifsetSecurityManager(SecurityManager)was also called.
-
build
-