Last active
October 21, 2021 00:57
-
-
Save romain-grecourt/daa69708a2ae038b54005dd4b670f29e to your computer and use it in GitHub Desktop.
Helidon Archetype Groovy DSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.helidon.build.archetype.dsl | |
interface ArchetypeScript { | |
/** | |
* Declares an archetype script. | |
* @param body archetype body closure | |
*/ | |
void archetype(@DelegatesTo(Archetype) Closure body) | |
interface ArchetypeClosure { | |
/** | |
* Define the help text. | |
* @param message help message, in markdown format | |
*/ | |
void help(String message) | |
/** | |
* Execute the given script by changing directory. | |
* @param script path of the script to execute | |
*/ | |
void exec(String script) | |
/** | |
* Execute the given script without changing directory. | |
* @param script path of the script to execute | |
*/ | |
void source(String script) | |
/** | |
* Define a step. | |
* @param label label for the step | |
* @param body step body | |
*/ | |
void step(String label, @DelegatesTo(Step) Closure body) | |
/** | |
* Define an input. | |
* @param body input body | |
*/ | |
void input(@DelegatesTo(Input) Closure body) | |
/** | |
* Define an output. | |
* @param body output body | |
*/ | |
void output(@DelegatesTo(Output) Closure body); | |
} | |
/** | |
* Set context values. | |
*/ | |
interface Context { | |
/** | |
* Define a boolean value in the context. | |
* @param path context path | |
* @param value context value | |
*/ | |
void bool(String path, boolean value) | |
/** | |
* Define a text value in the context. | |
* @param path context path | |
* @param value context value | |
*/ | |
void text(String path, String value) | |
/** | |
* Define a list value in the context. | |
* @param path context path | |
* @param value context value | |
*/ | |
void list(String path, String... value) | |
/** | |
* Define an enum value in the context. | |
* @param path context path | |
* @param value context value | |
*/ | |
void enumeration(String path, String value) | |
} | |
/** | |
* Define an archetype script. | |
*/ | |
interface Archetype extends ArchetypeClosure { | |
/** | |
* Set context values. | |
* @param body context body | |
*/ | |
void context(@DelegatesTo(Context) Closure body) | |
} | |
/** | |
* Define a step. | |
*/ | |
interface Step extends ArchetypeClosure { | |
/** | |
* Set the expression guarding this step. | |
* @param expr logical expression | |
*/ | |
void predicate(String expr) | |
} | |
/** | |
* Input body. | |
*/ | |
static interface Input { | |
/** | |
* Define a boolean input. | |
* @param name input name | |
* @param label input label | |
* @param prompt input prompt | |
*/ | |
void bool(String name, String label, String prompt) | |
/** | |
* Define a boolean input. | |
* @param name input name | |
* @param label input label | |
* @param prompt input prompt | |
* @param body nested body | |
*/ | |
void bool(String name, String label, String prompt, @DelegatesTo(ArchetypeClosure) Closure body) | |
/** | |
* Define a text input. | |
* @param name input name | |
* @param label input label | |
* @param prompt input prompt | |
*/ | |
void text(String name, String label, String prompt) | |
/** | |
* Define a text input. | |
* @param name input name | |
* @param label input label | |
* @param prompt input prompt | |
* @param body nested body | |
*/ | |
void text(String name, String label, String prompt, @DelegatesTo(ArchetypeClosure) Closure body) | |
/** | |
* Define a list input. | |
* @param name input name | |
* @param label input label | |
* @param prompt input prompt | |
*/ | |
void list(String name, String label, String prompt) | |
/** | |
* Define a list input. | |
* @param name input name | |
* @param label input label | |
* @param prompt input prompt | |
* @param body nested body | |
*/ | |
void list(String name, String label, String prompt, @DelegatesTo(ListInput) Closure body) | |
/** | |
* Define an enum input. | |
* @param name input name | |
* @param label input label | |
* @param prompt input prompt | |
*/ | |
void enumeration(String name, String label, String prompt) | |
/** | |
* Define an enum input. | |
* @param name input name | |
* @param label input label | |
* @param prompt input prompt | |
* @param body nested body | |
*/ | |
void enumeration(String name, String label, String prompt, @DelegatesTo(EnumerationInput) Closure body) | |
} | |
/** | |
* Multi value input base closure. | |
*/ | |
interface OptionsInput { | |
/** | |
* Define an option. | |
* @param name option name | |
* @param label option label | |
*/ | |
void option(String name, String label) | |
/** | |
* Define an option. | |
* @param name option name | |
* @param label option label | |
* @param body option nested body | |
*/ | |
void option(String name, String label, @DelegatesTo(ArchetypeClosure) Closure body) | |
} | |
/** | |
* List input. | |
*/ | |
interface ListInput extends OptionsInput { | |
} | |
/** | |
* Enum input. | |
*/ | |
interface EnumerationInput extends OptionsInput { | |
} | |
/** | |
* Output body. | |
*/ | |
interface Output { | |
/** | |
* Define a transformation. | |
* @param id transformation id | |
* @param body transformation body | |
*/ | |
void transformation(String id, @DelegatesTo(Transformation) Closure body) | |
/** | |
* Define a set of templates to be rendered. | |
* @param body templates body | |
*/ | |
void templates(@DelegatesTo(Templates) Closure body) | |
/** | |
* Define a set of static files to be copied. | |
* @param body files body | |
*/ | |
void files(@DelegatesTo(Files) Closure body) | |
/** | |
* Define the output model. | |
* @param body model body | |
*/ | |
void model(@DelegatesTo(Model) Closure body) | |
} | |
/** | |
* Transformation closure. | |
*/ | |
interface Transformation { | |
/** | |
* Add a replace rule. | |
* @param regex regular expression to match | |
* @param replacement replacement for the match | |
*/ | |
void replace(String regex, String replacement) | |
} | |
/** | |
* Static files closure. | |
*/ | |
interface Files { | |
/** | |
* Configure transformations to apply on the file paths. | |
* @param transformations transformations | |
*/ | |
void transformations(String... transformations) | |
/** | |
* Set the directory where to scan the files. | |
* @param directory directory | |
*/ | |
void directory(String directory) | |
/** | |
* Set the includes for the files scanning. | |
* @param includes ANT globs. | |
*/ | |
void includes(String... includes) | |
/** | |
* Set the excludes for the files scanning. | |
* @param excludes ANT globs. | |
*/ | |
void excludes(String... excludes) | |
} | |
/** | |
* Templates closure. | |
*/ | |
interface Templates extends Files { | |
/** | |
* Set the template engine to use for rendering the templates. | |
* @param engine engine id | |
*/ | |
void engine(String engine) | |
} | |
/** | |
* Model closure. | |
*/ | |
interface Model { | |
/** | |
* Add a new entry. | |
* @param key entry key | |
* @param value entry value | |
*/ | |
void entry(String key, String value) | |
/** | |
* Add a new entry. | |
* @param key entry key | |
* @param value entry value | |
* @param body entry closure | |
*/ | |
void entry(String key, String value, @DelegatesTo(ModelEntry) Closure body) | |
/** | |
* Add a new list entry. | |
* @param key entry key | |
* @param body list body | |
*/ | |
void list(String key, @DelegatesTo(ModelListEntry) Closure body) | |
/** | |
* Add a new map entry. | |
* @param key entry key | |
* @param body map body | |
*/ | |
void map(String key, @DelegatesTo(ModelMapEntry) Closure body) | |
} | |
/** | |
* List entry closure. | |
*/ | |
interface ModelListEntry extends ModelEntry { | |
/** | |
* Add a new list entry. | |
* @param key entry key | |
* @param value entry value | |
*/ | |
void entry(String key, String value) | |
/** | |
* Add a new list entry. | |
* @param key entry key | |
* @param value entry value | |
* @param body entry closure | |
*/ | |
void entry(String key, String value, @DelegatesTo(ModelEntry) Closure body) | |
/** | |
* Add a new map entry. | |
* @param body map entry closure | |
*/ | |
void map(@DelegatesTo(ModelMapEntry) Closure body) | |
} | |
/** | |
* Map entry closure. | |
*/ | |
interface ModelMapEntry extends ModelEntry { | |
/** | |
* Add a new entry to the map. | |
* @param body entry body | |
*/ | |
void entry(@DelegatesTo(ModelEntry) Closure body) | |
} | |
/** | |
* Model entry closure. | |
*/ | |
interface ModelEntry { | |
/** | |
* Set the expression guarding this entry. | |
* @param expr logical expression | |
*/ | |
void predicate(String expr) | |
/** | |
* Set the merge order. | |
* @param order merge order | |
*/ | |
void order(int order) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ctx = context(scope: scriptScope(null)) | |
contributor(ctx, { | |
delegatesTo(findClass('io.helidon.build.archetype.dsl.ArchetypeScript')) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
archetype { | |
help ''' | |
# Help text | |
## Markdown goes here... | |
''' | |
context { | |
bool 'test.option1', true | |
text 'test.option2', "hello" | |
list 'test.option3', "foo", "bar" | |
enumeration 'test.option4', "bob" | |
} | |
exec 'script.groovy' | |
source 'script.groovy' | |
step 'MyStep', { | |
predicate '${foo} == "bar"' | |
help ''' | |
# Help text | |
## Markdown goes here... | |
''' | |
input { | |
bool 'foo', 'Foo', 'Do you want foo option?' | |
list 'select-item', 'Select an item', 'Please select an item', { | |
option "foo", "Foo", { | |
help ''' | |
# Help text | |
## Markdown goes here... | |
''' | |
exec 'foo.groovy' | |
source 'foo.groovy' | |
step 'Nested foo step', { | |
input { | |
text 'foo-name', 'Foo name', 'Please give a name for Foo' | |
} | |
} | |
input { | |
bool 'foo-option', 'Foo option', 'Do you want foo option?' | |
} | |
} | |
} | |
} | |
} | |
output { | |
transformation 'mustache', { replace '\\.mustache$', '' } | |
transformation 'foo-ext', { replace '\\.foo$', '\\.bar' } | |
templates { | |
engine 'mustache' | |
transformations 'mustache' | |
directory 'files' | |
includes '**/*.mustache' | |
} | |
files { | |
transformations 'foo-ext' | |
directory 'files' | |
excludes '**/*.mustache' | |
} | |
model { | |
entry 'bob', 'alice', { | |
predicate '${bar} == "foo"' | |
} | |
list 'names', { | |
map { | |
entry 'foo', 'bar' | |
entry 'bar', 'foo' | |
} | |
} | |
map 'dependencies', { | |
entry 'groupId', 'com.example' | |
entry 'artifactId', 'my-project' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment