Ant. , , . , - , ${basedir} - .
, ..:
:
<property name="myprop" value="${basedir}/x" />
<property name="myprop2" value="${basedir}/x:${basedir}/y" />
<property name="myprop_rel" location="${myprop}" relative="yes"/>
<path id="mypath2" path="${myprop2}" />
<pathconvert property="myprop2_rel" refid="mypath2" pathsep=",">
<map from="${basedir}/" to="" />
</pathconvert>
<fileset id="my_fileset" dir="." includes="${myprop2_rel}" />
: Ant,
, script, , " ".
"input" .
<macrodef name="common-prefix-dir">
<attribute name="refid" />
<attribute name="outputproperty" />
<sequential>
<script language="javascript"><![CDATA[
srcFiles = project.getReference( "@{refid}" )
.getDirectoryScanner( project )
.getIncludedFiles( );
if ( srcFiles.length > 0 ) {
prefix = "" + srcFiles[0];
for ( i = 0; i < srcFiles.length; i++ ) {
while ( prefix.length && 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 );
]]></script>
</sequential>
</macrodef>
( php-.)
- :
<property name="my.dir" location="...your dir here..." />
<fileset id="my.fs" dir="${my.dir}">
</fileset>
<echo message="Input fileset is: '${toString:my.fs}'" />
<common-prefix-dir refid="my.fs" outputproperty="prefix" />
<echo message="Longest common prefix is: '${prefix}'" />
pathconvert , :
<pathconvert property="shrink" refid="my.fs" pathsep=",">
<map from="${my.dir}/${prefix}/" to="" />
</pathconvert>
<fileset id="my.fs.out" dir="${my.dir}/${prefix}" includes="${shrink}" />
<echo message="Shrink-wrapped fileset is: '${toString:my.fs.out}'" />