fairyhawk / protostuff

Automatically exported from code.google.com/p/protostuff
Apache License 2.0
0 stars 0 forks source link

Maven plugin to attach generated source directory to the project compile source roots #69

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently, I have to use build-helper plugin to attach generated source 
directory to the project sources. It would be convenient if protostuff plugin 
did it for me automatically.

This is as simple as calling the following method after 'compile' goal 
completion:

    project.addCompileSourceRoot(outputDirectory.getAbsolutePath());

For reference, this is how I have to do it currently:

<properties>
    <protoc.sourceDirectory>${project.basedir}/src/main/proto</protoc.sourceDirectory>
    <protoc.outputDirectory>${project.build.directory}/generated-sources/proto</protoc.outputDirectory>
    <protostuff.outputDirectory>${project.build.directory}/generated-sources/protostuff</protostuff.outputDirectory>
</properties>

...

<plugin>
    <groupId>com.dyuproject.protostuff</groupId>
    <artifactId>protostuff-maven-plugin</artifactId>
    <configuration>
        <protoModules>
            <protoModule>
                <source>${protoc.sourceDirectory}/test.proto</source>
                <outputDir>${protostuff.outputDirectory}</outputDir>
                <output>java_v2protoc_schema</output>
                <encoding>UTF-8</encoding>
                <options>
                    <property>
                        <name>generate_field_map</name>
                    </property>
                </options>
            </protoModule>
        </protoModules>
    </configuration>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>process-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${protostuff.outputDirectory}</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

Original issue reported on code.google.com by sergei.s...@gmail.com on 29 Jun 2011 at 12:50

GoogleCodeExporter commented 8 years ago
Feel free to submit a patch.
Cheers

Original comment by david.yu...@gmail.com on 29 Jun 2011 at 1:49

GoogleCodeExporter commented 8 years ago
I'm not sure how to proceed.
Your procedure certainly works fine.
If you have a patch, it can still be included in the 1.0.1 release (w/c is very 
soon).

Cheers

Original comment by david.yu...@gmail.com on 7 Jul 2011 at 10:23

GoogleCodeExporter commented 8 years ago
Hello David,

Sorry, I did not have much time recently to sit down and work on the plugin. I 
still promise I shall do it (worst case end of next week). Please go ahead with 
the release anyway, this issue is not a blocker.

I suggest that meanwhile you include the example above into the relevant 
section of your wikis. But what would be really nice is to have a proper 
generated Maven site for the whole protostuff suite including the plugin.

Regards,
Sergei

Original comment by sergei.s...@gmail.com on 7 Jul 2011 at 10:36

GoogleCodeExporter commented 8 years ago
Cool.  I've to iron out some android compat still ... you'll have some more 
time :-)

I'm not too particular about the maven stuff.  If you have any ideas, feel free 
to have a go at it as well.

Thanks

Original comment by david.yu...@gmail.com on 7 Jul 2011 at 5:19

GoogleCodeExporter commented 8 years ago
As our project is making more and more use of protobuf (and protostuff is 
considered for some aspects of it), I have a determination (unfortunately not 
always backed by free time) to provide a 1st class Maven support for 
protobuf/protostuff stack, and make sure it fits properly into the Maven way of 
doing things.

Curiously, our project is stuck with Ant+Ivy cruft for a build system at the 
moment, but I hope that my effort will help with our eventual migration to 
Maven.

Original comment by sergei.s...@gmail.com on 7 Jul 2011 at 5:40

GoogleCodeExporter commented 8 years ago
Hello David,

Please find the patch attached.

Regards,
Sergei

Original comment by sergei.s...@gmail.com on 10 Jul 2011 at 11:48

Attachments:

GoogleCodeExporter commented 8 years ago
A note about the patch: it will not update compile source roots if a property 
file is supplied in a plugin config. This is because property file parsing 
happens inside the compiler, and the results are not available to the Maven 
plugin.

To be honest, I'd prefer to have a simplified the plugin config, so that it 
does not have any individual module configuration or a property file reference. 
Instead, I'd let it have:
- a single proto source directory (defaults to 'src/main/proto')
- two optional lists for source include/exclude patterns (defaults to include 
'**/*proto')
- a single output directory (defaults to target/generated-sources/protostuff)
- a list of directories for proto imports (empty by default)
- output, encoding and options, applicable to all proto sources matched by 
include/exclude patterns

The plugin would then transform the above into protostuff compiler inputs. The 
plugin could also optionally scan the dependencies (including the reactor) for 
proto imports and add them to the imports list for protostuff compiler (this is 
how the unofficial protoc maven plugin works).

If you need to compile proto sources using two schemas, you just define two 
separate executions, which is pretty much standard maven way of doing things.

What do you think of the above?

Original comment by sergei.s...@gmail.com on 11 Jul 2011 at 1:33

GoogleCodeExporter commented 8 years ago
Hi Sergei,

Thanks for the patch.
About your 2nd post, feel free to have a go at it (you now have write access).
We could still keep the current behavior (rename the goal to something else, 
maybe "compile-modules") and reserve the "compile" goal for the new behavior.

Original comment by david.yu...@gmail.com on 13 Jul 2011 at 5:39

GoogleCodeExporter commented 8 years ago
Would you mind if I do a 1.0.1 release now before your proposed changes?
I was supposed to do it 3 days ago but my internet was down for like 3 days.

Cheers

Original comment by david.yu...@gmail.com on 13 Jul 2011 at 12:24

GoogleCodeExporter commented 8 years ago
Hello David,

You may still check in the attached patch ahead of 1.0.1 release. It must be 
fully backwards-compatible. All other proposed changes will require some 
refactoring and development effort and will definitely not make it into 1.0.2.

Thanks,
Sergei

Original comment by sergei.s...@gmail.com on 13 Jul 2011 at 12:53

GoogleCodeExporter commented 8 years ago
Cool.  I've just applied your patch with some minor modifications to make 
adding to compile source root optional (its still enabled by default though).

Cheers

Original comment by david.yu...@gmail.com on 13 Jul 2011 at 3:31