ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Ivy (Apache Ant subproject) > Generate EAR deployment descriptor from Ivy resolution report
Date Tue, 17 Apr 2012 09:43:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=IVY&amp;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 (2)</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" >In its current form the XSLT does
not take into account the following: <br>* EAR deployment descriptor version and resulting
document structure <br></td></tr>
            <tr><td class="diff-changed-lines" >* WAR module <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;context-root&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">context-root</span>
element is being omitted <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">*
JAAS security roles are 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">&lt;target name=<span class="code-quote">"generate"</span>
depends=<span class="code-quote">"resolve"</span>&gt;
    &lt;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-appxml14.xsl"</span>/&gt;
&lt;/target&gt;
</pre>
</div></div>

<p>The part that does all the actual work is the following XSLT definition (<a href="/confluence/download/attachments/27844165/ivy-report-appxml.xsl?version=1&amp;modificationDate=1334655243000">ivy-report-appxml14.xsl</a>
in the above example):</p>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">&lt;?xml version=<span class="code-quote">"1.0"</span>
encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;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>&gt;
</span>
    &lt;xsl:output indent=<span class="code-quote">"yes"</span>/&gt;

    &lt;xsl:variable name=<span class="code-quote">"modules"</span> select=<span
class="code-quote">"/ivy-report/dependencies/module"</span>/&gt;
    &lt;xsl:variable name=<span class="code-quote">"revisions"</span> select=<span
class="code-quote">"$modules/revision"</span>/&gt;
    &lt;xsl:variable name=<span class="code-quote">"artifacts"</span> select=<span
class="code-quote">"$revisions/artifacts/artifact"</span>/&gt;
    
    &lt;xsl:template name=<span class="code-quote">"calling"</span>&gt;
        &lt;xsl:param name=<span class="code-quote">"org"</span>/&gt;
        &lt;xsl:param name=<span class="code-quote">"mod"</span>/&gt;
        &lt;xsl:param name=<span class="code-quote">"rev"</span>/&gt;
        &lt;xsl:<span class="code-keyword">if</span> test=<span class="code-quote">"count($modules/revision/caller[(@organisation=$org
and @name=$mod) and @callerrev=$rev]) &gt; 0"</span>&gt;
            &lt;module&gt;
               &lt;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>&gt;
                 &lt;xsl:call-template name=<span class="code-quote">"called"</span>&gt;
                   &lt;xsl:with-param name=<span class="code-quote">"revision"</span>
select=<span class="code-quote">".."</span>/&gt;
                 &lt;/xsl:call-template&gt;
               &lt;/xsl:<span class="code-keyword">for</span>-each&gt; 
 
            &lt;/module&gt;
        &lt;/xsl:<span class="code-keyword">if</span>&gt;
    &lt;/xsl:template&gt;
    
    &lt;xsl:template name=<span class="code-quote">"called"</span>&gt;
        &lt;xsl:param name=<span class="code-quote">"revision"</span>/&gt;
    
        &lt;xsl:param name=<span class="code-quote">"module"</span>
select=<span class="code-quote">"$revision/../@name"</span>/&gt;
        &lt;xsl:param name=<span class="code-quote">"rev"</span> select=<span
class="code-quote">"$revision/@name"</span>/&gt;
        &lt;xsl:param name=<span class="code-quote">"type"</span> select=<span
class="code-quote">"$revision/artifacts/artifact/@type"</span>/&gt;
        &lt;xsl:param name=<span class="code-quote">"ext"</span> select=<span
class="code-quote">"$revision/artifacts/artifact/@ext"</span>/&gt;
        &lt;xsl:param name=<span class="code-quote">"artifact"</span>
select=<span class="code-quote">"concat($module, '-', $rev, '.', $ext)"</span>/&gt;
        
        &lt;xsl:<span class="code-keyword">if</span> test=<span class="code-quote">"$type='ejb'"</span>&gt;
            &lt;ejb&gt;
                &lt;xsl:value-of select=<span class="code-quote">"$artifact"</span>/&gt;
            &lt;/ejb&gt;
        &lt;/xsl:<span class="code-keyword">if</span>&gt;
        
        &lt;xsl:<span class="code-keyword">if</span> test=<span class="code-quote">"$type='war'"</span>&gt;
            &lt;web&gt;
                &lt;web-uri&gt;
                    &lt;xsl:value-of select=<span class="code-quote">"$artifact"</span>/&gt;
                &lt;/web-uri&gt;
            &lt;/web&gt;
        &lt;/xsl:<span class="code-keyword">if</span>&gt;

        &lt;xsl:<span class="code-keyword">if</span> test=<span class="code-quote">"$type='jar'"</span>&gt;
            &lt;web&gt;
                &lt;module&gt;
                    &lt;java&gt;&lt;xsl:value-of select=<span
class="code-quote">"$artifact"</span>/&gt;&lt;/java&gt;
                &lt;/module&gt;
            &lt;/web&gt;
        &lt;/xsl:<span class="code-keyword">if</span>&gt;
    &lt;/xsl:template&gt;
    
    &lt;xsl:template match=<span class="code-quote">"/ivy-report"</span>&gt;
        &lt;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>&gt;
</span>            &lt;display-name&gt;&lt;xsl:value-of select=<span
class="code-quote">"info/@module"</span>/&gt;&lt;/display-name&gt;
            &lt;xsl:call-template name=<span class="code-quote">"calling"</span>&gt;
                &lt;xsl:with-param name=<span class="code-quote">"org"</span>
select=<span class="code-quote">"info/@organisation"</span>/&gt;
                &lt;xsl:with-param name=<span class="code-quote">"mod"</span>
select=<span class="code-quote">"info/@module"</span>/&gt;
                &lt;xsl:with-param name=<span class="code-quote">"rev"</span>
select=<span class="code-quote">"info/@revision"</span>/&gt;
            &lt;/xsl:call-template&gt;
        &lt;/application&gt;
    &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;
</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>

<p>When run from within the EAR project context it does the following:</p>
<ul>
	<li>Iterate over the top-level dependencies of the EAR project (its application modules/wars/ejb-jars)</li>
	<li>Construct an appropriate module element in the resulting deployment descriptor
based on the published artifact type definition in the dependencies ivy.xml</li>
</ul>



<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>
	<li>JAAS security roles are 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=9&originalVersion=8">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/IVY/Generate+EAR+deployment+descriptor+from+Ivy+resolution+report?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message