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 08:40: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>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~b.nossing@finan.nl">Bas
Nossing</a>
    </h4>
         <br/>
    <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>asd</p>

<p>&lt;target name="generate"&gt;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;ivy:info/&gt;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;ivy:resolve/&gt;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;ivy:report todir="$</p>
<div class="error"><span class="error">Unknown macro: {bin.archive.dir}</span>
</div>
<p>/META-INF" outputpattern="application.xml" graph="false" xslfile="ivy-report-appxml.xsl"/&gt;<br/>
&lt;/target&gt;</p>

<p>asd</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>asd</p>

<p>asd</p>
    </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/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