Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's no particular rules about absolute versus relative with Ant. You should avoid hard-coding absolute paths if possible - to make your build more portable. If you have to use absolute paths for some part of the build, try to construct them - say from the <code>${basedir}</code> of the project - so that changes are easier to make.</p> <p>Two things that may be useful for converting absolute paths to relative paths for use in filesets and the like:</p> <ul> <li>the <a href="http://ant.apache.org/manual/Tasks/property.html" rel="nofollow noreferrer"><code>property</code> task</a> supports an attribute <code>relative=</code> that can be used to convert from an absolute path to relative.</li> <li>the <a href="http://ant.apache.org/manual/Tasks/pathconvert.html" rel="nofollow noreferrer"><code>pathconvert</code> task</a> can be used to do the same, when there are several absolute paths in one property.</li> </ul> <p>Examples:</p> <pre><code>&lt;!-- Absolute paths --&gt; &lt;property name="myprop" value="${basedir}/x" /&gt; &lt;property name="myprop2" value="${basedir}/x:${basedir}/y" /&gt; &lt;!-- Convert single path to relative to basedir --&gt; &lt;property name="myprop_rel" location="${myprop}" relative="yes"/&gt; &lt;!-- Go via path/pathconvert for the property with multiple paths --&gt; &lt;path id="mypath2" path="${myprop2}" /&gt; &lt;pathconvert property="myprop2_rel" refid="mypath2" pathsep=","&gt; &lt;map from="${basedir}/" to="" /&gt; &lt;/pathconvert&gt; &lt;fileset id="my_fileset" dir="." includes="${myprop2_rel}" /&gt; </code></pre> <p><em>In response to a comment:</em> I'm not aware of a simple way to get the longest common prefix directory of a fileset in Ant, but here's a macro wrapping a script task that does what you might call 'shrink wrapping'. You call it with a reference to the 'input' fileset, and the name of the property to set.</p> <pre><code>&lt;macrodef name="common-prefix-dir"&gt; &lt;attribute name="refid" /&gt; &lt;attribute name="outputproperty" /&gt; &lt;sequential&gt; &lt;script language="javascript"&gt;&lt;![CDATA[ srcFiles = project.getReference( "@{refid}" ) .getDirectoryScanner( project ) .getIncludedFiles( ); if ( srcFiles.length &gt; 0 ) { prefix = "" + srcFiles[0]; for ( i = 0; i &lt; srcFiles.length; i++ ) { while ( prefix.length &amp;&amp; srcFiles[i].substr( 0, prefix.length ) != prefix ) { prefix = prefix.substr( 0, prefix.length - 1); } if ( !prefix.length ) { break; } } } else { prefix = ""; } prefix = prefix.substring( 0, prefix.lastIndexOf( '/' ) ); project.setProperty( "@{outputproperty}", prefix ); ]]&gt;&lt;/script&gt; &lt;/sequential&gt; &lt;/macrodef&gt; </code></pre> <p>(This was derived from a <a href="https://stackoverflow.com/questions/1336207/finding-common-prefix-of-array-of-strings/1336357#1336357">php implementation</a>.)</p> <p>You can try it out with something like:</p> <pre><code>&lt;property name="my.dir" location="...your dir here..." /&gt; &lt;fileset id="my.fs" dir="${my.dir}"&gt; &lt;!-- define fileset here --&gt; &lt;/fileset&gt; &lt;echo message="Input fileset is: '${toString:my.fs}'" /&gt; &lt;common-prefix-dir refid="my.fs" outputproperty="prefix" /&gt; &lt;echo message="Longest common prefix is: '${prefix}'" /&gt; </code></pre> <p>The <code>pathconvert</code> task can now be used to create a shrink-wrapped fileset:</p> <pre><code>&lt;pathconvert property="shrink" refid="my.fs" pathsep=","&gt; &lt;map from="${my.dir}/${prefix}/" to="" /&gt; &lt;/pathconvert&gt; &lt;fileset id="my.fs.out" dir="${my.dir}/${prefix}" includes="${shrink}" /&gt; &lt;echo message="Shrink-wrapped fileset is: '${toString:my.fs.out}'" /&gt; </code></pre>
    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.
 

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