<html>
<head>
<base href="https://cwiki.apache.org/confluence">
<link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=IVY&forWysiwyg=true"
type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://cwiki.apache.org/confluence/display/IVY/Generate+EAR+deployment+descriptor+from+Ivy+resolution+report">Generate
EAR deployment descriptor from Ivy resolution report</a></h2>
<h4>Page <b>edited</b> by <a href="https://cwiki.apache.org/confluence/display/~b.nossing@finan.nl">Bas
Nossing</a>
</h4>
<br/>
<h4>Changes (9)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" >Using the wealth of information available
from the resolution report in combination with the ANT ivy:report task I came up with the
following solution: <br> <br></td></tr>
<tr><td class="diff-changed-lines" >The following is just an example
ANT target that <span class="diff-added-words"style="background-color: #dfd;">demonstrates
the use of the actual XSLT:</span> <br></td></tr>
<tr><td class="diff-unchanged" > <br> <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" ></target> <br>{code}
<br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">>
<br></td></tr>
<tr><td class="diff-unchanged" > <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">asd
<br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">The
part that does all the actual work is the following XSLT definition: <br></td></tr>
<tr><td class="diff-unchanged" > <br> <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" ></xsl:stylesheet> <br>{code}
<br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">asd
<br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">It
is very much based on the default HTML report generator supplied together with the Ivy distribution.
By no means is this a solution that will work in any situation. But with minor tweaks it should
be applicable to most EAR projects that define their module dependencies through Ivy. <br>*
When run from within the EAR project context it does the following: <br>* Iterate over
the top-level dependencies of the EAR project (its application modules/wars/ejb-jars) <br></td></tr>
<tr><td class="diff-unchanged" > <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">Construct
an appropriate module element in the resulting deployment descriptor based on the published
artifact type definition in the dependencies ivy.xml <br></td></tr>
<tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">asd</span>
<span class="diff-added-words"style="background-color: #dfd;"> </span> <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>In its current form the XSLT does not take into account the following: <br>*
EAR deployment descriptor version and resulting document structure <br>* WAR module
<context-root> element is being omitted <br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<p>An old <a href="http://www.fnogol.de/archives/2006/08/21/generate-applicationxml-from-ivyxml-for-packaging-an-ear/"
class="external-link" rel="nofollow">blogpost </a>prompted me to try and devise a
more current and elegant method of compiling the EAR deployment descriptor (application.xml)
from an Ivy resolution report. Being a novice to XSLT use and syntax I chose to base this
transformation/translation on the default Ivy report templates provided with the latest distribution
(at the time of this writing that is Ivy version 2.2.0).</p>
<p>Using the wealth of information available from the resolution report in combination
with the ANT ivy:report task I came up with the following solution:</p>
<p>The following is just an example ANT target that demonstrates the use of the actual
XSLT:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><target name=<span class="code-quote">"generate"</span>
depends=<span class="code-quote">"resolve"</span>>
<ivy:report todir=<span class="code-quote">"${bin.archive.dir}/META-INF"</span>
outputpattern=<span class="code-quote">"application.xml"</span> graph=<span
class="code-quote">"<span class="code-keyword">false</span>"</span> xslfile=<span
class="code-quote">"ivy-report-appxml.xsl"</span>/>
</target>
</pre>
</div></div>
<p>The part that does all the actual work is the following XSLT definition:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><?xml version=<span class="code-quote">"1.0"</span>
encoding=<span class="code-quote">"UTF-8"</span>?>
<xsl:stylesheet version=<span class="code-quote">"1.0"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//java.sun.com/xml/ns/j2ee"</span>
xmlns:xsl=<span class="code-quote">"http://www.w3.org/1999/XSL/Transform"</span>>
</span>
<xsl:output indent=<span class="code-quote">"yes"</span>/>
<xsl:variable name=<span class="code-quote">"modules"</span> select=<span
class="code-quote">"/ivy-report/dependencies/module"</span>/>
<xsl:variable name=<span class="code-quote">"revisions"</span> select=<span
class="code-quote">"$modules/revision"</span>/>
<xsl:variable name=<span class="code-quote">"artifacts"</span> select=<span
class="code-quote">"$revisions/artifacts/artifact"</span>/>
<xsl:template name=<span class="code-quote">"calling"</span>>
<xsl:param name=<span class="code-quote">"org"</span>/>
<xsl:param name=<span class="code-quote">"mod"</span>/>
<xsl:param name=<span class="code-quote">"rev"</span>/>
<xsl:<span class="code-keyword">if</span> test=<span class="code-quote">"count($modules/revision/caller[(@organisation=$org
and @name=$mod) and @callerrev=$rev]) > 0"</span>>
<module>
<xsl:<span class="code-keyword">for</span>-each
select=<span class="code-quote">"$modules/revision/caller[(@organisation=$org and @name=$mod)
and @callerrev=$rev]"</span>>
<xsl:call-template name=<span class="code-quote">"called"</span>>
<xsl:with-param name=<span class="code-quote">"revision"</span>
select=<span class="code-quote">".."</span>/>
</xsl:call-template>
</xsl:<span class="code-keyword">for</span>-each>
</module>
</xsl:<span class="code-keyword">if</span>>
</xsl:template>
<xsl:template name=<span class="code-quote">"called"</span>>
<xsl:param name=<span class="code-quote">"revision"</span>/>
<xsl:param name=<span class="code-quote">"module"</span>
select=<span class="code-quote">"$revision/../@name"</span>/>
<xsl:param name=<span class="code-quote">"rev"</span> select=<span
class="code-quote">"$revision/@name"</span>/>
<xsl:param name=<span class="code-quote">"type"</span> select=<span
class="code-quote">"$revision/artifacts/artifact/@type"</span>/>
<xsl:param name=<span class="code-quote">"ext"</span> select=<span
class="code-quote">"$revision/artifacts/artifact/@ext"</span>/>
<xsl:param name=<span class="code-quote">"artifact"</span>
select=<span class="code-quote">"concat($module, '-', $rev, '.', $ext)"</span>/>
<xsl:<span class="code-keyword">if</span> test=<span class="code-quote">"$type='ejb'"</span>>
<ejb>
<xsl:value-of select=<span class="code-quote">"$artifact"</span>/>
</ejb>
</xsl:<span class="code-keyword">if</span>>
<xsl:<span class="code-keyword">if</span> test=<span class="code-quote">"$type='war'"</span>>
<web>
<web-uri>
<xsl:value-of select=<span class="code-quote">"$artifact"</span>/>
</web-uri>
</web>
</xsl:<span class="code-keyword">if</span>>
<xsl:<span class="code-keyword">if</span> test=<span class="code-quote">"$type='jar'"</span>>
<web>
<module>
<java><xsl:value-of select=<span
class="code-quote">"$artifact"</span>/></java>
</module>
</web>
</xsl:<span class="code-keyword">if</span>>
</xsl:template>
<xsl:template match=<span class="code-quote">"/ivy-report"</span>>
<application version=<span class="code-quote">"1.4"</span>
xmlns=<span class="code-quote">"http:<span class="code-comment">//java.sun.com/xml/ns/j2ee"</span>
xmlns:xsi=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
xsi:schemaLocation=<span class="code-quote">"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"</span>>
</span> <display-name><xsl:value-of select=<span
class="code-quote">"info/@module"</span>/></display-name>
<xsl:call-template name=<span class="code-quote">"calling"</span>>
<xsl:with-param name=<span class="code-quote">"org"</span>
select=<span class="code-quote">"info/@organisation"</span>/>
<xsl:with-param name=<span class="code-quote">"mod"</span>
select=<span class="code-quote">"info/@module"</span>/>
<xsl:with-param name=<span class="code-quote">"rev"</span>
select=<span class="code-quote">"info/@revision"</span>/>
</xsl:call-template>
</application>
</xsl:template>
</xsl:stylesheet>
</pre>
</div></div>
<p>It is very much based on the default HTML report generator supplied together with
the Ivy distribution. By no means is this a solution that will work in any situation. But
with minor tweaks it should be applicable to most EAR projects that define their module dependencies
through Ivy.</p>
<ul>
<li>When run from within the EAR project context it does the following:</li>
<li>Iterate over the top-level dependencies of the EAR project (its application modules/wars/ejb-jars)</li>
</ul>
<p>Construct an appropriate module element in the resulting deployment descriptor based
on the published artifact type definition in the dependencies ivy.xml</p>
<p>In its current form the XSLT does not take into account the following:</p>
<ul>
<li>EAR deployment descriptor version and resulting document structure</li>
<li>WAR module <context-root> element is being omitted</li>
</ul>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;">
<a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
</div>
<a href="https://cwiki.apache.org/confluence/display/IVY/Generate+EAR+deployment+descriptor+from+Ivy+resolution+report">View
Online</a>
|
<a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27844165&revisedVersion=3&originalVersion=2">View
Changes</a>
|
<a href="https://cwiki.apache.org/confluence/display/IVY/Generate+EAR+deployment+descriptor+from+Ivy+resolution+report?showComments=true&showCommentArea=true#addcomment">Add
Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
|