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