Class EvaluatorBuilder
- java.lang.Object
-
- org.pkl.core.EvaluatorBuilder
-
public final class EvaluatorBuilder extends java.lang.ObjectA builder for anEvaluator. Can be reused to build multiple evaluators.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description EvaluatorBuilderaddEnvironmentVariable(java.lang.String name, java.lang.String value)Adds the given environment variable, overriding any environment variable previously added under the same name.EvaluatorBuilderaddEnvironmentVariables(java.util.Map<java.lang.String,java.lang.String> envVars)Adds the given environment variables, overriding any environment variables previously added under the same name.EvaluatorBuilderaddExternalProperties(java.util.Map<java.lang.String,java.lang.String> properties)Adds the given external properties, overriding any properties previously set under the same name.EvaluatorBuilderaddExternalProperty(java.lang.String name, java.lang.String value)Adds the given external property, overriding any property previously set under the same name.EvaluatorBuilderaddModuleKeyFactories(java.util.Collection<ModuleKeyFactory> factories)Adds the given module key factories.EvaluatorBuilderaddModuleKeyFactory(ModuleKeyFactory factory)Adds the given module key factory.EvaluatorBuilderaddResourceReader(ResourceReader reader)EvaluatorBuilderaddResourceReaders(java.util.Collection<ResourceReader> readers)EvaluatorBuilderapplyFromProject(Project project)Given a project, sets its dependencies, and also applies any evaluator settings if set.Evaluatorbuild()java.util.List<java.util.regex.Pattern>getAllowedModules()Returns the set of patterns to be allowed when importing modules.java.util.List<java.util.regex.Pattern>getAllowedResources()Returns the set of patterns to be allowed when reading resources.java.util.Map<java.lang.String,java.lang.String>getEnvironmentVariables()Returns the currently set environment variables.java.util.Map<java.lang.String,java.lang.String>getExternalProperties()Returns the currently set external properties.LoggergetLogger()Returns the currently set logger.@Nullable java.nio.file.PathgetModuleCacheDir()Returns the directory where `package:` modules are cached.java.util.List<ModuleKeyFactory>getModuleKeyFactories()Returns the currently set module key factories.@Nullable java.lang.StringgetOutputFormat()Returns the currently set output format, if any.java.util.List<ResourceReader>getResourceReaders()Returns the currently set resource readers.@Nullable java.nio.file.PathgetRootDir()Returns the currently set root directory, if set.@Nullable SecurityManagergetSecurityManager()Returns the currently set security manager.@Nullable StackFrameTransformergetStackFrameTransformer()Returns the currently set stack frame transformer.@Nullable java.time.DurationgetTimeout()Returns the currently set evaluation timeout.static EvaluatorBuilderpreconfigured()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()System.getProperties()EvaluatorBuildersetAllowedModules(java.util.Collection<java.util.regex.Pattern> patterns)Sets the set of URI patterns to be allowed when importing modules.EvaluatorBuildersetAllowedResources(java.util.Collection<java.util.regex.Pattern> patterns)Sets the set of URI patterns to be allowed when reading resources.EvaluatorBuildersetEnvironmentVariables(java.util.Map<java.lang.String,java.lang.String> envVars)Removes any existing environment variables, then adds the given environment variables.EvaluatorBuildersetExternalProperties(java.util.Map<java.lang.String,java.lang.String> properties)Removes any existing external properties, then adds the given properties.EvaluatorBuildersetLogger(Logger logger)Sets the given logger, replacing any previously set logger.EvaluatorBuildersetModuleCacheDir(@Nullable java.nio.file.Path moduleCacheDir)Sets the directory where `package:` modules are cached.EvaluatorBuildersetModuleKeyFactories(java.util.Collection<ModuleKeyFactory> factories)Removes any existing module key factories, then adds the given factories.EvaluatorBuildersetOutputFormat(@Nullable java.lang.String outputFormat)Sets the desired output format, if any.EvaluatorBuildersetOutputFormat(@Nullable OutputFormat outputFormat)Sets the desired output format, if any.EvaluatorBuildersetProjectDependencies(DeclaredDependencies dependencies)Sets the project dependencies for the evaluator.EvaluatorBuildersetResourceReaders(java.util.Collection<ResourceReader> readers)EvaluatorBuildersetRootDir(@Nullable java.nio.file.Path rootDir)Sets the root directory, which restricts access to file-based modules and resources located under this directory.EvaluatorBuildersetSecurityManager(@Nullable SecurityManager manager)Sets the given security manager, replacing any previously set security manager.EvaluatorBuildersetStackFrameTransformer(StackFrameTransformer stackFrameTransformer)Sets the given stack frame transformer, replacing any previously set transformer.EvaluatorBuildersetTimeout(@Nullable java.time.Duration timeout)Sets an evaluation timeout to be enforced by theEvaluator'sevaluatemethods.static EvaluatorBuilderunconfigured()Creates a builder that is unconfigured.EvaluatorBuilderunsetSecurityManager()
-
-
-
Method Detail
-
preconfigured
public static EvaluatorBuilder 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()System.getProperties()
-
unconfigured
public static EvaluatorBuilder unconfigured()
Creates a builder that is unconfigured. At a minimum, a security manager will need to be set before building an instance.
-
setStackFrameTransformer
public EvaluatorBuilder setStackFrameTransformer(StackFrameTransformer stackFrameTransformer)
Sets the given stack frame transformer, replacing any previously set transformer.
-
getStackFrameTransformer
public @Nullable StackFrameTransformer getStackFrameTransformer()
Returns the currently set stack frame transformer.
-
setSecurityManager
public EvaluatorBuilder setSecurityManager(@Nullable SecurityManager manager)
Sets the given security manager, replacing any previously set security manager.
-
unsetSecurityManager
public EvaluatorBuilder unsetSecurityManager()
-
getSecurityManager
public @Nullable SecurityManager getSecurityManager()
Returns the currently set security manager.
-
setAllowedModules
public EvaluatorBuilder setAllowedModules(java.util.Collection<java.util.regex.Pattern> patterns)
Sets the set of URI patterns to be allowed when importing modules.- Throws:
java.lang.IllegalStateException- ifsetSecurityManager(SecurityManager)was also called.
-
getAllowedModules
public java.util.List<java.util.regex.Pattern> getAllowedModules()
Returns the set of patterns to be allowed when importing modules.
-
setAllowedResources
public EvaluatorBuilder setAllowedResources(java.util.Collection<java.util.regex.Pattern> patterns)
Sets the set of URI patterns to be allowed when reading resources.- Throws:
java.lang.IllegalStateException- ifsetSecurityManager(SecurityManager)was also called.
-
getAllowedResources
public java.util.List<java.util.regex.Pattern> getAllowedResources()
Returns the set of patterns to be allowed when reading resources.
-
setRootDir
public EvaluatorBuilder setRootDir(@Nullable java.nio.file.Path rootDir)
Sets the root directory, which restricts access to file-based modules and resources located under this directory.
-
getRootDir
public @Nullable java.nio.file.Path getRootDir()
Returns the currently set root directory, if set.
-
setLogger
public EvaluatorBuilder setLogger(Logger logger)
Sets the given logger, replacing any previously set logger.
-
getLogger
public Logger getLogger()
Returns the currently set logger.
-
addModuleKeyFactory
public EvaluatorBuilder addModuleKeyFactory(ModuleKeyFactory factory)
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
public EvaluatorBuilder addModuleKeyFactories(java.util.Collection<ModuleKeyFactory> factories)
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
public EvaluatorBuilder setModuleKeyFactories(java.util.Collection<ModuleKeyFactory> factories)
Removes any existing module key factories, then adds the given factories.
-
getModuleKeyFactories
public java.util.List<ModuleKeyFactory> getModuleKeyFactories()
Returns the currently set module key factories.
-
addResourceReader
public EvaluatorBuilder addResourceReader(ResourceReader reader)
-
addResourceReaders
public EvaluatorBuilder addResourceReaders(java.util.Collection<ResourceReader> readers)
-
setResourceReaders
public EvaluatorBuilder setResourceReaders(java.util.Collection<ResourceReader> readers)
-
getResourceReaders
public java.util.List<ResourceReader> getResourceReaders()
Returns the currently set resource readers.
-
addEnvironmentVariable
public EvaluatorBuilder addEnvironmentVariable(java.lang.String name, java.lang.String value)
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
public EvaluatorBuilder addEnvironmentVariables(java.util.Map<java.lang.String,java.lang.String> envVars)
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
public EvaluatorBuilder setEnvironmentVariables(java.util.Map<java.lang.String,java.lang.String> envVars)
Removes any existing environment variables, then adds the given environment variables.
-
getEnvironmentVariables
public java.util.Map<java.lang.String,java.lang.String> getEnvironmentVariables()
Returns the currently set environment variables.
-
addExternalProperty
public EvaluatorBuilder addExternalProperty(java.lang.String name, java.lang.String value)
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
public EvaluatorBuilder addExternalProperties(java.util.Map<java.lang.String,java.lang.String> properties)
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
public EvaluatorBuilder setExternalProperties(java.util.Map<java.lang.String,java.lang.String> properties)
Removes any existing external properties, then adds the given properties.
-
getExternalProperties
public java.util.Map<java.lang.String,java.lang.String> getExternalProperties()
Returns the currently set external properties.
-
setTimeout
public EvaluatorBuilder setTimeout(@Nullable java.time.Duration timeout)
Sets an evaluation timeout to be enforced by theEvaluator'sevaluatemethods.
-
getTimeout
public @Nullable java.time.Duration getTimeout()
Returns the currently set evaluation timeout.
-
setModuleCacheDir
public EvaluatorBuilder setModuleCacheDir(@Nullable java.nio.file.Path moduleCacheDir)
Sets the directory where `package:` modules are cached.If
null, the module cache is disabled.
-
getModuleCacheDir
public @Nullable java.nio.file.Path getModuleCacheDir()
Returns the directory where `package:` modules are cached. Ifnull, the module cache is disabled.
-
setOutputFormat
public EvaluatorBuilder setOutputFormat(@Nullable java.lang.String outputFormat)
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
public EvaluatorBuilder setOutputFormat(@Nullable OutputFormat outputFormat)
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
public @Nullable java.lang.String getOutputFormat()
Returns the currently set output format, if any.
-
setProjectDependencies
public EvaluatorBuilder setProjectDependencies(DeclaredDependencies dependencies)
Sets the project dependencies for the evaluator.
-
applyFromProject
public EvaluatorBuilder applyFromProject(Project project)
Given a project, sets its dependencies, and also applies any evaluator settings if set.- Throws:
java.lang.IllegalStateException- ifsetSecurityManager(SecurityManager)was also called.
-
build
public Evaluator build()
-
-