maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jens Teglhus Møller <djar...@gmail.com>
Subject Re: Post processing generated sources
Date Tue, 22 Mar 2016 07:35:33 GMT
I think most plugins that generate source code add the target folders as
source folders themselves.

My current problem is to compile and run the rewrite code as part of the
generate-sources phase. What I have right now is the following antrun
invocation:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<dependencies>
<dependency><!-- compilation through ant failed, google revealed this
solution -->
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<id>pre-process-generated-classes</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<failOnError>true</failOnError>
<target>
<mkdir dir="target/rewrite-generated-code-classes" />
<javac destdir="target/rewrite-generated-code-classes"
classpathref="maven.test.classpath">
<src path="src/rewrite-generated-code/java/" /><!-- here is the source we
are actually compiling -->
<src path="src/main/java/" /><!-- RewriteGeneratedClasses references
classes in here -->
<src path="target/generated-sources/jsonschema2pojo"/><!--
RewriteGeneratedClasses references classes in here -->
<include name="RewriteGeneratedClasses.java"/><!-- make sure we only
compile the rewrite classed -->
</javac>
<java failonerror="true" classname="RewriteGeneratedClasses"
classpath="target/rewrite-generated-code-classes"
classpathref="maven.test.classpath"/>
</target>
</configuration>
</execution>
</executions>
</plugin>

So I gave src/rewrite-generated-code/java/RewriteGeneratedClasses.java
which I compile and execute through antrun. It reads the generated code
in target/generated-sources/jsonschema2pojo massages it a big and writes it
back to the same file.

It actually works fine, but I'm a bit unsure if it is just too complex, I
will probably not understand it myself in a week and the rest of the
dev-team will hunt me down with pitchforks if they have to maintain it one
day.

Best regards Jens


On Mon, Mar 21, 2016 at 12:50 PM, Jeff MAURY <jeffmaury@gmail.com> wrote:

> You can generate in any folder (under target) but you must add this folder
> to the list of source directories so that the maven compiler will process
> them
> This can be done with the maven API if you have your own Maven plugin or
> with the build-helper-plugin
>
> Jeff
> Le 21 mars 2016 12:45, "Jens Teglhus Møller" <djarnis@gmail.com> a écrit :
>
> > Thanks for the short and precise answer.
> >
> > Any guidelines as how to organize the code that performs the processing.
> > Should I create a new directory in src separate from main and test i.e.
> > preprocess and compile it to target/preprocess-classes?
> >
> > Best regards Jens
> >
> > And where should i put my source that does the post processing should i
> > create my own
> >
> > On Mon, Mar 21, 2016 at 12:29 PM, Jeff MAURY <jeffmaury@gmail.com>
> wrote:
> >
> > > Generate-sources
> > >
> > > Jeff
> > > Le 21 mars 2016 12:25, "Jens Teglhus Møller" <djarnis@gmail.com> a
> > écrit :
> > >
> > > > Hi
> > > >
> > > > I'm generating java sources (using jsonschema2pojo and
> > jaxb2-maven-plugin
> > > > plugin) and I would like to do some post processing on the generated
> > > source
> > > > files before compiling them (like have some of the generated files
> > > > implement certain interfaces, perhaps using roaster).
> > > >
> > > > I'm a bit unsure which phase I should do that in and if I do it with
> > > > roaster I will have probably have a few java files that I would need
> to
> > > > compile and run on the source files (I would prefer not to på that
> in a
> > > > separate project). It could probably be done quite easily with
> > > > maven-antrun-plugin but I'm but I'm interested to know if there is a
> > > smart
> > > > way to do it.
> > > >
> > > > Best regards Jens
> > > >
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message