retag
[mcs.git] / nunit24 / ClientUtilities / util / ProjectConfig.cs
blobceaaa924fc075f146720b7fc374d9a9b908b2004
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/?p=license&r=2.4.
5 // ****************************************************************
7 using System;
8 using System.Text;
9 using System.Collections;
10 using System.IO;
11 using NUnit.Core;
13 namespace NUnit.Util
15 public enum BinPathType
17 Auto,
18 Manual,
19 None
22 public class ProjectConfig
24 #region Instance Variables
26 /// <summary>
27 /// The name of this config
28 /// </summary>
29 private string name;
31 /// <summary>
32 /// IProject interface of containing project
33 /// </summary>
34 protected NUnitProject project = null;
36 /// <summary>
37 /// List of the names of the assemblies
38 /// </summary>
39 private AssemblyList assemblies;
41 /// <summary>
42 /// Base path specific to this configuration
43 /// </summary>
44 private string basePath;
46 /// <summary>
47 /// Our configuration file, if specified
48 /// </summary>
49 private string configFile;
51 /// <summary>
52 /// Private bin path, if specified
53 /// </summary>
54 private string binPath;
56 /// <summary>
57 /// True if assembly paths should be added to bin path
58 /// </summary>
59 private BinPathType binPathType = BinPathType.Auto;
61 #endregion
63 #region Constructor
64 public ProjectConfig( string name )
66 this.name = name;
67 this.assemblies = new AssemblyList();
68 assemblies.Changed += new EventHandler( assemblies_Changed );
70 #endregion
72 #region Properties and Events
74 public event EventHandler Changed;
76 public NUnitProject Project
78 // get { return project; }
79 set { project = value; }
82 public string Name
84 get { return name; }
85 set
87 if ( name != value )
89 name = value;
90 FireChangedEvent();
95 private bool BasePathSpecified
97 get
99 return project.BasePathSpecified || this.basePath != null && this.basePath != "";
103 /// <summary>
104 /// The base directory for this config - used
105 /// as the application base for loading tests.
106 /// </summary>
107 public string BasePath
111 if ( project == null || project.BasePath == null )
112 return basePath;
114 if ( basePath == null )
115 return project.BasePath;
117 return Path.Combine( project.BasePath, basePath );
119 set
121 if ( BasePath != value )
123 basePath = value;
124 FireChangedEvent();
129 /// <summary>
130 /// The base path relative to the project base
131 /// </summary>
132 public string RelativeBasePath
136 if ( project == null || basePath == null || !Path.IsPathRooted( basePath ) )
137 return basePath;
139 return PathUtils.RelativePath( project.BasePath, basePath );
143 private bool ConfigurationFileSpecified
145 get { return configFile != null; }
148 public string ConfigurationFile
150 get
152 return configFile == null && project != null
153 ? project.ConfigurationFile
154 : configFile;
158 if ( ConfigurationFile != value )
160 configFile = value;
161 FireChangedEvent();
166 public string ConfigurationFilePath
170 return BasePath != null && ConfigurationFile != null
171 ? Path.Combine( BasePath, ConfigurationFile )
172 : ConfigurationFile;
176 private bool PrivateBinPathSpecified
178 get { return binPath != null; }
181 /// <summary>
182 /// The Path.PathSeparator-separated path containing all the
183 /// assemblies in the list.
184 /// </summary>
185 public string PrivateBinPath
187 get { return binPath; }
190 if ( binPath != value )
192 binPath = value;
193 binPathType = binPath == null ? BinPathType.Auto : BinPathType.Manual;
194 FireChangedEvent();
199 /// <summary>
200 /// How our PrivateBinPath is generated
201 /// </summary>
202 public BinPathType BinPathType
204 get { return binPathType; }
205 set
207 if ( binPathType != value )
209 binPathType = value;
210 FireChangedEvent();
215 /// <summary>
216 /// Return our AssemblyList
217 /// </summary>
218 public AssemblyList Assemblies
220 get { return assemblies; }
222 #endregion
224 public TestPackage MakeTestPackage()
226 TestPackage package = new TestPackage( project.ProjectPath );
228 if ( !project.IsAssemblyWrapper )
229 foreach ( string assembly in this.Assemblies )
230 package.Assemblies.Add( assembly );
232 if ( this.BasePathSpecified || this.PrivateBinPathSpecified || this.ConfigurationFileSpecified )
234 package.BasePath = this.BasePath;
235 package.PrivateBinPath = this.PrivateBinPath;
236 package.ConfigurationFile = this.ConfigurationFile;
239 package.AutoBinPath = this.BinPathType == BinPathType.Auto;
241 return package;
244 private void assemblies_Changed( object sender, EventArgs e )
246 FireChangedEvent();
249 private void FireChangedEvent()
251 if ( Changed != null )
252 Changed( this, EventArgs.Empty );