Add better support for generated sources

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115648 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
epugh committed 2004-07-04 16:20:28 +00:00
1 parent 3f9b967188
commit 5bf7cc3091
4 files changed
+126 -46

No files matched your search

+1
View File
@@ -24,3 +24,4 @@
# This accepts two values: 'all' for all the goals,
# and 'plugins' to generate only the plugins' default goals.
maven.eclipse.goals = plugins
maven.gen.src=${maven.build.dir}/generated-sources
@@ -27,6 +27,15 @@
trim="true">
<classpath>
<!-- Add any generated source directories as seperate src directories -->
<u:available file="${maven.gen.src}">
<u:file var="genSrcRootDir" name="${maven.gen.src}"/>
<j:forEach var="genSrcDir" items="${genSrcRootDir.listFiles()}">
<maven:makeRelativePath var="srcDir" basedir="${basedir}" path="${genSrcDir}"/>
<classpathentry kind="src" path="${srcDir}"/>
</j:forEach>
</u:available>
<j:if test="${sourcesPresent}">
<maven:makeRelativePath var="srcDir" basedir="${basedir}" path="${pom.build.sourceDirectory}"/>
<j:set var="excluding" value=""/>
+73 -44
View File
@@ -20,7 +20,7 @@
xmlns:u="jelly:util"
xmlns:x="jelly:xml">
<goal name="testPlugin" prereqs="test-init,test-eclipse,test-natures,test-builders,test-natures-and-builders">
<goal name="testPlugin" prereqs="test-init,test-eclipse,test-natures,test-builders,test-natures-and-builders,test-classpath-has-generated-source">
</goal>
<goal name="test-init">
@@ -38,57 +38,86 @@
</goal>
<goal name="test-natures">
<delete file="${dotProject}" failonerror="false"/>
<j:set var="maven.eclipse.projectnatures" value="n1,a.b.c.n2"/>
<attainGoal name="eclipse:generate-project"/>
<goal name="test-natures">
<delete file="${dotProject}" failonerror="false"/>
<j:set var="maven.eclipse.projectnatures" value="n1,a.b.c.n2"/>
<attainGoal name="eclipse:generate-project"/>
<assert:assertFileExists file="${dotProject}" />
<assert:assertFileExists file="${dotProject}" />
<u:file var="projectFile" name="${dotProject}"/>
<x:parse var="projectDoc" xml="${projectFile.toURL()}" />
<x:set var="natures" select="$projectDoc/projectDescription/natures/nature"/>
<assert:assertEquals expected="n1" value="${natures[1].text}" msg="n1 is not the second nature"/>
<assert:assertEquals expected="a.b.c.n2" value="${natures[2].text}" msg="a.b.c.n2 is not the third nature"/>
</goal>
<u:file var="projectFile" name="${dotProject}"/>
<x:parse var="projectDoc" xml="${projectFile.toURL()}" />
<x:set var="natures" select="$projectDoc/projectDescription/natures/nature"/>
<assert:assertEquals expected="n1" value="${natures[1].text}" msg="n1 is not the second nature"/>
<assert:assertEquals expected="a.b.c.n2" value="${natures[2].text}" msg="a.b.c.n2 is not the third nature"/>
</goal>
<goal name="test-builders">
<j:set var="maven.eclipse.buildcommands" value="c1,c2,c3"/>
<delete file="${dotProject}" failonerror="false"/>
<attainGoal name="eclipse:generate-project"/>
<goal name="test-builders">
<j:set var="maven.eclipse.buildcommands" value="c1,c2,c3"/>
<delete file="${dotProject}" failonerror="false"/>
<attainGoal name="eclipse:generate-project"/>
<assert:assertFileExists file="${dotProject}" />
<u:file var="projectFile" name="${dotProject}"/>
<x:parse var="projectDoc" xml="${projectFile.toURL()}" />
<x:set var="builders" select="$projectDoc/projectDescription/buildSpec/buildCommand/name"/>
<assert:assertFileExists file="${dotProject}" />
<u:file var="projectFile" name="${dotProject}"/>
<x:parse var="projectDoc" xml="${projectFile.toURL()}" />
<x:set var="builders" select="$projectDoc/projectDescription/buildSpec/buildCommand/name"/>
<assert:assertEquals expected="c1" value="${builders[1].text}" msg="c1 is not the second build command name"/>
<assert:assertEquals expected="c2" value="${builders[2].text}" msg="c2 is not the third build command name"/>
<assert:assertEquals expected="c3" value="${builders[3].text}" msg="c3 is not the fourth build command name"/>
</goal>
<assert:assertEquals expected="c1" value="${builders[1].text}" msg="c1 is not the second build command name"/>
<assert:assertEquals expected="c2" value="${builders[2].text}" msg="c2 is not the third build command name"/>
<assert:assertEquals expected="c3" value="${builders[3].text}" msg="c3 is not the fourth build command name"/>
</goal>
<goal name="test-natures-and-builders">
<delete file="${dotProject}" failonerror="false"/>
<j:set var="maven.eclipse.projectnatures" value="n7,n9,n11"/>
<j:set var="maven.eclipse.buildcommands" value="c11,c21,c31"/>
<attainGoal name="eclipse:generate-project"/>
<goal name="test-natures-and-builders">
<delete file="${dotProject}" failonerror="false"/>
<j:set var="maven.eclipse.projectnatures" value="n7,n9,n11"/>
<j:set var="maven.eclipse.buildcommands" value="c11,c21,c31"/>
<attainGoal name="eclipse:generate-project"/>
<assert:assertFileExists file="${dotProject}" />
<u:file var="projectFile" name="${dotProject}"/>
<x:parse var="projectDoc" xml="${projectFile.toURL()}" />
<x:set var="natures" select="$projectDoc/projectDescription/natures/nature"/>
<x:set var="builders" select="$projectDoc/projectDescription/buildSpec/buildCommand/name"/>
<assert:assertFileExists file="${dotProject}" />
<u:file var="projectFile" name="${dotProject}"/>
<x:parse var="projectDoc" xml="${projectFile.toURL()}" />
<x:set var="natures" select="$projectDoc/projectDescription/natures/nature"/>
<x:set var="builders" select="$projectDoc/projectDescription/buildSpec/buildCommand/name"/>
<!-- check natures -->
<assert:assertEquals expected="n7" value="${natures[1].text}" msg="n7 is not the second nature"/>
<assert:assertEquals expected="n9" value="${natures[2].text}" msg="n9 is not the second nature"/>
<assert:assertEquals expected="n11" value="${natures[3].text}" msg="n11 is not the second nature"/>
<!-- check natures -->
<assert:assertEquals expected="n7" value="${natures[1].text}" msg="n7 is not the second nature"/>
<assert:assertEquals expected="n9" value="${natures[2].text}" msg="n9 is not the second nature"/>
<assert:assertEquals expected="n11" value="${natures[3].text}" msg="n11 is not the second nature"/>
<!-- check builders -->
<assert:assertEquals expected="c11" value="${builders[1].text}" msg="c11 is not the second build command name"/>
<assert:assertEquals expected="c21" value="${builders[2].text}" msg="c21 is not the second build command name"/>
<assert:assertEquals expected="c31" value="${builders[3].text}" msg="c31 is not the second build command name"/>
</goal>
<goal name="test-classpath-has-generated-source">
<delete file="${dotProject}" failonerror="false"/>
<delete file="${dotClasspath}" failonerror="false"/>
<mkdir dir="${maven.gen.src}/gensrc1"/>
<mkdir dir="${maven.gen.src}/gensrc2"/>
<attainGoal name="eclipse"/>
<assert:assertFileExists file="${dotProject}" />
<assert:assertFileExists file="${dotClasspath}" />
<u:file var="classpathFile" name="${dotClasspath}"/>
<x:parse var="classpathDoc" xml="${classpathFile.toURL()}" />
<!-- FIXME. This should filter where kind="src" -->
<x:set var="count" select="count($classpathDoc/classpath/classpathentry)"/>
<assert:assertEquals expected="5" value="${count.intValue().toString()}"/>
</goal>
<goal name="test1">
<u:file var="dude" name="${maven.build.dir}"/>
<echo>Dude ${dude}</echo>
<echo>Dude Parent ${dude.parent}</echo>
<echo>Dude Parent ${dude.files}</echo>
<j:forEach var="file" items="${dude.listFiles()}">
<echo>file ${file}</echo>
</j:forEach>
</goal>
<!-- check builders -->
<assert:assertEquals expected="c11" value="${builders[1].text}" msg="c11 is not the second build command name"/>
<assert:assertEquals expected="c21" value="${builders[2].text}" msg="c21 is not the second build command name"/>
<assert:assertEquals expected="c31" value="${builders[3].text}" msg="c31 is not the second build command name"/>
</goal>
</project>
+43 -2
View File
@@ -81,7 +81,7 @@
the classpath, like <code>src/conf</code>.
</td>
</tr>
<tr>
<tr>
<td>maven.eclipse.buildcommands</td>
<td>Yes</td>
<td>
@@ -89,7 +89,7 @@
to include in the project description file.
</td>
</tr>
<tr>
<tr>
<td>maven.eclipse.projectnatures</td>
<td>Yes</td>
<td>
@@ -98,6 +98,16 @@
will be added after the java nature.
</td>
</tr>
<tr>
<td>maven.gen.src</td>
<td>Yes (default=${maven.build.dir}/generated-sources)</td>
<td>
The directory that generated source code is placed. Maven will select
any directories under this as source code. This prevents the generated
source from being removed whenever Eclipse does a clean build, and allows
the generated code to be clearly in the build directory.
</td>
</tr>
</table>
<p>
Note that you will need to defined a <code>MAVEN_REPO</code> Java
@@ -132,5 +142,36 @@
in the eclipse classpath then you can set <code>eclipse.dependency=false</code>
</p>
</section>
<section name="Generated Source Code integration w/ Eclipse">
<p>
When Eclipse is not generating source code for you there is a conflict between
Maven generating the source code and then Eclipse treating it as compiled code.
Typically when generating code using Maven the code ends up in the target/classes
directory. This is fine as long as Maven is doing the build. However, if Eclipse
is then setup to do the build, when Eclipse performs a clean build all the generated
code in target/classes will be removed.
</p>
<p>
The alternatives typically are to place the generated code in the /src/java directory
and allow Maven and Eclipse to treat it the same. However, this leads to a tendency
to check generated code into source control, which typically is not appropriate for
generated code. Alternatively, it can be placed in some sort of /src/generated or
target/generated directory. In Maven2, generated code lives in target/generated-sources,
in a manner similiar to generated xdoc's live in target/generated-xdocs. Within the
target/generated-sources would be each type of generated code.
</p>
<p>
For example, if you used the XDoclet Plugin for Maven to generate Hibernate mapping files,
they would be placed in /target/generated-sources/xdoclet/. While, if you used the
Hibernate Plugin for Maven to generate the SQL scripts for generating a database then that
would be placed in /target/generated-sources/schema/.
<br/>
Settings in project.properties:
<source>
maven.xdoclet.hibernatedoclet.destDir=${maven.build.dir}/generated-sources/xdoclet
maven.hibernate.output.dir=${maven.build.dir}/generated-sources/schema
</source>
</p>
</section>
</body>
</document>