Skip to content

Instantly share code, notes, and snippets.

@eskatos
Last active December 3, 2015 14:29
Show Gist options
  • Save eskatos/88cabcd40a12b0dc83a2 to your computer and use it in GitHub Desktop.
Save eskatos/88cabcd40a12b0dc83a2 to your computer and use it in GitHub Desktop.
Initialize @Unmanaged property on @Managed type
def "Initialize @Unmanaged property on @Managed type"() {
given:
buildFile << """
interface SomeThing {
void doSomething(String param)
}
class DefaultSomeThing implements SomeThing {
@Override
public void doSomething(String param) {
println param
}
}
@Managed
interface MyComponentSpec extends ComponentSpec {
@Unmanaged SomeThing getSomeThing()
void setSomeThing(SomeThing some)
}
class MyLanguagePlugin extends RuleSource {
@ComponentType void registerCompType(ComponentTypeBuilder<MyComponentSpec> builder) {}
@Defaults void initalizeStuff(ModelMap<MyComponentSpec> components) {
components.beforeEach { component -> component.someThing = new DefaultSomeThing() }
}
}
apply plugin: MyLanguagePlugin
model {
components {
utils(MyComponentSpec) {
someThing.doSomething "with that"
}
}
}
"""
when:
succeeds "model"
then:
output.contains "with that"
org.gradle.api.reporting.model.ModelReportOutput.from(output).modelNode.components.utils.someThing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment