type
Env
src
abstract const class Env : Obj
Env defines a pluggable class used to boot and manage a Fantom runtime environment. Use cur
to access the current Env instance.
constructors
make |
Subclasses are constructed from a parent environment. |
---|
methods
addShutdownHook |
Add a function to be called on VM shutdown. |
---|---|
arch |
Microprocessor architecture name as one of the following constants |
args |
Get the command line arguments used to run the fan process as an immutable List of strings. |
compileScript |
Compile a script file into a pod and return the first public type declared in the script file. |
compileScriptToJs |
Compile a script file into a pod and return the JS source code of resulting pod. |
config |
Lookup a configuration property for given pod/key pair. |
cur |
Get the current runtime environment |
diagnostics |
Poll for a platform dependent map of diagnostics name/value pairs for the current state of the VM. |
err |
Standard error output stream. |
exit |
Terminate the current virtual machine. |
findAllFiles |
Find all the files in the environment which match a relative path such as "etc/foo/config.props". |
findAllPodNames |
Return the list of pod names for all the pods currently installed in this environemnt. |
findFile |
Find a file in the environment using a relative path such as "etc/foo/config.props". |
findPodFile |
Resolve the pod file for the given pod name. |
gc |
Run the garbage collector. |
homeDir |
Get the home directory of Fantom installation. |
host |
Get the local host name of the machine running the virtual machine process. |
idHash |
Return the default hash code of |
in |
Standard input stream. |
index |
Lookup all the matching values for a pod indexed key. |
indexKeys |
Get listing of all keys mapped by indexed props. |
indexPodNames |
Return list of all pod names that define the given key. |
javaVersion |
Get the Java VM Version as a single integer (8, 9, etc.). |
locale |
Lookup a localized property for the specified pod/key pair. |
mainMethod |
Get the main method which was used to run this Fantom VM. |
os |
Operating system name as one of the following constants |
out |
Standard output stream. |
parent |
Get the parent environment or null if this is the bootstrap environment. |
path | |
platform |
Name of the host platform as a string formatted as "<os>-<arch>". |
prompt |
Prompt the user to enter a command line from standard input. |
promptPassword |
Prompt the user to enter a password from standard input with echo disabled. |
props |
Return a merged key/value map of all the prop files found using the following resolution rules |
removeShutdownHook |
Remove a shutdown hook function which was added by |
runtime |
Virtual machine runtime as one of the following constants |
tempDir |
Get the temp directory to use for scratch files. |
user |
Get the user name of the user account used to run the virtual machine process. |
vars |
Get the environment variables as a case insensitive, immutable map of Str name/value pairs. |
workDir |
Get the working directory to use for saving compiled pods and configuration information. |
Slot Details
addShutdownHook
arch
args
compileScript
src
virtual Type compileScript(File f, [Str:Obj]? options := null)
Compile a script file into a pod and return the first public type declared in the script file. If the file has been previously compiled and hasn't changed, then a cached type is returned. If the script contains errors then the first CompilerErr found is thrown. The options available:
- logLevel: the default
LogLevel
to use for logging the compilation process and errors - log: the
CompilerLog
to use for logging the compilation process and errors - logOut: an output stream to capture logging
- force: pass
true
to not use caching, always forces a recompile
compileScriptToJs
src
virtual Str compileScriptToJs(File f, [Str:Obj]? options := null)
Compile a script file into a pod and return the JS source code of resulting pod. If the script contains errors then the first CompilerErr found is thrown. The options available:
- podName: the name of pod created for script
- logLevel: the default
LogLevel
to use for logging the compilation process and errors - log: the
CompilerLog
to use for logging the compilation process and errors - logOut: an output stream to capture logging
config
cur
diagnostics
err
exit
findAllFiles
src
virtual File[] findAllFiles(Uri uri)
Find all the files in the environment which match a relative path such as "etc/foo/config.props". It is possible to have multiple matches if the environment uses a search path model. If the list contains more than one item, then the first file has the highest priority and the last item has the lowest priority. If the URI is not relative then throw ArgErr. Return empty list if the file is not found in environment. Default implementation delegates to parent
.
findAllPodNames
src
virtual Str[] findAllPodNames()
Return the list of pod names for all the pods currently installed in this environemnt. This method is used by Pod.list
and for constructing the type database. Each of these names must be resolvable by findPodFile
. The default implementation routes to findFile
to look in the "lib/fan" directory and assumes a naming convention of "{name}.pod".
findFile
src
virtual File? findFile(Uri uri, Bool checked := true)
Find a file in the environment using a relative path such as "etc/foo/config.props". If the URI is not relative then throw ArgErr. If the file is not found in the environment then throw UnresolvedErr or return null based on checked flag. If findAllFiles
would return multiple matches, then this method should always return the file with the highest priority. Default implementation delegates to parent
.
findPodFile
gc
homeDir
host
idHash
in
index
indexKeys
indexPodNames
javaVersion
locale
src
virtual Str? locale(Pod pod, Str key, Str? def := "pod::key", Locale locale := Locale.cur())
Lookup a localized property for the specified pod/key pair. The following rules are used for resolution:
props(pod, `locale/{locale}.props`)
props(pod, `locale/{lang}.props`)
props(pod, `locale/en.props`)
- Fallback to
pod::key
unlessdef
specified
Where {locale}
is Locale.toStr
and {lang}
is Locale.lang
. The maxAge parameter is set to Duration.maxVal (cached for life of the VM).
Also see Pod.locale
and Localization.
mainMethod
make
os
out
parent
path
platform
prompt
src
virtual Str? prompt(Str msg := "")
Prompt the user to enter a command line from standard input. This method routes to Console.prompt
.
promptPassword
src
virtual Str? promptPassword(Str msg := "")
Prompt the user to enter a password from standard input with echo disabled. This method routes to Console.promptPassword
.
props
src
virtual Str:Str props(Pod pod, Uri uri, Duration maxAge)
Return a merged key/value map of all the prop files found using the following resolution rules:
Env.findAllFiles
: "etc/{pod}/{uri}"- Pods indexed with
sys.envProps
: "/{pod}/uri" Pod.files
: "/{uri}"
The uri must be relative. Note that props such as locale files can be bundled into a pod for deployment and searched by adding an indexed prop with the key "sys.envProps" and the pod name as the value. This feature does not support "config.props".
The files are parsed using InStream.readProps
and merged according to their priority order. If the file is defined as a resource in the pod itself, then it is treated as lowest priority. The first file returned by findAllFiles
is treated as highest priority and overwrites any key-value pairs defined at a lower priority.
The map is cached so that subsequent calls for the same path don't require accessing the file system again. The maxAge
parameter specifies the tolerance accepted before a cache refresh is performed to check if any of the files have been modified.
removeShutdownHook
src
virtual Bool removeShutdownHook(|->Void| hook)
Remove a shutdown hook function which was added by addShutdownHook
. Remove true if hook had been previously added and was unregistered, false otherwise. Default implementation delegates to parent
.
runtime
tempDir
user
vars
Get the environment variables as a case insensitive, immutable map of Str name/value pairs. The environment map is initialized from the following sources from lowest priority to highest priority:
- shell environment variables
- Java system properties (Java VM only obviously)
Default implementation delegates to parent
.