PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/util/ProjectConfig.cs

#
C# | 282 lines | 197 code | 39 blank | 46 comment | 50 complexity | 817653149dec29ca474623634299587f MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // This is free software licensed under the NUnit license. You
  3. // may obtain a copy of the license as well as information regarding
  4. // copyright ownership at http://nunit.org.
  5. // ****************************************************************
  6. using System;
  7. using System.Text;
  8. using System.Collections;
  9. using System.IO;
  10. using NUnit.Core;
  11. namespace NUnit.Util
  12. {
  13. public enum BinPathType
  14. {
  15. Auto,
  16. Manual,
  17. None
  18. }
  19. public class ProjectConfig
  20. {
  21. #region Instance Variables
  22. /// <summary>
  23. /// The name of this config
  24. /// </summary>
  25. private string name;
  26. /// <summary>
  27. /// IProject interface of containing project
  28. /// </summary>
  29. protected NUnitProject project = null;
  30. /// <summary>
  31. /// List of the names of the assemblies
  32. /// </summary>
  33. private AssemblyList assemblies;
  34. /// <summary>
  35. /// Base path specific to this configuration
  36. /// </summary>
  37. private string basePath;
  38. /// <summary>
  39. /// Our configuration file, if specified
  40. /// </summary>
  41. private string configFile;
  42. /// <summary>
  43. /// Private bin path, if specified
  44. /// </summary>
  45. private string binPath;
  46. /// <summary>
  47. /// True if assembly paths should be added to bin path
  48. /// </summary>
  49. private BinPathType binPathType = BinPathType.Auto;
  50. /// <summary>
  51. /// The CLR under which tests are to be run
  52. /// </summary>
  53. private RuntimeFramework runtimeFramework;
  54. #endregion
  55. #region Constructor
  56. public ProjectConfig( string name )
  57. {
  58. this.name = name;
  59. this.assemblies = new AssemblyList();
  60. assemblies.Changed += new EventHandler( assemblies_Changed );
  61. }
  62. #endregion
  63. #region Properties and Events
  64. public NUnitProject Project
  65. {
  66. set { project = value; }
  67. }
  68. public string Name
  69. {
  70. get { return name; }
  71. set
  72. {
  73. if ( name != value )
  74. {
  75. name = value;
  76. NotifyProjectOfChange();
  77. }
  78. }
  79. }
  80. private bool BasePathSpecified
  81. {
  82. get
  83. {
  84. return project.BasePathSpecified || this.basePath != null && this.basePath != "";
  85. }
  86. }
  87. /// <summary>
  88. /// The base directory for this config - used
  89. /// as the application base for loading tests.
  90. /// </summary>
  91. public string BasePath
  92. {
  93. get
  94. {
  95. if ( project == null || project.BasePath == null )
  96. return basePath;
  97. if ( basePath == null )
  98. return project.BasePath;
  99. return Path.Combine( project.BasePath, basePath );
  100. }
  101. set
  102. {
  103. if ( BasePath != value )
  104. {
  105. basePath = value;
  106. NotifyProjectOfChange();
  107. }
  108. }
  109. }
  110. /// <summary>
  111. /// The base path relative to the project base
  112. /// </summary>
  113. public string RelativeBasePath
  114. {
  115. get
  116. {
  117. if ( project == null || basePath == null || !Path.IsPathRooted( basePath ) )
  118. return basePath;
  119. return PathUtils.RelativePath( project.BasePath, basePath );
  120. }
  121. }
  122. private bool ConfigurationFileSpecified
  123. {
  124. get { return configFile != null; }
  125. }
  126. public string ConfigurationFile
  127. {
  128. get
  129. {
  130. return configFile == null && project != null
  131. ? project.ConfigurationFile
  132. : configFile;
  133. }
  134. set
  135. {
  136. if ( ConfigurationFile != value )
  137. {
  138. configFile = value;
  139. NotifyProjectOfChange();
  140. }
  141. }
  142. }
  143. public string ConfigurationFilePath
  144. {
  145. get
  146. {
  147. return BasePath != null && ConfigurationFile != null
  148. ? Path.Combine( BasePath, ConfigurationFile )
  149. : ConfigurationFile;
  150. }
  151. }
  152. private bool PrivateBinPathSpecified
  153. {
  154. get { return binPath != null; }
  155. }
  156. /// <summary>
  157. /// The Path.PathSeparator-separated path containing all the
  158. /// assemblies in the list.
  159. /// </summary>
  160. public string PrivateBinPath
  161. {
  162. get { return binPath; }
  163. set
  164. {
  165. if ( binPath != value )
  166. {
  167. binPath = value;
  168. binPathType = binPath == null ? BinPathType.Auto : BinPathType.Manual;
  169. NotifyProjectOfChange();
  170. }
  171. }
  172. }
  173. /// <summary>
  174. /// How our PrivateBinPath is generated
  175. /// </summary>
  176. public BinPathType BinPathType
  177. {
  178. get { return binPathType; }
  179. set
  180. {
  181. if ( binPathType != value )
  182. {
  183. binPathType = value;
  184. NotifyProjectOfChange();
  185. }
  186. }
  187. }
  188. /// <summary>
  189. /// Return our AssemblyList
  190. /// </summary>
  191. public AssemblyList Assemblies
  192. {
  193. get { return assemblies; }
  194. }
  195. public RuntimeFramework RuntimeFramework
  196. {
  197. get { return runtimeFramework; }
  198. set
  199. {
  200. if ( runtimeFramework != value )
  201. {
  202. runtimeFramework = value;
  203. NotifyProjectOfChange();
  204. }
  205. }
  206. }
  207. #endregion
  208. public TestPackage MakeTestPackage()
  209. {
  210. TestPackage package = new TestPackage( project.ProjectPath );
  211. if ( !project.IsAssemblyWrapper )
  212. foreach ( string assembly in this.Assemblies )
  213. package.Assemblies.Add( assembly );
  214. if ( this.BasePathSpecified || this.PrivateBinPathSpecified || this.ConfigurationFileSpecified )
  215. {
  216. package.BasePath = this.BasePath;
  217. package.PrivateBinPath = this.PrivateBinPath;
  218. package.ConfigurationFile = this.ConfigurationFile;
  219. }
  220. package.AutoBinPath = this.BinPathType == BinPathType.Auto;
  221. if (this.RuntimeFramework != null)
  222. package.Settings["RuntimeFramework"] = this.RuntimeFramework;
  223. if (project.ProcessModel != ProcessModel.Default)
  224. package.Settings["ProcessModel"] = project.ProcessModel;
  225. if (project.DomainUsage != DomainUsage.Default)
  226. package.Settings["DomainUsage"] = project.DomainUsage;
  227. return package;
  228. }
  229. private void assemblies_Changed( object sender, EventArgs e )
  230. {
  231. NotifyProjectOfChange();
  232. }
  233. private void NotifyProjectOfChange()
  234. {
  235. if (project != null)
  236. {
  237. project.IsDirty = true;
  238. if (ReferenceEquals(this, project.ActiveConfig))
  239. project.HasChangesRequiringReload = true;
  240. }
  241. }
  242. }
  243. }