Hi all,
we have a maven plugin which generates java code, and we would like to
unit-test it. One obvious test for such a plugin is to let it generate some
code, compile that code, and unit-test the generated code.
For this, the following steps need to be executed:
1) compile the plugin mojo
2) compile the test case which starts the plugin mojo in order to generate
code
3) execute the test case which starts the plugin mojo in order to generate
code
4) compile the generated code
5) compile the test cases which test the generated code
6) execute the test cases which test the generated code
1), 5) and 6) are achieved automatically in the life cycle phases compile,
test-compile and test. 2) and 3) can be achieved by adding extra executions
[1] to the surefire and compile plugin.
Our problem is how to achieve 4): the problem is that the generated code
must be in the compile source path of the compile plugin in order to be
compiled.
The best solution would be IMHO to generate the code in the target
directory and then add the path as compile source root to the currently
executing maven project, but in order to do this, the currently executing
maven project needs to be accessed in some test case, and I have no idea
how this could be done.
The best working solution I have till now is to generate the test class in
the src/test/java direcrory (so 4) is also executed automatically in the
lifecycle phase test-compile) and put a svn:ignore on the generated class
so that it is not checked in, but I consider that a bad hack.
Any ideas how to avoid generating to src/test/java ?
Thanks in advance,
Thomas
[1] pom snippet for 2) and 3):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<!--
compile the test case which starts the plugin mojo in order to
generate code
-->
<execution>
<id>compileGenerationTest</id>
<phase>generate-test-sources</phase>
<configuration>
<testIncludes>
<include>**/TestCreateSource.java</include>
</testIncludes>
</configuration>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/generated/**/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<!--
execute the test case which starts the plugin mojo in order
to generate code
-->
<id>generateTestCode</id>
<phase>process-test-sources</phase>
<configuration>
<includes>
<include>**/TestCreateSource.class</include>
</includes>
<excludes>
</excludes>
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]