Created
January 26, 2016 01:32
-
-
Save ethankhall/309854ac3cc6d11e30f9 to your computer and use it in GitHub Desktop.
This file contains 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
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