aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Targets/NAntTarget.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Targets/NAntTarget.cs')
-rw-r--r--Prebuild/src/Core/Targets/NAntTarget.cs738
1 files changed, 0 insertions, 738 deletions
diff --git a/Prebuild/src/Core/Targets/NAntTarget.cs b/Prebuild/src/Core/Targets/NAntTarget.cs
deleted file mode 100644
index 9a6ee17..0000000
--- a/Prebuild/src/Core/Targets/NAntTarget.cs
+++ /dev/null
@@ -1,738 +0,0 @@
1#region BSD License
2/*
3Copyright (c) 2004 - 2008
4Matthew Holmes (matthew@wildfiregames.com),
5Dan Moorehead (dan05a@gmail.com),
6C.J. Adams-Collier (cjac@colliertech.org),
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are
10met:
11
12* Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15* Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18
19* The name of the author may not be used to endorse or promote
20 products derived from this software without specific prior written
21 permission.
22
23THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#endregion
37
38using System;
39using System.Collections;
40using System.Collections.Specialized;
41using System.IO;
42using System.Reflection;
43using System.Text.RegularExpressions;
44
45using Prebuild.Core.Attributes;
46using Prebuild.Core.Interfaces;
47using Prebuild.Core.Nodes;
48using Prebuild.Core.Utilities;
49
50namespace Prebuild.Core.Targets
51{
52 /// <summary>
53 ///
54 /// </summary>
55 [Target("nant")]
56 public class NAntTarget : ITarget
57 {
58 #region Fields
59
60 private Kernel m_Kernel;
61
62 #endregion
63
64 #region Private Methods
65
66 private static string PrependPath(string path)
67 {
68 string tmpPath = Helper.NormalizePath(path, '/');
69 Regex regex = new Regex(@"(\w):/(\w+)");
70 Match match = regex.Match(tmpPath);
71 //if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
72 //{
73 tmpPath = Helper.NormalizePath(tmpPath);
74 //}
75 // else
76 // {
77 // tmpPath = Helper.NormalizePath("./" + tmpPath);
78 // }
79
80 return tmpPath;
81 }
82
83 private static string BuildReference(SolutionNode solution, ProjectNode currentProject, ReferenceNode refr)
84 {
85
86 if (!String.IsNullOrEmpty(refr.Path))
87 {
88 return refr.Path;
89 }
90
91 if (solution.ProjectsTable.ContainsKey(refr.Name))
92 {
93 ProjectNode projectRef = (ProjectNode) solution.ProjectsTable[refr.Name];
94 string finalPath =
95 Helper.NormalizePath(refr.Name + GetProjectExtension(projectRef), '/');
96 return finalPath;
97 }
98
99 ProjectNode project = (ProjectNode) refr.Parent;
100
101 // Do we have an explicit file reference?
102 string fileRef = FindFileReference(refr.Name, project);
103 if (fileRef != null)
104 {
105 return fileRef;
106 }
107
108 // Is there an explicit path in the project ref?
109 if (refr.Path != null)
110 {
111 return Helper.NormalizePath(refr.Path + "/" + refr.Name + GetProjectExtension(project), '/');
112 }
113
114 // No, it's an extensionless GAC ref, but nant needs the .dll extension anyway
115 return refr.Name + ".dll";
116 }
117
118 public static string GetRefFileName(string refName)
119 {
120 if (ExtensionSpecified(refName))
121 {
122 return refName;
123 }
124 else
125 {
126 return refName + ".dll";
127 }
128 }
129
130 private static bool ExtensionSpecified(string refName)
131 {
132 return refName.EndsWith(".dll") || refName.EndsWith(".exe");
133 }
134
135 private static string GetProjectExtension(ProjectNode project)
136 {
137 string extension = ".dll";
138 if (project.Type == ProjectType.Exe || project.Type == ProjectType.WinExe)
139 {
140 extension = ".exe";
141 }
142 return extension;
143 }
144
145 private static string FindFileReference(string refName, ProjectNode project)
146 {
147 foreach (ReferencePathNode refPath in project.ReferencePaths)
148 {
149 string fullPath = Helper.MakeFilePath(refPath.Path, refName);
150
151 if (File.Exists(fullPath))
152 {
153 return fullPath;
154 }
155
156 fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
157
158 if (File.Exists(fullPath))
159 {
160 return fullPath;
161 }
162
163 fullPath = Helper.MakeFilePath(refPath.Path, refName, "exe");
164
165 if (File.Exists(fullPath))
166 {
167 return fullPath;
168 }
169 }
170
171 return null;
172 }
173
174 /// <summary>
175 /// Gets the XML doc file.
176 /// </summary>
177 /// <param name="project">The project.</param>
178 /// <param name="conf">The conf.</param>
179 /// <returns></returns>
180 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
181 {
182 if (conf == null)
183 {
184 throw new ArgumentNullException("conf");
185 }
186 if (project == null)
187 {
188 throw new ArgumentNullException("project");
189 }
190 string docFile = (string)conf.Options["XmlDocFile"];
191 // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
192 // {
193 // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
194 // }
195 return docFile;
196 }
197
198 private void WriteProject(SolutionNode solution, ProjectNode project)
199 {
200 string projFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build");
201 StreamWriter ss = new StreamWriter(projFile);
202
203 m_Kernel.CurrentWorkingDirectory.Push();
204 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
205 bool hasDoc = false;
206
207 using (ss)
208 {
209 ss.WriteLine("<?xml version=\"1.0\" ?>");
210 ss.WriteLine("<project name=\"{0}\" default=\"build\">", project.Name);
211 ss.WriteLine(" <target name=\"{0}\">", "build");
212 ss.WriteLine(" <echo message=\"Build Directory is ${project::get-base-directory()}/${build.dir}\" />");
213 ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/${build.dir}\" />");
214 ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/${build.dir}\" flatten=\"true\">");
215 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
216 foreach (ReferenceNode refr in project.References)
217 {
218 if (refr.LocalCopy)
219 {
220 ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)) + "\" />", '/'));
221 }
222 }
223
224 ss.WriteLine(" </fileset>");
225 ss.WriteLine(" </copy>");
226 if (project.ConfigFile != null && project.ConfigFile.Length!=0)
227 {
228 ss.Write(" <copy file=\"" + project.ConfigFile + "\" tofile=\"${project::get-base-directory()}/${build.dir}/${project::get-name()}");
229
230 if (project.Type == ProjectType.Library)
231 {
232 ss.Write(".dll.config\"");
233 }
234 else
235 {
236 ss.Write(".exe.config\"");
237 }
238 ss.WriteLine(" />");
239 }
240
241 // Add the content files to just be copied
242 ss.WriteLine(" {0}", "<copy todir=\"${project::get-base-directory()}/${build.dir}\">");
243 ss.WriteLine(" {0}", "<fileset basedir=\".\">");
244
245 foreach (string file in project.Files)
246 {
247 // Ignore if we aren't content
248 if (project.Files.GetBuildAction(file) != BuildAction.Content)
249 continue;
250
251 // Create a include tag
252 ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
253 }
254
255 ss.WriteLine(" {0}", "</fileset>");
256 ss.WriteLine(" {0}", "</copy>");
257
258 ss.Write(" <csc");
259 ss.Write(" target=\"{0}\"", project.Type.ToString().ToLower());
260 ss.Write(" debug=\"{0}\"", "${build.debug}");
261 foreach (ConfigurationNode conf in project.Configurations)
262 {
263 if (conf.Options.KeyFile != "")
264 {
265 ss.Write(" keyfile=\"{0}\"", conf.Options.KeyFile);
266 break;
267 }
268 }
269 foreach (ConfigurationNode conf in project.Configurations)
270 {
271 ss.Write(" unsafe=\"{0}\"", conf.Options.AllowUnsafe);
272 break;
273 }
274 foreach (ConfigurationNode conf in project.Configurations)
275 {
276 ss.Write(" warnaserror=\"{0}\"", conf.Options.WarningsAsErrors);
277 break;
278 }
279 foreach (ConfigurationNode conf in project.Configurations)
280 {
281 ss.Write(" define=\"{0}\"", conf.Options.CompilerDefines);
282 break;
283 }
284 foreach (ConfigurationNode conf in project.Configurations)
285 {
286 ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]);
287 break;
288 }
289
290 ss.Write(" main=\"{0}\"", project.StartupObject);
291
292 foreach (ConfigurationNode conf in project.Configurations)
293 {
294 if (GetXmlDocFile(project, conf) != "")
295 {
296 ss.Write(" doc=\"{0}\"", "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile(project, conf));
297 hasDoc = true;
298 }
299 break;
300 }
301 ss.Write(" output=\"{0}", "${project::get-base-directory()}/${build.dir}/${project::get-name()}");
302 if (project.Type == ProjectType.Library)
303 {
304 ss.Write(".dll\"");
305 }
306 else
307 {
308 ss.Write(".exe\"");
309 }
310 if (project.AppIcon != null && project.AppIcon.Length != 0)
311 {
312 ss.Write(" win32icon=\"{0}\"", Helper.NormalizePath(project.AppIcon, '/'));
313 }
314 ss.WriteLine(">");
315 ss.WriteLine(" <resources prefix=\"{0}\" dynamicprefix=\"true\" >", project.RootNamespace);
316 foreach (string file in project.Files)
317 {
318 switch (project.Files.GetBuildAction(file))
319 {
320 case BuildAction.EmbeddedResource:
321 ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
322 break;
323 default:
324 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
325 {
326 ss.WriteLine(" <include name=\"{0}\" />", file.Substring(0, file.LastIndexOf('.')) + ".resx");
327 }
328 break;
329 }
330 }
331 //if (project.Files.GetSubType(file).ToString() != "Code")
332 //{
333 // ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
334
335 ss.WriteLine(" </resources>");
336 ss.WriteLine(" <sources failonempty=\"true\">");
337 foreach (string file in project.Files)
338 {
339 switch (project.Files.GetBuildAction(file))
340 {
341 case BuildAction.Compile:
342 ss.WriteLine(" <include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
343 break;
344 default:
345 break;
346 }
347 }
348 ss.WriteLine(" </sources>");
349 ss.WriteLine(" <references basedir=\"${project::get-base-directory()}\">");
350 ss.WriteLine(" <lib>");
351 ss.WriteLine(" <include name=\"${project::get-base-directory()}\" />");
352 foreach(ReferencePathNode refPath in project.ReferencePaths)
353 {
354 ss.WriteLine(" <include name=\"${project::get-base-directory()}/" + refPath.Path.TrimEnd('/', '\\') + "\" />");
355 }
356 ss.WriteLine(" </lib>");
357 foreach (ReferenceNode refr in project.References)
358 {
359 string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)), '/');
360 ss.WriteLine(" <include name=\"" + path + "\" />");
361 }
362 ss.WriteLine(" </references>");
363
364 ss.WriteLine(" </csc>");
365
366 foreach (ConfigurationNode conf in project.Configurations)
367 {
368 if (!String.IsNullOrEmpty(conf.Options.OutputPath))
369 {
370 string targetDir = Helper.NormalizePath(conf.Options.OutputPath, '/');
371
372 ss.WriteLine(" <echo message=\"Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/" + targetDir + "\" />");
373
374 ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/" + targetDir + "\"/>");
375
376 ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/" + targetDir + "\">");
377 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}/${build.dir}/\" >");
378 ss.WriteLine(" <include name=\"*.dll\"/>");
379 ss.WriteLine(" <include name=\"*.exe\"/>");
380 ss.WriteLine(" <include name=\"*.mdb\" if='${build.debug}'/>");
381 ss.WriteLine(" <include name=\"*.pdb\" if='${build.debug}'/>");
382 ss.WriteLine(" </fileset>");
383 ss.WriteLine(" </copy>");
384 break;
385 }
386 }
387
388 ss.WriteLine(" </target>");
389
390 ss.WriteLine(" <target name=\"clean\">");
391 ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />");
392 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
393 ss.WriteLine(" </target>");
394
395 ss.WriteLine(" <target name=\"doc\" description=\"Creates documentation.\">");
396 if (hasDoc)
397 {
398 ss.WriteLine(" <property name=\"doc.target\" value=\"\" />");
399 ss.WriteLine(" <if test=\"${platform::is-unix()}\">");
400 ss.WriteLine(" <property name=\"doc.target\" value=\"Web\" />");
401 ss.WriteLine(" </if>");
402 ss.WriteLine(" <ndoc failonerror=\"false\" verbose=\"true\">");
403 ss.WriteLine(" <assemblies basedir=\"${project::get-base-directory()}\">");
404 ss.Write(" <include name=\"${build.dir}/${project::get-name()}");
405 if (project.Type == ProjectType.Library)
406 {
407 ss.WriteLine(".dll\" />");
408 }
409 else
410 {
411 ss.WriteLine(".exe\" />");
412 }
413
414 ss.WriteLine(" </assemblies>");
415 ss.WriteLine(" <summaries basedir=\"${project::get-base-directory()}\">");
416 ss.WriteLine(" <include name=\"${build.dir}/${project::get-name()}.xml\"/>");
417 ss.WriteLine(" </summaries>");
418 ss.WriteLine(" <referencepaths basedir=\"${project::get-base-directory()}\">");
419 ss.WriteLine(" <include name=\"${build.dir}\" />");
420 // foreach(ReferenceNode refr in project.References)
421 // {
422 // string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/');
423 // if (path != "")
424 // {
425 // ss.WriteLine(" <include name=\"{0}\" />", path);
426 // }
427 // }
428 ss.WriteLine(" </referencepaths>");
429 ss.WriteLine(" <documenters>");
430 ss.WriteLine(" <documenter name=\"MSDN\">");
431 ss.WriteLine(" <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />");
432 ss.WriteLine(" <property name=\"OutputTarget\" value=\"${doc.target}\" />");
433 ss.WriteLine(" <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />");
434 ss.WriteLine(" <property name=\"IncludeFavorites\" value=\"False\" />");
435 ss.WriteLine(" <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />");
436 ss.WriteLine(" <property name=\"SplitTOCs\" value=\"False\" />");
437 ss.WriteLine(" <property name=\"DefaulTOC\" value=\"\" />");
438 ss.WriteLine(" <property name=\"ShowVisualBasic\" value=\"True\" />");
439 ss.WriteLine(" <property name=\"AutoDocumentConstructors\" value=\"True\" />");
440 ss.WriteLine(" <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />");
441 ss.WriteLine(" <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />");
442 ss.WriteLine(" <property name=\"ShowMissingParams\" value=\"${build.debug}\" />");
443 ss.WriteLine(" <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />");
444 ss.WriteLine(" <property name=\"ShowMissingValues\" value=\"${build.debug}\" />");
445 ss.WriteLine(" <property name=\"DocumentInternals\" value=\"False\" />");
446 ss.WriteLine(" <property name=\"DocumentPrivates\" value=\"False\" />");
447 ss.WriteLine(" <property name=\"DocumentProtected\" value=\"True\" />");
448 ss.WriteLine(" <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />");
449 ss.WriteLine(" <property name=\"IncludeAssemblyVersion\" value=\"True\" />");
450 ss.WriteLine(" </documenter>");
451 ss.WriteLine(" </documenters>");
452 ss.WriteLine(" </ndoc>");
453 }
454 ss.WriteLine(" </target>");
455 ss.WriteLine("</project>");
456 }
457 m_Kernel.CurrentWorkingDirectory.Pop();
458 }
459
460 private void WriteCombine(SolutionNode solution)
461 {
462 m_Kernel.Log.Write("Creating NAnt build files");
463 foreach (ProjectNode project in solution.Projects)
464 {
465 if (m_Kernel.AllowProject(project.FilterGroups))
466 {
467 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
468 WriteProject(solution, project);
469 }
470 }
471
472 m_Kernel.Log.Write("");
473 string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
474 StreamWriter ss = new StreamWriter(combFile);
475
476 m_Kernel.CurrentWorkingDirectory.Push();
477 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
478
479 using (ss)
480 {
481 ss.WriteLine("<?xml version=\"1.0\" ?>");
482 ss.WriteLine("<project name=\"{0}\" default=\"build\">", solution.Name);
483 ss.WriteLine(" <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>");
484 ss.WriteLine();
485
486 //ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />");
487 //ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />");
488 ss.WriteLine(" <property name=\"bin.dir\" value=\"bin\" />");
489 ss.WriteLine(" <property name=\"obj.dir\" value=\"obj\" />");
490 ss.WriteLine(" <property name=\"doc.dir\" value=\"doc\" />");
491 ss.WriteLine(" <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />");
492
493 // actually use active config out of prebuild.xml
494 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", solution.ActiveConfig);
495
496 foreach (ConfigurationNode conf in solution.Configurations)
497 {
498 ss.WriteLine();
499 ss.WriteLine(" <target name=\"{0}\" description=\"\">", conf.Name);
500 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name);
501 ss.WriteLine(" <property name=\"build.debug\" value=\"{0}\" />", conf.Options["DebugInformation"].ToString().ToLower());
502 ss.WriteLine(" </target>");
503 ss.WriteLine();
504 }
505
506 ss.WriteLine(" <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">");
507 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />");
508 ss.WriteLine(" </target>");
509 ss.WriteLine();
510
511 ss.WriteLine(" <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">");
512 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />");
513 ss.WriteLine(" </target>");
514 ss.WriteLine();
515
516 ss.WriteLine(" <target name=\"net-3.5\" description=\"Sets framework to .NET 3.5\">");
517 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-3.5\" />");
518 ss.WriteLine(" </target>");
519 ss.WriteLine();
520
521 ss.WriteLine(" <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">");
522 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />");
523 ss.WriteLine(" </target>");
524 ss.WriteLine();
525
526 ss.WriteLine(" <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">");
527 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />");
528 ss.WriteLine(" </target>");
529 ss.WriteLine();
530
531 ss.WriteLine(" <target name=\"mono-3.5\" description=\"Sets framework to mono 3.5\">");
532 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-3.5\" />");
533 ss.WriteLine(" </target>");
534 ss.WriteLine();
535
536 ss.WriteLine(" <target name=\"init\" description=\"\">");
537 ss.WriteLine(" <call target=\"${project.config}\" />");
538 ss.WriteLine(" <property name=\"sys.os.platform\"");
539 ss.WriteLine(" value=\"${platform::get-name()}\"");
540 ss.WriteLine(" />");
541 ss.WriteLine(" <echo message=\"Platform ${sys.os.platform}\" />");
542 ss.WriteLine(" <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />");
543 ss.WriteLine(" </target>");
544 ss.WriteLine();
545
546
547 // sdague - ok, this is an ugly hack, but what it lets
548 // us do is native include of files into the nant
549 // created files from all .nant/*include files. This
550 // lets us keep using prebuild, but allows for
551 // extended nant targets to do build and the like.
552
553 try
554 {
555 Regex re = new Regex(".include$");
556 DirectoryInfo nantdir = new DirectoryInfo(".nant");
557 foreach (FileSystemInfo item in nantdir.GetFileSystemInfos())
558 {
559 if (item is DirectoryInfo) { }
560 else if (item is FileInfo)
561 {
562 if (re.Match(((FileInfo)item).FullName) !=
563 System.Text.RegularExpressions.Match.Empty)
564 {
565 Console.WriteLine("Including file: " + ((FileInfo)item).FullName);
566
567 using (FileStream fs = new FileStream(((FileInfo)item).FullName,
568 FileMode.Open,
569 FileAccess.Read,
570 FileShare.None))
571 {
572 using (StreamReader sr = new StreamReader(fs))
573 {
574 ss.WriteLine("<!-- included from {0} -->", ((FileInfo)item).FullName);
575 while (sr.Peek() != -1)
576 {
577 ss.WriteLine(sr.ReadLine());
578 }
579 ss.WriteLine();
580 }
581 }
582 }
583 }
584 }
585 }
586 catch { }
587 // ss.WriteLine(" <include buildfile=\".nant/local.include\" />");
588 // ss.WriteLine(" <target name=\"zip\" description=\"\">");
589 // ss.WriteLine(" <zip zipfile=\"{0}-{1}.zip\">", solution.Name, solution.Version);
590 // ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
591
592 // ss.WriteLine(" <include name=\"${project::get-base-directory()}/**/*.cs\" />");
593 // // ss.WriteLine(" <include name=\"${project.main.dir}/**/*\" />");
594 // ss.WriteLine(" </fileset>");
595 // ss.WriteLine(" </zip>");
596 // ss.WriteLine(" <echo message=\"Building zip target\" />");
597 // ss.WriteLine(" </target>");
598 ss.WriteLine();
599
600
601 ss.WriteLine(" <target name=\"clean\" description=\"\">");
602 ss.WriteLine(" <echo message=\"Deleting all builds from all configurations\" />");
603 //ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />");
604 ss.WriteLine(" <delete failonerror=\"false\">");
605 ss.WriteLine(" <fileset basedir=\"${bin.dir}\">");
606 ss.WriteLine(" <include name=\"OpenSim*.dll\"/>");
607 ss.WriteLine(" <include name=\"OpenSim*.exe\"/>");
608 ss.WriteLine(" <include name=\"ScriptEngines/*\"/>");
609 ss.WriteLine(" <include name=\"Physics/*\"/>");
610 ss.WriteLine(" <exclude name=\"OpenSim.32BitLaunch.exe\"/>");
611 ss.WriteLine(" <exclude name=\"ScriptEngines/Default.lsl\"/>");
612 ss.WriteLine(" </fileset>");
613 ss.WriteLine(" </delete>");
614 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
615 foreach (ProjectNode project in solution.Projects)
616 {
617 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
618 ss.Write(" <nant buildfile=\"{0}\"",
619 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
620 ss.WriteLine(" target=\"clean\" />");
621 }
622 ss.WriteLine(" </target>");
623 ss.WriteLine();
624
625 ss.WriteLine(" <target name=\"build\" depends=\"init\" description=\"\">");
626
627 foreach (ProjectNode project in solution.ProjectsTableOrder)
628 {
629 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
630 ss.Write(" <nant buildfile=\"{0}\"",
631 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
632 ss.WriteLine(" target=\"build\" />");
633 }
634 ss.WriteLine(" </target>");
635 ss.WriteLine();
636
637 ss.WriteLine(" <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />");
638 ss.WriteLine();
639 ss.WriteLine(" <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />");
640 ss.WriteLine();
641 //ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />");
642 ss.WriteLine(" <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />");
643 ss.WriteLine();
644
645 ss.WriteLine(" <target name=\"doc\" depends=\"build-release\">");
646 ss.WriteLine(" <echo message=\"Generating all documentation from all builds\" />");
647 foreach (ProjectNode project in solution.Projects)
648 {
649 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
650 ss.Write(" <nant buildfile=\"{0}\"",
651 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
652 ss.WriteLine(" target=\"doc\" />");
653 }
654 ss.WriteLine(" </target>");
655 ss.WriteLine();
656 ss.WriteLine("</project>");
657 }
658
659 m_Kernel.CurrentWorkingDirectory.Pop();
660 }
661
662 private void CleanProject(ProjectNode project)
663 {
664 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
665 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build");
666 Helper.DeleteIfExists(projectFile);
667 }
668
669 private void CleanSolution(SolutionNode solution)
670 {
671 m_Kernel.Log.Write("Cleaning NAnt build files for", solution.Name);
672
673 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
674 Helper.DeleteIfExists(slnFile);
675
676 foreach (ProjectNode project in solution.Projects)
677 {
678 CleanProject(project);
679 }
680
681 m_Kernel.Log.Write("");
682 }
683
684 #endregion
685
686 #region ITarget Members
687
688 /// <summary>
689 /// Writes the specified kern.
690 /// </summary>
691 /// <param name="kern">The kern.</param>
692 public void Write(Kernel kern)
693 {
694 if (kern == null)
695 {
696 throw new ArgumentNullException("kern");
697 }
698 m_Kernel = kern;
699 foreach (SolutionNode solution in kern.Solutions)
700 {
701 WriteCombine(solution);
702 }
703 m_Kernel = null;
704 }
705
706 /// <summary>
707 /// Cleans the specified kern.
708 /// </summary>
709 /// <param name="kern">The kern.</param>
710 public virtual void Clean(Kernel kern)
711 {
712 if (kern == null)
713 {
714 throw new ArgumentNullException("kern");
715 }
716 m_Kernel = kern;
717 foreach (SolutionNode sol in kern.Solutions)
718 {
719 CleanSolution(sol);
720 }
721 m_Kernel = null;
722 }
723
724 /// <summary>
725 /// Gets the name.
726 /// </summary>
727 /// <value>The name.</value>
728 public string Name
729 {
730 get
731 {
732 return "nant";
733 }
734 }
735
736 #endregion
737 }
738}