Search in sources :

Example 1 with GenerateProtoTask

use of org.curioswitch.gradle.protobuf.tasks.GenerateProtoTask in project curiostack by curioswitch.

the class ProtobufPlugin method configureSourceSet.

private static SourceSetTasks configureSourceSet(String sourceSetName, Project project, ProtobufExtension extension) {
    NamedDomainObjectProvider<SourceDirectorySet> sources = extension.getSources().register(sourceSetName);
    Configuration protobufConfiguration = project.getConfigurations().create(SourceSetUtils.getConfigName(sourceSetName, "protobuf"), c -> {
        c.setVisible(false);
        c.setTransitive(true);
        c.setExtendsFrom(ImmutableList.of());
    });
    TaskProvider<ExtractProtosTask> extract = project.getTasks().register("extract" + SourceSetUtils.getTaskSuffix(sourceSetName) + "Proto", ExtractProtosTask.class, t -> {
        t.getFiles().from(protobufConfiguration);
        t.setDestDir(project.file("build/extracted-protos/" + sourceSetName));
    });
    TaskProvider<ExtractProtosTask> extractInclude = project.getTasks().register("extractInclude" + SourceSetUtils.getTaskSuffix(sourceSetName) + "Proto", ExtractProtosTask.class, t -> t.setDestDir(project.file("build/extracted-include-protos/" + sourceSetName)));
    TaskProvider<GenerateProtoTask> generateProto = project.getTasks().register("generate" + SourceSetUtils.getTaskSuffix(sourceSetName) + "Proto", GenerateProtoTask.class, sourceSetName, extension);
    // To ensure languages are added in order, we have to make sure this is hooked up eagerly.
    var languages = project.getObjects().listProperty(LanguageSettings.class).empty();
    extension.getLanguages().all(languages::add);
    generateProto.configure(t -> {
        t.dependsOn(extract, extractInclude);
        t.getSources().source(sources.get()).srcDir(extract.get().getDestDir());
        t.include(extractInclude.get().getDestDir());
        t.setLanguages(languages);
    });
    return ImmutableSourceSetTasks.builder().extractProtos(extract).extractIncludeProtos(extractInclude).generateProto(generateProto).build();
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) ExtractProtosTask(org.curioswitch.gradle.protobuf.tasks.ExtractProtosTask) LanguageSettings(org.curioswitch.gradle.protobuf.ProtobufExtension.LanguageSettings) GenerateProtoTask(org.curioswitch.gradle.protobuf.tasks.GenerateProtoTask)

Aggregations

LanguageSettings (org.curioswitch.gradle.protobuf.ProtobufExtension.LanguageSettings)1 ExtractProtosTask (org.curioswitch.gradle.protobuf.tasks.ExtractProtosTask)1 GenerateProtoTask (org.curioswitch.gradle.protobuf.tasks.GenerateProtoTask)1 Configuration (org.gradle.api.artifacts.Configuration)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1