// **************************************************************** // This is free software licensed under the NUnit license. You // may obtain a copy of the license as well as information regarding // copyright ownership at http://nunit.org/?p=license&r=2.4. // **************************************************************** using System; using System.Text; using System.Collections; using System.IO; using NUnit.Core; namespace NUnit.Util { public enum BinPathType { Auto, Manual, None } public class ProjectConfig { #region Instance Variables /// /// The name of this config /// private string name; /// /// IProject interface of containing project /// protected NUnitProject project = null; /// /// List of the names of the assemblies /// private AssemblyList assemblies; /// /// Base path specific to this configuration /// private string basePath; /// /// Our configuration file, if specified /// private string configFile; /// /// Private bin path, if specified /// private string binPath; /// /// True if assembly paths should be added to bin path /// private BinPathType binPathType = BinPathType.Auto; #endregion #region Constructor public ProjectConfig( string name ) { this.name = name; this.assemblies = new AssemblyList(); assemblies.Changed += new EventHandler( assemblies_Changed ); } #endregion #region Properties and Events public event EventHandler Changed; public NUnitProject Project { // get { return project; } set { project = value; } } public string Name { get { return name; } set { if ( name != value ) { name = value; FireChangedEvent(); } } } private bool BasePathSpecified { get { return project.BasePathSpecified || this.basePath != null && this.basePath != ""; } } /// /// The base directory for this config - used /// as the application base for loading tests. /// public string BasePath { get { if ( project == null || project.BasePath == null ) return basePath; if ( basePath == null ) return project.BasePath; return Path.Combine( project.BasePath, basePath ); } set { if ( BasePath != value ) { basePath = value; FireChangedEvent(); } } } /// /// The base path relative to the project base /// public string RelativeBasePath { get { if ( project == null || basePath == null || !Path.IsPathRooted( basePath ) ) return basePath; return PathUtils.RelativePath( project.BasePath, basePath ); } } private bool ConfigurationFileSpecified { get { return configFile != null; } } public string ConfigurationFile { get { return configFile == null && project != null ? project.ConfigurationFile : configFile; } set { if ( ConfigurationFile != value ) { configFile = value; FireChangedEvent(); } } } public string ConfigurationFilePath { get { return BasePath != null && ConfigurationFile != null ? Path.Combine( BasePath, ConfigurationFile ) : ConfigurationFile; } } private bool PrivateBinPathSpecified { get { return binPath != null; } } /// /// The Path.PathSeparator-separated path containing all the /// assemblies in the list. /// public string PrivateBinPath { get { return binPath; } set { if ( binPath != value ) { binPath = value; binPathType = binPath == null ? BinPathType.Auto : BinPathType.Manual; FireChangedEvent(); } } } /// /// How our PrivateBinPath is generated /// public BinPathType BinPathType { get { return binPathType; } set { if ( binPathType != value ) { binPathType = value; FireChangedEvent(); } } } /// /// Return our AssemblyList /// public AssemblyList Assemblies { get { return assemblies; } } #endregion public TestPackage MakeTestPackage() { TestPackage package = new TestPackage( project.ProjectPath ); if ( !project.IsAssemblyWrapper ) foreach ( string assembly in this.Assemblies ) package.Assemblies.Add( assembly ); if ( this.BasePathSpecified || this.PrivateBinPathSpecified || this.ConfigurationFileSpecified ) { package.BasePath = this.BasePath; package.PrivateBinPath = this.PrivateBinPath; package.ConfigurationFile = this.ConfigurationFile; } package.AutoBinPath = this.BinPathType == BinPathType.Auto; return package; } private void assemblies_Changed( object sender, EventArgs e ) { FireChangedEvent(); } private void FireChangedEvent() { if ( Changed != null ) Changed( this, EventArgs.Empty ); } } }