You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ja...@rzf.fin-nrw.de on 2007/11/30 08:16:45 UTC
Select "marked" directories (WAS: Alternative to subant)
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
> <to...@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
Re: Select "marked" directories (WAS: Alternative to subant)
Posted by Dominique Devienne <dd...@gmail.com>.
On Nov 30, 2007 10:08 AM, Matt Benson <gu...@yahoo.com> wrote:
> Hmm... if all he wanted was to select build.xml where
> a project.properties lives alongside, the following
> seems to work for me:
>
> <fileset dir="${basedir}" includes="*/build.xml">
> <present targetdir="${basedir}">
> <mapper type="glob" from="*/build.xml" to="*/project.properties" />
> </present>
> </fileset>
I knew selector+mapper could do it, but I missed the mention to mapper
in <present> doc!
Thanks for the reminder Matt ;-) That's indeed the way to do it. --DD
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Select "marked" directories (WAS: Alternative to subant)
Posted by Matt Benson <gu...@yahoo.com>.
Hmm... if all he wanted was to select build.xml where
a project.properties lives alongside, the following
seems to work for me:
<fileset dir="${basedir}" includes="*/build.xml">
<present targetdir="${basedir}">
<mapper type="glob" from="*/build.xml"
to="*/project.properties" />
</present>
</fileset>
-Matt
--- Jan.Materne@rzf.fin-nrw.de wrote:
> 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
> > <to...@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
>
>
____________________________________________________________________________________
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org