Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A colleague and I came up with the answer by looking through the <code>&lt;zip&gt;</code> and <code>&lt;concat&gt;</code> source. There are really two answers:</p> <ol> <li><code>&lt;concat&gt;</code>'s implementation of the <code>ResourceCollection</code> interface is odd, but we understand why.</li> <li>There's a way around that.</li> </ol> <p>For #1, while <code>&lt;concat&gt;</code> is a <code>ResourceCollection</code> (like <code>FileSet</code>), under the hood it returns as the name of single <code>Resource</code> it contains a hard-coded value:</p> <pre><code>"concat (" + String.valueOf(c) + ")"; </code></pre> <p>Look familiar?</p> <p>The name of resources is normally ignored--except by <code>&lt;zip&gt;</code> and its related tasks, which uses the resource name as the <code>ZipEntry</code> name. Since <code>&lt;concat&gt;</code> returns the odd-looking name, that's what we get in the zip file.</p> <p>I haven't quite figured out why I get multiple entries, but it doesn't matter: the observation leads to a convoluted solution.</p> <p>Since I know the name of the <code>ZipEntry</code> I want to create, I can use a <code>&lt;mapper&gt;</code> to give the <code>&lt;concat&gt;</code> resource a name. Here's what I came up with in all its glory:</p> <pre><code>&lt;zip destfile="target/distribution.zip"&gt; &lt;fileset dir="."&gt; &lt;exclude name="target/**" /&gt; &lt;exclude name="CHANGES.txt" /&gt; &lt;/fileset&gt; &lt;mappedresources&gt; &lt;concat&gt; &lt;fileset file="CHANGES.txt" /&gt; &lt;filterchain&gt; &lt;expandproperties /&gt; &lt;/filterchain&gt; &lt;/concat&gt; &lt;mergemapper to="CHANGES.txt" /&gt; &lt;/mappedresources&gt; &lt;/zip&gt; </code></pre> <p>As my colleague says "In Ant every problem can be solved using a mapper."</p> <p>This only works for Ant 1.8+ because <code>&lt;mappedresources&gt;</code> was added in that release.</p> <p>I'm going to post some comments to the Ant mailing list and suggest a couple of enhancements:</p> <ol> <li>Allow a resource name to be specified as an attribute on <code>&lt;concat&gt;</code> when it's being used as a <code>ResourceCollection</code>.</li> <li>Throw an exception (and don't create a synthetic value) if <code>getName()</code> is called without having a value specified.</li> <li>Finally, though not directly related, I do wish <code>&lt;expandproperties&gt;</code> could take a <code>&lt;propertyset&gt;</code> so I can control which properties get substituted.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload