Gert,

this new patch should be OK.

By the way, I've noticed something very strange;
to avoid the infinite loop, I've just modified
the code at line 782 from

do {
  currentTarget = (Target) sortedTargets[currentIndex++];
  if (currentTarget.Name.Equals(WildTarget) && _currentTarget != null) {
    currentTarget.Name = _currentTarget.Name;
  }

  _currentTarget = currentTarget;

  // only execute targets that have not been executed already,
  // if we are not forcing.
  if(forceDependencies || !_currentTarget.Executed) {
    _currentTarget.Execute();
  }
} while (!_currentTarget.Name.Equals(targetName));

... to

do {
  currentTarget = (Target) sortedTargets[currentIndex++];
  if (currentTarget.Name.Equals(WildTarget) && CurrentTarget != null) {
    currentTarget.Name = CurrentTarget.Name;
  }

  _currentTarget = currentTarget;

  // only execute targets that have not been executed already,
  // if we are not forcing.
  if(forceDependencies || !currentTarget.Executed) {
    currentTarget.Execute();
  }
} while (!currentTarget.Name.Equals(targetName));

Strange, isn't it?

...again, wild targets are nothing impressive, but I think
they would be very helpful when writing gateway build files
(no need of additional properties just to forward target names);
furthermore, as already said, it would be possible to define
a target that is executed when the user specifies a target
that does not exist in the current build file...

j3d.

On Fri, 2004-03-05 at 20:50, Gert Driesen wrote:
> Giuseppe,
> 
> There appears to be a problem with your changes. Have you tried applying the
> patch against NAnt cvs ?
> 
> NAnt seem to get stuck in an infinite loop, I'll look into it if you want
> ...
> 
> Regardless of this, I'd like to get feedback from other members of the
> community before committing your patch.  I don't mind committing the new
> target::get-current-target function, but I'm not sure about the wildcard
> target support ...
> 
> Gert
> 
> ----- Original Message ----- 
> From: "Giuseppe Greco" <[EMAIL PROTECTED]>
> To: "NAnt Developers" <[EMAIL PROTECTED]>
> Sent: Thursday, March 04, 2004 5:02 PM
> Subject: [nant-dev] Patch
> 
> 
> > Hi all,
> >
> > attached to this email you will find the patch
> > I promised yesterday.
> >
> > Now, it's up to you...
> >
> > j3d.
> >
> > -- 
> > ----------------------------------------
> > Giuseppe Greco
> >
> > ::agamura::
> >
> > phone:  +41 91 604 67 65
> > mobile: +41 76 390 60 32
> > email:  [EMAIL PROTECTED]
> > web:    www.agamura.com
> > ----------------------------------------
> >
-- 
----------------------------------------
Giuseppe Greco

::agamura::

phone:  +41 91 604 67 65
mobile: +41 76 390 60 32
email:  [EMAIL PROTECTED]
web:    www.agamura.com
----------------------------------------
? wildtarget.patch
? bin/ICSharpCode.SharpCvsLib.dll
? bin/NDoc.Core.dll
? bin/NDoc.Documenter.Msdn.dll
? bin/NUnitCore.dll
? bin/nunit.framework.dll
Index: bin/NAnt.Core.dll
===================================================================
RCS file: /cvsroot/nant/nant/bin/NAnt.Core.dll,v
retrieving revision 1.60
diff -c -r1.60 NAnt.Core.dll
Binary files /tmp/cvsBNzPjd and NAnt.Core.dll differ
Index: bin/NAnt.DotNetTasks.dll
===================================================================
RCS file: /cvsroot/nant/nant/bin/NAnt.DotNetTasks.dll,v
retrieving revision 1.31
diff -c -r1.31 NAnt.DotNetTasks.dll
Binary files /tmp/cvsCWSoGs and NAnt.DotNetTasks.dll differ
Index: bin/NAnt.exe
===================================================================
RCS file: /cvsroot/nant/nant/bin/NAnt.exe,v
retrieving revision 1.63
diff -c -r1.63 NAnt.exe
Binary files /tmp/cvs15yv4H and NAnt.exe differ
Index: bin/log4net.dll
===================================================================
RCS file: /cvsroot/nant/nant/bin/log4net.dll,v
retrieving revision 1.1
diff -c -r1.1 log4net.dll
Binary files /tmp/cvsUNjDxX and log4net.dll differ
Index: src/CommonAssemblyInfo.cs
===================================================================
RCS file: /cvsroot/nant/nant/src/CommonAssemblyInfo.cs,v
retrieving revision 1.10
diff -c -r1.10 CommonAssemblyInfo.cs
*** src/CommonAssemblyInfo.cs	3 Jan 2004 16:08:38 -0000	1.10
--- src/CommonAssemblyInfo.cs	5 Mar 2004 23:26:47 -0000
***************
*** 1,43 ****
! // NAnt - A .NET build tool
! // Copyright (C) 2001 Gerry Shaw
! //
! // This program is free software; you can redistribute it and/or modify
! // it under the terms of the GNU General Public License as published by
! // the Free Software Foundation; either version 2 of the License, or
! // (at your option) any later version.
! //
! // This program is distributed in the hope that it will be useful,
! // but WITHOUT ANY WARRANTY; without even the implied warranty of
! // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! // GNU General Public License for more details.
! //
! // You should have received a copy of the GNU General Public License
! // along with this program; if not, write to the Free Software
! // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
! //
! // Gerry Shaw ([EMAIL PROTECTED])
! // Scott Hernandez ([EMAIL PROTECTED])
! // Gert Driesen ([EMAIL PROTECTED])
! 
! using System;
  using System.Reflection;
  using System.Runtime.InteropServices;
  
! // Make assembly as NOT visible to COM
! [assembly: ComVisible(false)]
! 
! // Mark assembly CLS compliant
! [assembly: CLSCompliant(true)]
! 
! [assembly: AssemblyTitle("NAnt")]
! [assembly: AssemblyDescription("A .NET Build Tool")]
! [assembly: AssemblyConfiguration("net-1.0.win32; nightly")]
! [assembly: AssemblyCompany("http://nant.sourceforge.net";)]
! [assembly: AssemblyProduct("NAnt")]
! [assembly: AssemblyCopyright("Copyright (C) 2001-2004 Gerry Shaw")]
! [assembly: AssemblyTrademark("")]
! [assembly: AssemblyCulture("")]
  
! // build number expressed in number of days since 1/1/2000
! [assembly: AssemblyVersion("0.85.1447.0")]
! [assembly: AssemblyInformationalVersion("0.85")]
--- 1,26 ----
! using System;
  using System.Reflection;
  using System.Runtime.InteropServices;
  
! // ------------------------------------------------------------------------------
! //  <autogenerated>
! //      This code was generated by a tool.
! //      Mono Runtime Version: 1.1.4322.573
! // 
! //      Changes to this file may cause incorrect behavior and will be lost if 
! //      the code is regenerated.
! //  </autogenerated>
! // ------------------------------------------------------------------------------
  
! [assembly: ComVisibleAttribute(false)]
! [assembly: CLSCompliantAttribute(true)]
! [assembly: AssemblyTitleAttribute("NAnt")]
! [assembly: AssemblyDescriptionAttribute("A .NET Build Tool")]
! [assembly: AssemblyConfigurationAttribute("mono-1.0.unix; nightly")]
! [assembly: AssemblyCompanyAttribute("http://nant.sourceforge.net";)]
! [assembly: AssemblyProductAttribute("NAnt")]
! [assembly: AssemblyCopyrightAttribute("Copyright (C) 2001-2004 Gerry Shaw")]
! [assembly: AssemblyTrademarkAttribute("")]
! [assembly: AssemblyCultureAttribute("")]
! [assembly: AssemblyVersionAttribute("0.85.-5779.0")]
! [assembly: AssemblyInformationalVersionAttribute("0.85")]
Index: src/NAnt.Core/Project.cs
===================================================================
RCS file: /cvsroot/nant/nant/src/NAnt.Core/Project.cs,v
retrieving revision 1.63
diff -c -r1.63 Project.cs
*** src/NAnt.Core/Project.cs	28 Feb 2004 08:24:40 -0000	1.63
--- src/NAnt.Core/Project.cs	5 Mar 2004 23:26:56 -0000
***************
*** 78,83 ****
--- 78,84 ----
          private const string ProjectDefaultAttribte = "default";
          private const string ProjectBaseDirAttribute = "basedir";
          private const string TargetXml = "target";
+         private const string WildTarget = "*";
  
          /// <summary>
          /// Constant for the "visiting" state, used when traversing a DFS of 
***************
*** 128,133 ****
--- 129,135 ----
          private string _defaultTargetName = null;
          private int _indentationSize = 4;
          private int _indentationLevel = 0;
+         private Target _currentTarget = null;
          private BuildListenerCollection _buildListeners = new BuildListenerCollection();
          private StringCollection _buildTargets = new StringCollection();
          private TargetCollection _targets = new TargetCollection();
***************
*** 405,410 ****
--- 407,419 ----
              }
          }
  
+         /// <remarks>
+         /// Gets the current target.
+         /// </remarks>
+         public Target CurrentTarget {
+             get { return _currentTarget; }
+         }
+ 
          /// <summary>
          /// Gets the path to the build file.
          /// </summary>
***************
*** 761,774 ****
--- 770,799 ----
              int currentIndex = 0;
              Target currentTarget;
  
+             /*
+             do {
+                 currentTarget = (Target) sortedTargets[currentIndex++];
+                 //only execute targets that have not been executed already, if we are not forcing.
+                 if(forceDependencies || !currentTarget.Executed) {
+                     currentTarget.Execute();
+                 }
+             } while (!currentTarget.Name.Equals(targetName));
+             */
              do {
                  currentTarget = (Target) sortedTargets[currentIndex++];
+                 if (currentTarget.Name.Equals(WildTarget) && CurrentTarget != null) {
+                     currentTarget.Name = CurrentTarget.Name;
+                 }
+ 
+                 _currentTarget = currentTarget;
+ 
                  //only execute targets that have not been executed already, if we are not forcing.
                  if(forceDependencies || !currentTarget.Executed) {
                      currentTarget.Execute();
                  }
              } while (!currentTarget.Name.Equals(targetName));
          }
+ 
          /// <summary>
          /// Executes the default target and wraps in error handling and time 
          /// stamping.
***************
*** 1384,1389 ****
--- 1409,1422 ----
              visiting.Push(root);
  
              Target target = (Target) targets.Find(root);
+ 
+             if (target == null) {
+                 target = (Target) targets.Find(WildTarget);
+                 if (target != null) {
+                     target.Name = root;
+                     _currentTarget = target;
+                 }
+             }
  
              // Make sure the target exists
              if (target == null) {
Index: src/NAnt.Core/Functions/NAntFunctions.cs
===================================================================
RCS file: /cvsroot/nant/nant/src/NAnt.Core/Functions/NAntFunctions.cs,v
retrieving revision 1.5
diff -c -r1.5 NAntFunctions.cs
*** src/NAnt.Core/Functions/NAntFunctions.cs	27 Feb 2004 17:42:38 -0000	1.5
--- src/NAnt.Core/Functions/NAntFunctions.cs	5 Mar 2004 23:26:59 -0000
***************
*** 80,85 ****
--- 80,102 ----
              return target.Executed;
          }
  
+         /// <summary>
+         /// Returns the name of the target being executed.
+         /// </summary>
+         /// <returns>
+         /// A <see cref="System.String" /> that contains the name of the target
+         /// being executed.
+         /// </returns>
+         [Function("get-current-target")]
+         public string GetCurrentTarget() {
+             Target target = Project.CurrentTarget;
+             if (target == null) {
+                 throw new InvalidOperationException("No target is being executed.");
+             }
+ 
+             return target.Name;
+         }
+ 
          #endregion Public Instance Methods
      }
  

Reply via email to