ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject Select "marked" directories (WAS: Alternative to subant)
Date Fri, 30 Nov 2007 07:16:45 GMT
I think the easiest possibility is using a <scriptselector>:

<scriptselector language="javascript">
    if (file.isDirectory()) {
        markerName = project.getProperty("markerfile");
        markerFile = new java.io.File(file, markerName);
        self.setSelected( markerFile.exists() );
    }
</scriptselector>

I've created an AntUnit test ...


Jan





---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
<project xmlns:au="antlib:org.apache.ant.antunit" default="suite">
    <description>
        Select only directories which contain a marker file.
    </description>


    <property name="workingdir" value="working"/>
    <property name="markerfile" value=".marker"/>
    
    
    <target name="setUp">
        <!-- Create a small directory structure -->
        <mkdir dir="${workingdir}/dir1/dir11/dir111"/>
        <mkdir dir="${workingdir}/dir1/dir11/dir112"/>
        <mkdir dir="${workingdir}/dir2/dir22"/>
        <!-- Mark some of them -->
        <macrodef name="mark">
            <attribute name="dir"/>
            <sequential>
                <touch file="${workingdir}/@{dir}/${markerfile}"/>
            </sequential>
        </macrodef>
        <mark dir="dir1/dir11/dir112"/>
        <mark dir="dir2/dir22"/>
        <mark dir="dir2"/>
        <!-- The dirset which contains only marked directories -->
        <dirset id="dirset" dir="${workingdir}">
            <scriptselector language="javascript">
                if (file.isDirectory()) {
                    markerName = project.getProperty("markerfile");
                    markerFile = new java.io.File(file, markerName);
                    self.setSelected( markerFile.exists() );
                }
            </scriptselector>
        </dirset>
        <!-- Ensure we have a platform independend output format (in contrast to ${tostring:dirset}
-->
        <pathconvert property="selected" dirsep="/" pathsep="${line.separator}">
            <path><dirset refid="dirset"/></path>
        </pathconvert>
        <!-- Log the dirset so we can make some assertions -->
        <echo>${selected}</echo>
        <echo file="log.txt">${selected}</echo>
    </target>

    <target name="tearDown">
        <delete dir="${workingdir}"/>
    </target>
    
    <target name="suite">
        <au:antunit>
            <file file="${ant.file}"/>
            <au:plainlistener/>
        </au:antunit>
    </target>
    
    <target name="test-1-11-112-marked">
        <au:assertLogContains text="dir1/dir11/dir112${line.separator}"/>
    </target>
    
    <target name="test-1-11-111-notmarked">
        <au:assertLogDoesntContain text="dir1/dir11/dir111${line.separator}"/>
    </target>
    
    <target name="test-2-marked">
        <au:assertLogContains text="dir2${line.separator}"/>
    </target>

    <target name="test-1-notmarked">
        <au:assertLogDoesntContain text="dir1${line.separator}"/>
    </target>

</project>
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----

 

> -----Urspr√ľngliche Nachricht-----
> Von: Dominique Devienne [mailto:ddevienne@gmail.com] 
> Gesendet: Donnerstag, 29. November 2007 20:22
> An: Ant Users List
> Betreff: Re: AW: Alternative to subant
> 
> On Nov 29, 2007 12:40 PM, Francisco Tolmasky 
> <tolmasky@gmail.com> wrote:
> > Is there any way to say:
> > "Use the build file in the directory if the directory 
> contains a properties file?"
> 
> I would have thought it to be possible with selectors and a mapper,
> but I don't see how do it in practice. I thought I used to do
> something like this...
> 
> Note that 
> http://ant.apache.org/manual/CoreTypes/resources.html#restrict
> could be the solution, but I'm not very familiar with the new Resource
> Collection framework, as I have no practical experience with it.
> 
> I think Jan or Matt will know though ;-) --DD
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message