(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / nunit20 / util / ProjectConfig.cs
blobaac3f733f4d3bea41d8d5b852836260488c23d79
1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
4 ' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright 2000-2002 Philip A. Craig
7 ' This software is provided 'as-is', without any express or implied warranty. In no
8 ' event will the authors be held liable for any damages arising from the use of this
9 ' software.
11 ' Permission is granted to anyone to use this software for any purpose, including
12 ' commercial applications, and to alter it and redistribute it freely, subject to the
13 ' following restrictions:
15 ' 1. The origin of this software must not be misrepresented; you must not claim that
16 ' you wrote the original software. If you use this software in a product, an
17 ' acknowledgment (see the following) in the product documentation is required.
19 ' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright 2000-2002 Philip A. Craig
22 ' 2. Altered source versions must be plainly marked as such, and must not be
23 ' misrepresented as being the original software.
25 ' 3. This notice may not be removed or altered from any source distribution.
27 '***********************************************************************************/
28 #endregion
30 using System;
31 using System.Text;
32 using System.Collections;
33 using System.IO;
34 using NUnit.Core;
36 namespace NUnit.Util
38 public enum BinPathType
40 Auto,
41 Manual,
42 None
45 public class ProjectConfig
47 #region Instance Variables
49 /// <summary>
50 /// The name of this config
51 /// </summary>
52 private string name;
54 /// <summary>
55 /// IProject interface of containing project
56 /// </summary>
57 protected NUnitProject project = null;
59 /// <summary>
60 /// Mark this config as changed
61 /// </summary>
62 private bool isDirty = false;
64 /// <summary>
65 /// List of the names of the assemblies
66 /// </summary>
67 private AssemblyList assemblies;
69 /// <summary>
70 /// Base path specific to this configuration
71 /// </summary>
72 private string basePath;
74 /// <summary>
75 /// Our configuration file, if specified
76 /// </summary>
77 private string configFile;
79 /// <summary>
80 /// Private bin path, if specified
81 /// </summary>
82 private string binPath;
84 /// <summary>
85 /// True if assembly paths should be added to bin path
86 /// </summary>
87 private BinPathType binPathType = BinPathType.Auto;
89 #endregion
91 #region Construction
93 public ProjectConfig()
95 this.assemblies = new AssemblyList( this );
98 public ProjectConfig( string name )
100 this.name = name;
101 this.assemblies = new AssemblyList( this );
104 #endregion
106 #region Properties and Events
108 public NUnitProject Project
110 get { return project; }
111 set { project = value; }
114 public bool IsDirty
116 get { return isDirty; }
117 set
119 isDirty = value;
121 if ( isDirty )
123 if ( Changed != null )
124 Changed( this, EventArgs.Empty );
129 public string Name
131 get { return name; }
132 set
134 if ( name != value )
136 name = value;
137 IsDirty = true;
142 public event EventHandler Changed;
144 /// <summary>
145 /// The base directory for this config - used
146 /// as the application base for loading tests.
147 /// </summary>
148 public string BasePath
152 if ( project == null || project.BasePath == null )
153 return basePath;
155 if ( basePath == null )
156 return project.BasePath;
158 return Path.Combine( project.BasePath, basePath );
160 set
162 if ( BasePath != value )
164 basePath = value;
165 IsDirty = true;
170 /// <summary>
171 /// The base path relative to the project base
172 /// </summary>
173 public string RelativeBasePath
177 if ( project == null || basePath == null || !Path.IsPathRooted( basePath ) )
178 return basePath;
180 return ProjectPath.RelativePath( project.BasePath, basePath );
184 public string ConfigurationFile
186 get
188 return configFile == null && project != null
189 ? project.ConfigurationFile
190 : configFile;
194 if ( ConfigurationFile != value )
196 configFile = value;
197 IsDirty = true;
202 public string ConfigurationFilePath
206 return BasePath != null && ConfigurationFile != null
207 ? Path.Combine( BasePath, ConfigurationFile )
208 : ConfigurationFile;
212 /// <summary>
213 /// The semicolon-separated path containing all the
214 /// assemblies in the list.
215 /// </summary>
216 public string PrivateBinPath
220 switch( binPathType )
222 case BinPathType.Manual:
223 return binPath;
225 case BinPathType.Auto:
226 StringBuilder sb = new StringBuilder(200);
227 ArrayList dirList = new ArrayList();
229 foreach( AssemblyListItem assembly in Assemblies )
231 string dir = ProjectPath.RelativePath( BasePath, Path.GetDirectoryName( assembly.FullPath ) );
232 if ( dir != null && dir != "." && !dirList.Contains( dir ) )
234 dirList.Add( dir );
235 if ( sb.Length > 0 )
236 sb.Append( ';' );
237 sb.Append( dir );
241 return sb.Length == 0 ? null : sb.ToString();
243 default:
244 return null;
250 if ( binPath != value )
252 binPath = value;
253 binPathType = binPath == null ? BinPathType.Auto : BinPathType.Manual;
254 IsDirty = true;
259 /// <summary>
260 /// How our PrivateBinPath is generated
261 /// </summary>
262 public BinPathType BinPathType
264 get { return binPathType; }
265 set
267 if ( binPathType != value )
269 binPathType = value;
270 IsDirty = true;
275 /// <summary>
276 /// Return our AssemblyList
277 /// </summary>
278 public AssemblyList Assemblies
280 get { return assemblies; }
283 /// <summary>
284 /// Return a string array with the absolute paths of all assemblies
285 /// </summary>
286 public string[] AbsolutePaths
290 ArrayList paths = new ArrayList();
291 foreach( AssemblyListItem assembly in assemblies )
292 paths.Add( assembly.FullPath );
293 return (string[])paths.ToArray( typeof(string) );
297 /// <summary>
298 /// Return a string array with the relative paths of all
299 /// assemblies from the configuration BasePath.
300 /// </summary>
301 public string[] RelativePaths
305 ArrayList paths = new ArrayList();
306 foreach( AssemblyListItem assembly in Assemblies )
307 paths.Add( ProjectPath.RelativePath( BasePath, assembly.FullPath ) );
308 return (string[])paths.ToArray( typeof(string) );
312 /// <summary>
313 /// Return a string array with the absolute paths of all
314 /// assemblies that have tests
315 /// </summary>
316 public string[] TestAssemblies
320 ArrayList paths = new ArrayList();
321 foreach( AssemblyListItem assembly in Assemblies )
322 if ( assembly.HasTests )
323 paths.Add( assembly.FullPath );
324 return (string[])paths.ToArray( typeof(string) );
328 #endregion
330 #region Methods
332 public string RelativePathTo( string path )
334 return ProjectPath.RelativePath( BasePath, path );
337 #endregion