Since nobody has answered me on this I've decided to get creative. I'm currently testing this idea, but it seems to work for me.
 
Basically, I set a property within the loop. Once the condition is met where a I want to exit the loop (ie a build is needed), I set the value of ${build.needed} to true, and set the readonly flag to true as well.
 
With this method I still execute the rest of the loop, but since the property is now read only, it can't be set to false if a later project shows that a build isn't needed.
 
If there is another way, please share.  Thanks.

  <foreach item="String" in="${project.svn.path}" property="svn.path" verbose="true" delim=" " trim="Both">
  <do  unless="${build.needed}"> -->
   <exec program="svn.exe" commandline="info --xml ${project.svn.path}" output="${infolog}" />
   <xmlpeek xpath="/info/entry[1]/@revision" file="${infolog}" property="reposrev" />
   <xmlpeek xpath="//commit/@revision" file="${infolog}" property="maxcommitrev" />
   <echo message="++++++++++++++++++++++++++++++++++++++++++++++++" />
   <echo message="Max //comit/@revision: ${maxcommitrev}" />
   <echo message="++++++++++++++++++++++++++++++++++++++++++++++++" />
   <!-- Use ENV variables to return values -->
   <setenv name="ReposRev" value="${reposrev}" />
   <setenv name="maxcommitrev" value="${maxcommitrev}" />
   <!-- check automated.build.log for build needed statement and set VAR to true-->
   <if test="${environment::variable-exists('maxcommitrev')}">
    <property name="MaxCommitRev" value="${environment::get-variable('maxcommitrev')}" />
    <property name="ReposRev" value="${environment::get-variable('ReposRev')}" />
   </if>
   <loadfile file="${lastbuild.version.file}" property="LastBuildRev">
    <filterchain>
     <replacestring from="SVNREVISION: " to="" />
    </filterchain>
   </loadfile>
   
   <if test="${LastBuildRev &lt; MaxCommitRev}">
    <echo append="true" file="automated.build.log" message="${datetime::now()} - ${project.build.path}: Needs a Build" />
    <property name="build.needed" value="true" readonly="true"/>
   </if>
   <ifnot test="${LastBuildRev &lt; MaxCommitRev}">
    <echo append="true" file="automated.build.log" message="${datetime::now()} - ${project.build.path}: No Build needed." />
    <property name="build.needed" value="false" readonly="false"/>
   </ifnot>  
  </do>
  <echo message="Build needed: ${build.needed}" />
  </foreach>
 


Michael Craig <[EMAIL PROTECTED]> wrote:
How can I exist a <foreach> loop?
 
I've tried the following:
 
<foreach ... ... ... unless="${needs.build}">
 
and also:
 
<do unless="${needs.build}">
 
But the loops keep running through all items.
 
Basically, I'm trying to loop through a bunch of Subversion URLs, and detect if a build is needed based on last commit revision vs my last build revision. But I can't get the script to exit the <foreach> when it finds that the first one is true.
 
I'll paste the full target below...
 
Thanks,
 
Mike
 
 
 <target name="isbuildneeded" description="Check if a build is needed script to see if our build is up to date already." verbose="true">
  <foreach item="String" in="${project.svn.path}" property="svn.path" verbose="true" delim=" " trim="Both">
  <do  unless="${build.needed}">
   <exec program="svn.exe" commandline="info --xml ${svn.path}" output="${infolog}" />
   <xmlpeek xpath="/info/entry[1]/@revision" file="${infolog}" property="reposrev" />
   <xmlpeek xpath="//commit/@revision" file="${infolog}" property="maxcommitrev" />
   <echo message="++++++++++++++++++++++++++++++++++++++++++++++++" />
   <echo message="Max //comit/@revision: ${maxcommitrev}" />
   <echo message="++++++++++++++++++++++++++++++++++++++++++++++++" />
   <!-- Use ENV variables to return values -->
   <setenv name="ReposRev" value="${reposrev}" />
   <setenv name="maxcommitrev" value="${maxcommitrev}" />
   <!-- check automated.build.log for build needed statement and set VAR to true-->
   <if test="${environment::variable-exists('maxcommitrev')}">
    <property name="MaxCommitRev" value="${environment::get-variable('maxcommitrev')}" />
    <property name="ReposRev" value="${environment::get-variable('ReposRev')}" />
   </if>
   <loadfile file="${lastbuild.version.file}" property="LastBuildRev">
    <filterchain>
     <replacestring from="SVNREVISION: " to="" />
    </filterchain>
   </loadfile>
   
   <if test="${LastBuildRev &lt; MaxCommitRev}">
    <echo append="true" file="automated.build.log" message="${datetime::now()} - ${project.build.path}: Needs a Build" />
    <property name="build.needed" value="true" dynamic="true"/>
   </if>
   <ifnot test="${LastBuildRev &lt; MaxCommitRev}">
    <echo append="true" file="automated.build.log" message="${datetime::now()} - ${project.build.path}: No Build needed." />
    <property name="build.needed" value="false" dynamic="true"/>
   </ifnot>  
  </do>
  <echo message="Build needed: ${build.needed}" />
  </foreach>
 </target>

Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1ยข/min.-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users


Want to be your own boss? Learn how on Yahoo! Small Business.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to