Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Merge pull request #39 from atorstling/include_source_info
Browse files Browse the repository at this point in the history
support for including source info in descriptor set
  • Loading branch information
sergei-ivanov committed Dec 18, 2015
2 parents 122dbd0 + 8131de4 commit 485cafd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
23 changes: 19 additions & 4 deletions src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ abstract class AbstractProtocMojo extends AbstractMojo {
)
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.4.4
*/
@Parameter(
required = false,
defaultValue = "false"
)
protected boolean includeSourceInfoInDescriptorSet;

/**
* Specifies one of more custom protoc plugins, written in Java
* and available as Maven artifacts. An executable plugin will be created
Expand Down Expand Up @@ -507,9 +519,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
if (exitStatus != 0) {
getLog().error("PROTOC FAILED: " + protoc.getError());
for( File pf : protoFiles ) {
buildContext.removeMessages( pf );
buildContext.addMessage( pf, 0, 0, protoc.getError(), BuildContext.SEVERITY_ERROR, null);
for (File pf : protoFiles) {
buildContext.removeMessages(pf);
buildContext.addMessage(pf, 0, 0, protoc.getError(), BuildContext.SEVERITY_ERROR, null);
}
throw new MojoFailureException(
"protoc did not exit cleanly. Review output for more information.");
Expand Down Expand Up @@ -629,7 +641,10 @@ 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);
}
}

Expand Down
20 changes: 18 additions & 2 deletions src/main/java/com/google/protobuf/maven/Protoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -108,8 +110,10 @@ 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 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.
Expand All @@ -127,6 +131,7 @@ private Protoc(
final File customOutputDirectory,
final File descriptorSetFile,
final boolean includeImportsInDescriptorSet,
final boolean includeSourceInfoInDescriptorSet,
final ImmutableSet<ProtocPlugin> plugins,
final File pluginDirectory,
final String nativePluginId,
Expand All @@ -142,6 +147,7 @@ private Protoc(
this.customOutputDirectory = customOutputDirectory;
this.descriptorSetFile = descriptorSetFile;
this.includeImportsInDescriptorSet = includeImportsInDescriptorSet;
this.includeSourceInfoInDescriptorSet = includeSourceInfoInDescriptorSet;
this.plugins = plugins;
this.pluginDirectory = pluginDirectory;
this.nativePluginId = nativePluginId;
Expand Down Expand Up @@ -221,6 +227,9 @@ public ImmutableList<String> buildProtocCommand() {
if (includeImportsInDescriptorSet) {
command.add("--include_imports");
}
if (includeSourceInfoInDescriptorSet) {
command.add("--include_source_info");
}
}
return ImmutableList.copyOf(command);
}
Expand Down Expand Up @@ -366,6 +375,8 @@ static final class Builder {

private boolean includeImportsInDescriptorSet;

private boolean includeSourceInfoInDescriptorSet;

/**
* Constructs a new builder.
*
Expand Down Expand Up @@ -521,11 +532,15 @@ 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;
}

Expand Down Expand Up @@ -622,6 +637,7 @@ public Protoc build() {
customOutputDirectory,
descriptorSetFile,
includeImportsInDescriptorSet,
includeSourceInfoInDescriptorSet,
ImmutableSet.copyOf(plugins),
pluginDirectory,
nativePluginId,
Expand Down

0 comments on commit 485cafd

Please sign in to comment.