Last active
December 3, 2015 14:29
-
-
Save eskatos/88cabcd40a12b0dc83a2 to your computer and use it in GitHub Desktop.
Initialize @Unmanaged property on @Managed type
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 "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