Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import org.gradle.platform.*
interface CustomLanguageSourceSet extends LanguageSourceSet {}
interface SampleComponent extends ComponentSpec {}
interface SampleBinary extends BinarySpec {}
class DefaultCustomLanguageSourceSet extends BaseLanguageSourceSet implements CustomLanguageSourceSet {}
class DefaultSampleBinary extends BaseBinarySpec implements SampleBinary {}
class DefaultSampleComponent extends BaseComponentSpec implements SampleComponent {}
class MyTask extends DefaultTask {
def sourceSets = [] as Set
@TaskAction
void printSources() {
println sourceSets
}
}
class MyCustomBinariesPlugin extends RuleSource {
@LanguageType
void declareCustomLanguage(LanguageTypeBuilder<CustomLanguageSourceSet> builder) {
builder.setLanguageName("custom");
builder.defaultImplementation(DefaultCustomLanguageSourceSet)
}
@ComponentType
public void register(ComponentTypeBuilder<SampleComponent> builder) {
builder.defaultImplementation(DefaultSampleComponent.class);
}
@BinaryType
void register(BinaryTypeBuilder<SampleBinary> builder) {
builder.defaultImplementation(DefaultSampleBinary)
}
@BinaryTasks
public void createSourceDistTask(ModelMap<Task> tasks, final SampleBinary spec) {
String postFix = GUtil.toCamelCase(spec.getName());
tasks.create("generate" + spec.getName(), MyTask.class, new Action<MyTask>() {
void execute(MyTask t) {
spec.getSources().each { it
t.sourceSets << it
}
}
});
}
}
apply plugin: MyCustomBinariesPlugin
model {
components {
t(SampleComponent) {
sources {
ss(CustomLanguageSourceSet) {
source {
srcDir 'src/main/foo'
}
}
}
binaries {
bin(SampleBinary) { }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.