Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethankhall/309854ac3cc6d11e30f9 to your computer and use it in GitHub Desktop.
Save ethankhall/309854ac3cc6d11e30f9 to your computer and use it in GitHub Desktop.
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