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
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 '***********************************************************************************/
32 using System
.Collections
;
38 public enum BinPathType
45 public class ProjectConfig
47 #region Instance Variables
50 /// The name of this config
55 /// IProject interface of containing project
57 protected NUnitProject project
= null;
60 /// Mark this config as changed
62 private bool isDirty
= false;
65 /// List of the names of the assemblies
67 private AssemblyList assemblies
;
70 /// Base path specific to this configuration
72 private string basePath
;
75 /// Our configuration file, if specified
77 private string configFile
;
80 /// Private bin path, if specified
82 private string binPath
;
85 /// True if assembly paths should be added to bin path
87 private BinPathType binPathType
= BinPathType
.Auto
;
93 public ProjectConfig()
95 this.assemblies
= new AssemblyList( this );
98 public ProjectConfig( string name
)
101 this.assemblies
= new AssemblyList( this );
106 #region Properties and Events
108 public NUnitProject Project
110 get { return project; }
111 set { project = value; }
116 get { return isDirty; }
123 if ( Changed
!= null )
124 Changed( this, EventArgs
.Empty
);
142 public event EventHandler Changed
;
145 /// The base directory for this config - used
146 /// as the application base for loading tests.
148 public string BasePath
152 if ( project
== null || project
.BasePath
== null )
155 if ( basePath
== null )
156 return project
.BasePath
;
158 return Path
.Combine( project
.BasePath
, basePath
);
162 if ( BasePath
!= value )
171 /// The base path relative to the project base
173 public string RelativeBasePath
177 if ( project
== null || basePath
== null || !Path
.IsPathRooted( basePath
) )
180 return ProjectPath
.RelativePath( project
.BasePath
, basePath
);
184 public string ConfigurationFile
188 return configFile
== null && project
!= null
189 ? project
.ConfigurationFile
194 if ( ConfigurationFile
!= value )
202 public string ConfigurationFilePath
206 return BasePath
!= null && ConfigurationFile
!= null
207 ? Path
.Combine( BasePath
, ConfigurationFile
)
213 /// The semicolon-separated path containing all the
214 /// assemblies in the list.
216 public string PrivateBinPath
220 switch( binPathType
)
222 case BinPathType
.Manual
:
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
) )
241 return sb
.Length
== 0 ? null : sb
.ToString();
250 if ( binPath
!= value )
253 binPathType
= binPath
== null ? BinPathType
.Auto
: BinPathType
.Manual
;
260 /// How our PrivateBinPath is generated
262 public BinPathType BinPathType
264 get { return binPathType; }
267 if ( binPathType
!= value )
276 /// Return our AssemblyList
278 public AssemblyList Assemblies
280 get { return assemblies; }
284 /// Return a string array with the absolute paths of all assemblies
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) );
298 /// Return a string array with the relative paths of all
299 /// assemblies from the configuration BasePath.
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) );
313 /// Return a string array with the absolute paths of all
314 /// assemblies that have tests
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) );
332 public string RelativePathTo( string path
)
334 return ProjectPath
.RelativePath( BasePath
, path
);