Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(421)

Issue 912042: Add code generator plugin helpers

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 11 months ago by t.broyer
Modified:
11 years, 7 months ago
Reviewers:
kenton, Scott Blum
Base URL:
http://protobuf.googlecode.com/svn/trunk/
Visibility:
Public.

Description

In C++, writing a code generator plugin is as easy as implementing CodeGenerator and passing an instance to google::protobuf::compiler::PluginMain; it shouldn't be any harder in Java (or Python BTW). This patch adds a JavaHelpers class which is just a port of google/protobuf/compiler/java/java_helpers.{h,cc} with a few additional helper methods; and the abstract Plugin class. To implement a protoc plugin in Java, simply write an implementation of Plugin, then create a main() method like: public static void main(String[] args) { new MyPlugin().run(args); } The main difference with C++ is that the Java code needs to be launched from a shell/batch script (the patch includes a sample batch file for Windows), and expects that the name of the script be passed as the first command-line argument. The code currently lacks JavaDoc and unit tests but I'm providing it here for an early review.

Patch Set 1 #

Patch Set 2 : Fixes getDefaultValue for enum fields, and parseGeneratorParameter for empty parts #

Total comments: 40

Patch Set 3 : Factored out a CodeGenerator interface, Plugin now has only static methods #

Total comments: 25

Patch Set 4 : javadoc, unit tests, Context#getParsedFiles, streaming to stdout #

Total comments: 21

Patch Set 5 : Few tweaks based on review #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1311 lines, -0 lines) Patch
java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java View 3 4 1 chunk +129 lines, -0 lines 0 comments Download
java/src/main/java/com/google/protobuf/compiler/JavaHelpers.java View 1 2 3 4 1 chunk +475 lines, -0 lines 0 comments Download
java/src/main/java/com/google/protobuf/compiler/Plugin.java View 1 2 3 4 1 chunk +367 lines, -0 lines 0 comments Download
java/src/test/java/com/google/protobuf/compiler/PluginContextTest.java View 1 chunk +148 lines, -0 lines 0 comments Download
java/src/test/java/com/google/protobuf/compiler/PluginTest.java View 1 chunk +190 lines, -0 lines 0 comments Download
src/google/protobuf/compiler/plugin.proto View 1 2 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 16
t.broyer
13 years, 11 months ago (2010-04-14 10:15:30 UTC) #1
t.broyer
Fixes getDefaultValue for enum fields, and parseGeneratorParameter for empty parts
13 years, 11 months ago (2010-04-26 15:43:02 UTC) #2
kenton
Thanks for doing this! This probably should not be part of libprotobuf.jar, since most people ...
13 years, 11 months ago (2010-04-26 18:45:44 UTC) #3
t.broyer
Thanks for your review. I've only responded to some comments. I'll update my code and ...
13 years, 11 months ago (2010-04-26 22:29:05 UTC) #4
t.broyer
If you don't mind, I'd like to polish/fill-in JavaDoc in a "last call" patchset. http://codereview.appspot.com/912042/diff/6001/7002 ...
13 years, 10 months ago (2010-05-17 14:30:09 UTC) #5
t.broyer
Factored out a CodeGenerator interface, Plugin now has only static methods
13 years, 10 months ago (2010-05-17 16:27:24 UTC) #6
t.broyer
Next patchset will add unit test too. http://codereview.appspot.com/912042/diff/22001/23001 File java/protoc-gen-plugin.bat.tmpl (right): http://codereview.appspot.com/912042/diff/22001/23001#newcode11 java/protoc-gen-plugin.bat.tmpl:11: Oops! just ...
13 years, 10 months ago (2010-05-17 16:32:25 UTC) #7
kenton
I've CC'd Gregory Kick, the Maven expert. Greg, this patch is contributing a library for ...
13 years, 10 months ago (2010-05-21 02:40:35 UTC) #8
t.broyer
The OutputDirectory->Context move looks good, except for the "ListParsedFiles" method return type (see comments in ...
13 years, 10 months ago (2010-05-22 23:30:46 UTC) #9
t.broyer
http://codereview.appspot.com/912042/diff/22001/23003 File java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java (right): http://codereview.appspot.com/912042/diff/22001/23003#newcode9 java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java:9: public interface OutputDirectory { On 2010/05/22 23:30:46, t.broyer wrote: ...
13 years, 10 months ago (2010-05-24 09:43:03 UTC) #10
t.broyer
javadoc, unit tests, Context#getParsedFiles, streaming to stdout
13 years, 10 months ago (2010-05-25 15:38:16 UTC) #11
t.broyer
The 4th patch: - adds javadoc - adds unit tests - renames OutputDirectory to Context ...
13 years, 10 months ago (2010-05-25 16:17:43 UTC) #12
kenton
Looking pretty good. http://codereview.appspot.com/912042/diff/40001/41001 File java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java (right): http://codereview.appspot.com/912042/diff/40001/41001#newcode35 java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java:35: * The generator's {@link CodeGenerator#generate(FileDescriptor, String, ...
13 years, 10 months ago (2010-05-26 23:21:07 UTC) #13
t.broyer
http://codereview.appspot.com/912042/diff/40001/41001 File java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java (right): http://codereview.appspot.com/912042/diff/40001/41001#newcode35 java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java:35: * The generator's {@link CodeGenerator#generate(FileDescriptor, String, Context)} On 2010/05/26 ...
13 years, 10 months ago (2010-05-28 14:32:51 UTC) #14
t.broyer
Few tweaks based on review
13 years, 10 months ago (2010-05-28 14:45:38 UTC) #15
Scott Blum
11 years, 7 months ago (2012-08-07 20:51:08 UTC) #16
Did this change ever get merged in?  It turns out this is pretty much 
exactly what I need for writing a Java-based plugin.

On Wednesday, April 14, 2010 6:15:30 AM UTC-4, Thomas Broyer wrote:
>
> Reviewers: kenton,
>
> Description:
> In C++, writing a code generator plugin is as easy as implementing
> CodeGenerator and passing an instance to
> google::protobuf::compiler::PluginMain; it shouldn't be any harder in
> Java (or Python BTW).
>
> This patch adds a JavaHelpers class which is just a port of
> google/protobuf/compiler/java/java_helpers.{h,cc} with a few additional
> helper methods; and the abstract Plugin class.
>
> To implement a protoc plugin in Java, simply write an implementation of
> Plugin, then create a main() method like:
>    public static void main(String[] args) {
>      new MyPlugin().run(args);
>    }
>
> The main difference with C++ is that the Java code needs to be launched
> from a shell/batch script (the patch includes a sample batch file for
> Windows), and expects that the name of the script be passed as the first
> command-line argument.
>
> The code currently lacks JavaDoc and unit tests but I'm providing it
> here for an early review.
>
> Please review this at http://codereview.appspot.com/912042/show
>
> Affected files:
>    java/protoc-gen-plugin.bat.tmpl
>    java/src/main/java/com/google/protobuf/compiler/JavaHelpers.java
>    java/src/main/java/com/google/protobuf/compiler/Plugin.java
>    src/google/protobuf/compiler/plugin.proto
>
>
>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b