@Default
public void applyDefault(@Path(“components”) ModelMap<NativeLibrarySpec> components) {
components.named("cpp", new Action<NativeLibrarySpec>() {
public void execute(NativeLibrarySpec cppComponent) {
// do something if a component named cpp has been defined
}
});
}
And as soon as I sent this it occurred to me that you want it to work when the component is not defined. So, this modification does that:
apply plugin: 'cpp'
apply plugin: Rules
model {
components {
cppFoo(NativeLibrarySpec)
}
}
class Rules extends RuleSource {
@Defaults
public void applyDefault(@Path('components') ModelMap<NativeLibrarySpec> components) {
println "Running defaults"
components.all(new Action<NativeLibrarySpec>() {
public void execute(NativeLibrarySpec cppComponent) {
if ('cpp'.equals(cppComponent.getName()))
println "Running against $cppComponent"
}
});
}
}
Note that the component is now named cppFoo
And if you wanted an even more slimmed down variant you can use the new @Each annotation either with the NativeLibrarySpec or going to plain ComponentSpec I think.
apply plugin: 'cpp'
apply plugin: Rules
model {
components {
cpp(NativeLibrarySpec)
}
}
class Rules extends RuleSource {
@Defaults
public void applyDefault(@Each NativeLibrarySpec component) {
if ('cpp'.equals(component.getName()))
println "Running against $component"
}
}