From bef1c703ef4f0930d17fc743dd208f19644a968b Mon Sep 17 00:00:00 2001 From: Alexander Torstling Date: Thu, 17 Dec 2015 13:28:31 +0100 Subject: [PATCH 1/2] support for including source info in descriptor set --- .../protobuf/maven/AbstractProtocMojo.java | 16 +++++++++++++- .../com/google/protobuf/maven/Protoc.java | 21 +++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java b/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java index 112b4308..b2afb515 100644 --- a/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java +++ b/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java @@ -319,6 +319,18 @@ abstract class AbstractProtocMojo extends AbstractMojo { defaultValue = "false" ) protected boolean includeDependenciesInDescriptorSet; + + /** + * If {@code true} and {@code writeDescriptorSet} has been set, do not strip SourceCodeInfo + * from the FileDescriptorProto. This results in vastly larger descriptors that include information + * about the original location of each decl in the source file as well as surrounding comments. + * @since 0.3.1 + */ + @Parameter( + required = false, + defaultValue = "false" + ) + protected boolean includeSourceInfoInDescriptorSet; /** * Specifies one of more custom protoc plugins, written in Java @@ -629,7 +641,9 @@ protected void addProtocBuilderParameters(final Protoc.Builder protocBuilder) th final File descriptorSetFile = new File(getDescriptorSetOutputDirectory(), descriptorSetFileName); getLog().info("Will write descriptor set:"); getLog().info(" " + descriptorSetFile.getAbsolutePath()); - protocBuilder.withDescriptorSetFile(descriptorSetFile, includeDependenciesInDescriptorSet); + protocBuilder.withDescriptorSetFile(descriptorSetFile, + includeDependenciesInDescriptorSet, + includeSourceInfoInDescriptorSet); } } diff --git a/src/main/java/com/google/protobuf/maven/Protoc.java b/src/main/java/com/google/protobuf/maven/Protoc.java index 9b6a9df0..e5a0b774 100644 --- a/src/main/java/com/google/protobuf/maven/Protoc.java +++ b/src/main/java/com/google/protobuf/maven/Protoc.java @@ -86,6 +86,8 @@ final class Protoc { private final boolean includeImportsInDescriptorSet; + private final boolean includeSourceInfoInDescriptorSet; + /** * A buffer to consume standard output from the {@code protoc} executable. */ @@ -98,8 +100,7 @@ final class Protoc { /** * Constructs a new instance. This should only be used by the {@link Builder}. - * - * @param executable path to the {@code protoc} executable. + * @param executable path to the {@code protoc} executable. * @param protoPath a set of directories in which to search for definition imports. * @param protoFiles a set of protobuf definitions to process. * @param javaOutputDirectory a directory into which Java source files will be generated. @@ -108,8 +109,9 @@ final class Protoc { * @param pythonOutputDirectory a directory into which Python source files will be generated. * @param customOutputDirectory a directory into which a custom protoc plugin will generate files. * @param descriptorSetFile The directory into which a descriptor set will be generated; - * if {@code null}, no descriptor set will be written +* if {@code null}, no descriptor set will be written * @param includeImportsInDescriptorSet If {@code true}, dependencies will be included in the descriptor set. + * @param includeSourceInfoInDescriptorSet * @param plugins a set of java protoc plugins. * @param pluginDirectory location of protoc plugins to be added to system path. * @param nativePluginId a unique id of a native plugin. @@ -127,6 +129,7 @@ private Protoc( final File customOutputDirectory, final File descriptorSetFile, final boolean includeImportsInDescriptorSet, + final boolean includeSourceInfoInDescriptorSet, final ImmutableSet plugins, final File pluginDirectory, final String nativePluginId, @@ -142,6 +145,7 @@ private Protoc( this.customOutputDirectory = customOutputDirectory; this.descriptorSetFile = descriptorSetFile; this.includeImportsInDescriptorSet = includeImportsInDescriptorSet; + this.includeSourceInfoInDescriptorSet = includeSourceInfoInDescriptorSet; this.plugins = plugins; this.pluginDirectory = pluginDirectory; this.nativePluginId = nativePluginId; @@ -221,6 +225,9 @@ public ImmutableList buildProtocCommand() { if (includeImportsInDescriptorSet) { command.add("--include_imports"); } + if (includeSourceInfoInDescriptorSet) { + command.add("--include_source_info"); + } } return ImmutableList.copyOf(command); } @@ -365,6 +372,8 @@ static final class Builder { private File descriptorSetFile; private boolean includeImportsInDescriptorSet; + + private boolean includeSourceInfoInDescriptorSet; /** * Constructs a new builder. @@ -521,11 +530,14 @@ public void setNativePluginParameter(final String nativePluginParameter) { this.nativePluginParameter = nativePluginParameter; } - public Builder withDescriptorSetFile(final File descriptorSetFile, final boolean includeImports) { + public Builder withDescriptorSetFile(final File descriptorSetFile, + final boolean includeImports, + final boolean includeSourceInfoInDescriptorSet) { checkNotNull(descriptorSetFile, "descriptorSetFile"); checkArgument(descriptorSetFile.getParentFile().isDirectory()); this.descriptorSetFile = descriptorSetFile; this.includeImportsInDescriptorSet = includeImports; + this.includeSourceInfoInDescriptorSet = includeSourceInfoInDescriptorSet; return this; } @@ -622,6 +634,7 @@ public Protoc build() { customOutputDirectory, descriptorSetFile, includeImportsInDescriptorSet, + includeSourceInfoInDescriptorSet, ImmutableSet.copyOf(plugins), pluginDirectory, nativePluginId, From 8131de4f5dd51ce20af165fdde4dd3588453ebdb Mon Sep 17 00:00:00 2001 From: Alexander Torstling Date: Thu, 17 Dec 2015 15:18:25 +0100 Subject: [PATCH 2/2] review changes --- .../java/com/google/protobuf/maven/AbstractProtocMojo.java | 2 +- src/main/java/com/google/protobuf/maven/Protoc.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java b/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java index b2afb515..e4b4c84c 100644 --- a/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java +++ b/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java @@ -324,7 +324,7 @@ abstract class AbstractProtocMojo extends AbstractMojo { * If {@code true} and {@code writeDescriptorSet} has been set, do not strip SourceCodeInfo * from the FileDescriptorProto. This results in vastly larger descriptors that include information * about the original location of each decl in the source file as well as surrounding comments. - * @since 0.3.1 + * @since 0.4.4 */ @Parameter( required = false, diff --git a/src/main/java/com/google/protobuf/maven/Protoc.java b/src/main/java/com/google/protobuf/maven/Protoc.java index e5a0b774..45f3e0aa 100644 --- a/src/main/java/com/google/protobuf/maven/Protoc.java +++ b/src/main/java/com/google/protobuf/maven/Protoc.java @@ -111,7 +111,8 @@ final class Protoc { * @param descriptorSetFile The directory into which a descriptor set will be generated; * if {@code null}, no descriptor set will be written * @param includeImportsInDescriptorSet If {@code true}, dependencies will be included in the descriptor set. - * @param includeSourceInfoInDescriptorSet + * @param includeSourceInfoInDescriptorSet If {@code true}, source code information will be included + * in the descriptor set. * @param plugins a set of java protoc plugins. * @param pluginDirectory location of protoc plugins to be added to system path. * @param nativePluginId a unique id of a native plugin.