use of org.curioswitch.gradle.protobuf.ProtobufExtension.LanguageSettings in project curiostack by curioswitch.
the class GenerateProtoTask method exec.
@TaskAction
public void exec() {
Project project = getProject();
List<LanguageSettings> languages = this.languages.get();
ImmutableList.Builder<String> artifacts = ImmutableList.builder();
if (protocArtifact.isPresent()) {
artifacts.add(protocArtifact.get());
}
for (LanguageSettings language : languages) {
if (language.getPlugin().getArtifact().isPresent()) {
artifacts.add(language.getPlugin().getArtifact().get());
}
}
Map<String, File> downloadedTools = downloadTools(artifacts.build());
File protocPath = protocArtifact.isPresent() ? checkNotNull(downloadedTools.get(protocArtifact.get())) : this.protocPath.get();
ImmutableList.Builder<String> protocCommand = ImmutableList.builder();
protocCommand.add(protocPath.getAbsolutePath());
for (LanguageSettings language : languages) {
String optionsPrefix = optionsPrefix(language.getOptions().getOrElse(ImmutableList.of()));
String outputDir = getLanguageOutputDir(language).getAbsolutePath();
project.delete(outputDir);
project.mkdir(outputDir);
protocCommand.add("--" + language.getName() + "_out=" + optionsPrefix + outputDir);
Executable plugin = language.getPlugin();
if (plugin.isPresent()) {
String pluginPath = Objects.requireNonNullElseGet(plugin.getPath().getOrNull(), () -> downloadedTools.get(plugin.getArtifact().get())).getAbsolutePath();
protocCommand.add("--plugin=protoc-gen-" + language.getName() + "=" + pluginPath);
}
}
Streams.concat(sources.getSrcDirs().stream(), includeDirs.getSrcDirs().stream()).distinct().filter(File::exists).forEach(dir -> protocCommand.add("-I" + dir.getAbsolutePath()));
if (descriptorSetOptions.getEnabled().get()) {
File descriptorSetPath = descriptorSetOptions.getPath().getOrElse(project.file("build/descriptors/" + sourceSetName + ".dsc"));
project.mkdir(descriptorSetPath.getParent());
protocCommand.add("--descriptor_set_out=" + descriptorSetPath.getAbsolutePath());
if (descriptorSetOptions.getIncludeSourceInfo().get()) {
protocCommand.add("--include_source_info");
}
if (descriptorSetOptions.getIncludeImports().get()) {
protocCommand.add("--include_imports");
}
}
// Sort to ensure generated descriptors have a canonical representation
// to avoid triggering unnecessary rebuilds downstream
sources.getFiles().stream().map(File::getAbsolutePath).sorted().forEach(protocCommand::add);
ExternalExecUtil.exec(getProject(), workerExecutor, exec -> {
exec.commandLine(protocCommand.build());
execOverrides.forEach(a -> a.execute(exec));
});
}
Aggregations