cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Cayenne Documentation > maven2-cgen
Date Fri, 16 Oct 2009 20:46:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAYDOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAYDOC/maven2-cgen">maven2-cgen</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~andrus">Andrus
Adamchik</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <p><tt>cgen</tt> is an Maven 2 mojo that generates and maintains
DataObjects source files based on Cayenne DataMap.  By default, it is bound to the <tt>generate-sources</tt>
phase. If "makePairs" is set to "true" (default), this task will generate a pair of classes
(superclass/subclass) for each ObjEntity in the DataMap. Superclasses should not be changed
manually, since they are always overwritten. Subclasses are never overwritten and may be later
customized by the user. If "makePairs" is set to "false", a single class will be generated
for each ObjEntity.</p>

<p>By creating custom templates, <tt>cgen</tt> can also be used to generate
other output (such as web pages, reports, specialized code templates) based on DataMap information.</p>

<h3><a name="maven2-cgen-Parameters%28asXMLelements%29"></a>Parameters (as
XML elements)</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Attribute</th>
<th class='confluenceTh'>Description</th>
<th class='confluenceTh'>Required</th>
</tr>
<tr>
<td class='confluenceTd'>map</td>
<td class='confluenceTd'>DataMap XML file to use as a base for class generation.</td>
<td class='confluenceTd'>Yes</td>
</tr>
<tr>
<td class='confluenceTd'>additionalMaps</td>
<td class='confluenceTd'>Path to additional DataMap XML files to use for class generation.</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>destDir</td>
<td class='confluenceTd'>Destination directory for Java classes (ignoring their package
names).</td>
<td class='confluenceTd'>Yes</td>
</tr>
<tr>
<td class='confluenceTd'>overwrite</td>
<td class='confluenceTd'>If set to "true", will overwrite older versions of generated
classes. Ignored unless makepairs is set to "false".</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>makePairs</td>
<td class='confluenceTd'>If set to "true", will generate subclass/superclass pairs,
with all generated code included in superclass (default is "true").</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>template</td>
<td class='confluenceTd'>Location of Velocity template file for Entity class generation.
If omitted, default template is used.</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>superTemplate</td>
<td class='confluenceTd'>Location of Velocity template file for Entity superclass generation.
Ignored unless "makepairs" set to "true". If omitted, default template is used.</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>embeddableTemplate</td>
<td class='confluenceTd'>Location of Velocity template file for Embeddable class generation.
If omitted, default template is used.</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>embeddableSuperTemplate</td>
<td class='confluenceTd'>Location of Velocity template file for Embeddable superclass
generation. Ignored unless "makepairs" set to "true". If omitted, default template is used.</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>superPkg</td>
<td class='confluenceTd'>Java package name of generated superclasses. Ignored unless
"makepairs" set to "true". If omitted, each superclass will be assigned the same package as
subclass. Note that having superclass in a different package would only make sense when "usepkgpath"
is set to "true". Otherwise classes from different packages will end up in the same directory.</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>usePkgPath</td>
<td class='confluenceTd'>If set to "true" (default), a directory tree will be generated
in "destDir" corresponding to the class package structure, if set to "false", classes will
be generated in "destDir" ignoring their package.</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>encoding</td>
<td class='confluenceTd'>Specify generated file encoding if different from the default
on current platform. Target encoding must be supported by the JVM running Ant build. Standard
encodings supported by Java on all platforms are US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE,
UTF-16. See Sun Java Docs for java.nio.charset.Charset for more information.</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>version</td>
<td class='confluenceTd'><em><b>(deprecated)</b>)</em> Specifies
template location and generator behavior. "1.1" is the old behavior, with templates located
in "dotemplates" and "classgen" as the only velocity context attribute. "1.2" is the new behavior,
with templates located in "dotemplates/v1.2" and "objEntity", "entityUtils", "stringUtils",
and "importUtils" in the velocity context. (Default is "1.2")</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>excludeEntities</td>
<td class='confluenceTd'>Entities (expressed as a perl5 regex) to exclude from template
generation. (Default is to include all entities in the DataMap)</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>includeEntities</td>
<td class='confluenceTd'>Entities (expressed as a perl5 regex) to include in template
generation. (Default is to include all entities in the DataMap)</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>outputPattern</td>
<td class='confluenceTd'>Name of file for generated output. (Default is "*.java")</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>mode</td>
<td class='confluenceTd'>Specifies generator iteration target. "entity" performs one
iteration for each selected entity. "datamap" performs one iteration per datamap (This is
always one iteration since cgen currently supports specifying one-and-only-one datamap). (Default
is "entity")</td>
<td class='confluenceTd'>No</td>
</tr>
<tr>
<td class='confluenceTd'>client</td>
<td class='confluenceTd'>Whether we are generating classes for the client tier in a
<a href="/confluence/display/CAYDOC/Remote+Object+Persistence+Guide" title="Remote Object
Persistence Guide">Remote Object Persistence</a> application. Default is "false"</td>
<td class='confluenceTd'>No</td>
</tr>
</tbody></table>

<h3><a name="maven2-cgen-Examples"></a>Examples</h3>

<p>Load the Maven 2 plugin and configure the <tt>cgen</tt> mojo: </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;build&gt;</span>
    <span class="code-tag">&lt;plugins&gt;</span>
        <span class="code-tag">&lt;plugin&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.cayenne.plugins<span
class="code-tag">&lt;/groupId&gt;</span>
      	    <span class="code-tag">&lt;artifactId&gt;</span>maven-cayenne-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
      	    <span class="code-tag">&lt;executions&gt;</span>
                <span class="code-tag">&lt;execution&gt;</span>
      		    <span class="code-tag">&lt;id&gt;</span>cgen<span class="code-tag">&lt;/id&gt;</span>
      		    <span class="code-tag">&lt;configuration&gt;</span>
      			<span class="code-tag"><span class="code-comment">&lt;!-- Configuration
items go in here.  See table, above. --&gt;</span></span>
      		    <span class="code-tag">&lt;/configuration&gt;</span>
      		    <span class="code-tag">&lt;goals&gt;</span>
      			<span class="code-tag">&lt;goal&gt;</span>cgen<span class="code-tag">&lt;/goal&gt;</span>
      		    <span class="code-tag">&lt;/goals&gt;</span>
      		<span class="code-tag">&lt;/execution&gt;</span>
      	    <span class="code-tag">&lt;/executions&gt;</span>
        <span class="code-tag">&lt;/plugin&gt;</span>
    <span class="code-tag">&lt;/plugins&gt;</span>
<span class="code-tag">&lt;/build&gt;</span>
</pre>
</div></div>

<p>Here is an example of using CGen to generate Persistent subclass/superclass pairs
from DataMap located in "main/resources/datamap.map.xml".</p>


<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td>There's an intermitten
problem when using Maven/cgen in Eclipse with m2eclipse plugin that requires placing &lt;configuration&gt;..&lt;/configuration&gt;
at the plugin level, instead of execution level.</td></tr></table></div>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;build&gt;</span>
    <span class="code-tag">&lt;plugins&gt;</span>
        <span class="code-tag">&lt;plugin&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.cayenne.plugins<span
class="code-tag">&lt;/groupId&gt;</span>
      	    <span class="code-tag">&lt;artifactId&gt;</span>maven-cayenne-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
      	    <span class="code-tag">&lt;executions&gt;</span>
                <span class="code-tag">&lt;execution&gt;</span>
      		    <span class="code-tag">&lt;id&gt;</span>cgen<span class="code-tag">&lt;/id&gt;</span>
      		    <span class="code-tag">&lt;configuration&gt;</span>
      			<span class="code-tag">&lt;map&gt;</span>${project.build.sourceDirectory}/../resources/datamap.map.xml<span
class="code-tag">&lt;/map&gt;</span>
                        <span class="code-tag">&lt;destDir&gt;</span>${project.build.sourceDirectory}<span
class="code-tag">&lt;/destDir&gt;</span>
      		    <span class="code-tag">&lt;/configuration&gt;</span>
      		    <span class="code-tag">&lt;goals&gt;</span>
      			<span class="code-tag">&lt;goal&gt;</span>cgen<span class="code-tag">&lt;/goal&gt;</span>
      		    <span class="code-tag">&lt;/goals&gt;</span>
      		<span class="code-tag">&lt;/execution&gt;</span>
      	    <span class="code-tag">&lt;/executions&gt;</span>
        <span class="code-tag">&lt;/plugin&gt;</span>
    <span class="code-tag">&lt;/plugins&gt;</span>
<span class="code-tag">&lt;/build&gt;</span>
</pre>
</div></div>

<p>Here is an example of using CGen to generate html pages for all entities starting
with "Artist" in the DataMap:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;build&gt;</span>
    <span class="code-tag">&lt;plugins&gt;</span>
        <span class="code-tag">&lt;plugin&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.cayenne.plugins<span
class="code-tag">&lt;/groupId&gt;</span>
      	    <span class="code-tag">&lt;artifactId&gt;</span>maven-cayenne-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
      	    <span class="code-tag">&lt;executions&gt;</span>
                <span class="code-tag">&lt;execution&gt;</span>
      		    <span class="code-tag">&lt;id&gt;</span>cgen<span class="code-tag">&lt;/id&gt;</span>
      		    <span class="code-tag">&lt;configuration&gt;</span>
      			<span class="code-tag">&lt;map&gt;</span>${project.build.sourceDirectory}/datamap.xml<span
class="code-tag">&lt;/map&gt;</span>
                        <span class="code-tag">&lt;destDir&gt;</span>${project.build.sourceDirectory}/doc/web<span
class="code-tag">&lt;/destDir&gt;</span>
                        <span class="code-tag">&lt;makePairs&gt;</span>false<span
class="code-tag">&lt;/makePairs&gt;</span>
                        <span class="code-tag">&lt;usePkgPath&gt;</span>false<span
class="code-tag">&lt;/usePkgPath&gt;</span>
                        <span class="code-tag">&lt;template&gt;</span>EntityReport.vm<span
class="code-tag">&lt;/template&gt;</span>
                        <span class="code-tag">&lt;includeEntities&gt;</span>Artist*<span
class="code-tag">&lt;/includeEntities&gt;</span>
                        <span class="code-tag">&lt;outputPattern&gt;</span>*Report.html<span
class="code-tag">&lt;/outputPattern&gt;</span>
      		    <span class="code-tag">&lt;/configuration&gt;</span>
      		    <span class="code-tag">&lt;goals&gt;</span>
      			<span class="code-tag">&lt;goal&gt;</span>cgen<span class="code-tag">&lt;/goal&gt;</span>
      		    <span class="code-tag">&lt;/goals&gt;</span>
      		<span class="code-tag">&lt;/execution&gt;</span>
      	    <span class="code-tag">&lt;/executions&gt;</span>
        <span class="code-tag">&lt;/plugin&gt;</span>
    <span class="code-tag">&lt;/plugins&gt;</span>
<span class="code-tag">&lt;/build&gt;</span>
</pre>
</div></div>
     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAYDOC/maven2-cgen">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=28629&revisedVersion=13&originalVersion=12">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAYDOC/maven2-cgen?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message