Hi. I have tried a brand new rule base model configuration via Chapter 66. Rule based model configuration. I found that the order of method execution is different from api document. I think @Defaults
’s document is incorrect on order of method execution.
it says
Default rules execute after Model rules (i.e. after the element is created), but before Mutate rules. The first parameter of the rule is the rule subject, which is mutable for the duration of the rule.
But the order of @Default
method is executed before @Model
method.
I wrote.
class SampleRule extends RuleSource {
@Model
void sampleModel(SampleModel sm) {
println "@Model method[from: ${sm.from}, into: ${sm.into}]"
}
@Defaults
void defaultsMethod(SampleModel sm) {
println "@Defaults method[from: ${sm.from}, into: ${sm.into}]"
}
@Mutate
void create(CollectionBuilder<Task> tasks, SampleModel sm) {
println "@Mutate create[from: ${sm.from}, into: ${sm.into}]"
tasks.create('sampleRule') {
group = 'sample-rule'
doLast {
println "from [${sm.from}] into [${sm.into}]"
}
}
}
}
@Managed
public interface SampleModel {
void setFrom(String from);
String getFrom();
void setInto(String into);
String getInto();
}
build script is bellow.
model {
sampleModel {
from = 'here'
into = 'there'
}
}
And the result is bellow.
$ gradle sampleRule
@Defaults method[from: null, into: null]
@Model method[from: null, into: null]
@Mutate create[from: here, into: there]
:sampleRule
from [here] into [there]