Example #1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Do the job
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected override void ExecuteTask()
 {
     try
     {
         if (string.IsNullOrEmpty(Properties["fwroot"]))
         {
             Log(Level.Debug, "Checking environment variable FWROOT");
             string fwroot = Environment.GetEnvironmentVariable("FWROOT");
             if (string.IsNullOrEmpty(fwroot))
             {
                 Log(Level.Debug, "Checking based on build file: '{0}'", Project.BuildFileLocalName);
                 // first look in the buildfile directory and its parent directories
                 fwroot = FindFwRoot(Project.BuildFileLocalName);
                 if (fwroot.Length == 0)
                 {
                     // this didn't work, so look in the directory where NAnt.exe is
                     // and its parent directories
                     string nantFileName = Assembly.GetEntryAssembly().CodeBase;
                     if (nantFileName.StartsWith("file://"))
                     {
                         // Strip file:/// (on Windows) or file:// (on Linux) (cf FWNX-117)
                         nantFileName = nantFileName.Substring(Path.DirectorySeparatorChar == '\\' ? 8 : 7);
                     }
                     Log(Level.Debug, "Checking based on NAnt executable: '{0}'", nantFileName);
                     fwroot = FindFwRoot(nantFileName);
                     if (fwroot.Length == 0)
                     {
                         Log(Level.Debug,
                             "All else failed; falling back on hard coded path relativ to NAnt.exe");
                         // this didn't work, so just take the directory we know
                         // is fwroot at least sometimes...
                         string rawPath = Path.GetDirectoryName(Path.Combine(nantFileName,
                                                                             "../../.."));
                         fwroot = Path.GetFullPath(rawPath);
                     }
                 }
             }
             if (UseUnixPath)
             {
                 fwroot = fwroot.Replace('\\', '/');
             }
             Log(Level.Verbose, "Setting property fwroot to '{0}'", fwroot);
             Properties.AddReadOnly("fwroot", fwroot);
         }
         else
         {
             Log(Level.Verbose, "fwroot is already set");
         }
     }
     catch (Exception e)
     {
         throw new BuildException(
                   string.Format("Error {0} setting property 'fwroot'", e.Message),
                   Location, e);
     }
 }
Example #2
0
        /// <summary>
        /// Executes the task.
        /// </summary>
        protected override void ExecuteTask()
        {
            string value = GetValue();

            if (!Project.Properties.Contains(PropertyName))
            {
                if (ReadOnly)
                {
                    Properties.AddReadOnly(PropertyName, value);
                }
                else
                {
                    Properties[PropertyName] = value;
                }
                if (Dynamic)
                {
                    Properties.MarkDynamic(PropertyName);
                }
            }
            else if (Overwrite)
            {
                if (Project.Properties.IsReadOnlyProperty(PropertyName))
                {
                    Log(Level.Warning, "Read-only property \"{0}\" cannot be overwritten.", new object[] { PropertyName });
                }
                else
                {
                    Properties[PropertyName] = value;
                    if (Dynamic)
                    {
                        Properties.MarkDynamic(PropertyName);
                    }
                }
            }
            else
            {
                Log(Level.Verbose, "Property \"{0}\" already exists, and \"overwrite\" is set to false.",
                    new object[] { PropertyName });
            }
        }
Example #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Do the job
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected override void ExecuteTask()
 {
     try
     {
         if (Properties["fwroot"] == null || Properties["fwroot"] == string.Empty)
         {
             string fwroot = Environment.GetEnvironmentVariable("FWROOT");
             if (fwroot == null || fwroot == string.Empty)
             {
                 // first look in the buildfile directory and its parent directories
                 fwroot = FindFwRoot(Project.BuildFileLocalName);
                 if (fwroot.Length == 0)
                 {
                     // this didn't work, so look in the directory where NAnt.exe is
                     // and its parent directories
                     fwroot = FindFwRoot(Properties["nant.filename"]);
                     if (fwroot.Length == 0)
                     {
                         // this didn' work, so just take the directory we know
                         // is fwroot at least sometimes...
                         string rawPath = Path.GetDirectoryName(Path.Combine(Properties["nant.filename"],
                                                                             "../../.."));
                         if (rawPath.StartsWith(@"file:\"))
                         {
                             rawPath = rawPath.Substring(6);
                         }
                         fwroot = Path.GetFullPath(rawPath);
                     }
                 }
             }
             Properties.AddReadOnly("fwroot", fwroot);
         }
     }
     catch (Exception e)
     {
         throw new BuildException(
                   string.Format("Error {0} setting property 'fwroot'", e.Message),
                   Location, e);
     }
 }
Example #4
0
        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <exception cref="BuildException">If the target framework cannot be changed.</exception>
        protected override void ExecuteTask()
        {
            string propertyValue;

            if (!Dynamic)
            {
                propertyValue = Project.ExpandProperties(Value, Location);
            }
            else
            {
                propertyValue = Value;
            }

            // Special check for framework setting.
            if (PropertyName == "nant.settings.currentframework")
            {
                FrameworkInfo newTargetFramework = Project.Frameworks[propertyValue];

                // check if target framework exists
                if (newTargetFramework != null)
                {
                    if (Project.TargetFramework != null)
                    {
                        if (Project.TargetFramework != newTargetFramework)
                        {
                            Project.TargetFramework = newTargetFramework;
                            // only output message in build log if target
                            // framework is actually changed
                            Log(Level.Info, "Target framework changed to \"{0}\".",
                                newTargetFramework.Description);
                        }
                    }
                    else
                    {
                        Project.TargetFramework = newTargetFramework;
                        Log(Level.Info, "Target framework set to \"{0}\".",
                            newTargetFramework.Description);
                    }
                    return;
                }
                else
                {
                    ArrayList validvalues = new ArrayList();
                    foreach (FrameworkInfo framework in Project.Frameworks)
                    {
                        validvalues.Add(framework.Name);
                    }
                    string validvaluesare = string.Empty;
                    if (validvalues.Count > 0)
                    {
                        validvaluesare = string.Format(CultureInfo.InvariantCulture,
                                                       ResourceUtils.GetString("String_ValidValues"), string.Join(", ", (string[])validvalues.ToArray(typeof(string))));
                    }
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           ResourceUtils.GetString("NA1143"),
                                                           propertyValue, validvaluesare), Location);
                }
            }

            if (!Project.Properties.Contains(PropertyName))
            {
                if (ReadOnly)
                {
                    Properties.AddReadOnly(PropertyName, propertyValue);
                }
                else
                {
                    Properties[PropertyName] = propertyValue;
                }

                if (Dynamic)
                {
                    Properties.MarkDynamic(PropertyName);
                }
            }
            else
            {
                if (Overwrite)
                {
                    if (Project.Properties.IsReadOnlyProperty(PropertyName))
                    {
                        // for now, just output a warning when attempting to
                        // overwrite a readonly property
                        //
                        // we should actually be throwing a BuildException here, but
                        // we currently don't have a good mechanism in place to allow
                        // users to specify properties on the command line and provide
                        // default values for these properties in the build file
                        //
                        // users could use either the "overwrite" property or a
                        // "property::exists(...)" unless condition on the <property>
                        // task, but these do not seem to be intuitive for users
                        Log(Level.Warning, "Read-only property \"{0}\" cannot"
                            + " be overwritten.", PropertyName);
                    }
                    else
                    {
                        Properties[PropertyName] = propertyValue;

                        if (Dynamic)
                        {
                            Properties.MarkDynamic(PropertyName);
                        }
                    }
                }
                else
                {
                    Log(Level.Verbose, "Property \"{0}\" already exists, and \"overwrite\" is set to false.", PropertyName);
                }
            }
        }