Exit Full View

Feather2 / documentation / Configuration.md

Configuration

Feather is somewhat customisable. All the options are stored in FeatherConfiguration. Read the API documentation for full details.

The Sandbox

The Sandbox is the most important. It limits which external classes your scripts have access to. If you want to live dangerously, use PermissiveSandbox :

val myConfig = FeatherConfiguration().apply {
    sandbox = PermissiveSandbox
}

But usually AllowListSandbox is a better choice. Let's assume you want to give access to all classes in the package com.example.safe, as well as the class com.example.extra.Goodies :

val config = FeatherConfiguration().apply {
    sandbox = AllowListSandbox().apply {
        allowedPackageNames.add( "com.example.safe" )
        allowedClassNames.add( "com.example.extra.Goodies" )
    }
}

Implied Imports

When writing Java code, there are many classes which don't need to be explicitly imported, such as String. For Java, this is all the classes in package java.lang.

To cut down on cruft, feather lets you choose which classes/packages should be implicitly imported.

The default imports some classes from java.lang, and all classes from java.util. But we can add others. e.g.

val config = FeatherConfiguration().apply {
    impliedImportPackages.add( "com.example.safe" )
    impliedImportClasses["Goodies"] = "com.example.extra.Goodies"
}

So, now we can use the class Goodies, as well as all the classes in com.example.safe without any import statements in our feather script.

Note that impliedImportClasses is a map, not a list. This gives us the option to alias the class. For example :

val config = FeatherConfiguration().apply {
    impliedImportClasses["AWTColor"] = "java.awt.Color"
}

Inside our scripts, the type Color wouldn't be recognised, but AWTColor would.

Implied Import Static Methods

This is a bit more advanced, but very useful.

Consider the feather code :

println( "Hello World" )

Have you wondered how that works? Where/what is println? It is a Java static method (or what Feather would call a Function) in the class uk.co.nickthecoder.feather.runtime.FeatherPrint.

It is accessible without specifying the class name, because FeatherConfiguration.impliedImportStaticClasses contains "uk.co.nickthecoder.feather.runtime.FeatherPrint".

Let's assume we want to use the Goodies class in the same way :

val config = FeatherConfiguration().apply {
    impliedImportStaticClasses.add( "com.example.extra.Goodies" )
}

Next Steps

Look at the API documentation for FeatherConfiguration, as there are other options not mentioned here.

Look at the source code for package uk.co.nickthecoder.feather.runtime. It may give you ideas for your own functions, which will make feather script writing easier.

Now it is time to Compile some scripts.

Back to Contents