/// <summary> /// Initializes a new instance of the <see cref="ProjectSettingsLoader" /> /// class for the given <see cref="Project" />. /// </summary> /// <param name="project">The <see cref="Project" /> that should be configured.</param> internal ProjectSettingsLoader(Project project) { _project = project; // setup namespace manager _nsMgr = new XmlNamespaceManager(new NameTable()); _nsMgr.AddNamespace("nant", _nsMgr.DefaultNamespace); }
public ExpressionEvalBase(Project project) { if (project == null) throw new ArgumentNullException("project"); _project = project; }
public void Test_FilesInResources() { string buildFile = Path.Combine (_tempFolder, "default.build"); foreach (string resName in Assembly.GetExecutingAssembly().GetManifestResourceNames()) { if (!resName.StartsWith("XML_.Build.Files")) { continue; } using (FileStream fs = File.Open (buildFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { byte[] buffer = new byte[8192]; Stream rs = Assembly.GetExecutingAssembly().GetManifestResourceStream(resName); while (true) { int bytesRead = rs.Read(buffer, 0, buffer.Length); if (bytesRead == 0) { break; } fs.Write(buffer, 0, bytesRead); } } bool expectSuccess = (resName.IndexOf(".Valid.") > 0); try { XmlDocument doc = new XmlDocument(); doc.Load(buildFile); Project p = new Project(doc, Level.Info, 0); string output = BuildTestBase.ExecuteProject(p); Assert.IsTrue (expectSuccess, "#1: " + resName + " " + output); } catch (Exception ex) { Assert.IsFalse (expectSuccess, "#2: " +resName + " " + ex.ToString()); } } }
/// <summary> /// Initializes a new instance of the <see cref="ExpressionEvaluator"/> class. /// </summary> /// <param name="project">The project.</param> /// <param name="properties">The projects properties.</param> /// <param name="state">The state.</param> /// <param name="visiting">The visiting.</param> public ExpressionEvaluator(Project project, PropertyDictionary properties, Hashtable state, Stack visiting) : base(project) { _properties = properties; _state = state; _visiting = visiting; }
protected override void SetUp() { base.SetUp(); _buildFileName = Path.Combine(TempDirName, "test.build"); TempFile.CreateWithContents(FormatBuildFile("", ""), _buildFileName); _project = new Project(_buildFileName, Level.Info, 0); _project.Properties["prop1"] = "asdf"; }
public DummyCircularReferenceTask(string references, string buildFileXml) { m_References = references; XmlDocument doc = new XmlDocument(); doc.LoadXml(buildFileXml); Project = new Project(doc, Level.Info, 1); Project.Execute(); // this loads targets }
public AsyncProject(String logSrcName, Project proj, String target, ManualCloseLogEventQueue q) { _logSrcName = logSrcName; _project = proj; _target = target; _thread = null; _logEventQueue = q; }
internal static void UseDefaultNamespace(XmlDocument document, Project project) { string xmlCopy = document.OuterXml; xmlCopy = xmlCopy.Replace("xmlns=\"", "disabledxmlns=\""); string docStart = "<" + document.DocumentElement.Name; string newDocStart = docStart + " " + GetNamespaceDeclaration(project.Document); xmlCopy = xmlCopy.Replace(docStart, newDocStart); document.LoadXml(xmlCopy); }
/// <summary> /// Replaces existing build event handlers with a handler that enqueues /// build events into this queue /// </summary> /// <param name="proj"></param> public void Install(Project proj, String hideTarget) { _hideTarget = hideTarget; BuildListenerCollection coll = new BuildListenerCollection(); coll.Add(this); proj.DetachBuildListeners(); proj.AttachBuildListeners(coll); }
/// <summary> /// Sets a property to a value for a given NAnt project. If the property /// already exists on the project, the old value will be overwritten with /// the new value. /// </summary> /// <param name="proj">The project on which to set the property.</param> /// <param name="prop">The name of the property to set.</param> /// <param name="val">The value to set the property to.</param> public static void AddOrOverwriteProperty(Project proj, string prop, string val) { #region Preconditions if (proj == null) throw new ArgumentNullException("proj"); if (prop == null) throw new ArgumentNullException("prop"); if (val == null) throw new ArgumentNullException("val"); #endregion if (proj.Properties.Contains(prop)) proj.Properties.Remove(prop); proj.Properties.Add(prop, val); }
private static void TryExpandingProperty(Project project, IBuildProperty property) { try { property.DefaultExpandedValue = property.ExpandedValue = project.ExpandProperties(property.Value, new Location("Buildfile")); } catch (BuildException) { // TODO: Do something with the error message } }
public void Test_Initialization_DOMBuildFile() { XmlDocument doc = new XmlDocument(); doc.LoadXml(FormatBuildFile("", "")); Project p = new Project(doc, Level.Error, 0); Assert.IsNotNull(p.Properties["nant.version"], "Property not defined."); Assert.IsNull(p.Properties["nant.project.buildfile"], "location of buildfile should not exist!"); Assert.IsNotNull(p.Properties["nant.project.basedir"], "nant.project.basedir should not be null"); Assert.AreEqual(TempDirName, p.Properties["nant.project.basedir"]); Assert.AreEqual("test", p.Properties["nant.project.default"]); CheckCommon(p); Assert.AreEqual("The value is " + Boolean.TrueString + ".", p.ExpandProperties("The value is ${task::exists('fail')}.", null)); }
internal void RunProject(String threadName, Project proj, String targetName) { ManualCloseLogEventQueue q = new ManualCloseLogEventQueue(threadName); AsyncProject ap = new AsyncProject(threadName, proj, targetName, q); _logEventQueueList.Add(q); _asyncProjects.Add(ap); ap.Start(); InstallNewAutoCloseEventListener(); if (_serialize) { ap.WaitForFinish(); } }
public void Test_Initialization_FSBuildFile() { // create the build file in the temp folder TempFile.CreateWithContents(FormatBuildFile("", ""), _buildFileName); Project p = new Project(_buildFileName, Level.Error, 0); Assert.IsNotNull(p.Properties["nant.version"], "Property ('nant.version') not defined."); Assert.IsNotNull(p.Properties["nant.location"], "Property ('nant.location') not defined."); Assert.AreEqual(new Uri(_buildFileName), p.Properties["nant.project.buildfile"]); Assert.AreEqual(TempDirName, p.Properties["nant.project.basedir"]); Assert.AreEqual("test", p.Properties["nant.project.default"]); CheckCommon(p); Assert.AreEqual("The value is " + Boolean.TrueString + ".", p.ExpandProperties("The value is ${task::exists('fail')}.", null)); }
public TimeSpanFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
public ServiceFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
public FilterChainFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
public Int64ConversionFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
/// <summary> /// Initializes a new instance of the <see cref="Element" /> class /// from the specified element. /// </summary> /// <param name="e">The element that should be used to create a new instance of the <see cref="Element" /> class.</param> protected Element(Element e) : this() { _location = e._location; _project = e._project; _xmlNode = e._xmlNode; _nsMgr = e._nsMgr; }
public DirectoryFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
/// <summary> /// Initializes a new instance of the <see cref="TeamCityFunctions"/> class. /// </summary> /// <param name="project">The project.</param> /// <param name="properties">The properties.</param> public TeamCityFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
/// <summary> /// Initializes a new instance of the <see cref="BuildEventArgs" /> /// class for a <see cref="Task" /> level event. /// </summary> /// <param name="task">The <see cref="Task" /> that emitted the event.</param> public BuildEventArgs(Task task) { _project = task.Project; _target = task.Parent as Target; _task = task; }
/// <summary> /// Starts NAnt. This is the Main entry point. /// </summary> /// <param name="args">Command Line args, or whatever you want to pass it. They will treated as Command Line args.</param> /// <returns> /// The exit code. /// </returns> public static int Main(string[] args) { CommandLineParser commandLineParser = null; Project project = null; Level projectThreshold = Level.Info; // create assembly resolver AssemblyResolver assemblyResolver = new AssemblyResolver(); // attach assembly resolver to the current domain assemblyResolver.Attach(); CommandLineOptions cmdlineOptions = new CommandLineOptions(); try { commandLineParser = new CommandLineParser(typeof(CommandLineOptions), true); commandLineParser.Parse(args, cmdlineOptions); if (!cmdlineOptions.NoLogo) { Console.WriteLine(commandLineParser.LogoBanner); // insert empty line Console.WriteLine(); } if (cmdlineOptions.ShowHelp) { ConsoleDriver.ShowHelp(commandLineParser); return 0; } // determine the project message threshold if (cmdlineOptions.Debug) { projectThreshold = Level.Debug; } else if (cmdlineOptions.Verbose) { projectThreshold = Level.Verbose; } else if (cmdlineOptions.Quiet) { projectThreshold = Level.Warning; } if (cmdlineOptions.BuildFile != null) { if (project != null) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Buildfile has already been loaded! Using new value '{0}'; discarding old project file '{1}'", cmdlineOptions.BuildFile, project.BuildFileUri)); // insert empty line Console.WriteLine(); } project = new Project(cmdlineOptions.BuildFile, projectThreshold, cmdlineOptions.IndentationLevel); } // get build file name if the project has not been created. // If a build file was not specified on the command line. if (project == null) { project = new Project(GetBuildFileName(Environment.CurrentDirectory, null, cmdlineOptions.FindInParent), projectThreshold, cmdlineOptions.IndentationLevel); } // load extension asseemblies LoadExtensionAssemblies(cmdlineOptions.ExtensionAssemblies, project); PropertyDictionary buildOptionProps = new PropertyDictionary(project); // add build logger and build listeners to project ConsoleDriver.AddBuildListeners(cmdlineOptions, project); // copy cmd line targets foreach (string target in cmdlineOptions.Targets) { project.BuildTargets.Add(target); } // build collection of valid properties that were specified on // the command line. foreach (string key in cmdlineOptions.Properties) { buildOptionProps.AddReadOnly(key, cmdlineOptions.Properties.Get(key)); } // add valid properties to the project. foreach (System.Collections.DictionaryEntry de in buildOptionProps) { project.Properties.AddReadOnly((string) de.Key, (string) de.Value); } //add these here and in the project .ctor Assembly ass = Assembly.GetExecutingAssembly(); project.Properties.AddReadOnly(Project.NAntPropertyFileName, ass.Location); project.Properties.AddReadOnly(Project.NAntPropertyVersion, ass.GetName().Version.ToString()); project.Properties.AddReadOnly(Project.NAntPropertyLocation, Path.GetDirectoryName(ass.Location)); if (cmdlineOptions.TargetFramework != null) { FrameworkInfo framework = project.Frameworks[cmdlineOptions.TargetFramework]; if (framework != null) { try { framework.Validate(); project.TargetFramework = framework; } catch (Exception ex) { // write message of exception to console WriteException(ex); // output full stacktrace when NAnt is started in debug mode if (Level.Debug >= projectThreshold) { // insert empty line Console.Error.WriteLine(); // output header Console.Error.WriteLine("Stacktrace:"); // insert empty line Console.Error.WriteLine(); // output full stacktrace Console.Error.WriteLine(ex.ToString()); } // signal error return 1; } } else { Console.Error.WriteLine("Invalid framework '{0}' specified.", cmdlineOptions.TargetFramework); // insert empty line Console.Error.WriteLine(); FrameworkInfo[] installedFrameworks = project.GetFrameworks( FrameworkTypes.Installed); if (installedFrameworks.Length == 0) { Console.Error.WriteLine("There are no supported frameworks available on your system."); } else { Console.Error.WriteLine("Possible values include:"); // insert empty line Console.Error.WriteLine(); foreach (FrameworkInfo fi in installedFrameworks) { Console.Error.WriteLine("{0} ({1})", fi.Name, fi.Description); } } // signal error return 1; } } // Enable parallel execution of targets project.RunTargetsInParallel = cmdlineOptions.UseJobs; if (cmdlineOptions.ShowProjectHelp) { Console.WriteLine(); ConsoleDriver.ShowProjectHelp(project.Document); } else { if (!project.Run()) { return 1; } } // signal success return 0; } catch (CommandLineArgumentException ex) { // Write logo banner to console if parser was created successfully if (commandLineParser != null) { Console.WriteLine(commandLineParser.LogoBanner); // insert empty line Console.Error.WriteLine(); } // write message of exception to console WriteException(ex); // output full stacktrace when NAnt is started in debug mode if (Level.Debug >= projectThreshold) { // insert empty line Console.Error.WriteLine(); // output header Console.Error.WriteLine("Stacktrace:"); // insert empty line Console.Error.WriteLine(); // output full stacktrace Console.Error.WriteLine(ex.ToString()); } // insert empty line Console.WriteLine(); // instruct users to check the usage instructions Console.WriteLine("Try 'nant -help' for more information"); // signal error return 1; } catch (ApplicationException ex) { // insert empty line Console.Error.WriteLine(); // output build result Console.Error.WriteLine("BUILD FAILED"); // insert empty line Console.Error.WriteLine(); // write message of exception to console WriteException(ex); // output full stacktrace when NAnt is started in debug mode if (Level.Debug >= projectThreshold) { // insert empty line Console.Error.WriteLine(); // output header Console.Error.WriteLine("Stacktrace:"); // insert empty line Console.Error.WriteLine(); // output full stacktrace Console.Error.WriteLine(ex.ToString()); } else { // insert empty line Console.WriteLine(string.Empty); // output help text Console.WriteLine("For more information regarding the cause of the " + "build failure, run the build again in debug mode."); } // insert empty line Console.WriteLine(); // instruct users to check the usage instructions Console.WriteLine("Try 'nant -help' for more information"); // signal error return 1; } catch (Exception ex) { // insert empty line Console.Error.WriteLine(); // all other exceptions should have been caught Console.Error.WriteLine("INTERNAL ERROR"); // insert empty line Console.Error.WriteLine(); // write message of exception to console WriteException(ex); // output full stacktrace when NAnt is started in verbose mode if (Level.Verbose >= projectThreshold) { // insert empty line Console.Error.WriteLine(); // output header Console.Error.WriteLine("Stacktrace:"); // insert empty line Console.Error.WriteLine(); // output full stacktrace Console.Error.WriteLine(ex.ToString()); } else { // insert xempty line Console.WriteLine(); // output help text Console.WriteLine("For more information regarding the cause of the " + "build failure, run the build again in verbose mode."); } // insert empty line Console.WriteLine(); // instruct users to report this problem Console.WriteLine("Please send a bug report (including the version of NAnt you're using) to [email protected]"); // signal fatal error return 2; } finally { if (project != null) { project.DetachBuildListeners(); } // detach assembly resolver from the current domain assemblyResolver.Detach(); if (cmdlineOptions.Pause) Console.ReadKey(); } }
/// <summary> /// Initializes a new instance of the <see cref="BuildEventArgs" /> /// class for a <see cref="Target" /> level event. /// </summary> /// <param name="target">The <see cref="Target" /> that emitted the event.</param> public BuildEventArgs(Target target) { _project = target.Project; _target = target; }
/// <summary> /// Initializes a new instance of the <see cref="BuildEventArgs" /> /// class for a <see cref="Project" /> level event. /// </summary> /// <param name="project">The <see cref="Project" /> that emitted the event.</param> public BuildEventArgs(Project project) { _project = project; }
/// <summary> /// Add the listeners specified in the command line arguments, /// along with the default listener, to the specified project. /// </summary> /// <param name="cmdlineOptions">The command-line options.</param> /// <param name="project">The <see cref="Project" /> to add listeners to.</param> private static void AddBuildListeners(CommandLineOptions cmdlineOptions, Project project) { BuildListenerCollection listeners = new BuildListenerCollection(); IBuildLogger buildLogger = null; TextWriter outputWriter = Console.Out; if (cmdlineOptions.LogFile != null) { try { outputWriter = new StreamWriter(new FileStream(cmdlineOptions.LogFile.FullName, FileMode.Create, FileAccess.Write, FileShare.Read)); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1005"), cmdlineOptions.LogFile.FullName), Location.UnknownLocation, ex); } } if (cmdlineOptions.LoggerType != null) { try { buildLogger = ConsoleDriver.CreateLogger(cmdlineOptions.LoggerType); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1003"), cmdlineOptions.LoggerType), Location.UnknownLocation, ex); } } // if no logger was specified on the commandline or an error occurred // while creating an instance of the specified logger, use the default // logger. if (buildLogger == null) { buildLogger = new DefaultLogger(); } // only set OutputWriter if build logger does not derive from // DefaultLogger, or if logfile was specified on command-line. // Setting the OutputWriter of the DefaultLogger to Console.Out // would cause issues with unit tests. if (!typeof(DefaultLogger).IsAssignableFrom(buildLogger.GetType()) || cmdlineOptions.LogFile != null) { buildLogger.OutputWriter = outputWriter; } // set threshold of build logger equal to threshold of project buildLogger.Threshold = project.Threshold; // set emacs mode buildLogger.EmacsMode = cmdlineOptions.EmacsMode; // add build logger to listeners collection listeners.Add(buildLogger); // add listeners to listener collection foreach (string listenerTypeName in cmdlineOptions.Listeners) { try { IBuildListener listener = ConsoleDriver.CreateListener(listenerTypeName); listeners.Add(listener); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1002"), listenerTypeName), Location.UnknownLocation, ex); } } // attach listeners to project project.AttachBuildListeners(listeners); }
public CCNetFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
/// <summary> /// Loads the extension assemblies in the current <see cref="AppDomain" /> /// and scans them for extensions. /// </summary> /// <param name="extensionAssemblies">The extension assemblies to load.</param> /// <param name="project">The <see cref="Project" /> which will be used to output messages to the build log.</param> private static void LoadExtensionAssemblies(StringCollection extensionAssemblies, Project project) { LoadTasksTask loadTasks = new LoadTasksTask(); loadTasks.Project = project; loadTasks.NamespaceManager = project.NamespaceManager; loadTasks.Parent = project; loadTasks.Threshold = (project.Threshold == Level.Debug) ? Level.Debug : Level.Warning; foreach (string extensionAssembly in extensionAssemblies) { loadTasks.TaskFileSet.Includes.Add(extensionAssembly); } loadTasks.Execute(); }
/// <summary> /// Initializes a new instance of the <see cref="GacCache"/> class in /// the context of the given <see cref="Project" />. /// </summary> public GacCache(Project project) { _project = project; _gacQueryCache = CollectionsUtil.CreateCaseInsensitiveHashtable(); RecreateDomain(); }
private void AttachFiles(MailMessage mail, Project project, string filesetID) { if (StringUtils.IsNullOrEmpty(filesetID)) { return; } // lookup fileset FileSet fileset = project.DataTypeReferences[filesetID] as FileSet; if (fileset == null) { Console.Error.WriteLine("[MailLogger] Fileset \"{0}\" is not" + " defined. No files have been attached.", filesetID); return; } foreach (string fileName in fileset.FileNames) { if (!File.Exists(fileName)) { Console.Error.WriteLine("[MailLogger] Attachment \"{0}\"" + " does not exist. Skipping.", filesetID); continue; } // create attachment MailAttachment attachment = new MailAttachment(fileName, MailEncoding.UUEncode); // add attachment to mail mail.Attachments.Add(attachment); } }