diff options
author | MW | 2007-05-26 13:40:19 +0000 |
---|---|---|
committer | MW | 2007-05-26 13:40:19 +0000 |
commit | 3436961bb5c01d659d09be134368f4f69460cef9 (patch) | |
tree | 3753ba4d7818df2a6bce0bbe863ff033cdfd568a /Prebuild/src/Core | |
download | opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.zip opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.gz opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.bz2 opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.xz |
Start of rewrite 5279!
Diffstat (limited to 'Prebuild/src/Core')
36 files changed, 10380 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Attributes/DataNodeAttribute.cs b/Prebuild/src/Core/Attributes/DataNodeAttribute.cs new file mode 100644 index 0000000..dbdaf0b --- /dev/null +++ b/Prebuild/src/Core/Attributes/DataNodeAttribute.cs | |||
@@ -0,0 +1,81 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections.Specialized; | ||
37 | |||
38 | namespace Prebuild.Core.Attributes | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] | ||
44 | public sealed class DataNodeAttribute : Attribute | ||
45 | { | ||
46 | #region Fields | ||
47 | |||
48 | private string m_Name = "unknown"; | ||
49 | |||
50 | #endregion | ||
51 | |||
52 | #region Constructors | ||
53 | |||
54 | /// <summary> | ||
55 | /// Initializes a new instance of the <see cref="DataNodeAttribute"/> class. | ||
56 | /// </summary> | ||
57 | /// <param name="name">The name.</param> | ||
58 | public DataNodeAttribute(string name) | ||
59 | { | ||
60 | m_Name = name; | ||
61 | } | ||
62 | |||
63 | #endregion | ||
64 | |||
65 | #region Properties | ||
66 | |||
67 | /// <summary> | ||
68 | /// Gets the name. | ||
69 | /// </summary> | ||
70 | /// <value>The name.</value> | ||
71 | public string Name | ||
72 | { | ||
73 | get | ||
74 | { | ||
75 | return m_Name; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | #endregion | ||
80 | } | ||
81 | } | ||
diff --git a/Prebuild/src/Core/Attributes/OptionNodeAttribute.cs b/Prebuild/src/Core/Attributes/OptionNodeAttribute.cs new file mode 100644 index 0000000..edda56d --- /dev/null +++ b/Prebuild/src/Core/Attributes/OptionNodeAttribute.cs | |||
@@ -0,0 +1,80 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | |||
37 | namespace Prebuild.Core.Attributes | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// | ||
41 | /// </summary> | ||
42 | [AttributeUsage(AttributeTargets.Field)] | ||
43 | public sealed class OptionNodeAttribute : Attribute | ||
44 | { | ||
45 | #region Fields | ||
46 | |||
47 | private string m_NodeName; | ||
48 | |||
49 | #endregion | ||
50 | |||
51 | #region Constructors | ||
52 | |||
53 | /// <summary> | ||
54 | /// Initializes a new instance of the <see cref="OptionNodeAttribute"/> class. | ||
55 | /// </summary> | ||
56 | /// <param name="nodeName">Name of the node.</param> | ||
57 | public OptionNodeAttribute(string nodeName) | ||
58 | { | ||
59 | m_NodeName = nodeName; | ||
60 | } | ||
61 | |||
62 | #endregion | ||
63 | |||
64 | #region Properties | ||
65 | |||
66 | /// <summary> | ||
67 | /// Gets the name of the node. | ||
68 | /// </summary> | ||
69 | /// <value>The name of the node.</value> | ||
70 | public string NodeName | ||
71 | { | ||
72 | get | ||
73 | { | ||
74 | return m_NodeName; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | #endregion | ||
79 | } | ||
80 | } | ||
diff --git a/Prebuild/src/Core/Attributes/TargetAttribute.cs b/Prebuild/src/Core/Attributes/TargetAttribute.cs new file mode 100644 index 0000000..985f180 --- /dev/null +++ b/Prebuild/src/Core/Attributes/TargetAttribute.cs | |||
@@ -0,0 +1,80 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | |||
37 | namespace Prebuild.Core.Attributes | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// | ||
41 | /// </summary> | ||
42 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] | ||
43 | public sealed class TargetAttribute : Attribute | ||
44 | { | ||
45 | #region Fields | ||
46 | |||
47 | private string m_Name; | ||
48 | |||
49 | #endregion | ||
50 | |||
51 | #region Constructors | ||
52 | |||
53 | /// <summary> | ||
54 | /// Initializes a new instance of the <see cref="TargetAttribute"/> class. | ||
55 | /// </summary> | ||
56 | /// <param name="name">The name.</param> | ||
57 | public TargetAttribute(string name) | ||
58 | { | ||
59 | m_Name = name; | ||
60 | } | ||
61 | |||
62 | #endregion | ||
63 | |||
64 | #region Properties | ||
65 | |||
66 | /// <summary> | ||
67 | /// Gets the name. | ||
68 | /// </summary> | ||
69 | /// <value>The name.</value> | ||
70 | public string Name | ||
71 | { | ||
72 | get | ||
73 | { | ||
74 | return m_Name; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | #endregion | ||
79 | } | ||
80 | } | ||
diff --git a/Prebuild/src/Core/FatalException.cs b/Prebuild/src/Core/FatalException.cs new file mode 100644 index 0000000..92aad3d --- /dev/null +++ b/Prebuild/src/Core/FatalException.cs | |||
@@ -0,0 +1,94 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Runtime.Serialization; | ||
37 | |||
38 | namespace Prebuild.Core | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | [Serializable()] | ||
44 | public class FatalException : Exception | ||
45 | { | ||
46 | #region Constructors | ||
47 | |||
48 | |||
49 | /// <summary> | ||
50 | /// Initializes a new instance of the <see cref="FatalException"/> class. | ||
51 | /// </summary> | ||
52 | public FatalException() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | /// <summary> | ||
57 | /// Initializes a new instance of the <see cref="FatalException"/> class. | ||
58 | /// </summary> | ||
59 | /// <param name="format">The format.</param> | ||
60 | /// <param name="args">The args.</param> | ||
61 | public FatalException(string format, params object[] args) | ||
62 | : base(String.Format(format, args)) | ||
63 | { | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// Exception with specified string | ||
68 | /// </summary> | ||
69 | /// <param name="message">Exception message</param> | ||
70 | public FatalException(string message): base(message) | ||
71 | { | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// | ||
76 | /// </summary> | ||
77 | /// <param name="message"></param> | ||
78 | /// <param name="exception"></param> | ||
79 | public FatalException(string message, Exception exception) : base(message, exception) | ||
80 | { | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// | ||
85 | /// </summary> | ||
86 | /// <param name="info"></param> | ||
87 | /// <param name="context"></param> | ||
88 | protected FatalException(SerializationInfo info, StreamingContext context) : base( info, context ) | ||
89 | { | ||
90 | } | ||
91 | |||
92 | #endregion | ||
93 | } | ||
94 | } | ||
diff --git a/Prebuild/src/Core/Interfaces/IDataNode.cs b/Prebuild/src/Core/Interfaces/IDataNode.cs new file mode 100644 index 0000000..0bad97c --- /dev/null +++ b/Prebuild/src/Core/Interfaces/IDataNode.cs | |||
@@ -0,0 +1,56 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Xml; | ||
37 | |||
38 | namespace Prebuild.Core.Interfaces | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | public interface IDataNode | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// Gets or sets the parent. | ||
47 | /// </summary> | ||
48 | /// <value>The parent.</value> | ||
49 | IDataNode Parent { get; set; } | ||
50 | /// <summary> | ||
51 | /// Parses the specified node. | ||
52 | /// </summary> | ||
53 | /// <param name="node">The node.</param> | ||
54 | void Parse(XmlNode node); | ||
55 | } | ||
56 | } | ||
diff --git a/Prebuild/src/Core/Interfaces/ITarget.cs b/Prebuild/src/Core/Interfaces/ITarget.cs new file mode 100644 index 0000000..dac6cd6 --- /dev/null +++ b/Prebuild/src/Core/Interfaces/ITarget.cs | |||
@@ -0,0 +1,60 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | |||
37 | namespace Prebuild.Core.Interfaces | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// | ||
41 | /// </summary> | ||
42 | public interface ITarget | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// Writes the specified kern. | ||
46 | /// </summary> | ||
47 | /// <param name="kern">The kern.</param> | ||
48 | void Write(Kernel kern); | ||
49 | /// <summary> | ||
50 | /// Cleans the specified kern. | ||
51 | /// </summary> | ||
52 | /// <param name="kern">The kern.</param> | ||
53 | void Clean(Kernel kern); | ||
54 | /// <summary> | ||
55 | /// Gets the name. | ||
56 | /// </summary> | ||
57 | /// <value>The name.</value> | ||
58 | string Name { get; } | ||
59 | } | ||
60 | } \ No newline at end of file | ||
diff --git a/Prebuild/src/Core/Kernel.cs b/Prebuild/src/Core/Kernel.cs new file mode 100644 index 0000000..3117e7c --- /dev/null +++ b/Prebuild/src/Core/Kernel.cs | |||
@@ -0,0 +1,758 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: robloach $ | ||
30 | * $Date: 2006-09-26 00:30:53 +0200 (ti, 26 sep 2006) $ | ||
31 | * $Revision: 165 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Diagnostics; | ||
37 | using System.Collections; | ||
38 | using System.Collections.Specialized; | ||
39 | using System.IO; | ||
40 | using System.Reflection; | ||
41 | using System.Xml; | ||
42 | using System.Xml.Schema; | ||
43 | using System.Text; | ||
44 | |||
45 | using Prebuild.Core.Attributes; | ||
46 | using Prebuild.Core.Interfaces; | ||
47 | using Prebuild.Core.Nodes; | ||
48 | using Prebuild.Core.Parse; | ||
49 | using Prebuild.Core.Utilities; | ||
50 | |||
51 | namespace Prebuild.Core | ||
52 | { | ||
53 | /// <summary> | ||
54 | /// | ||
55 | /// </summary> | ||
56 | public class Kernel : IDisposable | ||
57 | { | ||
58 | #region Inner Classes | ||
59 | |||
60 | private struct NodeEntry | ||
61 | { | ||
62 | public Type Type; | ||
63 | public DataNodeAttribute Attribute; | ||
64 | } | ||
65 | |||
66 | #endregion | ||
67 | |||
68 | #region Fields | ||
69 | |||
70 | private static Kernel m_Instance = new Kernel(); | ||
71 | |||
72 | /// <summary> | ||
73 | /// This must match the version of the schema that is embeeded | ||
74 | /// </summary> | ||
75 | private static string m_SchemaVersion = "1.7"; | ||
76 | private static string m_Schema = "prebuild-" + m_SchemaVersion + ".xsd"; | ||
77 | private static string m_SchemaURI = "http://dnpb.sourceforge.net/schemas/" + m_Schema; | ||
78 | bool disposed; | ||
79 | private Version m_Version; | ||
80 | private string m_Revision = ""; | ||
81 | private CommandLineCollection m_CommandLine; | ||
82 | private Log m_Log; | ||
83 | private CurrentDirectory m_CurrentWorkingDirectory; | ||
84 | private XmlSchemaCollection m_Schemas; | ||
85 | |||
86 | private Hashtable m_Targets; | ||
87 | private Hashtable m_Nodes; | ||
88 | |||
89 | ArrayList m_Solutions; | ||
90 | string m_Target; | ||
91 | string m_Clean; | ||
92 | string[] m_RemoveDirectories; | ||
93 | string m_CurrentFile; | ||
94 | bool m_PauseAfterFinish; | ||
95 | string[] m_ProjectGroups; | ||
96 | StringCollection m_Refs; | ||
97 | |||
98 | |||
99 | #endregion | ||
100 | |||
101 | #region Constructors | ||
102 | |||
103 | private Kernel() | ||
104 | { | ||
105 | } | ||
106 | |||
107 | #endregion | ||
108 | |||
109 | #region Properties | ||
110 | |||
111 | /// <summary> | ||
112 | /// Gets a value indicating whether [pause after finish]. | ||
113 | /// </summary> | ||
114 | /// <value><c>true</c> if [pause after finish]; otherwise, <c>false</c>.</value> | ||
115 | public bool PauseAfterFinish | ||
116 | { | ||
117 | get | ||
118 | { | ||
119 | return m_PauseAfterFinish; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// Gets the instance. | ||
125 | /// </summary> | ||
126 | /// <value>The instance.</value> | ||
127 | public static Kernel Instance | ||
128 | { | ||
129 | get | ||
130 | { | ||
131 | return m_Instance; | ||
132 | } | ||
133 | } | ||
134 | |||
135 | /// <summary> | ||
136 | /// Gets the version. | ||
137 | /// </summary> | ||
138 | /// <value>The version.</value> | ||
139 | public string Version | ||
140 | { | ||
141 | get | ||
142 | { | ||
143 | return String.Format("{0}.{1}.{2}{3}", m_Version.Major, m_Version.Minor, m_Version.Build, m_Revision); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | /// <summary> | ||
148 | /// Gets the command line. | ||
149 | /// </summary> | ||
150 | /// <value>The command line.</value> | ||
151 | public CommandLineCollection CommandLine | ||
152 | { | ||
153 | get | ||
154 | { | ||
155 | return m_CommandLine; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | /// <summary> | ||
160 | /// Gets the targets. | ||
161 | /// </summary> | ||
162 | /// <value>The targets.</value> | ||
163 | public Hashtable Targets | ||
164 | { | ||
165 | get | ||
166 | { | ||
167 | return m_Targets; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | /// <summary> | ||
172 | /// Gets the log. | ||
173 | /// </summary> | ||
174 | /// <value>The log.</value> | ||
175 | public Log Log | ||
176 | { | ||
177 | get | ||
178 | { | ||
179 | return m_Log; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// Gets the current working directory. | ||
185 | /// </summary> | ||
186 | /// <value>The current working directory.</value> | ||
187 | public CurrentDirectory CurrentWorkingDirectory | ||
188 | { | ||
189 | get | ||
190 | { | ||
191 | return m_CurrentWorkingDirectory; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | /// <summary> | ||
196 | /// Gets the solutions. | ||
197 | /// </summary> | ||
198 | /// <value>The solutions.</value> | ||
199 | public ArrayList Solutions | ||
200 | { | ||
201 | get | ||
202 | { | ||
203 | return m_Solutions; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | #endregion | ||
208 | |||
209 | #region Private Methods | ||
210 | |||
211 | private void RemoveDirectories(string rootDir, string[] dirNames) | ||
212 | { | ||
213 | foreach(string dir in Directory.GetDirectories(rootDir)) | ||
214 | { | ||
215 | string simpleName = Path.GetFileName(dir); | ||
216 | |||
217 | if(Array.IndexOf(dirNames, simpleName) != -1) | ||
218 | { | ||
219 | //delete if the name matches one of the directory names to delete | ||
220 | string fullDirPath = Path.GetFullPath(dir); | ||
221 | Directory.Delete(fullDirPath,true); | ||
222 | } | ||
223 | else//not a match, so check children | ||
224 | { | ||
225 | RemoveDirectories(dir,dirNames); | ||
226 | //recurse, checking children for them | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | // private void RemoveDirectoryMatches(string rootDir, string dirPattern) | ||
232 | // { | ||
233 | // foreach(string dir in Directory.GetDirectories(rootDir)) | ||
234 | // { | ||
235 | // foreach(string match in Directory.GetDirectories(dir)) | ||
236 | // {//delete all child directories that match | ||
237 | // Directory.Delete(Path.GetFullPath(match),true); | ||
238 | // } | ||
239 | // //recure through the rest checking for nested matches to delete | ||
240 | // RemoveDirectoryMatches(dir,dirPattern); | ||
241 | // } | ||
242 | // } | ||
243 | |||
244 | private void LoadSchema() | ||
245 | { | ||
246 | Assembly assembly = this.GetType().Assembly; | ||
247 | Stream stream = assembly.GetManifestResourceStream("Prebuild.data." + m_Schema); | ||
248 | if(stream == null) | ||
249 | { | ||
250 | //try without the default namespace prepending to it in case was compiled with SharpDevelop or MonoDevelop instead of Visual Studio .NET | ||
251 | stream = assembly.GetManifestResourceStream(m_Schema); | ||
252 | if(stream == null) | ||
253 | { | ||
254 | throw new System.Reflection.TargetException(string.Format("Could not find the scheme embedded resource file '{0}'.", m_Schema)); | ||
255 | } | ||
256 | } | ||
257 | XmlReader schema = new XmlTextReader(stream); | ||
258 | |||
259 | m_Schemas = new XmlSchemaCollection(); | ||
260 | m_Schemas.Add(m_SchemaURI, schema); | ||
261 | } | ||
262 | |||
263 | private void CacheVersion() | ||
264 | { | ||
265 | m_Version = Assembly.GetEntryAssembly().GetName().Version; | ||
266 | } | ||
267 | |||
268 | private void CacheTargets(Assembly assm) | ||
269 | { | ||
270 | foreach(Type t in assm.GetTypes()) | ||
271 | { | ||
272 | TargetAttribute ta = (TargetAttribute)Helper.CheckType(t, typeof(TargetAttribute), typeof(ITarget)); | ||
273 | if(ta == null) | ||
274 | { | ||
275 | continue; | ||
276 | } | ||
277 | |||
278 | ITarget target = (ITarget)assm.CreateInstance(t.FullName); | ||
279 | if(target == null) | ||
280 | { | ||
281 | throw new MissingMethodException("Could not create ITarget instance"); | ||
282 | } | ||
283 | |||
284 | m_Targets[ta.Name] = target; | ||
285 | } | ||
286 | } | ||
287 | |||
288 | private void CacheNodeTypes(Assembly assm) | ||
289 | { | ||
290 | foreach(Type t in assm.GetTypes()) | ||
291 | { | ||
292 | DataNodeAttribute dna = (DataNodeAttribute)Helper.CheckType(t, typeof(DataNodeAttribute), typeof(IDataNode)); | ||
293 | if(dna == null) | ||
294 | { | ||
295 | continue; | ||
296 | } | ||
297 | |||
298 | NodeEntry ne = new NodeEntry(); | ||
299 | ne.Type = t; | ||
300 | ne.Attribute = dna; | ||
301 | m_Nodes[dna.Name] = ne; | ||
302 | } | ||
303 | } | ||
304 | |||
305 | private void LogBanner() | ||
306 | { | ||
307 | m_Log.Write("Prebuild v" + this.Version); | ||
308 | m_Log.Write("Copyright (c) Matthew Holmes, Dan Moorehead and David Hudson"); | ||
309 | m_Log.Write("See 'prebuild /usage' for help"); | ||
310 | m_Log.Write(); | ||
311 | } | ||
312 | |||
313 | private void ProcessFile(string file) | ||
314 | { | ||
315 | m_CurrentWorkingDirectory.Push(); | ||
316 | |||
317 | string path = file; | ||
318 | try | ||
319 | { | ||
320 | try | ||
321 | { | ||
322 | path = Helper.ResolvePath(path); | ||
323 | } | ||
324 | catch(ArgumentException) | ||
325 | { | ||
326 | m_Log.Write("Could not open Prebuild file: " + path); | ||
327 | m_CurrentWorkingDirectory.Pop(); | ||
328 | return; | ||
329 | } | ||
330 | |||
331 | m_CurrentFile = path; | ||
332 | Helper.SetCurrentDir(Path.GetDirectoryName(path)); | ||
333 | |||
334 | |||
335 | XmlTextReader reader = new XmlTextReader(path); | ||
336 | |||
337 | Core.Parse.Preprocessor pre = new Core.Parse.Preprocessor(); | ||
338 | |||
339 | //register command line arguments as XML variables | ||
340 | IDictionaryEnumerator dict = m_CommandLine.GetEnumerator(); | ||
341 | while (dict.MoveNext()) | ||
342 | { | ||
343 | string name = dict.Key.ToString().Trim(); | ||
344 | if (name.Length > 0) | ||
345 | pre.RegisterVariable(name, dict.Value.ToString()); | ||
346 | } | ||
347 | |||
348 | string xml = pre.Process(reader);//remove script and evaulate pre-proccessing to get schema-conforming XML | ||
349 | |||
350 | |||
351 | XmlDocument doc = new XmlDocument(); | ||
352 | try | ||
353 | { | ||
354 | XmlValidatingReader validator = new XmlValidatingReader(new XmlTextReader(new StringReader(xml))); | ||
355 | |||
356 | //validate while reading from string into XmlDocument DOM structure in memory | ||
357 | foreach(XmlSchema schema in m_Schemas) | ||
358 | { | ||
359 | validator.Schemas.Add(schema); | ||
360 | } | ||
361 | doc.Load(validator); | ||
362 | } | ||
363 | catch(XmlException e) | ||
364 | { | ||
365 | throw new XmlException(e.ToString()); | ||
366 | } | ||
367 | |||
368 | //is there a purpose to writing it? An syntax/schema problem would have been found during pre.Process() and reported with details | ||
369 | if(m_CommandLine.WasPassed("ppo")) | ||
370 | { | ||
371 | string ppoFile = m_CommandLine["ppo"]; | ||
372 | if(ppoFile == null || ppoFile.Trim().Length < 1) | ||
373 | { | ||
374 | ppoFile = "preprocessed.xml"; | ||
375 | } | ||
376 | |||
377 | StreamWriter writer = null; | ||
378 | try | ||
379 | { | ||
380 | writer = new StreamWriter(ppoFile); | ||
381 | writer.Write(xml); | ||
382 | } | ||
383 | catch(IOException ex) | ||
384 | { | ||
385 | Console.WriteLine("Could not write PPO file '{0}': {1}", ppoFile, ex.Message); | ||
386 | } | ||
387 | finally | ||
388 | { | ||
389 | if(writer != null) | ||
390 | { | ||
391 | writer.Close(); | ||
392 | } | ||
393 | } | ||
394 | return; | ||
395 | } | ||
396 | //start reading the xml config file | ||
397 | XmlElement rootNode = doc.DocumentElement; | ||
398 | //string suggestedVersion = Helper.AttributeValue(rootNode,"version","1.0"); | ||
399 | Helper.CheckForOSVariables = Helper.ParseBoolean(rootNode,"checkOsVars",false); | ||
400 | |||
401 | foreach(XmlNode node in rootNode.ChildNodes)//solutions or if pre-proc instructions | ||
402 | { | ||
403 | IDataNode dataNode = ParseNode(node, null); | ||
404 | if(dataNode is ProcessNode) | ||
405 | { | ||
406 | ProcessNode proc = (ProcessNode)dataNode; | ||
407 | if(proc.IsValid) | ||
408 | { | ||
409 | ProcessFile(proc.Path); | ||
410 | } | ||
411 | } | ||
412 | else if(dataNode is SolutionNode) | ||
413 | { | ||
414 | m_Solutions.Add(dataNode); | ||
415 | } | ||
416 | } | ||
417 | } | ||
418 | catch(XmlSchemaException xse) | ||
419 | { | ||
420 | m_Log.Write("XML validation error at line {0} in {1}:\n\n{2}", | ||
421 | xse.LineNumber, path, xse.Message); | ||
422 | } | ||
423 | finally | ||
424 | { | ||
425 | m_CurrentWorkingDirectory.Pop(); | ||
426 | } | ||
427 | } | ||
428 | |||
429 | #endregion | ||
430 | |||
431 | #region Public Methods | ||
432 | |||
433 | /// <summary> | ||
434 | /// Allows the project. | ||
435 | /// </summary> | ||
436 | /// <param name="projectGroupsFlags">The project groups flags.</param> | ||
437 | /// <returns></returns> | ||
438 | public bool AllowProject(string projectGroupsFlags) | ||
439 | { | ||
440 | if(m_ProjectGroups != null && m_ProjectGroups.Length > 0) | ||
441 | { | ||
442 | if(projectGroupsFlags != null && projectGroupsFlags.Length == 0) | ||
443 | { | ||
444 | foreach(string group in projectGroupsFlags.Split('|')) | ||
445 | { | ||
446 | if(Array.IndexOf(m_ProjectGroups, group) != -1) //if included in the filter list | ||
447 | { | ||
448 | return true; | ||
449 | } | ||
450 | } | ||
451 | } | ||
452 | return false;//not included in the list or no groups specified for the project | ||
453 | } | ||
454 | return true;//no filter specified in the command line args | ||
455 | } | ||
456 | |||
457 | /// <summary> | ||
458 | /// Gets the type of the node. | ||
459 | /// </summary> | ||
460 | /// <param name="node">The node.</param> | ||
461 | /// <returns></returns> | ||
462 | public Type GetNodeType(XmlNode node) | ||
463 | { | ||
464 | if( node == null ) | ||
465 | { | ||
466 | throw new ArgumentNullException("node"); | ||
467 | } | ||
468 | if(!m_Nodes.ContainsKey(node.Name)) | ||
469 | { | ||
470 | return null; | ||
471 | } | ||
472 | |||
473 | NodeEntry ne = (NodeEntry)m_Nodes[node.Name]; | ||
474 | return ne.Type; | ||
475 | } | ||
476 | |||
477 | /// <summary> | ||
478 | /// | ||
479 | /// </summary> | ||
480 | /// <param name="node"></param> | ||
481 | /// <param name="parent"></param> | ||
482 | /// <returns></returns> | ||
483 | public IDataNode ParseNode(XmlNode node, IDataNode parent) | ||
484 | { | ||
485 | return ParseNode(node, parent, null); | ||
486 | } | ||
487 | |||
488 | //Create an instance of the data node type that is mapped to the name of the xml DOM node | ||
489 | /// <summary> | ||
490 | /// Parses the node. | ||
491 | /// </summary> | ||
492 | /// <param name="node">The node.</param> | ||
493 | /// <param name="parent">The parent.</param> | ||
494 | /// <param name="preNode">The pre node.</param> | ||
495 | /// <returns></returns> | ||
496 | public IDataNode ParseNode(XmlNode node, IDataNode parent, IDataNode preNode) | ||
497 | { | ||
498 | IDataNode dataNode = null; | ||
499 | |||
500 | try | ||
501 | { | ||
502 | if( node == null ) | ||
503 | { | ||
504 | throw new ArgumentNullException("node"); | ||
505 | } | ||
506 | if(preNode == null) | ||
507 | { | ||
508 | if(!m_Nodes.ContainsKey(node.Name)) | ||
509 | { | ||
510 | //throw new XmlException("Unknown XML node: " + node.Name); | ||
511 | return null; | ||
512 | } | ||
513 | |||
514 | NodeEntry ne = (NodeEntry)m_Nodes[node.Name]; | ||
515 | Type type = ne.Type; | ||
516 | //DataNodeAttribute dna = ne.Attribute; | ||
517 | |||
518 | dataNode = (IDataNode)type.Assembly.CreateInstance(type.FullName); | ||
519 | if(dataNode == null) | ||
520 | { | ||
521 | throw new System.Reflection.TargetException("Could not create new parser instance: " + type.FullName); | ||
522 | } | ||
523 | } | ||
524 | else | ||
525 | dataNode = preNode; | ||
526 | |||
527 | dataNode.Parent = parent; | ||
528 | dataNode.Parse(node); | ||
529 | } | ||
530 | catch(WarningException wex) | ||
531 | { | ||
532 | m_Log.Write(LogType.Warning, wex.Message); | ||
533 | return null; | ||
534 | } | ||
535 | catch(FatalException fex) | ||
536 | { | ||
537 | m_Log.WriteException(LogType.Error, fex); | ||
538 | throw; | ||
539 | } | ||
540 | catch(Exception ex) | ||
541 | { | ||
542 | m_Log.WriteException(LogType.Error, ex); | ||
543 | throw; | ||
544 | } | ||
545 | |||
546 | return dataNode; | ||
547 | } | ||
548 | |||
549 | /// <summary> | ||
550 | /// Initializes the specified target. | ||
551 | /// </summary> | ||
552 | /// <param name="target">The target.</param> | ||
553 | /// <param name="args">The args.</param> | ||
554 | public void Initialize(LogTargets target, string[] args) | ||
555 | { | ||
556 | m_Targets = new Hashtable(); | ||
557 | CacheTargets(this.GetType().Assembly); | ||
558 | m_Nodes = new Hashtable(); | ||
559 | CacheNodeTypes(this.GetType().Assembly); | ||
560 | CacheVersion(); | ||
561 | |||
562 | m_CommandLine = new CommandLineCollection(args); | ||
563 | |||
564 | string logFile = null; | ||
565 | if(m_CommandLine.WasPassed("log")) | ||
566 | { | ||
567 | logFile = m_CommandLine["log"]; | ||
568 | |||
569 | if(logFile != null && logFile.Length == 0) | ||
570 | { | ||
571 | logFile = "Prebuild.log"; | ||
572 | } | ||
573 | } | ||
574 | else | ||
575 | { | ||
576 | target = target & ~LogTargets.File; //dont output to a file | ||
577 | } | ||
578 | |||
579 | m_Log = new Log(target, logFile); | ||
580 | LogBanner(); | ||
581 | |||
582 | m_CurrentWorkingDirectory = new CurrentDirectory(); | ||
583 | |||
584 | m_Target = m_CommandLine["target"]; | ||
585 | m_Clean = m_CommandLine["clean"]; | ||
586 | string removeDirs = m_CommandLine["removedir"]; | ||
587 | if(removeDirs != null && removeDirs.Length == 0) | ||
588 | { | ||
589 | m_RemoveDirectories = removeDirs.Split('|'); | ||
590 | } | ||
591 | |||
592 | string flags = m_CommandLine["allowedgroups"];//allows filtering by specifying a pipe-delimited list of groups to include | ||
593 | if(flags != null && flags.Length == 0) | ||
594 | { | ||
595 | m_ProjectGroups = flags.Split('|'); | ||
596 | } | ||
597 | m_PauseAfterFinish = m_CommandLine.WasPassed("pause"); | ||
598 | |||
599 | LoadSchema(); | ||
600 | |||
601 | m_Solutions = new ArrayList(); | ||
602 | m_Refs = new StringCollection(); | ||
603 | } | ||
604 | |||
605 | /// <summary> | ||
606 | /// Processes this instance. | ||
607 | /// </summary> | ||
608 | public void Process() | ||
609 | { | ||
610 | bool perfomedOtherTask = false; | ||
611 | if(m_RemoveDirectories != null && m_RemoveDirectories.Length > 0) | ||
612 | { | ||
613 | try | ||
614 | { | ||
615 | RemoveDirectories(".",m_RemoveDirectories); | ||
616 | } | ||
617 | catch(IOException e) | ||
618 | { | ||
619 | m_Log.Write("Failed to remove directories named {0}",m_RemoveDirectories); | ||
620 | m_Log.WriteException(LogType.Error,e); | ||
621 | } | ||
622 | catch(UnauthorizedAccessException e) | ||
623 | { | ||
624 | m_Log.Write("Failed to remove directories named {0}",m_RemoveDirectories); | ||
625 | m_Log.WriteException(LogType.Error,e); | ||
626 | } | ||
627 | perfomedOtherTask = true; | ||
628 | } | ||
629 | |||
630 | if(m_Target != null && m_Clean != null) | ||
631 | { | ||
632 | m_Log.Write(LogType.Error, "The options /target and /clean cannot be passed together"); | ||
633 | return; | ||
634 | } | ||
635 | else if(m_Target == null && m_Clean == null) | ||
636 | { | ||
637 | if(perfomedOtherTask) //finished | ||
638 | { | ||
639 | return; | ||
640 | } | ||
641 | m_Log.Write(LogType.Error, "Must pass either /target or /clean to process a Prebuild file"); | ||
642 | return; | ||
643 | } | ||
644 | |||
645 | string file = "./prebuild.xml"; | ||
646 | if(m_CommandLine.WasPassed("file")) | ||
647 | { | ||
648 | file = m_CommandLine["file"]; | ||
649 | } | ||
650 | |||
651 | ProcessFile(file); | ||
652 | |||
653 | string target = (m_Target != null ? m_Target.ToLower() : m_Clean.ToLower()); | ||
654 | bool clean = (m_Target == null); | ||
655 | if(clean && target != null && target.Length == 0) | ||
656 | { | ||
657 | target = "all"; | ||
658 | } | ||
659 | if(clean && target == "all")//default to all if no target was specified for clean | ||
660 | { | ||
661 | //check if they passed yes | ||
662 | if (!m_CommandLine.WasPassed("yes")) | ||
663 | { | ||
664 | Console.WriteLine("WARNING: This operation will clean ALL project files for all targets, are you sure? (y/n):"); | ||
665 | string ret = Console.ReadLine(); | ||
666 | if(ret == null) | ||
667 | { | ||
668 | return; | ||
669 | } | ||
670 | ret = ret.Trim().ToLower(); | ||
671 | if((ret.ToLower() != "y" && ret.ToLower() != "yes")) | ||
672 | { | ||
673 | return; | ||
674 | } | ||
675 | } | ||
676 | //clean all targets (just cleaning vs2002 target didn't clean nant) | ||
677 | foreach(ITarget targ in m_Targets.Values) | ||
678 | { | ||
679 | targ.Clean(this); | ||
680 | } | ||
681 | } | ||
682 | else | ||
683 | { | ||
684 | ITarget targ = (ITarget)m_Targets[target]; | ||
685 | |||
686 | if(clean) | ||
687 | { | ||
688 | targ.Clean(this); | ||
689 | } | ||
690 | else | ||
691 | { | ||
692 | targ.Write(this); | ||
693 | } | ||
694 | } | ||
695 | |||
696 | m_Log.Flush(); | ||
697 | } | ||
698 | |||
699 | #endregion | ||
700 | |||
701 | #region IDisposable Members | ||
702 | |||
703 | /// <summary> | ||
704 | /// | ||
705 | /// </summary> | ||
706 | public void Dispose() | ||
707 | { | ||
708 | Dispose(true); | ||
709 | GC.SuppressFinalize(this); | ||
710 | } | ||
711 | |||
712 | /// <summary> | ||
713 | /// Dispose objects | ||
714 | /// </summary> | ||
715 | /// <param name="disposing"> | ||
716 | /// If true, it will dispose close the handle | ||
717 | /// </param> | ||
718 | /// <remarks> | ||
719 | /// Will dispose managed and unmanaged resources. | ||
720 | /// </remarks> | ||
721 | protected virtual void Dispose(bool disposing) | ||
722 | { | ||
723 | if (!this.disposed) | ||
724 | { | ||
725 | if (disposing) | ||
726 | { | ||
727 | if (this.m_Log != null) | ||
728 | { | ||
729 | this.m_Log.Close(); | ||
730 | this.m_Log = null; | ||
731 | } | ||
732 | } | ||
733 | } | ||
734 | this.disposed = true; | ||
735 | } | ||
736 | |||
737 | /// <summary> | ||
738 | /// | ||
739 | /// </summary> | ||
740 | ~Kernel() | ||
741 | { | ||
742 | this.Dispose(false); | ||
743 | } | ||
744 | |||
745 | /// <summary> | ||
746 | /// Closes and destroys this object | ||
747 | /// </summary> | ||
748 | /// <remarks> | ||
749 | /// Same as Dispose(true) | ||
750 | /// </remarks> | ||
751 | public void Close() | ||
752 | { | ||
753 | Dispose(); | ||
754 | } | ||
755 | |||
756 | #endregion | ||
757 | } | ||
758 | } \ No newline at end of file | ||
diff --git a/Prebuild/src/Core/Nodes/ConfigurationNode.cs b/Prebuild/src/Core/Nodes/ConfigurationNode.cs new file mode 100644 index 0000000..e1488a7 --- /dev/null +++ b/Prebuild/src/Core/Nodes/ConfigurationNode.cs | |||
@@ -0,0 +1,177 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Xml; | ||
37 | |||
38 | using Prebuild.Core.Attributes; | ||
39 | using Prebuild.Core.Interfaces; | ||
40 | using Prebuild.Core.Utilities; | ||
41 | |||
42 | namespace Prebuild.Core.Nodes | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// | ||
46 | /// </summary> | ||
47 | [DataNode("Configuration")] | ||
48 | public class ConfigurationNode : DataNode, ICloneable | ||
49 | { | ||
50 | #region Fields | ||
51 | |||
52 | private string m_Name = "unknown"; | ||
53 | private OptionsNode m_Options; | ||
54 | |||
55 | #endregion | ||
56 | |||
57 | #region Constructors | ||
58 | |||
59 | /// <summary> | ||
60 | /// Initializes a new instance of the <see cref="ConfigurationNode"/> class. | ||
61 | /// </summary> | ||
62 | public ConfigurationNode() | ||
63 | { | ||
64 | m_Options = new OptionsNode(); | ||
65 | } | ||
66 | |||
67 | #endregion | ||
68 | |||
69 | #region Properties | ||
70 | |||
71 | /// <summary> | ||
72 | /// Gets or sets the parent. | ||
73 | /// </summary> | ||
74 | /// <value>The parent.</value> | ||
75 | public override IDataNode Parent | ||
76 | { | ||
77 | get | ||
78 | { | ||
79 | return base.Parent; | ||
80 | } | ||
81 | set | ||
82 | { | ||
83 | base.Parent = value; | ||
84 | if(base.Parent is SolutionNode) | ||
85 | { | ||
86 | SolutionNode node = (SolutionNode)base.Parent; | ||
87 | if(node != null && node.Options != null) | ||
88 | { | ||
89 | node.Options.CopyTo(m_Options); | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | /// <summary> | ||
96 | /// Gets the name. | ||
97 | /// </summary> | ||
98 | /// <value>The name.</value> | ||
99 | public string Name | ||
100 | { | ||
101 | get | ||
102 | { | ||
103 | return m_Name; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | /// <summary> | ||
108 | /// Gets or sets the options. | ||
109 | /// </summary> | ||
110 | /// <value>The options.</value> | ||
111 | public OptionsNode Options | ||
112 | { | ||
113 | get | ||
114 | { | ||
115 | return m_Options; | ||
116 | } | ||
117 | set | ||
118 | { | ||
119 | m_Options = value; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | #endregion | ||
124 | |||
125 | #region Public Methods | ||
126 | |||
127 | /// <summary> | ||
128 | /// Parses the specified node. | ||
129 | /// </summary> | ||
130 | /// <param name="node">The node.</param> | ||
131 | public override void Parse(XmlNode node) | ||
132 | { | ||
133 | m_Name = Helper.AttributeValue(node, "name", m_Name); | ||
134 | if( node == null ) | ||
135 | { | ||
136 | throw new ArgumentNullException("node"); | ||
137 | } | ||
138 | foreach(XmlNode child in node.ChildNodes) | ||
139 | { | ||
140 | IDataNode dataNode = Kernel.Instance.ParseNode(child, this); | ||
141 | if(dataNode is OptionsNode) | ||
142 | { | ||
143 | ((OptionsNode)dataNode).CopyTo(m_Options); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Copies to. | ||
150 | /// </summary> | ||
151 | /// <param name="conf">The conf.</param> | ||
152 | public void CopyTo(ConfigurationNode conf) | ||
153 | { | ||
154 | m_Options.CopyTo(conf.m_Options); | ||
155 | } | ||
156 | |||
157 | #endregion | ||
158 | |||
159 | #region ICloneable Members | ||
160 | |||
161 | /// <summary> | ||
162 | /// Creates a new object that is a copy of the current instance. | ||
163 | /// </summary> | ||
164 | /// <returns> | ||
165 | /// A new object that is a copy of this instance. | ||
166 | /// </returns> | ||
167 | public object Clone() | ||
168 | { | ||
169 | ConfigurationNode ret = new ConfigurationNode(); | ||
170 | ret.m_Name = m_Name; | ||
171 | m_Options.CopyTo(ret.m_Options); | ||
172 | return ret; | ||
173 | } | ||
174 | |||
175 | #endregion | ||
176 | } | ||
177 | } | ||
diff --git a/Prebuild/src/Core/Nodes/DataNode.cs b/Prebuild/src/Core/Nodes/DataNode.cs new file mode 100644 index 0000000..ef5f7ee --- /dev/null +++ b/Prebuild/src/Core/Nodes/DataNode.cs | |||
@@ -0,0 +1,82 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Xml; | ||
37 | |||
38 | using Prebuild.Core.Attributes; | ||
39 | using Prebuild.Core.Interfaces; | ||
40 | |||
41 | namespace Prebuild.Core.Nodes | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// | ||
45 | /// </summary> | ||
46 | public class DataNode : IDataNode | ||
47 | { | ||
48 | #region Fields | ||
49 | |||
50 | private IDataNode parent; | ||
51 | |||
52 | #endregion | ||
53 | |||
54 | #region IDataNode Members | ||
55 | |||
56 | /// <summary> | ||
57 | /// Gets or sets the parent. | ||
58 | /// </summary> | ||
59 | /// <value>The parent.</value> | ||
60 | public virtual IDataNode Parent | ||
61 | { | ||
62 | get | ||
63 | { | ||
64 | return parent; | ||
65 | } | ||
66 | set | ||
67 | { | ||
68 | parent = value; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | /// <summary> | ||
73 | /// Parses the specified node. | ||
74 | /// </summary> | ||
75 | /// <param name="node">The node.</param> | ||
76 | public virtual void Parse(XmlNode node) | ||
77 | { | ||
78 | } | ||
79 | |||
80 | #endregion | ||
81 | } | ||
82 | } | ||
diff --git a/Prebuild/src/Core/Nodes/ExcludeNode.cs b/Prebuild/src/Core/Nodes/ExcludeNode.cs new file mode 100644 index 0000000..bfcebca --- /dev/null +++ b/Prebuild/src/Core/Nodes/ExcludeNode.cs | |||
@@ -0,0 +1,85 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-31 16:35:39 +0100 (ti, 31 jan 2006) $ | ||
31 | * $Revision: 74 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Xml; | ||
37 | |||
38 | using Prebuild.Core.Attributes; | ||
39 | using Prebuild.Core.Interfaces; | ||
40 | using Prebuild.Core.Utilities; | ||
41 | |||
42 | namespace Prebuild.Core.Nodes | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// | ||
46 | /// </summary> | ||
47 | [DataNode("Exclude")] | ||
48 | public class ExcludeNode : DataNode | ||
49 | { | ||
50 | #region Fields | ||
51 | |||
52 | private string m_Name = "unknown"; | ||
53 | |||
54 | #endregion | ||
55 | |||
56 | #region Properties | ||
57 | |||
58 | /// <summary> | ||
59 | /// Gets the name. | ||
60 | /// </summary> | ||
61 | /// <value>The name.</value> | ||
62 | public string Name | ||
63 | { | ||
64 | get | ||
65 | { | ||
66 | return m_Name; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | #endregion | ||
71 | |||
72 | #region Public Methods | ||
73 | |||
74 | /// <summary> | ||
75 | /// Parses the specified node. | ||
76 | /// </summary> | ||
77 | /// <param name="node">The node.</param> | ||
78 | public override void Parse(XmlNode node) | ||
79 | { | ||
80 | m_Name = Helper.AttributeValue(node, "name", m_Name); | ||
81 | } | ||
82 | |||
83 | #endregion | ||
84 | } | ||
85 | } | ||
diff --git a/Prebuild/src/Core/Nodes/FileNode.cs b/Prebuild/src/Core/Nodes/FileNode.cs new file mode 100644 index 0000000..de3b69e --- /dev/null +++ b/Prebuild/src/Core/Nodes/FileNode.cs | |||
@@ -0,0 +1,238 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2007-01-08 17:55:40 +0100 (må, 08 jan 2007) $ | ||
31 | * $Revision: 197 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.IO; | ||
37 | using System.Xml; | ||
38 | |||
39 | using Prebuild.Core.Attributes; | ||
40 | using Prebuild.Core.Interfaces; | ||
41 | using Prebuild.Core.Utilities; | ||
42 | |||
43 | namespace Prebuild.Core.Nodes | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// | ||
47 | /// </summary> | ||
48 | public enum BuildAction | ||
49 | { | ||
50 | /// <summary> | ||
51 | /// | ||
52 | /// </summary> | ||
53 | None, | ||
54 | /// <summary> | ||
55 | /// | ||
56 | /// </summary> | ||
57 | Compile, | ||
58 | /// <summary> | ||
59 | /// | ||
60 | /// </summary> | ||
61 | Content, | ||
62 | /// <summary> | ||
63 | /// | ||
64 | /// </summary> | ||
65 | EmbeddedResource | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// | ||
70 | /// </summary> | ||
71 | public enum SubType | ||
72 | { | ||
73 | /// <summary> | ||
74 | /// | ||
75 | /// </summary> | ||
76 | Code, | ||
77 | /// <summary> | ||
78 | /// | ||
79 | /// </summary> | ||
80 | Component, | ||
81 | /// <summary> | ||
82 | /// | ||
83 | /// </summary> | ||
84 | Designer, | ||
85 | /// <summary> | ||
86 | /// | ||
87 | /// </summary> | ||
88 | Form, | ||
89 | /// <summary> | ||
90 | /// | ||
91 | /// </summary> | ||
92 | Settings, | ||
93 | /// <summary> | ||
94 | /// | ||
95 | /// </summary> | ||
96 | UserControl | ||
97 | } | ||
98 | |||
99 | public enum CopyToOutput | ||
100 | { | ||
101 | Never, | ||
102 | Always, | ||
103 | PreserveNewest | ||
104 | } | ||
105 | |||
106 | /// <summary> | ||
107 | /// | ||
108 | /// </summary> | ||
109 | [DataNode("File")] | ||
110 | public class FileNode : DataNode | ||
111 | { | ||
112 | #region Fields | ||
113 | |||
114 | private string m_Path; | ||
115 | private string m_ResourceName = ""; | ||
116 | private BuildAction m_BuildAction = BuildAction.Compile; | ||
117 | private bool m_Valid; | ||
118 | private SubType m_SubType = SubType.Code; | ||
119 | private CopyToOutput m_CopyToOutput = CopyToOutput.Never; | ||
120 | private bool m_Link = false; | ||
121 | |||
122 | |||
123 | #endregion | ||
124 | |||
125 | #region Properties | ||
126 | |||
127 | /// <summary> | ||
128 | /// | ||
129 | /// </summary> | ||
130 | public string Path | ||
131 | { | ||
132 | get | ||
133 | { | ||
134 | return m_Path; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | /// <summary> | ||
139 | /// | ||
140 | /// </summary> | ||
141 | public string ResourceName | ||
142 | { | ||
143 | get | ||
144 | { | ||
145 | return m_ResourceName; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// | ||
151 | /// </summary> | ||
152 | public BuildAction BuildAction | ||
153 | { | ||
154 | get | ||
155 | { | ||
156 | return m_BuildAction; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | public CopyToOutput CopyToOutput | ||
161 | { | ||
162 | get | ||
163 | { | ||
164 | return this.m_CopyToOutput; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | public bool IsLink | ||
169 | { | ||
170 | get | ||
171 | { | ||
172 | return this.m_Link; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | /// <summary> | ||
177 | /// | ||
178 | /// </summary> | ||
179 | public SubType SubType | ||
180 | { | ||
181 | get | ||
182 | { | ||
183 | return m_SubType; | ||
184 | } | ||
185 | } | ||
186 | |||
187 | /// <summary> | ||
188 | /// | ||
189 | /// </summary> | ||
190 | public bool IsValid | ||
191 | { | ||
192 | get | ||
193 | { | ||
194 | return m_Valid; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | #endregion | ||
199 | |||
200 | #region Public Methods | ||
201 | |||
202 | /// <summary> | ||
203 | /// | ||
204 | /// </summary> | ||
205 | /// <param name="node"></param> | ||
206 | public override void Parse(XmlNode node) | ||
207 | { | ||
208 | m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), | ||
209 | Helper.AttributeValue(node, "buildAction", m_BuildAction.ToString())); | ||
210 | m_SubType = (SubType)Enum.Parse(typeof(SubType), | ||
211 | Helper.AttributeValue(node, "subType", m_SubType.ToString())); | ||
212 | m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString()); | ||
213 | this.m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString)); | ||
214 | this.m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString())); | ||
215 | |||
216 | if( node == null ) | ||
217 | { | ||
218 | throw new ArgumentNullException("node"); | ||
219 | } | ||
220 | |||
221 | m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText); | ||
222 | if(m_Path == null) | ||
223 | { | ||
224 | m_Path = ""; | ||
225 | } | ||
226 | |||
227 | m_Path = m_Path.Trim(); | ||
228 | m_Valid = true; | ||
229 | if(!File.Exists(m_Path)) | ||
230 | { | ||
231 | m_Valid = false; | ||
232 | Kernel.Instance.Log.Write(LogType.Warning, "File does not exist: {0}", m_Path); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | #endregion | ||
237 | } | ||
238 | } | ||
diff --git a/Prebuild/src/Core/Nodes/FilesNode.cs b/Prebuild/src/Core/Nodes/FilesNode.cs new file mode 100644 index 0000000..442a45f --- /dev/null +++ b/Prebuild/src/Core/Nodes/FilesNode.cs | |||
@@ -0,0 +1,222 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-09-20 09:42:51 +0200 (on, 20 sep 2006) $ | ||
31 | * $Revision: 164 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.Xml; | ||
39 | |||
40 | using Prebuild.Core.Attributes; | ||
41 | using Prebuild.Core.Interfaces; | ||
42 | |||
43 | namespace Prebuild.Core.Nodes | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// | ||
47 | /// </summary> | ||
48 | [DataNode("Files")] | ||
49 | public class FilesNode : DataNode | ||
50 | { | ||
51 | #region Fields | ||
52 | |||
53 | private StringCollection m_Files; | ||
54 | private Hashtable m_BuildActions; | ||
55 | private Hashtable m_SubTypes; | ||
56 | private Hashtable m_ResourceNames; | ||
57 | private Hashtable m_CopyToOutputs; | ||
58 | private Hashtable m_Links; | ||
59 | |||
60 | |||
61 | #endregion | ||
62 | |||
63 | #region Constructors | ||
64 | |||
65 | /// <summary> | ||
66 | /// | ||
67 | /// </summary> | ||
68 | public FilesNode() | ||
69 | { | ||
70 | m_Files = new StringCollection(); | ||
71 | m_BuildActions = new Hashtable(); | ||
72 | m_SubTypes = new Hashtable(); | ||
73 | m_ResourceNames = new Hashtable(); | ||
74 | m_CopyToOutputs = new Hashtable(); | ||
75 | m_Links = new Hashtable(); | ||
76 | } | ||
77 | |||
78 | #endregion | ||
79 | |||
80 | #region Properties | ||
81 | |||
82 | /// <summary> | ||
83 | /// | ||
84 | /// </summary> | ||
85 | public int Count | ||
86 | { | ||
87 | get | ||
88 | { | ||
89 | return m_Files.Count; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | #endregion | ||
94 | |||
95 | #region Public Methods | ||
96 | |||
97 | /// <summary> | ||
98 | /// | ||
99 | /// </summary> | ||
100 | /// <param name="file"></param> | ||
101 | /// <returns></returns> | ||
102 | public BuildAction GetBuildAction(string file) | ||
103 | { | ||
104 | if(!m_BuildActions.ContainsKey(file)) | ||
105 | { | ||
106 | return BuildAction.Compile; | ||
107 | } | ||
108 | |||
109 | return (BuildAction)m_BuildActions[file]; | ||
110 | } | ||
111 | |||
112 | public CopyToOutput GetCopyToOutput(string file) | ||
113 | { | ||
114 | if (!this.m_CopyToOutputs.ContainsKey(file)) | ||
115 | { | ||
116 | return CopyToOutput.Never; | ||
117 | } | ||
118 | return (CopyToOutput) this.m_CopyToOutputs[file]; | ||
119 | } | ||
120 | |||
121 | public bool GetIsLink(string file) | ||
122 | { | ||
123 | if (!this.m_Links.ContainsKey(file)) | ||
124 | { | ||
125 | return false; | ||
126 | } | ||
127 | return (bool) this.m_Links[file]; | ||
128 | } | ||
129 | |||
130 | /// <summary> | ||
131 | /// | ||
132 | /// </summary> | ||
133 | /// <param name="file"></param> | ||
134 | /// <returns></returns> | ||
135 | public SubType GetSubType(string file) | ||
136 | { | ||
137 | if(!m_SubTypes.ContainsKey(file)) | ||
138 | { | ||
139 | return SubType.Code; | ||
140 | } | ||
141 | |||
142 | return (SubType)m_SubTypes[file]; | ||
143 | } | ||
144 | |||
145 | /// <summary> | ||
146 | /// | ||
147 | /// </summary> | ||
148 | /// <param name="file"></param> | ||
149 | /// <returns></returns> | ||
150 | public string GetResourceName(string file) | ||
151 | { | ||
152 | if(!m_ResourceNames.ContainsKey(file)) | ||
153 | { | ||
154 | return ""; | ||
155 | } | ||
156 | |||
157 | return (string)m_ResourceNames[file]; | ||
158 | } | ||
159 | |||
160 | /// <summary> | ||
161 | /// | ||
162 | /// </summary> | ||
163 | /// <param name="node"></param> | ||
164 | public override void Parse(XmlNode node) | ||
165 | { | ||
166 | if( node == null ) | ||
167 | { | ||
168 | throw new ArgumentNullException("node"); | ||
169 | } | ||
170 | foreach(XmlNode child in node.ChildNodes) | ||
171 | { | ||
172 | IDataNode dataNode = Kernel.Instance.ParseNode(child, this); | ||
173 | if(dataNode is FileNode) | ||
174 | { | ||
175 | FileNode fileNode = (FileNode)dataNode; | ||
176 | if(fileNode.IsValid) | ||
177 | { | ||
178 | if (!m_Files.Contains(fileNode.Path)) | ||
179 | { | ||
180 | m_Files.Add(fileNode.Path); | ||
181 | m_BuildActions[fileNode.Path] = fileNode.BuildAction; | ||
182 | m_SubTypes[fileNode.Path] = fileNode.SubType; | ||
183 | m_ResourceNames[fileNode.Path] = fileNode.ResourceName; | ||
184 | this.m_Links[fileNode.Path] = fileNode.IsLink; | ||
185 | this.m_CopyToOutputs[fileNode.Path] = fileNode.CopyToOutput; | ||
186 | |||
187 | } | ||
188 | } | ||
189 | } | ||
190 | else if(dataNode is MatchNode) | ||
191 | { | ||
192 | foreach(string file in ((MatchNode)dataNode).Files) | ||
193 | { | ||
194 | if (!m_Files.Contains(file)) | ||
195 | { | ||
196 | m_Files.Add(file); | ||
197 | m_BuildActions[file] = ((MatchNode)dataNode).BuildAction; | ||
198 | m_SubTypes[file] = ((MatchNode)dataNode).SubType; | ||
199 | m_ResourceNames[file] = ((MatchNode)dataNode).ResourceName; | ||
200 | this.m_Links[file] = ((MatchNode) dataNode).IsLink; | ||
201 | this.m_CopyToOutputs[file] = ((MatchNode) dataNode).CopyToOutput; | ||
202 | |||
203 | } | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | |||
209 | // TODO: Check in to why StringCollection's enumerator doesn't implement | ||
210 | // IEnumerator? | ||
211 | /// <summary> | ||
212 | /// | ||
213 | /// </summary> | ||
214 | /// <returns></returns> | ||
215 | public StringEnumerator GetEnumerator() | ||
216 | { | ||
217 | return m_Files.GetEnumerator(); | ||
218 | } | ||
219 | |||
220 | #endregion | ||
221 | } | ||
222 | } | ||
diff --git a/Prebuild/src/Core/Nodes/MatchNode.cs b/Prebuild/src/Core/Nodes/MatchNode.cs new file mode 100644 index 0000000..e0d2fa8 --- /dev/null +++ b/Prebuild/src/Core/Nodes/MatchNode.cs | |||
@@ -0,0 +1,299 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-09-20 09:42:51 +0200 (on, 20 sep 2006) $ | ||
31 | * $Revision: 164 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections.Specialized; | ||
37 | using System.IO; | ||
38 | using System.Text.RegularExpressions; | ||
39 | using System.Xml; | ||
40 | |||
41 | using Prebuild.Core.Attributes; | ||
42 | using Prebuild.Core.Interfaces; | ||
43 | using Prebuild.Core.Utilities; | ||
44 | |||
45 | namespace Prebuild.Core.Nodes | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// | ||
49 | /// </summary> | ||
50 | [DataNode("Match")] | ||
51 | public class MatchNode : DataNode | ||
52 | { | ||
53 | #region Fields | ||
54 | |||
55 | private StringCollection m_Files; | ||
56 | private Regex m_Regex; | ||
57 | private BuildAction m_BuildAction = BuildAction.Compile; | ||
58 | private SubType m_SubType = SubType.Code; | ||
59 | string m_ResourceName = ""; | ||
60 | private CopyToOutput m_CopyToOutput; | ||
61 | private bool m_Link; | ||
62 | |||
63 | |||
64 | #endregion | ||
65 | |||
66 | #region Constructors | ||
67 | |||
68 | /// <summary> | ||
69 | /// | ||
70 | /// </summary> | ||
71 | public MatchNode() | ||
72 | { | ||
73 | m_Files = new StringCollection(); | ||
74 | } | ||
75 | |||
76 | #endregion | ||
77 | |||
78 | #region Properties | ||
79 | |||
80 | /// <summary> | ||
81 | /// | ||
82 | /// </summary> | ||
83 | public StringCollection Files | ||
84 | { | ||
85 | get | ||
86 | { | ||
87 | return m_Files; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// | ||
93 | /// </summary> | ||
94 | public BuildAction BuildAction | ||
95 | { | ||
96 | get | ||
97 | { | ||
98 | return m_BuildAction; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | /// <summary> | ||
103 | /// | ||
104 | /// </summary> | ||
105 | public SubType SubType | ||
106 | { | ||
107 | get | ||
108 | { | ||
109 | return m_SubType; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | public CopyToOutput CopyToOutput | ||
114 | { | ||
115 | get | ||
116 | { | ||
117 | return this.m_CopyToOutput; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | public bool IsLink | ||
122 | { | ||
123 | get | ||
124 | { | ||
125 | return this.m_Link; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | /// <summary> | ||
130 | /// | ||
131 | /// </summary> | ||
132 | public string ResourceName | ||
133 | { | ||
134 | get | ||
135 | { | ||
136 | return m_ResourceName; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | |||
141 | #endregion | ||
142 | |||
143 | #region Private Methods | ||
144 | |||
145 | /// <summary> | ||
146 | /// Recurses the directories. | ||
147 | /// </summary> | ||
148 | /// <param name="path">The path.</param> | ||
149 | /// <param name="pattern">The pattern.</param> | ||
150 | /// <param name="recurse">if set to <c>true</c> [recurse].</param> | ||
151 | /// <param name="useRegex">if set to <c>true</c> [use regex].</param> | ||
152 | private void RecurseDirectories(string path, string pattern, bool recurse, bool useRegex) | ||
153 | { | ||
154 | try | ||
155 | { | ||
156 | string[] files; | ||
157 | |||
158 | if(!useRegex) | ||
159 | { | ||
160 | files = Directory.GetFiles(path, pattern); | ||
161 | if(files != null) | ||
162 | { | ||
163 | string fileTemp; | ||
164 | foreach (string file in files) | ||
165 | { | ||
166 | if (file.Substring(0,2) == "./" || file.Substring(0,2) == ".\\") | ||
167 | { | ||
168 | fileTemp = file.Substring(2); | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | fileTemp = file; | ||
173 | } | ||
174 | |||
175 | m_Files.Add(fileTemp); | ||
176 | } | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | return; | ||
181 | } | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | Match match; | ||
186 | files = Directory.GetFiles(path); | ||
187 | foreach(string file in files) | ||
188 | { | ||
189 | match = m_Regex.Match(file); | ||
190 | if(match.Success) | ||
191 | { | ||
192 | m_Files.Add(file); | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | |||
197 | if(recurse) | ||
198 | { | ||
199 | string[] dirs = Directory.GetDirectories(path); | ||
200 | if(dirs != null && dirs.Length > 0) | ||
201 | { | ||
202 | foreach(string str in dirs) | ||
203 | { | ||
204 | RecurseDirectories(Helper.NormalizePath(str), pattern, recurse, useRegex); | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | catch(DirectoryNotFoundException) | ||
210 | { | ||
211 | return; | ||
212 | } | ||
213 | catch(ArgumentException) | ||
214 | { | ||
215 | return; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | #endregion | ||
220 | |||
221 | #region Public Methods | ||
222 | |||
223 | /// <summary> | ||
224 | /// | ||
225 | /// </summary> | ||
226 | /// <param name="node"></param> | ||
227 | public override void Parse(XmlNode node) | ||
228 | { | ||
229 | if( node == null ) | ||
230 | { | ||
231 | throw new ArgumentNullException("node"); | ||
232 | } | ||
233 | string path = Helper.AttributeValue(node, "path", "."); | ||
234 | string pattern = Helper.AttributeValue(node, "pattern", "*"); | ||
235 | bool recurse = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false")); | ||
236 | bool useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false")); | ||
237 | m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), | ||
238 | Helper.AttributeValue(node, "buildAction", m_BuildAction.ToString())); | ||
239 | m_SubType = (SubType)Enum.Parse(typeof(SubType), | ||
240 | Helper.AttributeValue(node, "subType", m_SubType.ToString())); | ||
241 | m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString()); | ||
242 | this.m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString())); | ||
243 | this.m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString)); | ||
244 | |||
245 | |||
246 | if(path != null && path.Length == 0) | ||
247 | { | ||
248 | path = ".";//use current directory | ||
249 | } | ||
250 | //throw new WarningException("Match must have a 'path' attribute"); | ||
251 | |||
252 | if(pattern == null) | ||
253 | { | ||
254 | throw new WarningException("Match must have a 'pattern' attribute"); | ||
255 | } | ||
256 | |||
257 | path = Helper.NormalizePath(path); | ||
258 | if(!Directory.Exists(path)) | ||
259 | { | ||
260 | throw new WarningException("Match path does not exist: {0}", path); | ||
261 | } | ||
262 | |||
263 | try | ||
264 | { | ||
265 | if(useRegex) | ||
266 | { | ||
267 | m_Regex = new Regex(pattern); | ||
268 | } | ||
269 | } | ||
270 | catch(ArgumentException ex) | ||
271 | { | ||
272 | throw new WarningException("Could not compile regex pattern: {0}", ex.Message); | ||
273 | } | ||
274 | |||
275 | RecurseDirectories(path, pattern, recurse, useRegex); | ||
276 | |||
277 | foreach(XmlNode child in node.ChildNodes) | ||
278 | { | ||
279 | IDataNode dataNode = Kernel.Instance.ParseNode(child, this); | ||
280 | if(dataNode is ExcludeNode) | ||
281 | { | ||
282 | ExcludeNode excludeNode = (ExcludeNode)dataNode; | ||
283 | if (m_Files.Contains(Helper.NormalizePath(excludeNode.Name))) | ||
284 | { | ||
285 | m_Files.Remove(Helper.NormalizePath(excludeNode.Name)); | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | |||
290 | if(m_Files.Count < 1) | ||
291 | { | ||
292 | throw new WarningException("Match returned no files: {0}{1}", Helper.EndPath(path), pattern); | ||
293 | } | ||
294 | m_Regex = null; | ||
295 | } | ||
296 | |||
297 | #endregion | ||
298 | } | ||
299 | } | ||
diff --git a/Prebuild/src/Core/Nodes/OptionsNode.cs b/Prebuild/src/Core/Nodes/OptionsNode.cs new file mode 100644 index 0000000..b5a2f60 --- /dev/null +++ b/Prebuild/src/Core/Nodes/OptionsNode.cs | |||
@@ -0,0 +1,655 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2007-01-08 17:55:40 +0100 (må, 08 jan 2007) $ | ||
31 | * $Revision: 197 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | |||
36 | |||
37 | using System; | ||
38 | using System.Collections; | ||
39 | using System.Collections.Specialized; | ||
40 | using System.Reflection; | ||
41 | using System.Xml; | ||
42 | |||
43 | using Prebuild.Core.Attributes; | ||
44 | using Prebuild.Core.Interfaces; | ||
45 | using Prebuild.Core.Utilities; | ||
46 | |||
47 | namespace Prebuild.Core.Nodes | ||
48 | { | ||
49 | /// <summary> | ||
50 | /// | ||
51 | /// </summary> | ||
52 | [DataNode("Options")] | ||
53 | public class OptionsNode : DataNode | ||
54 | { | ||
55 | #region Fields | ||
56 | |||
57 | private static Hashtable m_OptionFields; | ||
58 | |||
59 | [OptionNode("CompilerDefines")] | ||
60 | private string m_CompilerDefines = ""; | ||
61 | |||
62 | /// <summary> | ||
63 | /// | ||
64 | /// </summary> | ||
65 | public string CompilerDefines | ||
66 | { | ||
67 | get | ||
68 | { | ||
69 | return m_CompilerDefines; | ||
70 | } | ||
71 | set | ||
72 | { | ||
73 | m_CompilerDefines = value; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | [OptionNode("OptimizeCode")] | ||
78 | private bool m_OptimizeCode; | ||
79 | |||
80 | /// <summary> | ||
81 | /// | ||
82 | /// </summary> | ||
83 | public bool OptimizeCode | ||
84 | { | ||
85 | get | ||
86 | { | ||
87 | return m_OptimizeCode; | ||
88 | } | ||
89 | set | ||
90 | { | ||
91 | m_OptimizeCode = value; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | [OptionNode("CheckUnderflowOverflow")] | ||
96 | private bool m_CheckUnderflowOverflow; | ||
97 | |||
98 | /// <summary> | ||
99 | /// | ||
100 | /// </summary> | ||
101 | public bool CheckUnderflowOverflow | ||
102 | { | ||
103 | get | ||
104 | { | ||
105 | return m_CheckUnderflowOverflow; | ||
106 | } | ||
107 | set | ||
108 | { | ||
109 | m_CheckUnderflowOverflow = value; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | [OptionNode("AllowUnsafe")] | ||
114 | private bool m_AllowUnsafe; | ||
115 | |||
116 | /// <summary> | ||
117 | /// | ||
118 | /// </summary> | ||
119 | public bool AllowUnsafe | ||
120 | { | ||
121 | get | ||
122 | { | ||
123 | return m_AllowUnsafe; | ||
124 | } | ||
125 | set | ||
126 | { | ||
127 | m_AllowUnsafe = value; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | [OptionNode("PreBuildEvent")] | ||
132 | private string m_PreBuildEvent; | ||
133 | |||
134 | /// <summary> | ||
135 | /// | ||
136 | /// </summary> | ||
137 | public string PreBuildEvent | ||
138 | { | ||
139 | get | ||
140 | { | ||
141 | return m_PreBuildEvent; | ||
142 | } | ||
143 | set | ||
144 | { | ||
145 | m_PreBuildEvent = value; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | [OptionNode("PostBuildEvent")] | ||
150 | private string m_PostBuildEvent; | ||
151 | |||
152 | /// <summary> | ||
153 | /// | ||
154 | /// </summary> | ||
155 | public string PostBuildEvent | ||
156 | { | ||
157 | get | ||
158 | { | ||
159 | return m_PostBuildEvent; | ||
160 | } | ||
161 | set | ||
162 | { | ||
163 | m_PostBuildEvent = value; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | [OptionNode("PreBuildEventArgs")] | ||
168 | private string m_PreBuildEventArgs; | ||
169 | |||
170 | /// <summary> | ||
171 | /// | ||
172 | /// </summary> | ||
173 | public string PreBuildEventArgs | ||
174 | { | ||
175 | get | ||
176 | { | ||
177 | return m_PreBuildEventArgs; | ||
178 | } | ||
179 | set | ||
180 | { | ||
181 | m_PreBuildEventArgs = value; | ||
182 | } | ||
183 | } | ||
184 | |||
185 | [OptionNode("PostBuildEventArgs")] | ||
186 | private string m_PostBuildEventArgs; | ||
187 | |||
188 | /// <summary> | ||
189 | /// | ||
190 | /// </summary> | ||
191 | public string PostBuildEventArgs | ||
192 | { | ||
193 | get | ||
194 | { | ||
195 | return m_PostBuildEventArgs; | ||
196 | } | ||
197 | set | ||
198 | { | ||
199 | m_PostBuildEventArgs = value; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | [OptionNode("RunPostBuildEvent")] | ||
204 | private string m_RunPostBuildEvent; | ||
205 | |||
206 | /// <summary> | ||
207 | /// | ||
208 | /// </summary> | ||
209 | public string RunPostBuildEvent | ||
210 | { | ||
211 | get | ||
212 | { | ||
213 | return m_RunPostBuildEvent; | ||
214 | } | ||
215 | set | ||
216 | { | ||
217 | m_RunPostBuildEvent = value; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | [OptionNode("RunScript")] | ||
222 | private string m_RunScript; | ||
223 | |||
224 | /// <summary> | ||
225 | /// | ||
226 | /// </summary> | ||
227 | public string RunScript | ||
228 | { | ||
229 | get | ||
230 | { | ||
231 | return m_RunScript; | ||
232 | } | ||
233 | set | ||
234 | { | ||
235 | m_RunScript = value; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | [OptionNode("WarningLevel")] | ||
240 | private int m_WarningLevel = 4; | ||
241 | |||
242 | /// <summary> | ||
243 | /// | ||
244 | /// </summary> | ||
245 | public int WarningLevel | ||
246 | { | ||
247 | get | ||
248 | { | ||
249 | return m_WarningLevel; | ||
250 | } | ||
251 | set | ||
252 | { | ||
253 | m_WarningLevel = value; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | [OptionNode("WarningsAsErrors")] | ||
258 | private bool m_WarningsAsErrors; | ||
259 | |||
260 | /// <summary> | ||
261 | /// | ||
262 | /// </summary> | ||
263 | public bool WarningsAsErrors | ||
264 | { | ||
265 | get | ||
266 | { | ||
267 | return m_WarningsAsErrors; | ||
268 | } | ||
269 | set | ||
270 | { | ||
271 | m_WarningsAsErrors = value; | ||
272 | } | ||
273 | } | ||
274 | |||
275 | [OptionNode("SuppressWarnings")] | ||
276 | private string m_SuppressWarnings = ""; | ||
277 | |||
278 | /// <summary> | ||
279 | /// | ||
280 | /// </summary> | ||
281 | public string SuppressWarnings | ||
282 | { | ||
283 | get | ||
284 | { | ||
285 | return m_SuppressWarnings; | ||
286 | } | ||
287 | set | ||
288 | { | ||
289 | m_SuppressWarnings = value; | ||
290 | } | ||
291 | } | ||
292 | |||
293 | [OptionNode("OutputPath")] | ||
294 | private string m_OutputPath = "bin/"; | ||
295 | |||
296 | /// <summary> | ||
297 | /// | ||
298 | /// </summary> | ||
299 | public string OutputPath | ||
300 | { | ||
301 | get | ||
302 | { | ||
303 | return m_OutputPath; | ||
304 | } | ||
305 | set | ||
306 | { | ||
307 | m_OutputPath = value; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | [OptionNode("GenerateDocumentation")] | ||
312 | private bool m_GenerateDocumentation; | ||
313 | |||
314 | /// <summary> | ||
315 | /// | ||
316 | /// </summary> | ||
317 | public bool GenerateDocumentation | ||
318 | { | ||
319 | get | ||
320 | { | ||
321 | return m_GenerateDocumentation; | ||
322 | } | ||
323 | set | ||
324 | { | ||
325 | m_GenerateDocumentation = value; | ||
326 | } | ||
327 | } | ||
328 | |||
329 | [OptionNode("GenerateXmlDocFile")] | ||
330 | private bool m_GenerateXmlDocFile; | ||
331 | |||
332 | /// <summary> | ||
333 | /// | ||
334 | /// </summary> | ||
335 | public bool GenerateXmlDocFile | ||
336 | { | ||
337 | get | ||
338 | { | ||
339 | return m_GenerateXmlDocFile; | ||
340 | } | ||
341 | set | ||
342 | { | ||
343 | m_GenerateXmlDocFile = value; | ||
344 | } | ||
345 | } | ||
346 | |||
347 | [OptionNode("XmlDocFile")] | ||
348 | private string m_XmlDocFile = ""; | ||
349 | |||
350 | /// <summary> | ||
351 | /// | ||
352 | /// </summary> | ||
353 | public string XmlDocFile | ||
354 | { | ||
355 | get | ||
356 | { | ||
357 | return m_XmlDocFile; | ||
358 | } | ||
359 | set | ||
360 | { | ||
361 | m_XmlDocFile = value; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | [OptionNode("KeyFile")] | ||
366 | private string m_KeyFile = ""; | ||
367 | |||
368 | /// <summary> | ||
369 | /// | ||
370 | /// </summary> | ||
371 | public string KeyFile | ||
372 | { | ||
373 | get | ||
374 | { | ||
375 | return m_KeyFile; | ||
376 | } | ||
377 | set | ||
378 | { | ||
379 | m_KeyFile = value; | ||
380 | } | ||
381 | } | ||
382 | |||
383 | [OptionNode("DebugInformation")] | ||
384 | private bool m_DebugInformation; | ||
385 | |||
386 | /// <summary> | ||
387 | /// | ||
388 | /// </summary> | ||
389 | public bool DebugInformation | ||
390 | { | ||
391 | get | ||
392 | { | ||
393 | return m_DebugInformation; | ||
394 | } | ||
395 | set | ||
396 | { | ||
397 | m_DebugInformation = value; | ||
398 | } | ||
399 | } | ||
400 | |||
401 | [OptionNode("RegisterComInterop")] | ||
402 | private bool m_RegisterComInterop; | ||
403 | |||
404 | /// <summary> | ||
405 | /// | ||
406 | /// </summary> | ||
407 | public bool RegisterComInterop | ||
408 | { | ||
409 | get | ||
410 | { | ||
411 | return m_RegisterComInterop; | ||
412 | } | ||
413 | set | ||
414 | { | ||
415 | m_RegisterComInterop = value; | ||
416 | } | ||
417 | } | ||
418 | |||
419 | [OptionNode("RemoveIntegerChecks")] | ||
420 | private bool m_RemoveIntegerChecks; | ||
421 | |||
422 | /// <summary> | ||
423 | /// | ||
424 | /// </summary> | ||
425 | public bool RemoveIntegerChecks | ||
426 | { | ||
427 | get | ||
428 | { | ||
429 | return m_RemoveIntegerChecks; | ||
430 | } | ||
431 | set | ||
432 | { | ||
433 | m_RemoveIntegerChecks = value; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | [OptionNode("IncrementalBuild")] | ||
438 | private bool m_IncrementalBuild; | ||
439 | |||
440 | /// <summary> | ||
441 | /// | ||
442 | /// </summary> | ||
443 | public bool IncrementalBuild | ||
444 | { | ||
445 | get | ||
446 | { | ||
447 | return m_IncrementalBuild; | ||
448 | } | ||
449 | set | ||
450 | { | ||
451 | m_IncrementalBuild = value; | ||
452 | } | ||
453 | } | ||
454 | |||
455 | [OptionNode("BaseAddress")] | ||
456 | private string m_BaseAddress = "285212672"; | ||
457 | |||
458 | /// <summary> | ||
459 | /// | ||
460 | /// </summary> | ||
461 | public string BaseAddress | ||
462 | { | ||
463 | get | ||
464 | { | ||
465 | return m_BaseAddress; | ||
466 | } | ||
467 | set | ||
468 | { | ||
469 | m_BaseAddress = value; | ||
470 | } | ||
471 | } | ||
472 | |||
473 | [OptionNode("FileAlignment")] | ||
474 | private int m_FileAlignment = 4096; | ||
475 | |||
476 | /// <summary> | ||
477 | /// | ||
478 | /// </summary> | ||
479 | public int FileAlignment | ||
480 | { | ||
481 | get | ||
482 | { | ||
483 | return m_FileAlignment; | ||
484 | } | ||
485 | set | ||
486 | { | ||
487 | m_FileAlignment = value; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | [OptionNode("NoStdLib")] | ||
492 | private bool m_NoStdLib; | ||
493 | |||
494 | /// <summary> | ||
495 | /// | ||
496 | /// </summary> | ||
497 | public bool NoStdLib | ||
498 | { | ||
499 | get | ||
500 | { | ||
501 | return m_NoStdLib; | ||
502 | } | ||
503 | set | ||
504 | { | ||
505 | m_NoStdLib = value; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | private StringCollection m_FieldsDefined; | ||
510 | |||
511 | #endregion | ||
512 | |||
513 | #region Constructors | ||
514 | |||
515 | /// <summary> | ||
516 | /// Initializes the <see cref="OptionsNode"/> class. | ||
517 | /// </summary> | ||
518 | static OptionsNode() | ||
519 | { | ||
520 | Type t = typeof(OptionsNode); | ||
521 | |||
522 | m_OptionFields = new Hashtable(); | ||
523 | foreach(FieldInfo f in t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) | ||
524 | { | ||
525 | object[] attrs = f.GetCustomAttributes(typeof(OptionNodeAttribute), false); | ||
526 | if(attrs == null || attrs.Length < 1) | ||
527 | { | ||
528 | continue; | ||
529 | } | ||
530 | |||
531 | OptionNodeAttribute ona = (OptionNodeAttribute)attrs[0]; | ||
532 | m_OptionFields[ona.NodeName] = f; | ||
533 | } | ||
534 | } | ||
535 | |||
536 | /// <summary> | ||
537 | /// Initializes a new instance of the <see cref="OptionsNode"/> class. | ||
538 | /// </summary> | ||
539 | public OptionsNode() | ||
540 | { | ||
541 | m_FieldsDefined = new StringCollection(); | ||
542 | } | ||
543 | |||
544 | #endregion | ||
545 | |||
546 | #region Properties | ||
547 | |||
548 | /// <summary> | ||
549 | /// Gets the <see cref="Object"/> at the specified index. | ||
550 | /// </summary> | ||
551 | /// <value></value> | ||
552 | public object this[string index] | ||
553 | { | ||
554 | get | ||
555 | { | ||
556 | if(!m_OptionFields.ContainsKey(index)) | ||
557 | { | ||
558 | return null; | ||
559 | } | ||
560 | |||
561 | FieldInfo f = (FieldInfo)m_OptionFields[index]; | ||
562 | return f.GetValue(this); | ||
563 | } | ||
564 | } | ||
565 | |||
566 | /// <summary> | ||
567 | /// Gets the <see cref="Object"/> at the specified index. | ||
568 | /// </summary> | ||
569 | /// <value></value> | ||
570 | public object this[string index, object defaultValue] | ||
571 | { | ||
572 | get | ||
573 | { | ||
574 | object valueObject = this[index]; | ||
575 | if(valueObject != null && valueObject is string && ((string)valueObject).Length == 0) | ||
576 | { | ||
577 | return defaultValue; | ||
578 | } | ||
579 | return valueObject; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | |||
584 | #endregion | ||
585 | |||
586 | #region Private Methods | ||
587 | |||
588 | private void FlagDefined(string name) | ||
589 | { | ||
590 | if(!m_FieldsDefined.Contains(name)) | ||
591 | { | ||
592 | m_FieldsDefined.Add(name); | ||
593 | } | ||
594 | } | ||
595 | |||
596 | private void SetOption(string nodeName, string val) | ||
597 | { | ||
598 | lock(m_OptionFields) | ||
599 | { | ||
600 | if(!m_OptionFields.ContainsKey(nodeName)) | ||
601 | { | ||
602 | return; | ||
603 | } | ||
604 | |||
605 | FieldInfo f = (FieldInfo)m_OptionFields[nodeName]; | ||
606 | f.SetValue(this, Helper.TranslateValue(f.FieldType, val)); | ||
607 | FlagDefined(f.Name); | ||
608 | } | ||
609 | } | ||
610 | |||
611 | #endregion | ||
612 | |||
613 | #region Public Methods | ||
614 | |||
615 | /// <summary> | ||
616 | /// Parses the specified node. | ||
617 | /// </summary> | ||
618 | /// <param name="node">The node.</param> | ||
619 | public override void Parse(XmlNode node) | ||
620 | { | ||
621 | if( node == null ) | ||
622 | { | ||
623 | throw new ArgumentNullException("node"); | ||
624 | } | ||
625 | |||
626 | foreach(XmlNode child in node.ChildNodes) | ||
627 | { | ||
628 | SetOption(child.Name, Helper.InterpolateForEnvironmentVariables(child.InnerText)); | ||
629 | } | ||
630 | } | ||
631 | |||
632 | /// <summary> | ||
633 | /// Copies to. | ||
634 | /// </summary> | ||
635 | /// <param name="opt">The opt.</param> | ||
636 | public void CopyTo(OptionsNode opt) | ||
637 | { | ||
638 | if(opt == null) | ||
639 | { | ||
640 | return; | ||
641 | } | ||
642 | |||
643 | foreach(FieldInfo f in m_OptionFields.Values) | ||
644 | { | ||
645 | if(m_FieldsDefined.Contains(f.Name)) | ||
646 | { | ||
647 | f.SetValue(opt, f.GetValue(this)); | ||
648 | opt.m_FieldsDefined.Add(f.Name); | ||
649 | } | ||
650 | } | ||
651 | } | ||
652 | |||
653 | #endregion | ||
654 | } | ||
655 | } | ||
diff --git a/Prebuild/src/Core/Nodes/ProcessNode.cs b/Prebuild/src/Core/Nodes/ProcessNode.cs new file mode 100644 index 0000000..f546a4b --- /dev/null +++ b/Prebuild/src/Core/Nodes/ProcessNode.cs | |||
@@ -0,0 +1,119 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.Xml; | ||
39 | |||
40 | using Prebuild.Core.Attributes; | ||
41 | using Prebuild.Core.Interfaces; | ||
42 | using Prebuild.Core.Utilities; | ||
43 | |||
44 | namespace Prebuild.Core.Nodes | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// | ||
48 | /// </summary> | ||
49 | [DataNode("Process")] | ||
50 | public class ProcessNode : DataNode | ||
51 | { | ||
52 | #region Fields | ||
53 | |||
54 | private string m_Path; | ||
55 | private bool m_IsValid = true; | ||
56 | |||
57 | #endregion | ||
58 | |||
59 | #region Properties | ||
60 | |||
61 | /// <summary> | ||
62 | /// Gets the path. | ||
63 | /// </summary> | ||
64 | /// <value>The path.</value> | ||
65 | public string Path | ||
66 | { | ||
67 | get | ||
68 | { | ||
69 | return m_Path; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | /// <summary> | ||
74 | /// Gets a value indicating whether this instance is valid. | ||
75 | /// </summary> | ||
76 | /// <value><c>true</c> if this instance is valid; otherwise, <c>false</c>.</value> | ||
77 | public bool IsValid | ||
78 | { | ||
79 | get | ||
80 | { | ||
81 | return m_IsValid; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | #endregion | ||
86 | |||
87 | #region Public Methods | ||
88 | |||
89 | /// <summary> | ||
90 | /// Parses the specified node. | ||
91 | /// </summary> | ||
92 | /// <param name="node">The node.</param> | ||
93 | public override void Parse(XmlNode node) | ||
94 | { | ||
95 | if( node == null ) | ||
96 | { | ||
97 | throw new ArgumentNullException("node"); | ||
98 | } | ||
99 | |||
100 | m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText); | ||
101 | if(m_Path == null) | ||
102 | { | ||
103 | m_Path = ""; | ||
104 | } | ||
105 | |||
106 | try | ||
107 | { | ||
108 | m_Path = Helper.ResolvePath(m_Path); | ||
109 | } | ||
110 | catch(ArgumentException) | ||
111 | { | ||
112 | Kernel.Instance.Log.Write(LogType.Warning, "Could not find prebuild file for processing: {0}", m_Path); | ||
113 | m_IsValid = false; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | #endregion | ||
118 | } | ||
119 | } | ||
diff --git a/Prebuild/src/Core/Nodes/ProjectNode.cs b/Prebuild/src/Core/Nodes/ProjectNode.cs new file mode 100644 index 0000000..84d9f5d --- /dev/null +++ b/Prebuild/src/Core/Nodes/ProjectNode.cs | |||
@@ -0,0 +1,494 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-11-11 05:43:20 +0100 (lö, 11 nov 2006) $ | ||
31 | * $Revision: 192 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.IO; | ||
38 | using System.Xml; | ||
39 | |||
40 | using Prebuild.Core.Attributes; | ||
41 | using Prebuild.Core.Interfaces; | ||
42 | using Prebuild.Core.Utilities; | ||
43 | |||
44 | namespace Prebuild.Core.Nodes | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// | ||
48 | /// </summary> | ||
49 | public enum ProjectType | ||
50 | { | ||
51 | /// <summary> | ||
52 | /// | ||
53 | /// </summary> | ||
54 | Exe, | ||
55 | /// <summary> | ||
56 | /// | ||
57 | /// </summary> | ||
58 | WinExe, | ||
59 | /// <summary> | ||
60 | /// | ||
61 | /// </summary> | ||
62 | Library | ||
63 | } | ||
64 | |||
65 | /// <summary> | ||
66 | /// | ||
67 | /// </summary> | ||
68 | public enum ClrRuntime | ||
69 | { | ||
70 | /// <summary> | ||
71 | /// | ||
72 | /// </summary> | ||
73 | Microsoft, | ||
74 | /// <summary> | ||
75 | /// | ||
76 | /// </summary> | ||
77 | Mono | ||
78 | } | ||
79 | |||
80 | /// <summary> | ||
81 | /// | ||
82 | /// </summary> | ||
83 | [DataNode("Project")] | ||
84 | public class ProjectNode : DataNode | ||
85 | { | ||
86 | #region Fields | ||
87 | |||
88 | private string m_Name = "unknown"; | ||
89 | private string m_Path = ""; | ||
90 | private string m_FullPath = ""; | ||
91 | private string m_AssemblyName; | ||
92 | private string m_AppIcon = ""; | ||
93 | private string m_DesignerFolder = ""; | ||
94 | private string m_Language = "C#"; | ||
95 | private ProjectType m_Type = ProjectType.Exe; | ||
96 | private ClrRuntime m_Runtime = ClrRuntime.Microsoft; | ||
97 | private string m_StartupObject = ""; | ||
98 | private string m_RootNamespace; | ||
99 | private string m_FilterGroups = ""; | ||
100 | private Guid m_Guid; | ||
101 | |||
102 | private Hashtable m_Configurations; | ||
103 | private ArrayList m_ReferencePaths; | ||
104 | private ArrayList m_References; | ||
105 | private FilesNode m_Files; | ||
106 | |||
107 | #endregion | ||
108 | |||
109 | #region Constructors | ||
110 | |||
111 | /// <summary> | ||
112 | /// Initializes a new instance of the <see cref="ProjectNode"/> class. | ||
113 | /// </summary> | ||
114 | public ProjectNode() | ||
115 | { | ||
116 | m_Configurations = new Hashtable(); | ||
117 | m_ReferencePaths = new ArrayList(); | ||
118 | m_References = new ArrayList(); | ||
119 | } | ||
120 | |||
121 | #endregion | ||
122 | |||
123 | #region Properties | ||
124 | |||
125 | /// <summary> | ||
126 | /// Gets the name. | ||
127 | /// </summary> | ||
128 | /// <value>The name.</value> | ||
129 | public string Name | ||
130 | { | ||
131 | get | ||
132 | { | ||
133 | return m_Name; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// Gets the path. | ||
139 | /// </summary> | ||
140 | /// <value>The path.</value> | ||
141 | public string Path | ||
142 | { | ||
143 | get | ||
144 | { | ||
145 | return m_Path; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// Gets the filter groups. | ||
151 | /// </summary> | ||
152 | /// <value>The filter groups.</value> | ||
153 | public string FilterGroups | ||
154 | { | ||
155 | get | ||
156 | { | ||
157 | return m_FilterGroups; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | /// <summary> | ||
162 | /// Gets the full path. | ||
163 | /// </summary> | ||
164 | /// <value>The full path.</value> | ||
165 | public string FullPath | ||
166 | { | ||
167 | get | ||
168 | { | ||
169 | return m_FullPath; | ||
170 | } | ||
171 | } | ||
172 | |||
173 | /// <summary> | ||
174 | /// Gets the name of the assembly. | ||
175 | /// </summary> | ||
176 | /// <value>The name of the assembly.</value> | ||
177 | public string AssemblyName | ||
178 | { | ||
179 | get | ||
180 | { | ||
181 | return m_AssemblyName; | ||
182 | } | ||
183 | } | ||
184 | |||
185 | /// <summary> | ||
186 | /// Gets the app icon. | ||
187 | /// </summary> | ||
188 | /// <value>The app icon.</value> | ||
189 | public string AppIcon | ||
190 | { | ||
191 | get | ||
192 | { | ||
193 | return m_AppIcon; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | /// <summary> | ||
198 | /// | ||
199 | /// </summary> | ||
200 | public string DesignerFolder | ||
201 | { | ||
202 | get | ||
203 | { | ||
204 | return m_DesignerFolder; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | /// <summary> | ||
209 | /// Gets the language. | ||
210 | /// </summary> | ||
211 | /// <value>The language.</value> | ||
212 | public string Language | ||
213 | { | ||
214 | get | ||
215 | { | ||
216 | return m_Language; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | /// <summary> | ||
221 | /// Gets the type. | ||
222 | /// </summary> | ||
223 | /// <value>The type.</value> | ||
224 | public ProjectType Type | ||
225 | { | ||
226 | get | ||
227 | { | ||
228 | return m_Type; | ||
229 | } | ||
230 | } | ||
231 | |||
232 | /// <summary> | ||
233 | /// Gets the runtime. | ||
234 | /// </summary> | ||
235 | /// <value>The runtime.</value> | ||
236 | public ClrRuntime Runtime | ||
237 | { | ||
238 | get | ||
239 | { | ||
240 | return m_Runtime; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | private bool m_GenerateAssemblyInfoFile = false; | ||
245 | |||
246 | /// <summary> | ||
247 | /// | ||
248 | /// </summary> | ||
249 | public bool GenerateAssemblyInfoFile | ||
250 | { | ||
251 | get | ||
252 | { | ||
253 | return m_GenerateAssemblyInfoFile; | ||
254 | } | ||
255 | set | ||
256 | { | ||
257 | m_GenerateAssemblyInfoFile = value; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | /// <summary> | ||
262 | /// Gets the startup object. | ||
263 | /// </summary> | ||
264 | /// <value>The startup object.</value> | ||
265 | public string StartupObject | ||
266 | { | ||
267 | get | ||
268 | { | ||
269 | return m_StartupObject; | ||
270 | } | ||
271 | } | ||
272 | |||
273 | /// <summary> | ||
274 | /// Gets the root namespace. | ||
275 | /// </summary> | ||
276 | /// <value>The root namespace.</value> | ||
277 | public string RootNamespace | ||
278 | { | ||
279 | get | ||
280 | { | ||
281 | return m_RootNamespace; | ||
282 | } | ||
283 | } | ||
284 | |||
285 | /// <summary> | ||
286 | /// Gets the configurations. | ||
287 | /// </summary> | ||
288 | /// <value>The configurations.</value> | ||
289 | public ICollection Configurations | ||
290 | { | ||
291 | get | ||
292 | { | ||
293 | return m_Configurations.Values; | ||
294 | } | ||
295 | } | ||
296 | |||
297 | /// <summary> | ||
298 | /// Gets the configurations table. | ||
299 | /// </summary> | ||
300 | /// <value>The configurations table.</value> | ||
301 | public Hashtable ConfigurationsTable | ||
302 | { | ||
303 | get | ||
304 | { | ||
305 | return m_Configurations; | ||
306 | } | ||
307 | } | ||
308 | |||
309 | /// <summary> | ||
310 | /// Gets the reference paths. | ||
311 | /// </summary> | ||
312 | /// <value>The reference paths.</value> | ||
313 | public ArrayList ReferencePaths | ||
314 | { | ||
315 | get | ||
316 | { | ||
317 | return m_ReferencePaths; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | /// <summary> | ||
322 | /// Gets the references. | ||
323 | /// </summary> | ||
324 | /// <value>The references.</value> | ||
325 | public ArrayList References | ||
326 | { | ||
327 | get | ||
328 | { | ||
329 | return m_References; | ||
330 | } | ||
331 | } | ||
332 | |||
333 | /// <summary> | ||
334 | /// Gets the files. | ||
335 | /// </summary> | ||
336 | /// <value>The files.</value> | ||
337 | public FilesNode Files | ||
338 | { | ||
339 | get | ||
340 | { | ||
341 | return m_Files; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | /// <summary> | ||
346 | /// Gets or sets the parent. | ||
347 | /// </summary> | ||
348 | /// <value>The parent.</value> | ||
349 | public override IDataNode Parent | ||
350 | { | ||
351 | get | ||
352 | { | ||
353 | return base.Parent; | ||
354 | } | ||
355 | set | ||
356 | { | ||
357 | base.Parent = value; | ||
358 | if(base.Parent is SolutionNode && m_Configurations.Count < 1) | ||
359 | { | ||
360 | SolutionNode parent = (SolutionNode)base.Parent; | ||
361 | foreach(ConfigurationNode conf in parent.Configurations) | ||
362 | { | ||
363 | m_Configurations[conf.Name] = conf.Clone(); | ||
364 | } | ||
365 | } | ||
366 | } | ||
367 | } | ||
368 | |||
369 | /// <summary> | ||
370 | /// Gets the GUID. | ||
371 | /// </summary> | ||
372 | /// <value>The GUID.</value> | ||
373 | public Guid Guid | ||
374 | { | ||
375 | get | ||
376 | { | ||
377 | return m_Guid; | ||
378 | } | ||
379 | } | ||
380 | |||
381 | #endregion | ||
382 | |||
383 | #region Private Methods | ||
384 | |||
385 | private void HandleConfiguration(ConfigurationNode conf) | ||
386 | { | ||
387 | if(String.Compare(conf.Name, "all", true) == 0) //apply changes to all, this may not always be applied first, | ||
388 | //so it *may* override changes to the same properties for configurations defines at the project level | ||
389 | { | ||
390 | foreach(ConfigurationNode confNode in this.m_Configurations.Values) | ||
391 | { | ||
392 | conf.CopyTo(confNode);//update the config templates defines at the project level with the overrides | ||
393 | } | ||
394 | } | ||
395 | if(m_Configurations.ContainsKey(conf.Name)) | ||
396 | { | ||
397 | ConfigurationNode parentConf = (ConfigurationNode)m_Configurations[conf.Name]; | ||
398 | conf.CopyTo(parentConf);//update the config templates defines at the project level with the overrides | ||
399 | } | ||
400 | else | ||
401 | { | ||
402 | m_Configurations[conf.Name] = conf; | ||
403 | } | ||
404 | } | ||
405 | |||
406 | #endregion | ||
407 | |||
408 | #region Public Methods | ||
409 | |||
410 | /// <summary> | ||
411 | /// Parses the specified node. | ||
412 | /// </summary> | ||
413 | /// <param name="node">The node.</param> | ||
414 | public override void Parse(XmlNode node) | ||
415 | { | ||
416 | m_Name = Helper.AttributeValue(node, "name", m_Name); | ||
417 | m_Path = Helper.AttributeValue(node, "path", m_Path); | ||
418 | m_FilterGroups = Helper.AttributeValue(node, "filterGroups", m_FilterGroups); | ||
419 | m_AppIcon = Helper.AttributeValue(node, "icon", m_AppIcon); | ||
420 | m_DesignerFolder = Helper.AttributeValue(node, "designerFolder", m_DesignerFolder); | ||
421 | m_AssemblyName = Helper.AttributeValue(node, "assemblyName", m_AssemblyName); | ||
422 | m_Language = Helper.AttributeValue(node, "language", m_Language); | ||
423 | m_Type = (ProjectType)Helper.EnumAttributeValue(node, "type", typeof(ProjectType), m_Type); | ||
424 | m_Runtime = (ClrRuntime)Helper.EnumAttributeValue(node, "runtime", typeof(ClrRuntime), m_Runtime); | ||
425 | m_StartupObject = Helper.AttributeValue(node, "startupObject", m_StartupObject); | ||
426 | m_RootNamespace = Helper.AttributeValue(node, "rootNamespace", m_RootNamespace); | ||
427 | |||
428 | int hash = m_Name.GetHashCode(); | ||
429 | |||
430 | m_Guid = new Guid( hash, 0, 0, 0, 0, 0, 0,0,0,0,0 ); | ||
431 | |||
432 | m_GenerateAssemblyInfoFile = Helper.ParseBoolean(node, "generateAssemblyInfoFile", false); | ||
433 | |||
434 | if(m_AssemblyName == null || m_AssemblyName.Length < 1) | ||
435 | { | ||
436 | m_AssemblyName = m_Name; | ||
437 | } | ||
438 | |||
439 | if(m_RootNamespace == null || m_RootNamespace.Length < 1) | ||
440 | { | ||
441 | m_RootNamespace = m_Name; | ||
442 | } | ||
443 | |||
444 | m_FullPath = m_Path; | ||
445 | try | ||
446 | { | ||
447 | m_FullPath = Helper.ResolvePath(m_FullPath); | ||
448 | } | ||
449 | catch | ||
450 | { | ||
451 | throw new WarningException("Could not resolve Solution path: {0}", m_Path); | ||
452 | } | ||
453 | |||
454 | Kernel.Instance.CurrentWorkingDirectory.Push(); | ||
455 | try | ||
456 | { | ||
457 | Helper.SetCurrentDir(m_FullPath); | ||
458 | |||
459 | if( node == null ) | ||
460 | { | ||
461 | throw new ArgumentNullException("node"); | ||
462 | } | ||
463 | |||
464 | foreach(XmlNode child in node.ChildNodes) | ||
465 | { | ||
466 | IDataNode dataNode = Kernel.Instance.ParseNode(child, this); | ||
467 | if(dataNode is ConfigurationNode) | ||
468 | { | ||
469 | HandleConfiguration((ConfigurationNode)dataNode); | ||
470 | } | ||
471 | else if(dataNode is ReferencePathNode) | ||
472 | { | ||
473 | m_ReferencePaths.Add(dataNode); | ||
474 | } | ||
475 | else if(dataNode is ReferenceNode) | ||
476 | { | ||
477 | m_References.Add(dataNode); | ||
478 | } | ||
479 | else if(dataNode is FilesNode) | ||
480 | { | ||
481 | m_Files = (FilesNode)dataNode; | ||
482 | } | ||
483 | } | ||
484 | } | ||
485 | finally | ||
486 | { | ||
487 | Kernel.Instance.CurrentWorkingDirectory.Pop(); | ||
488 | } | ||
489 | } | ||
490 | |||
491 | |||
492 | #endregion | ||
493 | } | ||
494 | } | ||
diff --git a/Prebuild/src/Core/Nodes/ReferenceNode.cs b/Prebuild/src/Core/Nodes/ReferenceNode.cs new file mode 100644 index 0000000..beb50dc --- /dev/null +++ b/Prebuild/src/Core/Nodes/ReferenceNode.cs | |||
@@ -0,0 +1,143 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-07-25 18:56:49 +0200 (ti, 25 jul 2006) $ | ||
31 | * $Revision: 132 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Xml; | ||
37 | |||
38 | using Prebuild.Core.Attributes; | ||
39 | using Prebuild.Core.Interfaces; | ||
40 | using Prebuild.Core.Utilities; | ||
41 | |||
42 | namespace Prebuild.Core.Nodes | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// | ||
46 | /// </summary> | ||
47 | [DataNode("Reference")] | ||
48 | public class ReferenceNode : DataNode | ||
49 | { | ||
50 | #region Fields | ||
51 | |||
52 | private string m_Name = "unknown"; | ||
53 | private string m_Path; | ||
54 | private string m_LocalCopy; | ||
55 | private string m_Version; | ||
56 | |||
57 | #endregion | ||
58 | |||
59 | #region Properties | ||
60 | |||
61 | /// <summary> | ||
62 | /// Gets the name. | ||
63 | /// </summary> | ||
64 | /// <value>The name.</value> | ||
65 | public string Name | ||
66 | { | ||
67 | get | ||
68 | { | ||
69 | return m_Name; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | /// <summary> | ||
74 | /// Gets the path. | ||
75 | /// </summary> | ||
76 | /// <value>The path.</value> | ||
77 | public string Path | ||
78 | { | ||
79 | get | ||
80 | { | ||
81 | return m_Path; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | /// <summary> | ||
86 | /// Gets a value indicating whether [local copy specified]. | ||
87 | /// </summary> | ||
88 | /// <value><c>true</c> if [local copy specified]; otherwise, <c>false</c>.</value> | ||
89 | public bool LocalCopySpecified | ||
90 | { | ||
91 | get | ||
92 | { | ||
93 | return ( m_LocalCopy != null && m_LocalCopy.Length == 0); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | /// <summary> | ||
98 | /// Gets a value indicating whether [local copy]. | ||
99 | /// </summary> | ||
100 | /// <value><c>true</c> if [local copy]; otherwise, <c>false</c>.</value> | ||
101 | public bool LocalCopy | ||
102 | { | ||
103 | get | ||
104 | { | ||
105 | if( m_LocalCopy == null) | ||
106 | { | ||
107 | return false; | ||
108 | } | ||
109 | return bool.Parse(m_LocalCopy); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Gets the version. | ||
115 | /// </summary> | ||
116 | /// <value>The version.</value> | ||
117 | public string Version | ||
118 | { | ||
119 | get | ||
120 | { | ||
121 | return m_Version; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | #endregion | ||
126 | |||
127 | #region Public Methods | ||
128 | |||
129 | /// <summary> | ||
130 | /// Parses the specified node. | ||
131 | /// </summary> | ||
132 | /// <param name="node">The node.</param> | ||
133 | public override void Parse(XmlNode node) | ||
134 | { | ||
135 | m_Name = Helper.AttributeValue(node, "name", m_Name); | ||
136 | m_Path = Helper.AttributeValue(node, "path", m_Path); | ||
137 | m_LocalCopy = Helper.AttributeValue(node, "localCopy", m_LocalCopy); | ||
138 | m_Version = Helper.AttributeValue(node, "version", m_Version); | ||
139 | } | ||
140 | |||
141 | #endregion | ||
142 | } | ||
143 | } | ||
diff --git a/Prebuild/src/Core/Nodes/ReferencePathNode.cs b/Prebuild/src/Core/Nodes/ReferencePathNode.cs new file mode 100644 index 0000000..5d98dda --- /dev/null +++ b/Prebuild/src/Core/Nodes/ReferencePathNode.cs | |||
@@ -0,0 +1,98 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.Xml; | ||
39 | |||
40 | using Prebuild.Core.Attributes; | ||
41 | using Prebuild.Core.Interfaces; | ||
42 | using Prebuild.Core.Utilities; | ||
43 | |||
44 | namespace Prebuild.Core.Nodes | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// | ||
48 | /// </summary> | ||
49 | [DataNode("ReferencePath")] | ||
50 | public class ReferencePathNode : DataNode | ||
51 | { | ||
52 | #region Fields | ||
53 | |||
54 | private string m_Path; | ||
55 | |||
56 | #endregion | ||
57 | |||
58 | #region Properties | ||
59 | |||
60 | /// <summary> | ||
61 | /// Gets the path. | ||
62 | /// </summary> | ||
63 | /// <value>The path.</value> | ||
64 | public string Path | ||
65 | { | ||
66 | get | ||
67 | { | ||
68 | return m_Path; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | #endregion | ||
73 | |||
74 | #region Public Methods | ||
75 | |||
76 | /// <summary> | ||
77 | /// Parses the specified node. | ||
78 | /// </summary> | ||
79 | /// <param name="node">The node.</param> | ||
80 | public override void Parse(XmlNode node) | ||
81 | { | ||
82 | if( node == null ) | ||
83 | { | ||
84 | throw new ArgumentNullException("node"); | ||
85 | } | ||
86 | |||
87 | m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText); | ||
88 | if(m_Path == null) | ||
89 | { | ||
90 | m_Path = ""; | ||
91 | } | ||
92 | |||
93 | m_Path = m_Path.Trim(); | ||
94 | } | ||
95 | |||
96 | #endregion | ||
97 | } | ||
98 | } | ||
diff --git a/Prebuild/src/Core/Nodes/SolutionNode.cs b/Prebuild/src/Core/Nodes/SolutionNode.cs new file mode 100644 index 0000000..0121075 --- /dev/null +++ b/Prebuild/src/Core/Nodes/SolutionNode.cs | |||
@@ -0,0 +1,284 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-02-28 17:15:42 +0100 (ti, 28 feb 2006) $ | ||
31 | * $Revision: 92 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Diagnostics; | ||
38 | using System.IO; | ||
39 | using System.Xml; | ||
40 | |||
41 | using Prebuild.Core.Attributes; | ||
42 | using Prebuild.Core.Interfaces; | ||
43 | using Prebuild.Core.Utilities; | ||
44 | |||
45 | namespace Prebuild.Core.Nodes | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// | ||
49 | /// </summary> | ||
50 | [DataNode("Solution")] | ||
51 | public class SolutionNode : DataNode | ||
52 | { | ||
53 | #region Fields | ||
54 | |||
55 | private string m_Name = "unknown"; | ||
56 | private string m_Path = ""; | ||
57 | private string m_FullPath = ""; | ||
58 | private string m_ActiveConfig = "Debug"; | ||
59 | |||
60 | private OptionsNode m_Options; | ||
61 | private FilesNode m_Files; | ||
62 | private Hashtable m_Configurations; | ||
63 | private Hashtable m_Projects; | ||
64 | private ArrayList m_ProjectsOrder; | ||
65 | |||
66 | #endregion | ||
67 | |||
68 | #region Constructors | ||
69 | |||
70 | /// <summary> | ||
71 | /// Initializes a new instance of the <see cref="SolutionNode"/> class. | ||
72 | /// </summary> | ||
73 | public SolutionNode() | ||
74 | { | ||
75 | m_Configurations = new Hashtable(); | ||
76 | m_Projects = new Hashtable(); | ||
77 | m_ProjectsOrder = new ArrayList(); | ||
78 | } | ||
79 | |||
80 | #endregion | ||
81 | |||
82 | #region Properties | ||
83 | |||
84 | /// <summary> | ||
85 | /// Gets or sets the active config. | ||
86 | /// </summary> | ||
87 | /// <value>The active config.</value> | ||
88 | public string ActiveConfig | ||
89 | { | ||
90 | get | ||
91 | { | ||
92 | return m_ActiveConfig; | ||
93 | } | ||
94 | set | ||
95 | { | ||
96 | m_ActiveConfig = value; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// Gets the name. | ||
102 | /// </summary> | ||
103 | /// <value>The name.</value> | ||
104 | public string Name | ||
105 | { | ||
106 | get | ||
107 | { | ||
108 | return m_Name; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | /// <summary> | ||
113 | /// Gets the path. | ||
114 | /// </summary> | ||
115 | /// <value>The path.</value> | ||
116 | public string Path | ||
117 | { | ||
118 | get | ||
119 | { | ||
120 | return m_Path; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | /// <summary> | ||
125 | /// Gets the full path. | ||
126 | /// </summary> | ||
127 | /// <value>The full path.</value> | ||
128 | public string FullPath | ||
129 | { | ||
130 | get | ||
131 | { | ||
132 | return m_FullPath; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// Gets the options. | ||
138 | /// </summary> | ||
139 | /// <value>The options.</value> | ||
140 | public OptionsNode Options | ||
141 | { | ||
142 | get | ||
143 | { | ||
144 | return m_Options; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Gets the files. | ||
150 | /// </summary> | ||
151 | /// <value>The files.</value> | ||
152 | public FilesNode Files | ||
153 | { | ||
154 | get | ||
155 | { | ||
156 | return m_Files; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | /// <summary> | ||
161 | /// Gets the configurations. | ||
162 | /// </summary> | ||
163 | /// <value>The configurations.</value> | ||
164 | public ICollection Configurations | ||
165 | { | ||
166 | get | ||
167 | { | ||
168 | return m_Configurations.Values; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | /// <summary> | ||
173 | /// Gets the configurations table. | ||
174 | /// </summary> | ||
175 | /// <value>The configurations table.</value> | ||
176 | public Hashtable ConfigurationsTable | ||
177 | { | ||
178 | get | ||
179 | { | ||
180 | return m_Configurations; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | /// <summary> | ||
185 | /// Gets the projects. | ||
186 | /// </summary> | ||
187 | /// <value>The projects.</value> | ||
188 | public ICollection Projects | ||
189 | { | ||
190 | get | ||
191 | { | ||
192 | return m_Projects.Values; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | /// <summary> | ||
197 | /// Gets the projects table. | ||
198 | /// </summary> | ||
199 | /// <value>The projects table.</value> | ||
200 | public Hashtable ProjectsTable | ||
201 | { | ||
202 | get | ||
203 | { | ||
204 | return m_Projects; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | /// <summary> | ||
209 | /// Gets the projects table. | ||
210 | /// </summary> | ||
211 | /// <value>The projects table.</value> | ||
212 | public ArrayList ProjectsTableOrder | ||
213 | { | ||
214 | get | ||
215 | { | ||
216 | return m_ProjectsOrder; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | #endregion | ||
221 | |||
222 | #region Public Methods | ||
223 | |||
224 | /// <summary> | ||
225 | /// Parses the specified node. | ||
226 | /// </summary> | ||
227 | /// <param name="node">The node.</param> | ||
228 | public override void Parse(XmlNode node) | ||
229 | { | ||
230 | m_Name = Helper.AttributeValue(node, "name", m_Name); | ||
231 | m_ActiveConfig = Helper.AttributeValue(node, "activeConfig", m_ActiveConfig); | ||
232 | m_Path = Helper.AttributeValue(node, "path", m_Path); | ||
233 | |||
234 | m_FullPath = m_Path; | ||
235 | try | ||
236 | { | ||
237 | m_FullPath = Helper.ResolvePath(m_FullPath); | ||
238 | } | ||
239 | catch | ||
240 | { | ||
241 | throw new WarningException("Could not resolve solution path: {0}", m_Path); | ||
242 | } | ||
243 | |||
244 | Kernel.Instance.CurrentWorkingDirectory.Push(); | ||
245 | try | ||
246 | { | ||
247 | Helper.SetCurrentDir(m_FullPath); | ||
248 | |||
249 | if( node == null ) | ||
250 | { | ||
251 | throw new ArgumentNullException("node"); | ||
252 | } | ||
253 | |||
254 | foreach(XmlNode child in node.ChildNodes) | ||
255 | { | ||
256 | IDataNode dataNode = Kernel.Instance.ParseNode(child, this); | ||
257 | if(dataNode is OptionsNode) | ||
258 | { | ||
259 | m_Options = (OptionsNode)dataNode; | ||
260 | } | ||
261 | else if(dataNode is FilesNode) | ||
262 | { | ||
263 | m_Files = (FilesNode)dataNode; | ||
264 | } | ||
265 | else if(dataNode is ConfigurationNode) | ||
266 | { | ||
267 | m_Configurations[((ConfigurationNode)dataNode).Name] = dataNode; | ||
268 | } | ||
269 | else if(dataNode is ProjectNode) | ||
270 | { | ||
271 | m_Projects[((ProjectNode)dataNode).Name] = dataNode; | ||
272 | m_ProjectsOrder.Add(dataNode); | ||
273 | } | ||
274 | } | ||
275 | } | ||
276 | finally | ||
277 | { | ||
278 | Kernel.Instance.CurrentWorkingDirectory.Pop(); | ||
279 | } | ||
280 | } | ||
281 | |||
282 | #endregion | ||
283 | } | ||
284 | } | ||
diff --git a/Prebuild/src/Core/Parse/IfContext.cs b/Prebuild/src/Core/Parse/IfContext.cs new file mode 100644 index 0000000..383049d --- /dev/null +++ b/Prebuild/src/Core/Parse/IfContext.cs | |||
@@ -0,0 +1,163 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | |||
37 | namespace Prebuild.Core.Parse | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// | ||
41 | /// </summary> | ||
42 | public enum IfState | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// | ||
46 | /// </summary> | ||
47 | None, | ||
48 | /// <summary> | ||
49 | /// | ||
50 | /// </summary> | ||
51 | If, | ||
52 | /// <summary> | ||
53 | /// | ||
54 | /// </summary> | ||
55 | ElseIf, | ||
56 | /// <summary> | ||
57 | /// | ||
58 | /// </summary> | ||
59 | Else | ||
60 | } | ||
61 | |||
62 | /// <summary> | ||
63 | /// Summary description for IfContext. | ||
64 | /// </summary> | ||
65 | // Inspired by the equivalent WiX class (see www.sourceforge.net/projects/wix/) | ||
66 | public class IfContext | ||
67 | { | ||
68 | #region Properties | ||
69 | |||
70 | bool m_Active; | ||
71 | bool m_Keep; | ||
72 | bool m_EverKept; | ||
73 | IfState m_State = IfState.None; | ||
74 | |||
75 | #endregion | ||
76 | |||
77 | #region Constructors | ||
78 | |||
79 | /// <summary> | ||
80 | /// Initializes a new instance of the <see cref="IfContext"/> class. | ||
81 | /// </summary> | ||
82 | /// <param name="active">if set to <c>true</c> [active].</param> | ||
83 | /// <param name="keep">if set to <c>true</c> [keep].</param> | ||
84 | /// <param name="state">The state.</param> | ||
85 | public IfContext(bool active, bool keep, IfState state) | ||
86 | { | ||
87 | m_Active = active; | ||
88 | m_Keep = keep; | ||
89 | m_EverKept = keep; | ||
90 | m_State = state; | ||
91 | } | ||
92 | |||
93 | #endregion | ||
94 | |||
95 | #region Properties | ||
96 | |||
97 | /// <summary> | ||
98 | /// Gets or sets a value indicating whether this <see cref="IfContext"/> is active. | ||
99 | /// </summary> | ||
100 | /// <value><c>true</c> if active; otherwise, <c>false</c>.</value> | ||
101 | public bool Active | ||
102 | { | ||
103 | get | ||
104 | { | ||
105 | return m_Active; | ||
106 | } | ||
107 | set | ||
108 | { | ||
109 | m_Active = value; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Gets or sets a value indicating whether this <see cref="IfContext"/> is keep. | ||
115 | /// </summary> | ||
116 | /// <value><c>true</c> if keep; otherwise, <c>false</c>.</value> | ||
117 | public bool Keep | ||
118 | { | ||
119 | get | ||
120 | { | ||
121 | return m_Keep; | ||
122 | } | ||
123 | set | ||
124 | { | ||
125 | m_Keep = value; | ||
126 | if(m_Keep) | ||
127 | { | ||
128 | m_EverKept = true; | ||
129 | } | ||
130 | } | ||
131 | } | ||
132 | |||
133 | /// <summary> | ||
134 | /// Gets a value indicating whether [ever kept]. | ||
135 | /// </summary> | ||
136 | /// <value><c>true</c> if [ever kept]; otherwise, <c>false</c>.</value> | ||
137 | public bool EverKept | ||
138 | { | ||
139 | get | ||
140 | { | ||
141 | return m_EverKept; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | /// <summary> | ||
146 | /// Gets or sets the state. | ||
147 | /// </summary> | ||
148 | /// <value>The state.</value> | ||
149 | public IfState State | ||
150 | { | ||
151 | get | ||
152 | { | ||
153 | return m_State; | ||
154 | } | ||
155 | set | ||
156 | { | ||
157 | m_State = value; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | #endregion | ||
162 | } | ||
163 | } | ||
diff --git a/Prebuild/src/Core/Parse/Preprocessor.cs b/Prebuild/src/Core/Parse/Preprocessor.cs new file mode 100644 index 0000000..85e92c3 --- /dev/null +++ b/Prebuild/src/Core/Parse/Preprocessor.cs | |||
@@ -0,0 +1,519 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-09-01 19:55:06 +0200 (fr, 01 sep 2006) $ | ||
31 | * $Revision: 147 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.IO; | ||
38 | using System.Xml; | ||
39 | |||
40 | namespace Prebuild.Core.Parse | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// | ||
44 | /// </summary> | ||
45 | public enum OperatorSymbol | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// | ||
49 | /// </summary> | ||
50 | None, | ||
51 | /// <summary> | ||
52 | /// | ||
53 | /// </summary> | ||
54 | Equal, | ||
55 | /// <summary> | ||
56 | /// | ||
57 | /// </summary> | ||
58 | NotEqual, | ||
59 | /// <summary> | ||
60 | /// | ||
61 | /// </summary> | ||
62 | LessThan, | ||
63 | /// <summary> | ||
64 | /// | ||
65 | /// </summary> | ||
66 | GreaterThan, | ||
67 | /// <summary> | ||
68 | /// | ||
69 | /// </summary> | ||
70 | LessThanEqual, | ||
71 | /// <summary> | ||
72 | /// | ||
73 | /// </summary> | ||
74 | GreaterThanEqual | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// | ||
79 | /// </summary> | ||
80 | public class Preprocessor | ||
81 | { | ||
82 | #region Fields | ||
83 | |||
84 | XmlDocument m_OutDoc; | ||
85 | Stack m_IfStack; | ||
86 | Hashtable m_Variables; | ||
87 | |||
88 | #endregion | ||
89 | |||
90 | #region Constructors | ||
91 | |||
92 | /// <summary> | ||
93 | /// Initializes a new instance of the <see cref="Preprocessor"/> class. | ||
94 | /// </summary> | ||
95 | public Preprocessor() | ||
96 | { | ||
97 | m_OutDoc = new XmlDocument(); | ||
98 | m_IfStack = new Stack(); | ||
99 | m_Variables = new Hashtable(); | ||
100 | |||
101 | RegisterVariable("OS", GetOS()); | ||
102 | RegisterVariable("RuntimeVersion", Environment.Version.Major); | ||
103 | RegisterVariable("RuntimeMajor", Environment.Version.Major); | ||
104 | RegisterVariable("RuntimeMinor", Environment.Version.Minor); | ||
105 | RegisterVariable("RuntimeRevision", Environment.Version.Revision); | ||
106 | } | ||
107 | |||
108 | #endregion | ||
109 | |||
110 | #region Properties | ||
111 | |||
112 | /// <summary> | ||
113 | /// Gets the processed doc. | ||
114 | /// </summary> | ||
115 | /// <value>The processed doc.</value> | ||
116 | public XmlDocument ProcessedDoc | ||
117 | { | ||
118 | get | ||
119 | { | ||
120 | return m_OutDoc; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | #endregion | ||
125 | |||
126 | #region Private Methods | ||
127 | |||
128 | /// <summary> | ||
129 | /// Parts of this code were taken from NAnt and is subject to the GPL | ||
130 | /// as per NAnt's license. Thanks to the NAnt guys for this little gem. | ||
131 | /// </summary> | ||
132 | /// <returns></returns> | ||
133 | public static string GetOS() | ||
134 | { | ||
135 | PlatformID platId = Environment.OSVersion.Platform; | ||
136 | if(platId == PlatformID.Win32NT || platId == PlatformID.Win32Windows) | ||
137 | { | ||
138 | return "Win32"; | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | * .NET 1.x, under Mono, the UNIX code is 128. Under | ||
143 | * .NET 2.x, Mono or MS, the UNIX code is 4 | ||
144 | */ | ||
145 | if(Environment.Version.Major == 1) | ||
146 | { | ||
147 | if((int)platId == 128) | ||
148 | { | ||
149 | return "UNIX"; | ||
150 | } | ||
151 | } | ||
152 | else if((int)platId == 4) | ||
153 | { | ||
154 | return "UNIX"; | ||
155 | } | ||
156 | |||
157 | return "Unknown"; | ||
158 | } | ||
159 | |||
160 | private static bool CompareNum(OperatorSymbol oper, int val1, int val2) | ||
161 | { | ||
162 | switch(oper) | ||
163 | { | ||
164 | case OperatorSymbol.Equal: | ||
165 | return (val1 == val2); | ||
166 | case OperatorSymbol.NotEqual: | ||
167 | return (val1 != val2); | ||
168 | case OperatorSymbol.LessThan: | ||
169 | return (val1 < val2); | ||
170 | case OperatorSymbol.LessThanEqual: | ||
171 | return (val1 <= val2); | ||
172 | case OperatorSymbol.GreaterThan: | ||
173 | return (val1 > val2); | ||
174 | case OperatorSymbol.GreaterThanEqual: | ||
175 | return (val1 >= val2); | ||
176 | } | ||
177 | |||
178 | throw new WarningException("Unknown operator type"); | ||
179 | } | ||
180 | |||
181 | private static bool CompareStr(OperatorSymbol oper, string val1, string val2) | ||
182 | { | ||
183 | switch(oper) | ||
184 | { | ||
185 | case OperatorSymbol.Equal: | ||
186 | return (val1 == val2); | ||
187 | case OperatorSymbol.NotEqual: | ||
188 | return (val1 != val2); | ||
189 | case OperatorSymbol.LessThan: | ||
190 | return (val1.CompareTo(val2) < 0); | ||
191 | case OperatorSymbol.LessThanEqual: | ||
192 | return (val1.CompareTo(val2) <= 0); | ||
193 | case OperatorSymbol.GreaterThan: | ||
194 | return (val1.CompareTo(val2) > 0); | ||
195 | case OperatorSymbol.GreaterThanEqual: | ||
196 | return (val1.CompareTo(val2) >= 0); | ||
197 | } | ||
198 | |||
199 | throw new WarningException("Unknown operator type"); | ||
200 | } | ||
201 | |||
202 | private static char NextChar(int idx, string str) | ||
203 | { | ||
204 | if((idx + 1) >= str.Length) | ||
205 | { | ||
206 | return Char.MaxValue; | ||
207 | } | ||
208 | |||
209 | return str[idx + 1]; | ||
210 | } | ||
211 | // Very very simple expression parser. Can only match expressions of the form | ||
212 | // <var> <op> <value>: | ||
213 | // OS = Windows | ||
214 | // OS != Linux | ||
215 | // RuntimeMinor > 0 | ||
216 | private bool ParseExpression(string exp) | ||
217 | { | ||
218 | if(exp == null) | ||
219 | { | ||
220 | throw new ArgumentException("Invalid expression, cannot be null"); | ||
221 | } | ||
222 | |||
223 | exp = exp.Trim(); | ||
224 | if(exp.Length < 1) | ||
225 | { | ||
226 | throw new ArgumentException("Invalid expression, cannot be 0 length"); | ||
227 | } | ||
228 | |||
229 | string id = ""; | ||
230 | string str = ""; | ||
231 | OperatorSymbol oper = OperatorSymbol.None; | ||
232 | bool inStr = false; | ||
233 | char c; | ||
234 | |||
235 | for(int i = 0; i < exp.Length; i++) | ||
236 | { | ||
237 | c = exp[i]; | ||
238 | if(Char.IsWhiteSpace(c)) | ||
239 | { | ||
240 | continue; | ||
241 | } | ||
242 | |||
243 | if(Char.IsLetterOrDigit(c) || c == '_') | ||
244 | { | ||
245 | if(inStr) | ||
246 | { | ||
247 | str += c; | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | id += c; | ||
252 | } | ||
253 | } | ||
254 | else if(c == '\"') | ||
255 | { | ||
256 | inStr = !inStr; | ||
257 | if(inStr) | ||
258 | { | ||
259 | str = ""; | ||
260 | } | ||
261 | } | ||
262 | else | ||
263 | { | ||
264 | if(inStr) | ||
265 | { | ||
266 | str += c; | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | switch(c) | ||
271 | { | ||
272 | case '=': | ||
273 | oper = OperatorSymbol.Equal; | ||
274 | break; | ||
275 | |||
276 | case '!': | ||
277 | if(NextChar(i, exp) == '=') | ||
278 | { | ||
279 | oper = OperatorSymbol.NotEqual; | ||
280 | } | ||
281 | |||
282 | break; | ||
283 | |||
284 | case '<': | ||
285 | if(NextChar(i, exp) == '=') | ||
286 | { | ||
287 | oper = OperatorSymbol.LessThanEqual; | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | oper = OperatorSymbol.LessThan; | ||
292 | } | ||
293 | |||
294 | break; | ||
295 | |||
296 | case '>': | ||
297 | if(NextChar(i, exp) == '=') | ||
298 | { | ||
299 | oper = OperatorSymbol.GreaterThanEqual; | ||
300 | } | ||
301 | else | ||
302 | { | ||
303 | oper = OperatorSymbol.GreaterThan; | ||
304 | } | ||
305 | |||
306 | break; | ||
307 | } | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | |||
312 | |||
313 | if(inStr) | ||
314 | { | ||
315 | throw new WarningException("Expected end of string in expression"); | ||
316 | } | ||
317 | |||
318 | if(oper == OperatorSymbol.None) | ||
319 | { | ||
320 | throw new WarningException("Expected operator in expression"); | ||
321 | } | ||
322 | else if(id.Length < 1) | ||
323 | { | ||
324 | throw new WarningException("Expected identifier in expression"); | ||
325 | } | ||
326 | else if(str.Length < 1) | ||
327 | { | ||
328 | throw new WarningException("Expected value in expression"); | ||
329 | } | ||
330 | |||
331 | bool ret = false; | ||
332 | try | ||
333 | { | ||
334 | object val = m_Variables[id.ToLower()]; | ||
335 | if(val == null) | ||
336 | { | ||
337 | throw new WarningException("Unknown identifier '{0}'", id); | ||
338 | } | ||
339 | |||
340 | int numVal, numVal2; | ||
341 | string strVal, strVal2; | ||
342 | Type t = val.GetType(); | ||
343 | if(t.IsAssignableFrom(typeof(int))) | ||
344 | { | ||
345 | numVal = (int)val; | ||
346 | numVal2 = Int32.Parse(str); | ||
347 | ret = CompareNum(oper, numVal, numVal2); | ||
348 | } | ||
349 | else | ||
350 | { | ||
351 | strVal = val.ToString(); | ||
352 | strVal2 = str; | ||
353 | ret = CompareStr(oper, strVal, strVal2); | ||
354 | } | ||
355 | } | ||
356 | catch(ArgumentException ex) | ||
357 | { | ||
358 | ex.ToString(); | ||
359 | throw new WarningException("Invalid value type for system variable '{0}', expected int", id); | ||
360 | } | ||
361 | |||
362 | return ret; | ||
363 | } | ||
364 | |||
365 | #endregion | ||
366 | |||
367 | #region Public Methods | ||
368 | |||
369 | /// <summary> | ||
370 | /// | ||
371 | /// </summary> | ||
372 | /// <param name="name"></param> | ||
373 | /// <param name="variableValue"></param> | ||
374 | public void RegisterVariable(string name, object variableValue) | ||
375 | { | ||
376 | if(name == null || variableValue == null) | ||
377 | { | ||
378 | return; | ||
379 | } | ||
380 | |||
381 | m_Variables[name.ToLower()] = variableValue; | ||
382 | } | ||
383 | |||
384 | /// <summary> | ||
385 | /// Performs validation on the xml source as well as evaluates conditional and flow expresions | ||
386 | /// </summary> | ||
387 | /// <exception cref="ArgumentException">For invalid use of conditional expressions or for invalid XML syntax. If a XmlValidatingReader is passed, then will also throw exceptions for non-schema-conforming xml</exception> | ||
388 | /// <param name="reader"></param> | ||
389 | /// <returns>the output xml </returns> | ||
390 | public string Process(XmlReader reader) | ||
391 | { | ||
392 | if(reader == null) | ||
393 | { | ||
394 | throw new ArgumentException("Invalid XML reader to pre-process"); | ||
395 | } | ||
396 | |||
397 | IfContext context = new IfContext(true, true, IfState.None); | ||
398 | StringWriter xmlText = new StringWriter(); | ||
399 | XmlTextWriter writer = new XmlTextWriter(xmlText); | ||
400 | writer.Formatting = Formatting.Indented; | ||
401 | while(reader.Read()) | ||
402 | { | ||
403 | if(reader.NodeType == XmlNodeType.ProcessingInstruction) | ||
404 | { | ||
405 | bool ignore = false; | ||
406 | switch(reader.LocalName) | ||
407 | { | ||
408 | case "if": | ||
409 | m_IfStack.Push(context); | ||
410 | context = new IfContext(context.Keep & context.Active, ParseExpression(reader.Value), IfState.If); | ||
411 | ignore = true; | ||
412 | break; | ||
413 | |||
414 | case "elseif": | ||
415 | if(m_IfStack.Count == 0) | ||
416 | { | ||
417 | throw new WarningException("Unexpected 'elseif' outside of 'if'"); | ||
418 | } | ||
419 | else if(context.State != IfState.If && context.State != IfState.ElseIf) | ||
420 | { | ||
421 | throw new WarningException("Unexpected 'elseif' outside of 'if'"); | ||
422 | } | ||
423 | |||
424 | context.State = IfState.ElseIf; | ||
425 | if(!context.EverKept) | ||
426 | { | ||
427 | context.Keep = ParseExpression(reader.Value); | ||
428 | } | ||
429 | else | ||
430 | { | ||
431 | context.Keep = false; | ||
432 | } | ||
433 | |||
434 | ignore = true; | ||
435 | break; | ||
436 | |||
437 | case "else": | ||
438 | if(m_IfStack.Count == 0) | ||
439 | { | ||
440 | throw new WarningException("Unexpected 'else' outside of 'if'"); | ||
441 | } | ||
442 | else if(context.State != IfState.If && context.State != IfState.ElseIf) | ||
443 | { | ||
444 | throw new WarningException("Unexpected 'else' outside of 'if'"); | ||
445 | } | ||
446 | |||
447 | context.State = IfState.Else; | ||
448 | context.Keep = !context.EverKept; | ||
449 | ignore = true; | ||
450 | break; | ||
451 | |||
452 | case "endif": | ||
453 | if(m_IfStack.Count == 0) | ||
454 | { | ||
455 | throw new WarningException("Unexpected 'endif' outside of 'if'"); | ||
456 | } | ||
457 | |||
458 | context = (IfContext)m_IfStack.Pop(); | ||
459 | ignore = true; | ||
460 | break; | ||
461 | } | ||
462 | |||
463 | if(ignore) | ||
464 | { | ||
465 | continue; | ||
466 | } | ||
467 | }//end pre-proc instruction | ||
468 | |||
469 | if(!context.Active || !context.Keep) | ||
470 | { | ||
471 | continue; | ||
472 | } | ||
473 | |||
474 | switch(reader.NodeType) | ||
475 | { | ||
476 | case XmlNodeType.Element: | ||
477 | bool empty = reader.IsEmptyElement; | ||
478 | writer.WriteStartElement(reader.Name); | ||
479 | |||
480 | while (reader.MoveToNextAttribute()) | ||
481 | { | ||
482 | writer.WriteAttributeString(reader.Name, reader.Value); | ||
483 | } | ||
484 | |||
485 | if(empty) | ||
486 | { | ||
487 | writer.WriteEndElement(); | ||
488 | } | ||
489 | |||
490 | break; | ||
491 | |||
492 | case XmlNodeType.EndElement: | ||
493 | writer.WriteEndElement(); | ||
494 | break; | ||
495 | |||
496 | case XmlNodeType.Text: | ||
497 | writer.WriteString(reader.Value); | ||
498 | break; | ||
499 | |||
500 | case XmlNodeType.CDATA: | ||
501 | writer.WriteCData(reader.Value); | ||
502 | break; | ||
503 | |||
504 | default: | ||
505 | break; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | if(m_IfStack.Count != 0) | ||
510 | { | ||
511 | throw new WarningException("Mismatched 'if', 'endif' pair"); | ||
512 | } | ||
513 | |||
514 | return xmlText.ToString(); | ||
515 | } | ||
516 | |||
517 | #endregion | ||
518 | } | ||
519 | } | ||
diff --git a/Prebuild/src/Core/Targets/AutotoolsTarget.cs b/Prebuild/src/Core/Targets/AutotoolsTarget.cs new file mode 100644 index 0000000..2b4a678 --- /dev/null +++ b/Prebuild/src/Core/Targets/AutotoolsTarget.cs | |||
@@ -0,0 +1,926 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | |||
4 | Copyright (c) 2004 - 2006 | ||
5 | Matthew Holmes (matthew@wildfiregames.com), | ||
6 | Dan Moorehead (dan05a@gmail.com), | ||
7 | Dave Hudson (jendave@yahoo.com), | ||
8 | C.J. Adams-Collier (cjcollier@colliertech.org), | ||
9 | |||
10 | Redistribution and use in source and binary forms, with or without | ||
11 | modification, are permitted provided that the following conditions are | ||
12 | met: | ||
13 | |||
14 | * Redistributions of source code must retain the above copyright | ||
15 | notice, this list of conditions and the following disclaimer. | ||
16 | |||
17 | * Redistributions in binary form must reproduce the above copyright | ||
18 | notice, this list of conditions and the following disclaimer in the | ||
19 | documentation and/or other materials provided with the distribution. | ||
20 | |||
21 | * The name of the author may not be used to endorse or promote | ||
22 | products derived from this software without specific prior written | ||
23 | permission. | ||
24 | |||
25 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
26 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
28 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
29 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
31 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
32 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
34 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
35 | POSSIBILITY OF SUCH DAMAGE. | ||
36 | |||
37 | */ | ||
38 | #endregion | ||
39 | |||
40 | #region CVS Information | ||
41 | /* | ||
42 | * $Source$ | ||
43 | * $Author: jendave $ | ||
44 | * $Date: 2006-07-28 22:43:24 -0700 (Fri, 28 Jul 2006) $ | ||
45 | * $Revision: 136 $ | ||
46 | */ | ||
47 | #endregion | ||
48 | |||
49 | using System; | ||
50 | using System.Collections; | ||
51 | using System.Collections.Specialized; | ||
52 | using System.IO; | ||
53 | using System.Reflection; | ||
54 | using System.Text; | ||
55 | using System.Text.RegularExpressions; | ||
56 | |||
57 | using Prebuild.Core.Attributes; | ||
58 | using Prebuild.Core.Interfaces; | ||
59 | using Prebuild.Core.Nodes; | ||
60 | using Prebuild.Core.Parse; | ||
61 | using Prebuild.Core.Utilities; | ||
62 | |||
63 | namespace Prebuild.Core.Targets | ||
64 | { | ||
65 | /// <summary> | ||
66 | /// | ||
67 | /// </summary> | ||
68 | [Target("autotools")] | ||
69 | public class AutotoolsTarget : ITarget | ||
70 | { | ||
71 | #region Fields | ||
72 | |||
73 | private Kernel m_Kernel; | ||
74 | |||
75 | #endregion | ||
76 | |||
77 | #region Private Methods | ||
78 | |||
79 | private static string PrependPath(string path) | ||
80 | { | ||
81 | string tmpPath = Helper.NormalizePath(path, '/'); | ||
82 | Regex regex = new Regex(@"(\w):/(\w+)"); | ||
83 | Match match = regex.Match(tmpPath); | ||
84 | if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/') | ||
85 | { | ||
86 | tmpPath = Helper.NormalizePath(tmpPath); | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | tmpPath = Helper.NormalizePath("./" + tmpPath); | ||
91 | } | ||
92 | |||
93 | return tmpPath; | ||
94 | } | ||
95 | |||
96 | private static string BuildReference(SolutionNode solution, ReferenceNode refr) | ||
97 | { | ||
98 | string ret = ""; | ||
99 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
100 | { | ||
101 | ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name]; | ||
102 | string fileRef = FindFileReference(refr.Name, project); | ||
103 | string finalPath = Helper.NormalizePath(Helper.MakeFilePath(project.FullPath + "/$(BUILD_DIR)/$(CONFIG)/", refr.Name, "dll"), '/'); | ||
104 | ret += finalPath; | ||
105 | return ret; | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | ProjectNode project = (ProjectNode)refr.Parent; | ||
110 | string fileRef = FindFileReference(refr.Name, project); | ||
111 | |||
112 | if(refr.Path != null || fileRef != null) | ||
113 | { | ||
114 | string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path + "/" + refr.Name + ".dll", '/') : fileRef; | ||
115 | ret += Path.Combine(project.Path, finalPath); | ||
116 | return ret; | ||
117 | } | ||
118 | |||
119 | try | ||
120 | { | ||
121 | //Assembly assem = Assembly.Load(refr.Name); | ||
122 | //if (assem != null) | ||
123 | //{ | ||
124 | // int index = refr.Name.IndexOf(","); | ||
125 | // if ( index > 0) | ||
126 | // { | ||
127 | // ret += assem.Location; | ||
128 | // //Console.WriteLine("Location1: " + assem.Location); | ||
129 | // } | ||
130 | // else | ||
131 | // { | ||
132 | // ret += (refr.Name + ".dll"); | ||
133 | // //Console.WriteLine("Location2: " + assem.Location); | ||
134 | // } | ||
135 | //} | ||
136 | //else | ||
137 | //{ | ||
138 | int index = refr.Name.IndexOf(","); | ||
139 | if ( index > 0) | ||
140 | { | ||
141 | ret += refr.Name.Substring(0, index) + ".dll"; | ||
142 | //Console.WriteLine("Location3: " + assem.Location); | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | ret += (refr.Name + ".dll"); | ||
147 | //Console.WriteLine("Location4: " + assem.Location); | ||
148 | } | ||
149 | //} | ||
150 | } | ||
151 | catch (System.NullReferenceException e) | ||
152 | { | ||
153 | e.ToString(); | ||
154 | int index = refr.Name.IndexOf(","); | ||
155 | if ( index > 0) | ||
156 | { | ||
157 | ret += refr.Name.Substring(0, index) + ".dll"; | ||
158 | //Console.WriteLine("Location5: " + assem.Location); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | ret += (refr.Name + ".dll"); | ||
163 | //Console.WriteLine("Location6: " + assem.Location); | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | return ret; | ||
168 | } | ||
169 | |||
170 | private static string BuildReferencePath(SolutionNode solution, ReferenceNode refr) | ||
171 | { | ||
172 | string ret = ""; | ||
173 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
174 | { | ||
175 | ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name]; | ||
176 | string finalPath = Helper.NormalizePath(Helper.MakeReferencePath(project.FullPath + "/${build.dir}/"), '/'); | ||
177 | ret += finalPath; | ||
178 | return ret; | ||
179 | } | ||
180 | else | ||
181 | { | ||
182 | ProjectNode project = (ProjectNode)refr.Parent; | ||
183 | string fileRef = FindFileReference(refr.Name, project); | ||
184 | |||
185 | |||
186 | if(refr.Path != null || fileRef != null) | ||
187 | { | ||
188 | string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path, '/') : fileRef; | ||
189 | ret += finalPath; | ||
190 | return ret; | ||
191 | } | ||
192 | |||
193 | try | ||
194 | { | ||
195 | Assembly assem = Assembly.Load(refr.Name); | ||
196 | if (assem != null) | ||
197 | { | ||
198 | ret += ""; | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | ret += ""; | ||
203 | } | ||
204 | } | ||
205 | catch (System.NullReferenceException e) | ||
206 | { | ||
207 | e.ToString(); | ||
208 | ret += ""; | ||
209 | } | ||
210 | } | ||
211 | return ret; | ||
212 | } | ||
213 | |||
214 | private static string FindFileReference(string refName, ProjectNode project) | ||
215 | { | ||
216 | foreach(ReferencePathNode refPath in project.ReferencePaths) | ||
217 | { | ||
218 | string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll"); | ||
219 | |||
220 | if(File.Exists(fullPath)) | ||
221 | { | ||
222 | return fullPath; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | return null; | ||
227 | } | ||
228 | |||
229 | /// <summary> | ||
230 | /// Gets the XML doc file. | ||
231 | /// </summary> | ||
232 | /// <param name="project">The project.</param> | ||
233 | /// <param name="conf">The conf.</param> | ||
234 | /// <returns></returns> | ||
235 | public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf) | ||
236 | { | ||
237 | if( conf == null ) | ||
238 | { | ||
239 | throw new ArgumentNullException("conf"); | ||
240 | } | ||
241 | if( project == null ) | ||
242 | { | ||
243 | throw new ArgumentNullException("project"); | ||
244 | } | ||
245 | string docFile = (string)conf.Options["XmlDocFile"]; | ||
246 | // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified | ||
247 | // { | ||
248 | // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml"; | ||
249 | // } | ||
250 | return docFile; | ||
251 | } | ||
252 | |||
253 | /// <summary> | ||
254 | /// Normalizes the path. | ||
255 | /// </summary> | ||
256 | /// <param name="path">The path.</param> | ||
257 | /// <returns></returns> | ||
258 | public static string NormalizePath(string path) | ||
259 | { | ||
260 | if(path == null) | ||
261 | { | ||
262 | return ""; | ||
263 | } | ||
264 | |||
265 | StringBuilder tmpPath; | ||
266 | |||
267 | if (Core.Parse.Preprocessor.GetOS() == "Win32") | ||
268 | { | ||
269 | tmpPath = new StringBuilder(path.Replace('\\', '/')); | ||
270 | tmpPath.Replace("/", @"\\"); | ||
271 | } | ||
272 | else | ||
273 | { | ||
274 | tmpPath = new StringBuilder(path.Replace('\\', '/')); | ||
275 | tmpPath = tmpPath.Replace('/', Path.DirectorySeparatorChar); | ||
276 | } | ||
277 | return tmpPath.ToString(); | ||
278 | } | ||
279 | |||
280 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
281 | { | ||
282 | string projFile = Helper.MakeFilePath(project.FullPath, "Include", "am"); | ||
283 | StreamWriter ss = new StreamWriter(projFile); | ||
284 | ss.NewLine = "\n"; | ||
285 | |||
286 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
287 | Helper.SetCurrentDir(Path.GetDirectoryName(projFile)); | ||
288 | |||
289 | using(ss) | ||
290 | { | ||
291 | ss.WriteLine(Helper.AssemblyFullName(project.AssemblyName, project.Type) + ":"); | ||
292 | ss.WriteLine("\tmkdir -p " + Helper.MakePathRelativeTo(solution.FullPath, project.Path) + "/$(BUILD_DIR)/$(CONFIG)/"); | ||
293 | foreach(string file in project.Files) | ||
294 | { | ||
295 | if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings) | ||
296 | { | ||
297 | ss.Write("\tresgen "); | ||
298 | ss.Write(Helper.NormalizePath(Path.Combine(project.Path, file.Substring(0, file.LastIndexOf('.')) + ".resx "), '/')); | ||
299 | if (project.Files.GetResourceName(file) != "") | ||
300 | { | ||
301 | ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, project.RootNamespace + "." + project.Files.GetResourceName(file) + ".resources"), '/')); | ||
302 | } | ||
303 | else | ||
304 | { | ||
305 | ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, project.RootNamespace + "." + file.Substring(0, file.LastIndexOf('.')) + ".resources"), '/')); | ||
306 | } | ||
307 | } | ||
308 | } | ||
309 | ss.WriteLine("\t$(CSC)\t/out:" + Helper.MakePathRelativeTo(solution.FullPath, project.Path) + "/$(BUILD_DIR)/$(CONFIG)/" + Helper.AssemblyFullName(project.AssemblyName, project.Type) + " \\"); | ||
310 | ss.WriteLine("\t\t/target:" + project.Type.ToString().ToLower() + " \\"); | ||
311 | if (project.References.Count > 0) | ||
312 | { | ||
313 | ss.Write("\t\t/reference:"); | ||
314 | bool firstref = true; | ||
315 | foreach(ReferenceNode refr in project.References) | ||
316 | { | ||
317 | if (firstref) | ||
318 | { | ||
319 | firstref = false; | ||
320 | } | ||
321 | else | ||
322 | { | ||
323 | ss.Write(","); | ||
324 | } | ||
325 | ss.Write("{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(solution.FullPath, BuildReference(solution, refr)), '/')); | ||
326 | } | ||
327 | ss.WriteLine(" \\"); | ||
328 | } | ||
329 | //ss.WriteLine("\t\tProperties/AssemblyInfo.cs \\"); | ||
330 | |||
331 | foreach(string file in project.Files) | ||
332 | { | ||
333 | switch(project.Files.GetBuildAction(file)) | ||
334 | { | ||
335 | case BuildAction.EmbeddedResource: | ||
336 | ss.Write("\t\t/resource:"); | ||
337 | ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, file), '/') + " \\"); | ||
338 | break; | ||
339 | default: | ||
340 | if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings) | ||
341 | { | ||
342 | ss.Write("\t\t/resource:"); | ||
343 | if (project.Files.GetResourceName(file) != "") | ||
344 | { | ||
345 | ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, project.RootNamespace + "." + project.Files.GetResourceName(file) + ".resources"), '/') + "," + project.RootNamespace + "." + project.Files.GetResourceName(file) + ".resources" + " \\"); | ||
346 | } | ||
347 | else | ||
348 | { | ||
349 | ss.WriteLine(Helper.NormalizePath(Path.Combine(project.Path, project.RootNamespace + "." + file.Substring(0, file.LastIndexOf('.')) + ".resources"), '/') + "," + project.RootNamespace + "." + file.Substring(0, file.LastIndexOf('.')) + ".resources" + " \\"); | ||
350 | } | ||
351 | } | ||
352 | break; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | foreach(ConfigurationNode conf in project.Configurations) | ||
357 | { | ||
358 | if (conf.Options.KeyFile !="") | ||
359 | { | ||
360 | ss.WriteLine("\t\t/keyfile:" + Helper.NormalizePath(Path.Combine(project.Path, conf.Options.KeyFile), '/') + " \\"); | ||
361 | break; | ||
362 | } | ||
363 | } | ||
364 | foreach(ConfigurationNode conf in project.Configurations) | ||
365 | { | ||
366 | if (conf.Options.AllowUnsafe) | ||
367 | { | ||
368 | ss.WriteLine("\t\t/unsafe \\"); | ||
369 | break; | ||
370 | } | ||
371 | } | ||
372 | if (project.AppIcon != "") | ||
373 | { | ||
374 | ss.WriteLine("\t\t/win32icon:" + Helper.NormalizePath(Path.Combine(project.Path, project.AppIcon), '/') + " \\"); | ||
375 | } | ||
376 | |||
377 | foreach(ConfigurationNode conf in project.Configurations) | ||
378 | { | ||
379 | ss.WriteLine("\t\t/define:{0}", conf.Options.CompilerDefines.Replace(';', ',') + " \\"); | ||
380 | break; | ||
381 | } | ||
382 | |||
383 | foreach(ConfigurationNode conf in project.Configurations) | ||
384 | { | ||
385 | if (GetXmlDocFile(project, conf) !="") | ||
386 | { | ||
387 | ss.WriteLine("\t\t/doc:" + Helper.MakePathRelativeTo(solution.FullPath, project.Path) + "/$(BUILD_DIR)/$(CONFIG)/" + project.Name + ".xml \\"); | ||
388 | break; | ||
389 | } | ||
390 | } | ||
391 | foreach(string file in project.Files) | ||
392 | { | ||
393 | switch(project.Files.GetBuildAction(file)) | ||
394 | { | ||
395 | case BuildAction.Compile: | ||
396 | ss.WriteLine("\t\t\\"); | ||
397 | ss.Write("\t\t" + NormalizePath(Path.Combine(Helper.MakePathRelativeTo(solution.FullPath, project.Path), file))); | ||
398 | break; | ||
399 | default: | ||
400 | break; | ||
401 | } | ||
402 | } | ||
403 | ss.WriteLine(); | ||
404 | ss.WriteLine(); | ||
405 | |||
406 | if (project.Type == ProjectType.Library) | ||
407 | { | ||
408 | ss.WriteLine("install-data-local:"); | ||
409 | ss.WriteLine(" echo \"$(GACUTIL) /i bin/Release/" + project.Name + ".dll /f $(GACUTIL_FLAGS)\"; \\"); | ||
410 | ss.WriteLine(" $(GACUTIL) /i bin/Release/" + project.Name + ".dll /f $(GACUTIL_FLAGS) || exit 1;"); | ||
411 | ss.WriteLine(); | ||
412 | ss.WriteLine("uninstall-local:"); | ||
413 | ss.WriteLine(" echo \"$(GACUTIL) /u " + project.Name + " $(GACUTIL_FLAGS)\"; \\"); | ||
414 | ss.WriteLine(" $(GACUTIL) /u " + project.Name + " $(GACUTIL_FLAGS) || exit 1;"); | ||
415 | ss.WriteLine(); | ||
416 | } | ||
417 | ss.WriteLine("CLEANFILES = $(BUILD_DIR)/$(CONFIG)/" + Helper.AssemblyFullName(project.AssemblyName, project.Type) + " $(BUILD_DIR)/$(CONFIG)/" + project.AssemblyName + ".mdb $(BUILD_DIR)/$(CONFIG)/" + project.AssemblyName + ".pdb " + project.AssemblyName + ".xml"); | ||
418 | ss.WriteLine("EXTRA_DIST = \\"); | ||
419 | ss.Write(" $(FILES)"); | ||
420 | foreach(ConfigurationNode conf in project.Configurations) | ||
421 | { | ||
422 | if (conf.Options.KeyFile != "") | ||
423 | { | ||
424 | ss.Write(" \\"); | ||
425 | ss.WriteLine("\t" + conf.Options.KeyFile); | ||
426 | } | ||
427 | break; | ||
428 | } | ||
429 | } | ||
430 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
431 | } | ||
432 | bool hasLibrary = false; | ||
433 | |||
434 | private void WriteCombine(SolutionNode solution) | ||
435 | { | ||
436 | |||
437 | /* TODO: These vars should be pulled from the prebuild.xml file */ | ||
438 | string releaseVersion = "2.0.0"; | ||
439 | string assemblyVersion = "2.1.0.0"; | ||
440 | string description = | ||
441 | "Tao Framework " + solution.Name + " Binding For .NET"; | ||
442 | |||
443 | hasLibrary = false; | ||
444 | m_Kernel.Log.Write("Creating Autotools make files"); | ||
445 | foreach(ProjectNode project in solution.Projects) | ||
446 | { | ||
447 | if(m_Kernel.AllowProject(project.FilterGroups)) | ||
448 | { | ||
449 | m_Kernel.Log.Write("...Creating makefile: {0}", project.Name); | ||
450 | WriteProject(solution, project); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | m_Kernel.Log.Write(""); | ||
455 | string combFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "am"); | ||
456 | StreamWriter ss = new StreamWriter(combFile); | ||
457 | ss.NewLine = "\n"; | ||
458 | |||
459 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
460 | Helper.SetCurrentDir(Path.GetDirectoryName(combFile)); | ||
461 | |||
462 | using(ss) | ||
463 | { | ||
464 | foreach(ProjectNode project in solution.ProjectsTableOrder) | ||
465 | { | ||
466 | if (project.Type == ProjectType.Library) | ||
467 | { | ||
468 | hasLibrary = true; | ||
469 | break; | ||
470 | } | ||
471 | } | ||
472 | |||
473 | if (hasLibrary) | ||
474 | { | ||
475 | ss.Write("pkgconfig_in_files = "); | ||
476 | foreach(ProjectNode project in solution.ProjectsTableOrder) | ||
477 | { | ||
478 | if (project.Type == ProjectType.Library) | ||
479 | { | ||
480 | string combFilepc = Helper.MakeFilePath(solution.FullPath, project.Name, "pc.in"); | ||
481 | ss.Write(" " + project.Name + ".pc.in "); | ||
482 | StreamWriter sspc = new StreamWriter(combFilepc); | ||
483 | sspc.NewLine = "\n"; | ||
484 | using(sspc) | ||
485 | { | ||
486 | sspc.WriteLine("prefix=@prefix@"); | ||
487 | sspc.WriteLine("exec_prefix=${prefix}"); | ||
488 | sspc.WriteLine("libdir=${exec_prefix}/lib"); | ||
489 | sspc.WriteLine(); | ||
490 | sspc.WriteLine("Name: @PACKAGE_NAME@"); | ||
491 | sspc.WriteLine("Description: @DESCRIPTION@"); | ||
492 | sspc.WriteLine("Version: @ASSEMBLY_VERSION@"); | ||
493 | sspc.WriteLine("Libs: -r:${libdir}/mono/gac/@PACKAGE_NAME@/@ASSEMBLY_VERSION@__@PUBKEY@/@PACKAGE_NAME@.dll"); | ||
494 | } | ||
495 | } | ||
496 | } | ||
497 | |||
498 | ss.WriteLine(); | ||
499 | ss.WriteLine("pkgconfigdir=$(prefix)/lib/pkgconfig"); | ||
500 | ss.WriteLine("pkgconfig_DATA=$(pkgconfig_in_files:.pc.in=.pc)"); | ||
501 | } | ||
502 | ss.WriteLine(); | ||
503 | foreach(ProjectNode project in solution.ProjectsTableOrder) | ||
504 | { | ||
505 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
506 | ss.WriteLine("-include x {0}", | ||
507 | Helper.NormalizePath(Helper.MakeFilePath(path, "Include", "am"),'/')); | ||
508 | } | ||
509 | ss.WriteLine(); | ||
510 | ss.WriteLine("all: \\"); | ||
511 | ss.Write("\t"); | ||
512 | foreach(ProjectNode project in solution.ProjectsTableOrder) | ||
513 | { | ||
514 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
515 | ss.Write(Helper.AssemblyFullName(project.AssemblyName, project.Type) + " "); | ||
516 | |||
517 | } | ||
518 | ss.WriteLine(); | ||
519 | if (hasLibrary) | ||
520 | { | ||
521 | ss.WriteLine("EXTRA_DIST = \\"); | ||
522 | ss.WriteLine("\t$(pkgconfig_in_files)"); | ||
523 | } | ||
524 | else | ||
525 | { | ||
526 | ss.WriteLine("EXTRA_DIST = "); | ||
527 | } | ||
528 | ss.WriteLine(); | ||
529 | ss.WriteLine("DISTCLEANFILES = \\"); | ||
530 | ss.WriteLine("\tconfigure \\"); | ||
531 | ss.WriteLine("\tMakefile.in \\"); | ||
532 | ss.WriteLine("\taclocal.m4"); | ||
533 | } | ||
534 | combFile = Helper.MakeFilePath(solution.FullPath, "configure", "ac"); | ||
535 | StreamWriter ts = new StreamWriter(combFile); | ||
536 | ts.NewLine = "\n"; | ||
537 | using(ts) | ||
538 | { | ||
539 | if (this.hasLibrary) | ||
540 | { | ||
541 | foreach(ProjectNode project in solution.ProjectsTableOrder) | ||
542 | { | ||
543 | if (project.Type == ProjectType.Library) | ||
544 | { | ||
545 | ts.WriteLine("AC_INIT(" + project.Name + ".pc.in)"); | ||
546 | break; | ||
547 | } | ||
548 | } | ||
549 | } | ||
550 | else | ||
551 | { | ||
552 | ts.WriteLine("AC_INIT(Makefile.am)"); | ||
553 | } | ||
554 | ts.WriteLine("AC_PREREQ(2.53)"); | ||
555 | ts.WriteLine("AC_CANONICAL_SYSTEM"); | ||
556 | |||
557 | ts.WriteLine("PACKAGE_NAME={0}", solution.Name); | ||
558 | ts.WriteLine("PACKAGE_VERSION={0}", releaseVersion); | ||
559 | ts.WriteLine("DESCRIPTION=\"{0}\"", description); | ||
560 | ts.WriteLine("AC_SUBST(DESCRIPTION)"); | ||
561 | ts.WriteLine("AM_INIT_AUTOMAKE([$PACKAGE_NAME],[$PACKAGE_VERSION],[$DESCRIPTION])"); | ||
562 | |||
563 | ts.WriteLine("ASSEMBLY_VERSION={0}", assemblyVersion); | ||
564 | ts.WriteLine("AC_SUBST(ASSEMBLY_VERSION)"); | ||
565 | |||
566 | ts.WriteLine("PUBKEY=`sn -t $PACKAGE_NAME.snk | grep 'Public Key Token' | awk -F: '{print $2}' | sed -e 's/^ //'`"); | ||
567 | ts.WriteLine("AC_SUBST(PUBKEY)"); | ||
568 | |||
569 | ts.WriteLine(); | ||
570 | ts.WriteLine("AM_MAINTAINER_MODE"); | ||
571 | ts.WriteLine(); | ||
572 | ts.WriteLine("dnl AC_PROG_INTLTOOL([0.25])"); | ||
573 | ts.WriteLine(); | ||
574 | ts.WriteLine("AC_PROG_INSTALL"); | ||
575 | ts.WriteLine(); | ||
576 | ts.WriteLine("MONO_REQUIRED_VERSION=1.1"); | ||
577 | ts.WriteLine(); | ||
578 | ts.WriteLine("AC_MSG_CHECKING([whether we're compiling from CVS])"); | ||
579 | ts.WriteLine("if test -f \"$srcdir/.cvs_version\" ; then"); | ||
580 | ts.WriteLine(" from_cvs=yes"); | ||
581 | ts.WriteLine("else"); | ||
582 | ts.WriteLine(" if test -f \"$srcdir/.svn\" ; then"); | ||
583 | ts.WriteLine(" from_cvs=yes"); | ||
584 | ts.WriteLine(" else"); | ||
585 | ts.WriteLine(" from_cvs=no"); | ||
586 | ts.WriteLine(" fi"); | ||
587 | ts.WriteLine("fi"); | ||
588 | ts.WriteLine(); | ||
589 | ts.WriteLine("AC_MSG_RESULT($from_cvs)"); | ||
590 | ts.WriteLine(); | ||
591 | ts.WriteLine("AC_PATH_PROG(MONO, mono)"); | ||
592 | ts.WriteLine("AC_PATH_PROG(GMCS, gmcs)"); | ||
593 | ts.WriteLine("AC_PATH_PROG(GACUTIL, gacutil)"); | ||
594 | ts.WriteLine(); | ||
595 | ts.WriteLine("AC_MSG_CHECKING([for mono])"); | ||
596 | ts.WriteLine("dnl if test \"x$MONO\" = \"x\" ; then"); | ||
597 | ts.WriteLine("dnl AC_MSG_ERROR([Can't find \"mono\" in your PATH])"); | ||
598 | ts.WriteLine("dnl else"); | ||
599 | ts.WriteLine(" AC_MSG_RESULT([found])"); | ||
600 | ts.WriteLine("dnl fi"); | ||
601 | ts.WriteLine(); | ||
602 | ts.WriteLine("AC_MSG_CHECKING([for gmcs])"); | ||
603 | ts.WriteLine("dnl if test \"x$GMCS\" = \"x\" ; then"); | ||
604 | ts.WriteLine("dnl AC_MSG_ERROR([Can't find \"gmcs\" in your PATH])"); | ||
605 | ts.WriteLine("dnl else"); | ||
606 | ts.WriteLine(" AC_MSG_RESULT([found])"); | ||
607 | ts.WriteLine("dnl fi"); | ||
608 | ts.WriteLine(); | ||
609 | //ts.WriteLine("AC_MSG_CHECKING([for gacutil])"); | ||
610 | //ts.WriteLine("if test \"x$GACUTIL\" = \"x\" ; then"); | ||
611 | //ts.WriteLine(" AC_MSG_ERROR([Can't find \"gacutil\" in your PATH])"); | ||
612 | //ts.WriteLine("else"); | ||
613 | //ts.WriteLine(" AC_MSG_RESULT([found])"); | ||
614 | //ts.WriteLine("fi"); | ||
615 | ts.WriteLine(); | ||
616 | ts.WriteLine("AC_SUBST(PATH)"); | ||
617 | ts.WriteLine("AC_SUBST(LD_LIBRARY_PATH)"); | ||
618 | ts.WriteLine(); | ||
619 | ts.WriteLine("dnl CSFLAGS=\"-debug -nowarn:1574\""); | ||
620 | ts.WriteLine("CSFLAGS=\"\""); | ||
621 | ts.WriteLine("AC_SUBST(CSFLAGS)"); | ||
622 | ts.WriteLine(); | ||
623 | // ts.WriteLine("AC_MSG_CHECKING(--disable-sdl argument)"); | ||
624 | // ts.WriteLine("AC_ARG_ENABLE(sdl,"); | ||
625 | // ts.WriteLine(" [ --disable-sdl Disable Sdl interface.],"); | ||
626 | // ts.WriteLine(" [disable_sdl=$disableval],"); | ||
627 | // ts.WriteLine(" [disable_sdl=\"no\"])"); | ||
628 | // ts.WriteLine("AC_MSG_RESULT($disable_sdl)"); | ||
629 | // ts.WriteLine("if test \"$disable_sdl\" = \"yes\"; then"); | ||
630 | // ts.WriteLine(" AC_DEFINE(FEAT_SDL)"); | ||
631 | // ts.WriteLine("fi"); | ||
632 | ts.WriteLine(); | ||
633 | ts.WriteLine("dnl Find pkg-config"); | ||
634 | ts.WriteLine("AC_PATH_PROG(PKGCONFIG, pkg-config, no)"); | ||
635 | ts.WriteLine("if test \"x$PKG_CONFIG\" = \"xno\"; then"); | ||
636 | ts.WriteLine(" AC_MSG_ERROR([You need to install pkg-config])"); | ||
637 | ts.WriteLine("fi"); | ||
638 | ts.WriteLine(); | ||
639 | ts.WriteLine("PKG_CHECK_MODULES(MONO_DEPENDENCY, mono >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)"); | ||
640 | ts.WriteLine("BUILD_DIR=\"bin\""); | ||
641 | ts.WriteLine("AC_SUBST(BUILD_DIR)"); | ||
642 | ts.WriteLine("CONFIG=\"Release\""); | ||
643 | ts.WriteLine("AC_SUBST(CONFIG)"); | ||
644 | ts.WriteLine(); | ||
645 | ts.WriteLine("if test \"x$has_mono\" = \"xtrue\"; then"); | ||
646 | ts.WriteLine(" AC_PATH_PROG(RUNTIME, mono, no)"); | ||
647 | ts.WriteLine(" AC_PATH_PROG(CSC, gmcs, no)"); | ||
648 | ts.WriteLine(" if test `uname -s` = \"Darwin\"; then"); | ||
649 | ts.WriteLine(" LIB_PREFIX="); | ||
650 | ts.WriteLine(" LIB_SUFFIX=.dylib"); | ||
651 | ts.WriteLine(" else"); | ||
652 | ts.WriteLine(" LIB_PREFIX=.so"); | ||
653 | ts.WriteLine(" LIB_SUFFIX="); | ||
654 | ts.WriteLine(" fi"); | ||
655 | ts.WriteLine("else"); | ||
656 | ts.WriteLine(" AC_PATH_PROG(CSC, csc.exe, no)"); | ||
657 | ts.WriteLine(" if test x$CSC = \"xno\"; then"); | ||
658 | ts.WriteLine(" AC_MSG_ERROR([You need to install either mono or .Net])"); | ||
659 | ts.WriteLine(" else"); | ||
660 | ts.WriteLine(" RUNTIME="); | ||
661 | ts.WriteLine(" LIB_PREFIX="); | ||
662 | ts.WriteLine(" LIB_SUFFIX=.dylib"); | ||
663 | ts.WriteLine(" fi"); | ||
664 | ts.WriteLine("fi"); | ||
665 | ts.WriteLine(); | ||
666 | ts.WriteLine("AC_SUBST(LIB_PREFIX)"); | ||
667 | ts.WriteLine("AC_SUBST(LIB_SUFFIX)"); | ||
668 | ts.WriteLine(); | ||
669 | ts.WriteLine("AC_SUBST(BASE_DEPENDENCIES_CFLAGS)"); | ||
670 | ts.WriteLine("AC_SUBST(BASE_DEPENDENCIES_LIBS)"); | ||
671 | ts.WriteLine(); | ||
672 | ts.WriteLine("dnl Find monodoc"); | ||
673 | ts.WriteLine("MONODOC_REQUIRED_VERSION=1.0"); | ||
674 | ts.WriteLine("AC_SUBST(MONODOC_REQUIRED_VERSION)"); | ||
675 | ts.WriteLine("PKG_CHECK_MODULES(MONODOC_DEPENDENCY, monodoc >= $MONODOC_REQUIRED_VERSION, enable_monodoc=yes, enable_monodoc=no)"); | ||
676 | ts.WriteLine(); | ||
677 | ts.WriteLine("if test \"x$enable_monodoc\" = \"xyes\"; then"); | ||
678 | ts.WriteLine(" AC_PATH_PROG(MONODOC, monodoc, no)"); | ||
679 | ts.WriteLine(" if test x$MONODOC = xno; then"); | ||
680 | ts.WriteLine(" enable_monodoc=no"); | ||
681 | ts.WriteLine(" fi"); | ||
682 | ts.WriteLine("else"); | ||
683 | ts.WriteLine(" MONODOC="); | ||
684 | ts.WriteLine("fi"); | ||
685 | ts.WriteLine(); | ||
686 | ts.WriteLine("AC_SUBST(MONODOC)"); | ||
687 | ts.WriteLine("AM_CONDITIONAL(ENABLE_MONODOC, test \"x$enable_monodoc\" = \"xyes\")"); | ||
688 | ts.WriteLine(); | ||
689 | ts.WriteLine("AC_PATH_PROG(GACUTIL, gacutil, no)"); | ||
690 | ts.WriteLine("if test \"x$GACUTIL\" = \"xno\" ; then"); | ||
691 | ts.WriteLine(" AC_MSG_ERROR([No gacutil tool found])"); | ||
692 | ts.WriteLine("fi"); | ||
693 | ts.WriteLine(); | ||
694 | // foreach(ProjectNode project in solution.ProjectsTableOrder) | ||
695 | // { | ||
696 | // if (project.Type == ProjectType.Library) | ||
697 | // { | ||
698 | // } | ||
699 | // } | ||
700 | ts.WriteLine("GACUTIL_FLAGS='/package $(PACKAGE_NAME) /gacdir $(DESTDIR)$(prefix)'"); | ||
701 | ts.WriteLine("AC_SUBST(GACUTIL_FLAGS)"); | ||
702 | ts.WriteLine(); | ||
703 | ts.WriteLine("winbuild=no"); | ||
704 | ts.WriteLine("case \"$host\" in"); | ||
705 | ts.WriteLine(" *-*-mingw*|*-*-cygwin*)"); | ||
706 | ts.WriteLine(" winbuild=yes"); | ||
707 | ts.WriteLine(" ;;"); | ||
708 | ts.WriteLine("esac"); | ||
709 | ts.WriteLine("AM_CONDITIONAL(WINBUILD, test x$winbuild = xyes)"); | ||
710 | ts.WriteLine(); | ||
711 | // ts.WriteLine("dnl Check for SDL"); | ||
712 | // ts.WriteLine(); | ||
713 | // ts.WriteLine("AC_PATH_PROG([SDL_CONFIG], [sdl-config])"); | ||
714 | // ts.WriteLine("have_sdl=no"); | ||
715 | // ts.WriteLine("if test -n \"${SDL_CONFIG}\"; then"); | ||
716 | // ts.WriteLine(" have_sdl=yes"); | ||
717 | // ts.WriteLine(" SDL_CFLAGS=`$SDL_CONFIG --cflags`"); | ||
718 | // ts.WriteLine(" SDL_LIBS=`$SDL_CONFIG --libs`"); | ||
719 | // ts.WriteLine(" #"); | ||
720 | // ts.WriteLine(" # sdl-config sometimes emits an rpath flag pointing at its library"); | ||
721 | // ts.WriteLine(" # installation directory. We don't want this, as it prevents users from"); | ||
722 | // ts.WriteLine(" # linking sdl-viewer against, for example, a locally compiled libGL when a"); | ||
723 | // ts.WriteLine(" # version of the library also exists in SDL's library installation"); | ||
724 | // ts.WriteLine(" # directory, typically /usr/lib."); | ||
725 | // ts.WriteLine(" #"); | ||
726 | // ts.WriteLine(" SDL_LIBS=`echo $SDL_LIBS | sed 's/-Wl,-rpath,[[^ ]]* //'`"); | ||
727 | // ts.WriteLine("fi"); | ||
728 | // ts.WriteLine("AC_SUBST([SDL_CFLAGS])"); | ||
729 | // ts.WriteLine("AC_SUBST([SDL_LIBS])"); | ||
730 | ts.WriteLine(); | ||
731 | ts.WriteLine("AC_OUTPUT(["); | ||
732 | ts.WriteLine("Makefile"); | ||
733 | // TODO: this does not work quite right. | ||
734 | //ts.WriteLine("Properties/AssemblyInfo.cs"); | ||
735 | foreach(ProjectNode project in solution.ProjectsTableOrder) | ||
736 | { | ||
737 | if (project.Type == ProjectType.Library) | ||
738 | { | ||
739 | ts.WriteLine(project.Name + ".pc"); | ||
740 | } | ||
741 | // string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
742 | // ts.WriteLine(Helper.NormalizePath(Helper.MakeFilePath(path, "Include"),'/')); | ||
743 | } | ||
744 | ts.WriteLine("])"); | ||
745 | ts.WriteLine(); | ||
746 | ts.WriteLine("#po/Makefile.in"); | ||
747 | ts.WriteLine(); | ||
748 | ts.WriteLine("echo \"---\""); | ||
749 | ts.WriteLine("echo \"Configuration summary\""); | ||
750 | ts.WriteLine("echo \"\""); | ||
751 | ts.WriteLine("echo \" * Installation prefix: $prefix\""); | ||
752 | ts.WriteLine("echo \" * compiler: $CSC\""); | ||
753 | ts.WriteLine("echo \" * Documentation: $enable_monodoc ($MONODOC)\""); | ||
754 | ts.WriteLine("echo \" * Package Name: $PACKAGE_NAME\""); | ||
755 | ts.WriteLine("echo \" * Version: $PACKAGE_VERSION\""); | ||
756 | ts.WriteLine("echo \" * Public Key: $PUBKEY\""); | ||
757 | ts.WriteLine("echo \"\""); | ||
758 | ts.WriteLine("echo \"---\""); | ||
759 | ts.WriteLine(); | ||
760 | } | ||
761 | |||
762 | ts.NewLine = "\n"; | ||
763 | foreach (ProjectNode project in solution.ProjectsTableOrder) | ||
764 | { | ||
765 | if (project.GenerateAssemblyInfoFile) | ||
766 | { | ||
767 | GenerateAssemblyInfoFile(solution, combFile); | ||
768 | } | ||
769 | } | ||
770 | } | ||
771 | |||
772 | private static void GenerateAssemblyInfoFile(SolutionNode solution, string combFile) | ||
773 | { | ||
774 | System.IO.Directory.CreateDirectory(Helper.MakePathRelativeTo(solution.FullPath, "Properties")); | ||
775 | combFile = Helper.MakeFilePath(solution.FullPath + "/Properties/", "AssemblyInfo.cs", "in"); | ||
776 | StreamWriter ai = new StreamWriter(combFile); | ||
777 | |||
778 | using (ai) | ||
779 | { | ||
780 | ai.WriteLine("#region License"); | ||
781 | ai.WriteLine("/*"); | ||
782 | ai.WriteLine("MIT License"); | ||
783 | ai.WriteLine("Copyright (c)2003-2006 Tao Framework Team"); | ||
784 | ai.WriteLine("http://www.taoframework.com"); | ||
785 | ai.WriteLine("All rights reserved."); | ||
786 | ai.WriteLine(""); | ||
787 | ai.WriteLine("Permission is hereby granted, free of charge, to any person obtaining a copy"); | ||
788 | ai.WriteLine("of this software and associated documentation files (the \"Software\"), to deal"); | ||
789 | ai.WriteLine("in the Software without restriction, including without limitation the rights"); | ||
790 | ai.WriteLine("to use, copy, modify, merge, publish, distribute, sublicense, and/or sell"); | ||
791 | ai.WriteLine("copies of the Software, and to permit persons to whom the Software is"); | ||
792 | ai.WriteLine("furnished to do so, subject to the following conditions:"); | ||
793 | ai.WriteLine(""); | ||
794 | ai.WriteLine("The above copyright notice and this permission notice shall be included in all"); | ||
795 | ai.WriteLine("copies or substantial portions of the Software."); | ||
796 | ai.WriteLine(""); | ||
797 | ai.WriteLine("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR"); | ||
798 | ai.WriteLine("IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,"); | ||
799 | ai.WriteLine("FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE"); | ||
800 | ai.WriteLine("AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER"); | ||
801 | ai.WriteLine("LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,"); | ||
802 | ai.WriteLine("OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE"); | ||
803 | ai.WriteLine("SOFTWARE."); | ||
804 | ai.WriteLine("*/"); | ||
805 | ai.WriteLine("#endregion License"); | ||
806 | ai.WriteLine(""); | ||
807 | ai.WriteLine("using System;"); | ||
808 | ai.WriteLine("using System.Reflection;"); | ||
809 | ai.WriteLine("using System.Runtime.InteropServices;"); | ||
810 | ai.WriteLine("using System.Security;"); | ||
811 | ai.WriteLine("using System.Security.Permissions;"); | ||
812 | ai.WriteLine(""); | ||
813 | ai.WriteLine("[assembly: AllowPartiallyTrustedCallers]"); | ||
814 | ai.WriteLine("[assembly: AssemblyCompany(\"Tao Framework -- http://www.taoframework.com\")]"); | ||
815 | ai.WriteLine("[assembly: AssemblyConfiguration(\"Retail\")]"); | ||
816 | ai.WriteLine("[assembly: AssemblyCopyright(\"Copyright (c)2003-2006 Tao Framework Team. All rights reserved.\")]"); | ||
817 | ai.WriteLine("[assembly: AssemblyCulture(\"\")]"); | ||
818 | ai.WriteLine("[assembly: AssemblyDefaultAlias(\"@PACKAGE_NAME@\")]"); | ||
819 | ai.WriteLine("[assembly: AssemblyDelaySign(false)]"); | ||
820 | ai.WriteLine("[assembly: AssemblyDescription(\"@DESCRIPTION@\")]"); | ||
821 | ai.WriteLine("[assembly: AssemblyFileVersion(\"@ASSEMBLY_VERSION@\")]"); | ||
822 | ai.WriteLine("[assembly: AssemblyInformationalVersion(\"@ASSEMBLY_VERSION@\")]"); | ||
823 | ai.WriteLine("[assembly: AssemblyKeyName(\"\")]"); | ||
824 | ai.WriteLine("[assembly: AssemblyProduct(\"@PACKAGE_NAME@.dll\")]"); | ||
825 | ai.WriteLine("[assembly: AssemblyTitle(\"@DESCRIPTION@\")]"); | ||
826 | ai.WriteLine("[assembly: AssemblyTrademark(\"Tao Framework -- http://www.taoframework.com\")]"); | ||
827 | ai.WriteLine("[assembly: AssemblyVersion(\"@ASSEMBLY_VERSION@\")]"); | ||
828 | ai.WriteLine("[assembly: CLSCompliant(true)]"); | ||
829 | ai.WriteLine("[assembly: ComVisible(false)]"); | ||
830 | ai.WriteLine("[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.Execution)]"); | ||
831 | ai.WriteLine("[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.SkipVerification)]"); | ||
832 | ai.WriteLine("[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.UnmanagedCode)]"); | ||
833 | |||
834 | } | ||
835 | //return combFile; | ||
836 | } | ||
837 | |||
838 | private void CleanProject(ProjectNode project) | ||
839 | { | ||
840 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
841 | string projectFile = Helper.MakeFilePath(project.FullPath, "Include", "am"); | ||
842 | Helper.DeleteIfExists(projectFile); | ||
843 | } | ||
844 | |||
845 | private void CleanSolution(SolutionNode solution) | ||
846 | { | ||
847 | m_Kernel.Log.Write("Cleaning Autotools make files for", solution.Name); | ||
848 | |||
849 | string slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "am"); | ||
850 | Helper.DeleteIfExists(slnFile); | ||
851 | |||
852 | slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "in"); | ||
853 | Helper.DeleteIfExists(slnFile); | ||
854 | |||
855 | slnFile = Helper.MakeFilePath(solution.FullPath, "configure", "ac"); | ||
856 | Helper.DeleteIfExists(slnFile); | ||
857 | |||
858 | slnFile = Helper.MakeFilePath(solution.FullPath, "configure"); | ||
859 | Helper.DeleteIfExists(slnFile); | ||
860 | |||
861 | slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile"); | ||
862 | Helper.DeleteIfExists(slnFile); | ||
863 | |||
864 | foreach(ProjectNode project in solution.Projects) | ||
865 | { | ||
866 | CleanProject(project); | ||
867 | } | ||
868 | |||
869 | m_Kernel.Log.Write(""); | ||
870 | } | ||
871 | |||
872 | #endregion | ||
873 | |||
874 | #region ITarget Members | ||
875 | |||
876 | /// <summary> | ||
877 | /// Writes the specified kern. | ||
878 | /// </summary> | ||
879 | /// <param name="kern">The kern.</param> | ||
880 | public void Write(Kernel kern) | ||
881 | { | ||
882 | if( kern == null ) | ||
883 | { | ||
884 | throw new ArgumentNullException("kern"); | ||
885 | } | ||
886 | m_Kernel = kern; | ||
887 | foreach(SolutionNode solution in kern.Solutions) | ||
888 | { | ||
889 | WriteCombine(solution); | ||
890 | } | ||
891 | m_Kernel = null; | ||
892 | } | ||
893 | |||
894 | /// <summary> | ||
895 | /// Cleans the specified kern. | ||
896 | /// </summary> | ||
897 | /// <param name="kern">The kern.</param> | ||
898 | public virtual void Clean(Kernel kern) | ||
899 | { | ||
900 | if( kern == null ) | ||
901 | { | ||
902 | throw new ArgumentNullException("kern"); | ||
903 | } | ||
904 | m_Kernel = kern; | ||
905 | foreach(SolutionNode sol in kern.Solutions) | ||
906 | { | ||
907 | CleanSolution(sol); | ||
908 | } | ||
909 | m_Kernel = null; | ||
910 | } | ||
911 | |||
912 | /// <summary> | ||
913 | /// Gets the name. | ||
914 | /// </summary> | ||
915 | /// <value>The name.</value> | ||
916 | public string Name | ||
917 | { | ||
918 | get | ||
919 | { | ||
920 | return "autotools"; | ||
921 | } | ||
922 | } | ||
923 | |||
924 | #endregion | ||
925 | } | ||
926 | } | ||
diff --git a/Prebuild/src/Core/Targets/DebugTarget.cs b/Prebuild/src/Core/Targets/DebugTarget.cs new file mode 100644 index 0000000..6baa623 --- /dev/null +++ b/Prebuild/src/Core/Targets/DebugTarget.cs | |||
@@ -0,0 +1,102 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-09-20 09:42:51 +0200 (on, 20 sep 2006) $ | ||
31 | * $Revision: 164 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | |||
37 | using Prebuild.Core.Attributes; | ||
38 | using Prebuild.Core.Interfaces; | ||
39 | using Prebuild.Core.Nodes; | ||
40 | |||
41 | #if (DEBUG && _DEBUG_TARGET) | ||
42 | namespace Prebuild.Core.Targets | ||
43 | { | ||
44 | [Target("debug")] | ||
45 | public class DebugTarget : ITarget | ||
46 | { | ||
47 | #region Fields | ||
48 | |||
49 | private Kernel m_Kernel = null; | ||
50 | |||
51 | #endregion | ||
52 | |||
53 | #region ITarget Members | ||
54 | |||
55 | public void Write() | ||
56 | { | ||
57 | foreach(SolutionNode s in m_Kernel.Solutions) | ||
58 | { | ||
59 | Console.WriteLine("Solution [ {0}, {1} ]", s.Name, s.Path); | ||
60 | foreach(string file in s.Files) | ||
61 | { | ||
62 | Console.WriteLine("\tFile [ {0} ]", file); | ||
63 | } | ||
64 | |||
65 | foreach(ProjectNode proj in s.Projects) | ||
66 | { | ||
67 | Console.WriteLine("\tProject [ {0}, {1}. {2} ]", proj.Name, proj.Path, proj.Language); | ||
68 | foreach(string file in proj.Files) | ||
69 | Console.WriteLine("\t\tFile [ {0} ]", file); | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | |||
74 | public void Clean() | ||
75 | { | ||
76 | Console.WriteLine("Not implemented"); | ||
77 | } | ||
78 | |||
79 | public string Name | ||
80 | { | ||
81 | get | ||
82 | { | ||
83 | return "debug"; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | public Kernel Kernel | ||
88 | { | ||
89 | get | ||
90 | { | ||
91 | return m_Kernel; | ||
92 | } | ||
93 | set | ||
94 | { | ||
95 | m_Kernel = value; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | #endregion | ||
100 | } | ||
101 | } | ||
102 | #endif | ||
diff --git a/Prebuild/src/Core/Targets/MonoDevelopTarget.cs b/Prebuild/src/Core/Targets/MonoDevelopTarget.cs new file mode 100644 index 0000000..8620e4b --- /dev/null +++ b/Prebuild/src/Core/Targets/MonoDevelopTarget.cs | |||
@@ -0,0 +1,458 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2007-02-13 22:07:07 +0100 (ti, 13 feb 2007) $ | ||
31 | * $Revision: 206 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.IO; | ||
39 | using System.Reflection; | ||
40 | using System.Text.RegularExpressions; | ||
41 | |||
42 | using Prebuild.Core.Attributes; | ||
43 | using Prebuild.Core.Interfaces; | ||
44 | using Prebuild.Core.Nodes; | ||
45 | using Prebuild.Core.Utilities; | ||
46 | |||
47 | namespace Prebuild.Core.Targets | ||
48 | { | ||
49 | /// <summary> | ||
50 | /// | ||
51 | /// </summary> | ||
52 | [Target("monodev")] | ||
53 | public class MonoDevelopTarget : ITarget | ||
54 | { | ||
55 | #region Fields | ||
56 | |||
57 | private Kernel m_Kernel; | ||
58 | |||
59 | #endregion | ||
60 | |||
61 | #region Private Methods | ||
62 | |||
63 | private static string PrependPath(string path) | ||
64 | { | ||
65 | string tmpPath = Helper.NormalizePath(path, '/'); | ||
66 | Regex regex = new Regex(@"(\w):/(\w+)"); | ||
67 | Match match = regex.Match(tmpPath); | ||
68 | if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/') | ||
69 | { | ||
70 | tmpPath = Helper.NormalizePath(tmpPath); | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | tmpPath = Helper.NormalizePath("./" + tmpPath); | ||
75 | } | ||
76 | |||
77 | return tmpPath; | ||
78 | } | ||
79 | |||
80 | private static string BuildReference(SolutionNode solution, ReferenceNode refr) | ||
81 | { | ||
82 | string ret = "<ProjectReference type=\""; | ||
83 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
84 | { | ||
85 | ret += "Project\""; | ||
86 | ret += " localcopy=\"" + refr.LocalCopy.ToString() + "\" refto=\"" + refr.Name + "\" />"; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | ProjectNode project = (ProjectNode)refr.Parent; | ||
91 | string fileRef = FindFileReference(refr.Name, project); | ||
92 | |||
93 | if(refr.Path != null || fileRef != null) | ||
94 | { | ||
95 | ret += "Assembly\" refto=\""; | ||
96 | |||
97 | string finalPath = (refr.Path != null) ? Helper.MakeFilePath(refr.Path, refr.Name, "dll") : fileRef; | ||
98 | |||
99 | ret += finalPath; | ||
100 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
101 | return ret; | ||
102 | } | ||
103 | |||
104 | ret += "Gac\""; | ||
105 | ret += " localcopy=\"" + refr.LocalCopy.ToString() + "\""; | ||
106 | ret += " refto=\""; | ||
107 | try | ||
108 | { | ||
109 | //Assembly assem = Assembly.Load(refr.Name); | ||
110 | //ret += assem.FullName; | ||
111 | ret += refr.Name; | ||
112 | } | ||
113 | catch (System.NullReferenceException e) | ||
114 | { | ||
115 | e.ToString(); | ||
116 | ret += refr.Name; | ||
117 | } | ||
118 | ret += "\" />"; | ||
119 | } | ||
120 | |||
121 | return ret; | ||
122 | } | ||
123 | |||
124 | private static string FindFileReference(string refName, ProjectNode project) | ||
125 | { | ||
126 | foreach(ReferencePathNode refPath in project.ReferencePaths) | ||
127 | { | ||
128 | string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll"); | ||
129 | |||
130 | if(File.Exists(fullPath)) | ||
131 | { | ||
132 | return fullPath; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | return null; | ||
137 | } | ||
138 | |||
139 | /// <summary> | ||
140 | /// Gets the XML doc file. | ||
141 | /// </summary> | ||
142 | /// <param name="project">The project.</param> | ||
143 | /// <param name="conf">The conf.</param> | ||
144 | /// <returns></returns> | ||
145 | public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf) | ||
146 | { | ||
147 | if( conf == null ) | ||
148 | { | ||
149 | throw new ArgumentNullException("conf"); | ||
150 | } | ||
151 | if( project == null ) | ||
152 | { | ||
153 | throw new ArgumentNullException("project"); | ||
154 | } | ||
155 | string docFile = (string)conf.Options["XmlDocFile"]; | ||
156 | if(docFile != null && docFile.Length == 0)//default to assembly name if not specified | ||
157 | { | ||
158 | return "False"; | ||
159 | } | ||
160 | return "True"; | ||
161 | } | ||
162 | |||
163 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
164 | { | ||
165 | string csComp = "Mcs"; | ||
166 | string netRuntime = "Mono"; | ||
167 | if(project.Runtime == ClrRuntime.Microsoft) | ||
168 | { | ||
169 | csComp = "Csc"; | ||
170 | netRuntime = "MsNet"; | ||
171 | } | ||
172 | |||
173 | string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "mdp"); | ||
174 | StreamWriter ss = new StreamWriter(projFile); | ||
175 | |||
176 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
177 | Helper.SetCurrentDir(Path.GetDirectoryName(projFile)); | ||
178 | |||
179 | using(ss) | ||
180 | { | ||
181 | ss.WriteLine( | ||
182 | "<Project name=\"{0}\" description=\"\" standardNamespace=\"{1}\" newfilesearch=\"None\" enableviewstate=\"True\" fileversion=\"2.0\" language=\"C#\" clr-version=\"Net_2_0\" ctype=\"DotNetProject\">", | ||
183 | project.Name, | ||
184 | project.RootNamespace | ||
185 | ); | ||
186 | |||
187 | int count = 0; | ||
188 | |||
189 | ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig); | ||
190 | |||
191 | foreach(ConfigurationNode conf in project.Configurations) | ||
192 | { | ||
193 | ss.WriteLine(" <Configuration name=\"{0}\" ctype=\"DotNetProjectConfiguration\">", conf.Name); | ||
194 | ss.Write(" <Output"); | ||
195 | ss.Write(" directory=\"{0}\"", Helper.EndPath(Helper.NormalizePath(".\\" + conf.Options["OutputPath"].ToString()))); | ||
196 | ss.Write(" assembly=\"{0}\"", project.AssemblyName); | ||
197 | ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]); | ||
198 | //ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]); | ||
199 | //ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]); | ||
200 | if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0) | ||
201 | { | ||
202 | ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString())); | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]); | ||
207 | } | ||
208 | if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0) | ||
209 | { | ||
210 | ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString())); | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]); | ||
215 | } | ||
216 | ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
217 | ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
218 | ss.WriteLine(" />"); | ||
219 | |||
220 | ss.Write(" <Build"); | ||
221 | ss.Write(" debugmode=\"True\""); | ||
222 | if (project.Type == ProjectType.WinExe) | ||
223 | { | ||
224 | ss.Write(" target=\"{0}\"", ProjectType.Exe.ToString()); | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | ss.Write(" target=\"{0}\"", project.Type); | ||
229 | } | ||
230 | ss.WriteLine(" />"); | ||
231 | |||
232 | ss.Write(" <Execution"); | ||
233 | ss.Write(" runwithwarnings=\"True\""); | ||
234 | ss.Write(" consolepause=\"True\""); | ||
235 | ss.Write(" runtime=\"{0}\"", netRuntime); | ||
236 | ss.Write(" clr-version=\"Net_2_0\""); | ||
237 | ss.WriteLine(" />"); | ||
238 | |||
239 | ss.Write(" <CodeGeneration"); | ||
240 | ss.Write(" compiler=\"{0}\"", csComp); | ||
241 | ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]); | ||
242 | ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]); | ||
243 | ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]); | ||
244 | ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]); | ||
245 | ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]); | ||
246 | ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]); | ||
247 | ss.Write(" mainclass=\"{0}\"", project.StartupObject); | ||
248 | ss.Write(" target=\"{0}\"", project.Type); | ||
249 | ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]); | ||
250 | ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf)); | ||
251 | ss.Write(" win32Icon=\"{0}\"", project.AppIcon); | ||
252 | ss.Write(" ctype=\"CSharpCompilerParameters\""); | ||
253 | ss.WriteLine(" />"); | ||
254 | ss.WriteLine(" </Configuration>"); | ||
255 | |||
256 | count++; | ||
257 | } | ||
258 | ss.WriteLine(" </Configurations>"); | ||
259 | |||
260 | ss.Write(" <DeploymentInformation"); | ||
261 | ss.Write(" target=\"\""); | ||
262 | ss.Write(" script=\"\""); | ||
263 | ss.Write(" strategy=\"File\""); | ||
264 | ss.WriteLine(">"); | ||
265 | ss.WriteLine(" <excludeFiles />"); | ||
266 | ss.WriteLine(" </DeploymentInformation>"); | ||
267 | |||
268 | ss.WriteLine(" <Contents>"); | ||
269 | foreach(string file in project.Files) | ||
270 | { | ||
271 | string buildAction = "Compile"; | ||
272 | switch(project.Files.GetBuildAction(file)) | ||
273 | { | ||
274 | case BuildAction.None: | ||
275 | buildAction = "Nothing"; | ||
276 | break; | ||
277 | |||
278 | case BuildAction.Content: | ||
279 | buildAction = "Exclude"; | ||
280 | break; | ||
281 | |||
282 | case BuildAction.EmbeddedResource: | ||
283 | buildAction = "EmbedAsResource"; | ||
284 | break; | ||
285 | |||
286 | default: | ||
287 | buildAction = "Compile"; | ||
288 | break; | ||
289 | } | ||
290 | |||
291 | // Sort of a hack, we try and resolve the path and make it relative, if we can. | ||
292 | string filePath = PrependPath(file); | ||
293 | ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\" dependson=\"\" data=\"\" />", filePath, buildAction); | ||
294 | } | ||
295 | ss.WriteLine(" </Contents>"); | ||
296 | |||
297 | ss.WriteLine(" <References>"); | ||
298 | foreach(ReferenceNode refr in project.References) | ||
299 | { | ||
300 | ss.WriteLine(" {0}", BuildReference(solution, refr)); | ||
301 | } | ||
302 | ss.WriteLine(" </References>"); | ||
303 | |||
304 | |||
305 | ss.WriteLine("</Project>"); | ||
306 | } | ||
307 | |||
308 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
309 | } | ||
310 | |||
311 | private void WriteCombine(SolutionNode solution) | ||
312 | { | ||
313 | m_Kernel.Log.Write("Creating MonoDevelop combine and project files"); | ||
314 | foreach(ProjectNode project in solution.Projects) | ||
315 | { | ||
316 | if(m_Kernel.AllowProject(project.FilterGroups)) | ||
317 | { | ||
318 | m_Kernel.Log.Write("...Creating project: {0}", project.Name); | ||
319 | WriteProject(solution, project); | ||
320 | } | ||
321 | } | ||
322 | |||
323 | m_Kernel.Log.Write(""); | ||
324 | string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "mds"); | ||
325 | StreamWriter ss = new StreamWriter(combFile); | ||
326 | |||
327 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
328 | Helper.SetCurrentDir(Path.GetDirectoryName(combFile)); | ||
329 | |||
330 | int count = 0; | ||
331 | |||
332 | using(ss) | ||
333 | { | ||
334 | ss.WriteLine("<Combine name=\"{0}\" fileversion=\"2.0\" description=\"\">", solution.Name); | ||
335 | |||
336 | count = 0; | ||
337 | foreach(ConfigurationNode conf in solution.Configurations) | ||
338 | { | ||
339 | if(count == 0) | ||
340 | { | ||
341 | ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name); | ||
342 | } | ||
343 | |||
344 | ss.WriteLine(" <Configuration name=\"{0}\" ctype=\"CombineConfiguration\">", conf.Name); | ||
345 | foreach(ProjectNode project in solution.Projects) | ||
346 | { | ||
347 | ss.WriteLine(" <Entry configuration=\"{1}\" build=\"True\" name=\"{0}\" />", project.Name, conf.Name); | ||
348 | } | ||
349 | ss.WriteLine(" </Configuration>"); | ||
350 | |||
351 | count++; | ||
352 | } | ||
353 | ss.WriteLine(" </Configurations>"); | ||
354 | |||
355 | count = 0; | ||
356 | |||
357 | foreach(ProjectNode project in solution.Projects) | ||
358 | { | ||
359 | if(count == 0) | ||
360 | ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name); | ||
361 | |||
362 | ss.WriteLine(" <Execute type=\"None\" entry=\"{0}\" />", project.Name); | ||
363 | count++; | ||
364 | } | ||
365 | ss.WriteLine(" </StartMode>"); | ||
366 | |||
367 | ss.WriteLine(" <Entries>"); | ||
368 | foreach(ProjectNode project in solution.Projects) | ||
369 | { | ||
370 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
371 | ss.WriteLine(" <Entry filename=\"{0}\" />", | ||
372 | Helper.MakeFilePath(path, project.Name, "mdp")); | ||
373 | } | ||
374 | ss.WriteLine(" </Entries>"); | ||
375 | |||
376 | ss.WriteLine("</Combine>"); | ||
377 | } | ||
378 | |||
379 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
380 | } | ||
381 | |||
382 | private void CleanProject(ProjectNode project) | ||
383 | { | ||
384 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
385 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "mdp"); | ||
386 | Helper.DeleteIfExists(projectFile); | ||
387 | } | ||
388 | |||
389 | private void CleanSolution(SolutionNode solution) | ||
390 | { | ||
391 | m_Kernel.Log.Write("Cleaning MonoDevelop combine and project files for", solution.Name); | ||
392 | |||
393 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "mds"); | ||
394 | Helper.DeleteIfExists(slnFile); | ||
395 | |||
396 | foreach(ProjectNode project in solution.Projects) | ||
397 | { | ||
398 | CleanProject(project); | ||
399 | } | ||
400 | |||
401 | m_Kernel.Log.Write(""); | ||
402 | } | ||
403 | |||
404 | #endregion | ||
405 | |||
406 | #region ITarget Members | ||
407 | |||
408 | /// <summary> | ||
409 | /// Writes the specified kern. | ||
410 | /// </summary> | ||
411 | /// <param name="kern">The kern.</param> | ||
412 | public void Write(Kernel kern) | ||
413 | { | ||
414 | if( kern == null ) | ||
415 | { | ||
416 | throw new ArgumentNullException("kern"); | ||
417 | } | ||
418 | m_Kernel = kern; | ||
419 | foreach(SolutionNode solution in kern.Solutions) | ||
420 | { | ||
421 | WriteCombine(solution); | ||
422 | } | ||
423 | m_Kernel = null; | ||
424 | } | ||
425 | |||
426 | /// <summary> | ||
427 | /// Cleans the specified kern. | ||
428 | /// </summary> | ||
429 | /// <param name="kern">The kern.</param> | ||
430 | public virtual void Clean(Kernel kern) | ||
431 | { | ||
432 | if( kern == null ) | ||
433 | { | ||
434 | throw new ArgumentNullException("kern"); | ||
435 | } | ||
436 | m_Kernel = kern; | ||
437 | foreach(SolutionNode sol in kern.Solutions) | ||
438 | { | ||
439 | CleanSolution(sol); | ||
440 | } | ||
441 | m_Kernel = null; | ||
442 | } | ||
443 | |||
444 | /// <summary> | ||
445 | /// Gets the name. | ||
446 | /// </summary> | ||
447 | /// <value>The name.</value> | ||
448 | public string Name | ||
449 | { | ||
450 | get | ||
451 | { | ||
452 | return "sharpdev"; | ||
453 | } | ||
454 | } | ||
455 | |||
456 | #endregion | ||
457 | } | ||
458 | } | ||
diff --git a/Prebuild/src/Core/Targets/NAntTarget.cs b/Prebuild/src/Core/Targets/NAntTarget.cs new file mode 100644 index 0000000..0f0deb2 --- /dev/null +++ b/Prebuild/src/Core/Targets/NAntTarget.cs | |||
@@ -0,0 +1,621 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2007-02-13 21:58:03 +0100 (ti, 13 feb 2007) $ | ||
31 | * $Revision: 205 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.IO; | ||
39 | using System.Reflection; | ||
40 | using System.Text.RegularExpressions; | ||
41 | |||
42 | using Prebuild.Core.Attributes; | ||
43 | using Prebuild.Core.Interfaces; | ||
44 | using Prebuild.Core.Nodes; | ||
45 | using Prebuild.Core.Utilities; | ||
46 | |||
47 | namespace Prebuild.Core.Targets | ||
48 | { | ||
49 | /// <summary> | ||
50 | /// | ||
51 | /// </summary> | ||
52 | [Target("nant")] | ||
53 | public class NAntTarget : ITarget | ||
54 | { | ||
55 | #region Fields | ||
56 | |||
57 | private Kernel m_Kernel; | ||
58 | |||
59 | #endregion | ||
60 | |||
61 | #region Private Methods | ||
62 | |||
63 | private static string PrependPath(string path) | ||
64 | { | ||
65 | string tmpPath = Helper.NormalizePath(path, '/'); | ||
66 | Regex regex = new Regex(@"(\w):/(\w+)"); | ||
67 | Match match = regex.Match(tmpPath); | ||
68 | //if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/') | ||
69 | //{ | ||
70 | tmpPath = Helper.NormalizePath(tmpPath); | ||
71 | //} | ||
72 | // else | ||
73 | // { | ||
74 | // tmpPath = Helper.NormalizePath("./" + tmpPath); | ||
75 | // } | ||
76 | |||
77 | return tmpPath; | ||
78 | } | ||
79 | |||
80 | private static string BuildReference(SolutionNode solution, ProjectNode currentProject, ReferenceNode refr) | ||
81 | { | ||
82 | string ret = ""; | ||
83 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
84 | { | ||
85 | ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name]; | ||
86 | |||
87 | string finalPath = Helper.NormalizePath(((ReferencePathNode)currentProject.ReferencePaths[0]).Path + refr.Name + ".dll", '/'); | ||
88 | |||
89 | return finalPath; | ||
90 | } | ||
91 | else | ||
92 | { | ||
93 | ProjectNode project = (ProjectNode)refr.Parent; | ||
94 | string fileRef = FindFileReference(refr.Name, project); | ||
95 | |||
96 | if(refr.Path != null || fileRef != null) | ||
97 | { | ||
98 | string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path + "/" + refr.Name + ".dll", '/') : fileRef; | ||
99 | ret += finalPath; | ||
100 | return ret; | ||
101 | } | ||
102 | |||
103 | try | ||
104 | { | ||
105 | //Assembly assem = Assembly.Load(refr.Name); | ||
106 | //if (assem != null) | ||
107 | //{ | ||
108 | //ret += (refr.Name + ".dll"); | ||
109 | //} | ||
110 | //else | ||
111 | //{ | ||
112 | ret += (refr.Name + ".dll"); | ||
113 | //} | ||
114 | } | ||
115 | catch (System.NullReferenceException e) | ||
116 | { | ||
117 | e.ToString(); | ||
118 | ret += refr.Name + ".dll"; | ||
119 | } | ||
120 | } | ||
121 | return ret; | ||
122 | } | ||
123 | |||
124 | private static string BuildReferencePath(SolutionNode solution, ReferenceNode refr) | ||
125 | { | ||
126 | string ret = ""; | ||
127 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
128 | { | ||
129 | ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name]; | ||
130 | string finalPath = Helper.NormalizePath(((ReferencePathNode)project.ReferencePaths[0]).Path, '/'); | ||
131 | |||
132 | return finalPath; | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | ProjectNode project = (ProjectNode)refr.Parent; | ||
137 | string fileRef = FindFileReference(refr.Name, project); | ||
138 | |||
139 | if(refr.Path != null || fileRef != null) | ||
140 | { | ||
141 | string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path, '/') : fileRef; | ||
142 | ret += finalPath; | ||
143 | return ret; | ||
144 | } | ||
145 | |||
146 | try | ||
147 | { | ||
148 | Assembly assem = Assembly.Load(refr.Name); | ||
149 | if (assem != null) | ||
150 | { | ||
151 | ret += ""; | ||
152 | } | ||
153 | else | ||
154 | { | ||
155 | ret += ""; | ||
156 | } | ||
157 | } | ||
158 | catch (System.NullReferenceException e) | ||
159 | { | ||
160 | e.ToString(); | ||
161 | ret += ""; | ||
162 | } | ||
163 | } | ||
164 | return ret; | ||
165 | } | ||
166 | |||
167 | private static string FindFileReference(string refName, ProjectNode project) | ||
168 | { | ||
169 | foreach(ReferencePathNode refPath in project.ReferencePaths) | ||
170 | { | ||
171 | string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll"); | ||
172 | |||
173 | if(File.Exists(fullPath)) | ||
174 | { | ||
175 | return fullPath; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | return null; | ||
180 | } | ||
181 | |||
182 | /// <summary> | ||
183 | /// Gets the XML doc file. | ||
184 | /// </summary> | ||
185 | /// <param name="project">The project.</param> | ||
186 | /// <param name="conf">The conf.</param> | ||
187 | /// <returns></returns> | ||
188 | public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf) | ||
189 | { | ||
190 | if( conf == null ) | ||
191 | { | ||
192 | throw new ArgumentNullException("conf"); | ||
193 | } | ||
194 | if( project == null ) | ||
195 | { | ||
196 | throw new ArgumentNullException("project"); | ||
197 | } | ||
198 | string docFile = (string)conf.Options["XmlDocFile"]; | ||
199 | // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified | ||
200 | // { | ||
201 | // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml"; | ||
202 | // } | ||
203 | return docFile; | ||
204 | } | ||
205 | |||
206 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
207 | { | ||
208 | string projFile = Helper.MakeFilePath(project.FullPath, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"); | ||
209 | StreamWriter ss = new StreamWriter(projFile); | ||
210 | |||
211 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
212 | Helper.SetCurrentDir(Path.GetDirectoryName(projFile)); | ||
213 | bool hasDoc = false; | ||
214 | |||
215 | using(ss) | ||
216 | { | ||
217 | ss.WriteLine("<?xml version=\"1.0\" ?>"); | ||
218 | ss.WriteLine("<project name=\"{0}\" default=\"build\">", project.Name); | ||
219 | ss.WriteLine(" <target name=\"{0}\">", "build"); | ||
220 | ss.WriteLine(" <echo message=\"Build Directory is ${project::get-base-directory()}/${build.dir}\" />"); | ||
221 | ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/${build.dir}\" />"); | ||
222 | ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/${build.dir}\">"); | ||
223 | ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">"); | ||
224 | foreach(ReferenceNode refr in project.References) | ||
225 | { | ||
226 | if (refr.LocalCopy) | ||
227 | { | ||
228 | ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr))+"\" />", '/')); | ||
229 | } | ||
230 | } | ||
231 | ss.WriteLine(" </fileset>"); | ||
232 | ss.WriteLine(" </copy>"); | ||
233 | ss.Write(" <csc"); | ||
234 | ss.Write(" target=\"{0}\"", project.Type.ToString().ToLower()); | ||
235 | ss.Write(" debug=\"{0}\"", "${build.debug}"); | ||
236 | foreach(ConfigurationNode conf in project.Configurations) | ||
237 | { | ||
238 | if (conf.Options.KeyFile !="") | ||
239 | { | ||
240 | ss.Write(" keyfile=\"{0}\"", conf.Options.KeyFile); | ||
241 | break; | ||
242 | } | ||
243 | } | ||
244 | foreach(ConfigurationNode conf in project.Configurations) | ||
245 | { | ||
246 | ss.Write(" unsafe=\"{0}\"", conf.Options.AllowUnsafe); | ||
247 | break; | ||
248 | } | ||
249 | foreach(ConfigurationNode conf in project.Configurations) | ||
250 | { | ||
251 | ss.Write(" define=\"{0}\"", conf.Options.CompilerDefines); | ||
252 | break; | ||
253 | } | ||
254 | foreach(ConfigurationNode conf in project.Configurations) | ||
255 | { | ||
256 | if (GetXmlDocFile(project, conf) !="") | ||
257 | { | ||
258 | ss.Write(" doc=\"{0}\"", "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile(project, conf)); | ||
259 | hasDoc = true; | ||
260 | } | ||
261 | break; | ||
262 | } | ||
263 | ss.Write(" output=\"{0}", "${project::get-base-directory()}/${build.dir}/${project::get-name()}"); | ||
264 | if (project.Type == ProjectType.Library) | ||
265 | { | ||
266 | ss.Write(".dll\""); | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | ss.Write(".exe\""); | ||
271 | } | ||
272 | if(project.AppIcon != null && project.AppIcon.Length != 0) | ||
273 | { | ||
274 | ss.Write(" win32icon=\"{0}\"", Helper.NormalizePath(project.AppIcon,'/')); | ||
275 | } | ||
276 | ss.WriteLine(">"); | ||
277 | ss.WriteLine(" <resources prefix=\"{0}\" dynamicprefix=\"true\" >", project.RootNamespace); | ||
278 | foreach (string file in project.Files) | ||
279 | { | ||
280 | switch (project.Files.GetBuildAction(file)) | ||
281 | { | ||
282 | case BuildAction.EmbeddedResource: | ||
283 | ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />"); | ||
284 | break; | ||
285 | default: | ||
286 | if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings) | ||
287 | { | ||
288 | ss.WriteLine(" <include name=\"{0}\" />", file.Substring(0, file.LastIndexOf('.')) + ".resx"); | ||
289 | } | ||
290 | break; | ||
291 | } | ||
292 | } | ||
293 | //if (project.Files.GetSubType(file).ToString() != "Code") | ||
294 | //{ | ||
295 | // ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx"); | ||
296 | |||
297 | ss.WriteLine(" </resources>"); | ||
298 | ss.WriteLine(" <sources failonempty=\"true\">"); | ||
299 | foreach(string file in project.Files) | ||
300 | { | ||
301 | switch(project.Files.GetBuildAction(file)) | ||
302 | { | ||
303 | case BuildAction.Compile: | ||
304 | ss.WriteLine(" <include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />"); | ||
305 | break; | ||
306 | default: | ||
307 | break; | ||
308 | } | ||
309 | } | ||
310 | ss.WriteLine(" </sources>"); | ||
311 | ss.WriteLine(" <references basedir=\"${project::get-base-directory()}\">"); | ||
312 | ss.WriteLine(" <lib>"); | ||
313 | ss.WriteLine(" <include name=\"${project::get-base-directory()}\" />"); | ||
314 | ss.WriteLine(" <include name=\"${project::get-base-directory()}/${build.dir}\" />"); | ||
315 | ss.WriteLine(" </lib>"); | ||
316 | foreach(ReferenceNode refr in project.References) | ||
317 | { | ||
318 | string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)), '/'); | ||
319 | ss.WriteLine(" <include name=\""+ path + "\" />" ); | ||
320 | } | ||
321 | ss.WriteLine(" </references>"); | ||
322 | |||
323 | ss.WriteLine(" </csc>"); | ||
324 | |||
325 | foreach (ConfigurationNode conf in project.Configurations) | ||
326 | { | ||
327 | if (!String.IsNullOrEmpty(conf.Options.OutputPath)) | ||
328 | { | ||
329 | string targetDir = Helper.NormalizePath(conf.Options.OutputPath, '/'); | ||
330 | |||
331 | ss.WriteLine(" <echo message=\"Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/" + targetDir + "\" />"); | ||
332 | |||
333 | ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/" + targetDir + "\"/>"); | ||
334 | |||
335 | ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/" + targetDir + "\">"); | ||
336 | ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}/${build.dir}/\" >"); | ||
337 | ss.WriteLine(" <include name=\"*.dll\"/>"); | ||
338 | ss.WriteLine(" <include name=\"*.exe\"/>"); | ||
339 | ss.WriteLine(" </fileset>"); | ||
340 | ss.WriteLine(" </copy>"); | ||
341 | break; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | ss.WriteLine(" </target>"); | ||
346 | |||
347 | ss.WriteLine(" <target name=\"clean\">"); | ||
348 | ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />"); | ||
349 | ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />"); | ||
350 | ss.WriteLine(" </target>"); | ||
351 | |||
352 | ss.WriteLine(" <target name=\"doc\" description=\"Creates documentation.\">"); | ||
353 | if (hasDoc) | ||
354 | { | ||
355 | ss.WriteLine(" <property name=\"doc.target\" value=\"\" />"); | ||
356 | ss.WriteLine(" <if test=\"${platform::is-unix()}\">"); | ||
357 | ss.WriteLine(" <property name=\"doc.target\" value=\"Web\" />"); | ||
358 | ss.WriteLine(" </if>"); | ||
359 | ss.WriteLine(" <ndoc failonerror=\"false\" verbose=\"true\">"); | ||
360 | ss.WriteLine(" <assemblies basedir=\"${project::get-base-directory()}\">"); | ||
361 | ss.Write(" <include name=\"${build.dir}/${project::get-name()}"); | ||
362 | if (project.Type == ProjectType.Library) | ||
363 | { | ||
364 | ss.WriteLine(".dll\" />"); | ||
365 | } | ||
366 | else | ||
367 | { | ||
368 | ss.WriteLine(".exe\" />"); | ||
369 | } | ||
370 | |||
371 | ss.WriteLine(" </assemblies>"); | ||
372 | ss.WriteLine(" <summaries basedir=\"${project::get-base-directory()}\">"); | ||
373 | ss.WriteLine(" <include name=\"${build.dir}/${project::get-name()}.xml\"/>"); | ||
374 | ss.WriteLine(" </summaries>"); | ||
375 | ss.WriteLine(" <referencepaths basedir=\"${project::get-base-directory()}\">"); | ||
376 | ss.WriteLine(" <include name=\"${build.dir}\" />"); | ||
377 | // foreach(ReferenceNode refr in project.References) | ||
378 | // { | ||
379 | // string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/'); | ||
380 | // if (path != "") | ||
381 | // { | ||
382 | // ss.WriteLine(" <include name=\"{0}\" />", path); | ||
383 | // } | ||
384 | // } | ||
385 | ss.WriteLine(" </referencepaths>"); | ||
386 | ss.WriteLine(" <documenters>"); | ||
387 | ss.WriteLine(" <documenter name=\"MSDN\">"); | ||
388 | ss.WriteLine(" <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />"); | ||
389 | ss.WriteLine(" <property name=\"OutputTarget\" value=\"${doc.target}\" />"); | ||
390 | ss.WriteLine(" <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />"); | ||
391 | ss.WriteLine(" <property name=\"IncludeFavorites\" value=\"False\" />"); | ||
392 | ss.WriteLine(" <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />"); | ||
393 | ss.WriteLine(" <property name=\"SplitTOCs\" value=\"False\" />"); | ||
394 | ss.WriteLine(" <property name=\"DefaulTOC\" value=\"\" />"); | ||
395 | ss.WriteLine(" <property name=\"ShowVisualBasic\" value=\"True\" />"); | ||
396 | ss.WriteLine(" <property name=\"AutoDocumentConstructors\" value=\"True\" />"); | ||
397 | ss.WriteLine(" <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />"); | ||
398 | ss.WriteLine(" <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />"); | ||
399 | ss.WriteLine(" <property name=\"ShowMissingParams\" value=\"${build.debug}\" />"); | ||
400 | ss.WriteLine(" <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />"); | ||
401 | ss.WriteLine(" <property name=\"ShowMissingValues\" value=\"${build.debug}\" />"); | ||
402 | ss.WriteLine(" <property name=\"DocumentInternals\" value=\"False\" />"); | ||
403 | ss.WriteLine(" <property name=\"DocumentPrivates\" value=\"False\" />"); | ||
404 | ss.WriteLine(" <property name=\"DocumentProtected\" value=\"True\" />"); | ||
405 | ss.WriteLine(" <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />"); | ||
406 | ss.WriteLine(" <property name=\"IncludeAssemblyVersion\" value=\"True\" />"); | ||
407 | ss.WriteLine(" </documenter>"); | ||
408 | ss.WriteLine(" </documenters>"); | ||
409 | ss.WriteLine(" </ndoc>"); | ||
410 | } | ||
411 | ss.WriteLine(" </target>"); | ||
412 | ss.WriteLine("</project>"); | ||
413 | } | ||
414 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
415 | } | ||
416 | |||
417 | private void WriteCombine(SolutionNode solution) | ||
418 | { | ||
419 | m_Kernel.Log.Write("Creating NAnt build files"); | ||
420 | foreach(ProjectNode project in solution.Projects) | ||
421 | { | ||
422 | if(m_Kernel.AllowProject(project.FilterGroups)) | ||
423 | { | ||
424 | m_Kernel.Log.Write("...Creating project: {0}", project.Name); | ||
425 | WriteProject(solution, project); | ||
426 | } | ||
427 | } | ||
428 | |||
429 | m_Kernel.Log.Write(""); | ||
430 | string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build"); | ||
431 | StreamWriter ss = new StreamWriter(combFile); | ||
432 | |||
433 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
434 | Helper.SetCurrentDir(Path.GetDirectoryName(combFile)); | ||
435 | |||
436 | using(ss) | ||
437 | { | ||
438 | ss.WriteLine("<?xml version=\"1.0\" ?>"); | ||
439 | ss.WriteLine("<project name=\"{0}\" default=\"build\">", solution.Name); | ||
440 | ss.WriteLine(" <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>"); | ||
441 | ss.WriteLine(); | ||
442 | |||
443 | //ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />"); | ||
444 | //ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />"); | ||
445 | ss.WriteLine(" <property name=\"bin.dir\" value=\"bin\" />"); | ||
446 | ss.WriteLine(" <property name=\"obj.dir\" value=\"obj\" />"); | ||
447 | ss.WriteLine(" <property name=\"doc.dir\" value=\"doc\" />"); | ||
448 | ss.WriteLine(" <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />"); | ||
449 | |||
450 | foreach(ConfigurationNode conf in solution.Configurations) | ||
451 | { | ||
452 | // Set the project.config to a non-debug configuration | ||
453 | if( conf.Options["DebugInformation"].ToString().ToLower() != "true" ) | ||
454 | { | ||
455 | ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name); | ||
456 | } | ||
457 | ss.WriteLine(); | ||
458 | ss.WriteLine(" <target name=\"{0}\" description=\"\">", conf.Name); | ||
459 | ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name); | ||
460 | ss.WriteLine(" <property name=\"build.debug\" value=\"{0}\" />", conf.Options["DebugInformation"].ToString().ToLower()); | ||
461 | ss.WriteLine(" </target>"); | ||
462 | ss.WriteLine(); | ||
463 | } | ||
464 | |||
465 | ss.WriteLine(" <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">"); | ||
466 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />"); | ||
467 | ss.WriteLine(" </target>"); | ||
468 | ss.WriteLine(); | ||
469 | |||
470 | ss.WriteLine(" <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">"); | ||
471 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />"); | ||
472 | ss.WriteLine(" </target>"); | ||
473 | ss.WriteLine(); | ||
474 | |||
475 | ss.WriteLine(" <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">"); | ||
476 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />"); | ||
477 | ss.WriteLine(" </target>"); | ||
478 | ss.WriteLine(); | ||
479 | |||
480 | ss.WriteLine(" <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">"); | ||
481 | ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />"); | ||
482 | ss.WriteLine(" </target>"); | ||
483 | ss.WriteLine(); | ||
484 | |||
485 | ss.WriteLine(" <target name=\"init\" description=\"\">"); | ||
486 | ss.WriteLine(" <call target=\"${project.config}\" />"); | ||
487 | ss.WriteLine(" <sysinfo />"); | ||
488 | ss.WriteLine(" <echo message=\"Platform ${sys.os.platform}\" />"); | ||
489 | ss.WriteLine(" <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />"); | ||
490 | ss.WriteLine(" </target>"); | ||
491 | ss.WriteLine(); | ||
492 | |||
493 | ss.WriteLine(" <target name=\"clean\" description=\"\">"); | ||
494 | ss.WriteLine(" <echo message=\"Deleting all builds from all configurations\" />"); | ||
495 | //ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />"); | ||
496 | ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />"); | ||
497 | ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />"); | ||
498 | foreach(ProjectNode project in solution.Projects) | ||
499 | { | ||
500 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
501 | ss.Write(" <nant buildfile=\"{0}\"", | ||
502 | Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"),'/')); | ||
503 | ss.WriteLine(" target=\"clean\" />"); | ||
504 | } | ||
505 | ss.WriteLine(" </target>"); | ||
506 | ss.WriteLine(); | ||
507 | |||
508 | ss.WriteLine(" <target name=\"build\" depends=\"init\" description=\"\">"); | ||
509 | |||
510 | foreach(ProjectNode project in solution.ProjectsTableOrder) | ||
511 | { | ||
512 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
513 | ss.Write(" <nant buildfile=\"{0}\"", | ||
514 | Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"),'/')); | ||
515 | ss.WriteLine(" target=\"build\" />"); | ||
516 | } | ||
517 | ss.WriteLine(" </target>"); | ||
518 | ss.WriteLine(); | ||
519 | |||
520 | ss.WriteLine(" <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />"); | ||
521 | ss.WriteLine(); | ||
522 | ss.WriteLine(" <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />"); | ||
523 | ss.WriteLine(); | ||
524 | //ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />"); | ||
525 | ss.WriteLine(" <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />"); | ||
526 | ss.WriteLine(); | ||
527 | |||
528 | ss.WriteLine(" <target name=\"doc\" depends=\"build-release\">"); | ||
529 | ss.WriteLine(" <echo message=\"Generating all documentation from all builds\" />"); | ||
530 | foreach (ProjectNode project in solution.Projects) | ||
531 | { | ||
532 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
533 | ss.Write(" <nant buildfile=\"{0}\"", | ||
534 | Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"), '/')); | ||
535 | ss.WriteLine(" target=\"doc\" />"); | ||
536 | } | ||
537 | ss.WriteLine(" </target>"); | ||
538 | ss.WriteLine(); | ||
539 | ss.WriteLine("</project>"); | ||
540 | } | ||
541 | |||
542 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
543 | } | ||
544 | |||
545 | private void CleanProject(ProjectNode project) | ||
546 | { | ||
547 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
548 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"); | ||
549 | Helper.DeleteIfExists(projectFile); | ||
550 | } | ||
551 | |||
552 | private void CleanSolution(SolutionNode solution) | ||
553 | { | ||
554 | m_Kernel.Log.Write("Cleaning NAnt build files for", solution.Name); | ||
555 | |||
556 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build"); | ||
557 | Helper.DeleteIfExists(slnFile); | ||
558 | |||
559 | foreach(ProjectNode project in solution.Projects) | ||
560 | { | ||
561 | CleanProject(project); | ||
562 | } | ||
563 | |||
564 | m_Kernel.Log.Write(""); | ||
565 | } | ||
566 | |||
567 | #endregion | ||
568 | |||
569 | #region ITarget Members | ||
570 | |||
571 | /// <summary> | ||
572 | /// Writes the specified kern. | ||
573 | /// </summary> | ||
574 | /// <param name="kern">The kern.</param> | ||
575 | public void Write(Kernel kern) | ||
576 | { | ||
577 | if( kern == null ) | ||
578 | { | ||
579 | throw new ArgumentNullException("kern"); | ||
580 | } | ||
581 | m_Kernel = kern; | ||
582 | foreach(SolutionNode solution in kern.Solutions) | ||
583 | { | ||
584 | WriteCombine(solution); | ||
585 | } | ||
586 | m_Kernel = null; | ||
587 | } | ||
588 | |||
589 | /// <summary> | ||
590 | /// Cleans the specified kern. | ||
591 | /// </summary> | ||
592 | /// <param name="kern">The kern.</param> | ||
593 | public virtual void Clean(Kernel kern) | ||
594 | { | ||
595 | if( kern == null ) | ||
596 | { | ||
597 | throw new ArgumentNullException("kern"); | ||
598 | } | ||
599 | m_Kernel = kern; | ||
600 | foreach(SolutionNode sol in kern.Solutions) | ||
601 | { | ||
602 | CleanSolution(sol); | ||
603 | } | ||
604 | m_Kernel = null; | ||
605 | } | ||
606 | |||
607 | /// <summary> | ||
608 | /// Gets the name. | ||
609 | /// </summary> | ||
610 | /// <value>The name.</value> | ||
611 | public string Name | ||
612 | { | ||
613 | get | ||
614 | { | ||
615 | return "nant"; | ||
616 | } | ||
617 | } | ||
618 | |||
619 | #endregion | ||
620 | } | ||
621 | } | ||
diff --git a/Prebuild/src/Core/Targets/SharpDevelop2Target.cs b/Prebuild/src/Core/Targets/SharpDevelop2Target.cs new file mode 100644 index 0000000..bc84b96 --- /dev/null +++ b/Prebuild/src/Core/Targets/SharpDevelop2Target.cs | |||
@@ -0,0 +1,90 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-27 16:49:58 -0800 (Fri, 27 Jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | |||
37 | using Prebuild.Core.Attributes; | ||
38 | |||
39 | namespace Prebuild.Core.Targets | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// | ||
43 | /// </summary> | ||
44 | [Target("sharpdev2")] | ||
45 | public class SharpDevelop2Target : VS2005Target | ||
46 | { | ||
47 | #region Private Methods | ||
48 | private void SetSharpDevelop2() | ||
49 | { | ||
50 | this.VersionName = "SharpDevelop2"; | ||
51 | } | ||
52 | #endregion | ||
53 | |||
54 | #region Public Methods | ||
55 | |||
56 | /// <summary> | ||
57 | /// Writes the specified kern. | ||
58 | /// </summary> | ||
59 | /// <param name="kern">The kern.</param> | ||
60 | public override void Write(Kernel kern) | ||
61 | { | ||
62 | SetSharpDevelop2(); | ||
63 | base.Write(kern); | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// Cleans the specified kern. | ||
68 | /// </summary> | ||
69 | /// <param name="kern">The kern.</param> | ||
70 | public override void Clean(Kernel kern) | ||
71 | { | ||
72 | SetSharpDevelop2(); | ||
73 | base.Clean(kern); | ||
74 | } | ||
75 | |||
76 | /// <summary> | ||
77 | /// Gets the name. | ||
78 | /// </summary> | ||
79 | /// <value>The name.</value> | ||
80 | public override string Name | ||
81 | { | ||
82 | get | ||
83 | { | ||
84 | return "sharpdev2"; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | #endregion | ||
89 | } | ||
90 | } | ||
diff --git a/Prebuild/src/Core/Targets/SharpDevelopTarget.cs b/Prebuild/src/Core/Targets/SharpDevelopTarget.cs new file mode 100644 index 0000000..c725730 --- /dev/null +++ b/Prebuild/src/Core/Targets/SharpDevelopTarget.cs | |||
@@ -0,0 +1,437 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2007-02-13 21:58:03 +0100 (ti, 13 feb 2007) $ | ||
31 | * $Revision: 205 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.IO; | ||
39 | using System.Text.RegularExpressions; | ||
40 | using System.Reflection; | ||
41 | |||
42 | using Prebuild.Core.Attributes; | ||
43 | using Prebuild.Core.Interfaces; | ||
44 | using Prebuild.Core.Nodes; | ||
45 | using Prebuild.Core.Utilities; | ||
46 | |||
47 | namespace Prebuild.Core.Targets | ||
48 | { | ||
49 | /// <summary> | ||
50 | /// | ||
51 | /// </summary> | ||
52 | [Target("sharpdev")] | ||
53 | public class SharpDevelopTarget : ITarget | ||
54 | { | ||
55 | #region Fields | ||
56 | |||
57 | private Kernel m_Kernel; | ||
58 | |||
59 | #endregion | ||
60 | |||
61 | #region Private Methods | ||
62 | |||
63 | private static string PrependPath(string path) | ||
64 | { | ||
65 | string tmpPath = Helper.NormalizePath(path, '/'); | ||
66 | Regex regex = new Regex(@"(\w):/(\w+)"); | ||
67 | Match match = regex.Match(tmpPath); | ||
68 | if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/') | ||
69 | { | ||
70 | tmpPath = Helper.NormalizePath(tmpPath); | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | tmpPath = Helper.NormalizePath("./" + tmpPath); | ||
75 | } | ||
76 | |||
77 | return tmpPath; | ||
78 | } | ||
79 | |||
80 | private static string BuildReference(SolutionNode solution, ReferenceNode refr) | ||
81 | { | ||
82 | string ret = "<Reference type=\""; | ||
83 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
84 | { | ||
85 | ret += "Project\" refto=\"" + refr.Name; | ||
86 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | ProjectNode project = (ProjectNode)refr.Parent; | ||
91 | string fileRef = FindFileReference(refr.Name, project); | ||
92 | |||
93 | if(refr.Path != null || fileRef != null) | ||
94 | { | ||
95 | ret += "Assembly\" refto=\""; | ||
96 | |||
97 | string finalPath = (refr.Path != null) ? Helper.MakeFilePath(refr.Path, refr.Name, "dll") : fileRef; | ||
98 | |||
99 | ret += finalPath; | ||
100 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
101 | return ret; | ||
102 | } | ||
103 | |||
104 | ret += "Gac\" refto=\""; | ||
105 | try | ||
106 | { | ||
107 | //Assembly assem = Assembly.Load(refr.Name); | ||
108 | ret += refr.Name;// assem.FullName; | ||
109 | } | ||
110 | catch (System.NullReferenceException e) | ||
111 | { | ||
112 | e.ToString(); | ||
113 | ret += refr.Name; | ||
114 | } | ||
115 | ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />"; | ||
116 | } | ||
117 | |||
118 | return ret; | ||
119 | } | ||
120 | |||
121 | private static string FindFileReference(string refName, ProjectNode project) | ||
122 | { | ||
123 | foreach(ReferencePathNode refPath in project.ReferencePaths) | ||
124 | { | ||
125 | string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll"); | ||
126 | |||
127 | if(File.Exists(fullPath)) | ||
128 | { | ||
129 | return fullPath; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | return null; | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// Gets the XML doc file. | ||
138 | /// </summary> | ||
139 | /// <param name="project">The project.</param> | ||
140 | /// <param name="conf">The conf.</param> | ||
141 | /// <returns></returns> | ||
142 | public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf) | ||
143 | { | ||
144 | if( conf == null ) | ||
145 | { | ||
146 | throw new ArgumentNullException("conf"); | ||
147 | } | ||
148 | if( project == null ) | ||
149 | { | ||
150 | throw new ArgumentNullException("project"); | ||
151 | } | ||
152 | string docFile = (string)conf.Options["XmlDocFile"]; | ||
153 | if(docFile != null && docFile.Length == 0)//default to assembly name if not specified | ||
154 | { | ||
155 | return "False"; | ||
156 | } | ||
157 | return "True"; | ||
158 | } | ||
159 | |||
160 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
161 | { | ||
162 | string csComp = "Csc"; | ||
163 | string netRuntime = "MsNet"; | ||
164 | if(project.Runtime == ClrRuntime.Mono) | ||
165 | { | ||
166 | csComp = "Mcs"; | ||
167 | netRuntime = "Mono"; | ||
168 | } | ||
169 | |||
170 | string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx"); | ||
171 | StreamWriter ss = new StreamWriter(projFile); | ||
172 | |||
173 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
174 | Helper.SetCurrentDir(Path.GetDirectoryName(projFile)); | ||
175 | |||
176 | using(ss) | ||
177 | { | ||
178 | ss.WriteLine( | ||
179 | "<Project name=\"{0}\" standardNamespace=\"{1}\" description=\"\" newfilesearch=\"None\" enableviewstate=\"True\" version=\"1.1\" projecttype=\"C#\">", | ||
180 | project.Name, | ||
181 | project.RootNamespace | ||
182 | ); | ||
183 | |||
184 | ss.WriteLine(" <Contents>"); | ||
185 | foreach(string file in project.Files) | ||
186 | { | ||
187 | string buildAction = "Compile"; | ||
188 | switch(project.Files.GetBuildAction(file)) | ||
189 | { | ||
190 | case BuildAction.None: | ||
191 | buildAction = "Nothing"; | ||
192 | break; | ||
193 | |||
194 | case BuildAction.Content: | ||
195 | buildAction = "Exclude"; | ||
196 | break; | ||
197 | |||
198 | case BuildAction.EmbeddedResource: | ||
199 | buildAction = "EmbedAsResource"; | ||
200 | break; | ||
201 | |||
202 | default: | ||
203 | buildAction = "Compile"; | ||
204 | break; | ||
205 | } | ||
206 | |||
207 | // Sort of a hack, we try and resolve the path and make it relative, if we can. | ||
208 | string filePath = PrependPath(file); | ||
209 | ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\" dependson=\"\" data=\"\" />", filePath, buildAction); | ||
210 | } | ||
211 | ss.WriteLine(" </Contents>"); | ||
212 | |||
213 | ss.WriteLine(" <References>"); | ||
214 | foreach(ReferenceNode refr in project.References) | ||
215 | { | ||
216 | ss.WriteLine(" {0}", BuildReference(solution, refr)); | ||
217 | } | ||
218 | ss.WriteLine(" </References>"); | ||
219 | |||
220 | ss.Write(" <DeploymentInformation"); | ||
221 | ss.Write(" target=\"\""); | ||
222 | ss.Write(" script=\"\""); | ||
223 | ss.Write(" strategy=\"File\""); | ||
224 | ss.WriteLine(" />"); | ||
225 | |||
226 | int count = 0; | ||
227 | |||
228 | ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig); | ||
229 | |||
230 | foreach(ConfigurationNode conf in project.Configurations) | ||
231 | { | ||
232 | ss.Write(" <Configuration"); | ||
233 | ss.Write(" runwithwarnings=\"True\""); | ||
234 | ss.Write(" name=\"{0}\"", conf.Name); | ||
235 | ss.WriteLine(">"); | ||
236 | ss.Write(" <CodeGeneration"); | ||
237 | ss.Write(" runtime=\"{0}\"", netRuntime); | ||
238 | ss.Write(" compiler=\"{0}\"", csComp); | ||
239 | ss.Write(" compilerversion=\"\""); | ||
240 | ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]); | ||
241 | ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]); | ||
242 | ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]); | ||
243 | ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]); | ||
244 | ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]); | ||
245 | ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]); | ||
246 | ss.Write(" mainclass=\"{0}\"", project.StartupObject); | ||
247 | ss.Write(" target=\"{0}\"", project.Type); | ||
248 | ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]); | ||
249 | ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf)); | ||
250 | ss.Write(" win32Icon=\"{0}\"", Helper.NormalizePath(".\\" + project.AppIcon)); | ||
251 | ss.Write(" noconfig=\"{0}\"", "False"); | ||
252 | ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]); | ||
253 | ss.WriteLine(" />"); | ||
254 | |||
255 | ss.Write(" <Execution"); | ||
256 | ss.Write(" commandlineparameters=\"\""); | ||
257 | ss.Write(" consolepause=\"True\""); | ||
258 | ss.WriteLine(" />"); | ||
259 | |||
260 | ss.Write(" <Output"); | ||
261 | ss.Write(" directory=\".\\{0}\"", Helper.NormalizePath(conf.Options["OutputPath"].ToString())); | ||
262 | ss.Write(" assembly=\"{0}\"", project.AssemblyName); | ||
263 | ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]); | ||
264 | if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0) | ||
265 | { | ||
266 | ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString())); | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]); | ||
271 | } | ||
272 | if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0) | ||
273 | { | ||
274 | ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString())); | ||
275 | } | ||
276 | else | ||
277 | { | ||
278 | ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]); | ||
279 | } | ||
280 | ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
281 | ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]); | ||
282 | ss.WriteLine(" />"); | ||
283 | ss.WriteLine(" </Configuration>"); | ||
284 | |||
285 | count++; | ||
286 | } | ||
287 | ss.WriteLine(" </Configurations>"); | ||
288 | ss.WriteLine("</Project>"); | ||
289 | } | ||
290 | |||
291 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
292 | } | ||
293 | |||
294 | private void WriteCombine(SolutionNode solution) | ||
295 | { | ||
296 | m_Kernel.Log.Write("Creating SharpDevelop combine and project files"); | ||
297 | foreach(ProjectNode project in solution.Projects) | ||
298 | { | ||
299 | if(m_Kernel.AllowProject(project.FilterGroups)) | ||
300 | { | ||
301 | m_Kernel.Log.Write("...Creating project: {0}", project.Name); | ||
302 | WriteProject(solution, project); | ||
303 | } | ||
304 | } | ||
305 | |||
306 | m_Kernel.Log.Write(""); | ||
307 | string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx"); | ||
308 | StreamWriter ss = new StreamWriter(combFile); | ||
309 | |||
310 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
311 | Helper.SetCurrentDir(Path.GetDirectoryName(combFile)); | ||
312 | |||
313 | using(ss) | ||
314 | { | ||
315 | ss.WriteLine("<Combine fileversion=\"1.0\" name=\"{0}\" description=\"\">", solution.Name); | ||
316 | |||
317 | int count = 0; | ||
318 | foreach(ProjectNode project in solution.Projects) | ||
319 | { | ||
320 | if(count == 0) | ||
321 | ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name); | ||
322 | |||
323 | ss.WriteLine(" <Execute entry=\"{0}\" type=\"None\" />", project.Name); | ||
324 | count++; | ||
325 | } | ||
326 | ss.WriteLine(" </StartMode>"); | ||
327 | |||
328 | ss.WriteLine(" <Entries>"); | ||
329 | foreach(ProjectNode project in solution.Projects) | ||
330 | { | ||
331 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
332 | ss.WriteLine(" <Entry filename=\"{0}\" />", | ||
333 | Helper.MakeFilePath(path, project.Name, "prjx")); | ||
334 | } | ||
335 | ss.WriteLine(" </Entries>"); | ||
336 | |||
337 | count = 0; | ||
338 | foreach(ConfigurationNode conf in solution.Configurations) | ||
339 | { | ||
340 | if(count == 0) | ||
341 | { | ||
342 | ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name); | ||
343 | } | ||
344 | |||
345 | ss.WriteLine(" <Configuration name=\"{0}\">", conf.Name); | ||
346 | foreach(ProjectNode project in solution.Projects) | ||
347 | { | ||
348 | ss.WriteLine(" <Entry name=\"{0}\" configurationname=\"{1}\" build=\"True\" />", project.Name, conf.Name); | ||
349 | } | ||
350 | ss.WriteLine(" </Configuration>"); | ||
351 | |||
352 | count++; | ||
353 | } | ||
354 | ss.WriteLine(" </Configurations>"); | ||
355 | ss.WriteLine("</Combine>"); | ||
356 | } | ||
357 | |||
358 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
359 | } | ||
360 | |||
361 | private void CleanProject(ProjectNode project) | ||
362 | { | ||
363 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
364 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx"); | ||
365 | Helper.DeleteIfExists(projectFile); | ||
366 | } | ||
367 | |||
368 | private void CleanSolution(SolutionNode solution) | ||
369 | { | ||
370 | m_Kernel.Log.Write("Cleaning SharpDevelop combine and project files for", solution.Name); | ||
371 | |||
372 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx"); | ||
373 | Helper.DeleteIfExists(slnFile); | ||
374 | |||
375 | foreach(ProjectNode project in solution.Projects) | ||
376 | { | ||
377 | CleanProject(project); | ||
378 | } | ||
379 | |||
380 | m_Kernel.Log.Write(""); | ||
381 | } | ||
382 | |||
383 | #endregion | ||
384 | |||
385 | #region ITarget Members | ||
386 | |||
387 | /// <summary> | ||
388 | /// Writes the specified kern. | ||
389 | /// </summary> | ||
390 | /// <param name="kern">The kern.</param> | ||
391 | public void Write(Kernel kern) | ||
392 | { | ||
393 | if( kern == null ) | ||
394 | { | ||
395 | throw new ArgumentNullException("kern"); | ||
396 | } | ||
397 | m_Kernel = kern; | ||
398 | foreach(SolutionNode solution in kern.Solutions) | ||
399 | { | ||
400 | WriteCombine(solution); | ||
401 | } | ||
402 | m_Kernel = null; | ||
403 | } | ||
404 | |||
405 | /// <summary> | ||
406 | /// Cleans the specified kern. | ||
407 | /// </summary> | ||
408 | /// <param name="kern">The kern.</param> | ||
409 | public virtual void Clean(Kernel kern) | ||
410 | { | ||
411 | if( kern == null ) | ||
412 | { | ||
413 | throw new ArgumentNullException("kern"); | ||
414 | } | ||
415 | m_Kernel = kern; | ||
416 | foreach(SolutionNode sol in kern.Solutions) | ||
417 | { | ||
418 | CleanSolution(sol); | ||
419 | } | ||
420 | m_Kernel = null; | ||
421 | } | ||
422 | |||
423 | /// <summary> | ||
424 | /// Gets the name. | ||
425 | /// </summary> | ||
426 | /// <value>The name.</value> | ||
427 | public string Name | ||
428 | { | ||
429 | get | ||
430 | { | ||
431 | return "sharpdev"; | ||
432 | } | ||
433 | } | ||
434 | |||
435 | #endregion | ||
436 | } | ||
437 | } | ||
diff --git a/Prebuild/src/Core/Targets/VS2002Target.cs b/Prebuild/src/Core/Targets/VS2002Target.cs new file mode 100644 index 0000000..66216dc --- /dev/null +++ b/Prebuild/src/Core/Targets/VS2002Target.cs | |||
@@ -0,0 +1,96 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | |||
37 | using Prebuild.Core.Attributes; | ||
38 | |||
39 | namespace Prebuild.Core.Targets | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// | ||
43 | /// </summary> | ||
44 | [Target("vs2002")] | ||
45 | public class VS2002Target : VS2003Target | ||
46 | { | ||
47 | #region Private Methods | ||
48 | |||
49 | private void SetVS2002() | ||
50 | { | ||
51 | this.SolutionVersion = "7.00"; | ||
52 | this.ProductVersion = "7.0.9254"; | ||
53 | this.SchemaVersion = "1.0"; | ||
54 | this.VersionName = "2002"; | ||
55 | this.Version = VSVersion.VS70; | ||
56 | } | ||
57 | |||
58 | #endregion | ||
59 | |||
60 | #region Public Methods | ||
61 | |||
62 | /// <summary> | ||
63 | /// Writes the specified kern. | ||
64 | /// </summary> | ||
65 | /// <param name="kern">The kern.</param> | ||
66 | public override void Write(Kernel kern) | ||
67 | { | ||
68 | SetVS2002(); | ||
69 | base.Write(kern); | ||
70 | } | ||
71 | |||
72 | /// <summary> | ||
73 | /// Cleans the specified kern. | ||
74 | /// </summary> | ||
75 | /// <param name="kern">The kern.</param> | ||
76 | public override void Clean(Kernel kern) | ||
77 | { | ||
78 | SetVS2002(); | ||
79 | base.Clean(kern); | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// Gets the name. | ||
84 | /// </summary> | ||
85 | /// <value>The name.</value> | ||
86 | public override string Name | ||
87 | { | ||
88 | get | ||
89 | { | ||
90 | return "vs2002"; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | #endregion | ||
95 | } | ||
96 | } | ||
diff --git a/Prebuild/src/Core/Targets/VS2003Target.cs b/Prebuild/src/Core/Targets/VS2003Target.cs new file mode 100644 index 0000000..b3236a8 --- /dev/null +++ b/Prebuild/src/Core/Targets/VS2003Target.cs | |||
@@ -0,0 +1,633 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-09-29 21:11:40 +0200 (fr, 29 sep 2006) $ | ||
31 | * $Revision: 177 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.IO; | ||
39 | |||
40 | using Prebuild.Core.Attributes; | ||
41 | using Prebuild.Core.Interfaces; | ||
42 | using Prebuild.Core.Nodes; | ||
43 | using Prebuild.Core.Utilities; | ||
44 | |||
45 | namespace Prebuild.Core.Targets | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// | ||
49 | /// </summary> | ||
50 | public enum VSVersion | ||
51 | { | ||
52 | /// <summary> | ||
53 | /// | ||
54 | /// </summary> | ||
55 | VS70, | ||
56 | /// <summary> | ||
57 | /// | ||
58 | /// </summary> | ||
59 | VS71, | ||
60 | /// <summary> | ||
61 | /// | ||
62 | /// </summary> | ||
63 | VS80 | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// | ||
68 | /// </summary> | ||
69 | [Target("vs2003")] | ||
70 | public class VS2003Target : ITarget | ||
71 | { | ||
72 | |||
73 | #region Fields | ||
74 | |||
75 | string solutionVersion = "8.00"; | ||
76 | string productVersion = "7.10.3077"; | ||
77 | string schemaVersion = "2.0"; | ||
78 | string versionName = "2003"; | ||
79 | VSVersion version = VSVersion.VS71; | ||
80 | |||
81 | Hashtable m_Tools; | ||
82 | Kernel m_Kernel; | ||
83 | |||
84 | /// <summary> | ||
85 | /// Gets or sets the solution version. | ||
86 | /// </summary> | ||
87 | /// <value>The solution version.</value> | ||
88 | protected string SolutionVersion | ||
89 | { | ||
90 | get | ||
91 | { | ||
92 | return this.solutionVersion; | ||
93 | } | ||
94 | set | ||
95 | { | ||
96 | this.solutionVersion = value; | ||
97 | } | ||
98 | } | ||
99 | /// <summary> | ||
100 | /// Gets or sets the product version. | ||
101 | /// </summary> | ||
102 | /// <value>The product version.</value> | ||
103 | protected string ProductVersion | ||
104 | { | ||
105 | get | ||
106 | { | ||
107 | return this.productVersion; | ||
108 | } | ||
109 | set | ||
110 | { | ||
111 | this.productVersion = value; | ||
112 | } | ||
113 | } | ||
114 | /// <summary> | ||
115 | /// Gets or sets the schema version. | ||
116 | /// </summary> | ||
117 | /// <value>The schema version.</value> | ||
118 | protected string SchemaVersion | ||
119 | { | ||
120 | get | ||
121 | { | ||
122 | return this.schemaVersion; | ||
123 | } | ||
124 | set | ||
125 | { | ||
126 | this.schemaVersion = value; | ||
127 | } | ||
128 | } | ||
129 | /// <summary> | ||
130 | /// Gets or sets the name of the version. | ||
131 | /// </summary> | ||
132 | /// <value>The name of the version.</value> | ||
133 | protected string VersionName | ||
134 | { | ||
135 | get | ||
136 | { | ||
137 | return this.versionName; | ||
138 | } | ||
139 | set | ||
140 | { | ||
141 | this.versionName = value; | ||
142 | } | ||
143 | } | ||
144 | /// <summary> | ||
145 | /// Gets or sets the version. | ||
146 | /// </summary> | ||
147 | /// <value>The version.</value> | ||
148 | protected VSVersion Version | ||
149 | { | ||
150 | get | ||
151 | { | ||
152 | return this.version; | ||
153 | } | ||
154 | set | ||
155 | { | ||
156 | this.version = value; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | #endregion | ||
161 | |||
162 | #region Constructors | ||
163 | |||
164 | /// <summary> | ||
165 | /// Initializes a new instance of the <see cref="VS2003Target"/> class. | ||
166 | /// </summary> | ||
167 | public VS2003Target() | ||
168 | { | ||
169 | m_Tools = new Hashtable(); | ||
170 | |||
171 | m_Tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP"); | ||
172 | m_Tools["VB.NET"] = new ToolInfo("VB.NET", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic"); | ||
173 | } | ||
174 | |||
175 | #endregion | ||
176 | |||
177 | #region Private Methods | ||
178 | |||
179 | private string MakeRefPath(ProjectNode project) | ||
180 | { | ||
181 | string ret = ""; | ||
182 | foreach(ReferencePathNode node in project.ReferencePaths) | ||
183 | { | ||
184 | try | ||
185 | { | ||
186 | string fullPath = Helper.ResolvePath(node.Path); | ||
187 | if(ret.Length < 1) | ||
188 | { | ||
189 | ret = fullPath; | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | ret += ";" + fullPath; | ||
194 | } | ||
195 | } | ||
196 | catch(ArgumentException) | ||
197 | { | ||
198 | m_Kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | return ret; | ||
203 | } | ||
204 | |||
205 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
206 | { | ||
207 | if(!m_Tools.ContainsKey(project.Language)) | ||
208 | { | ||
209 | throw new UnknownLanguageException("Unknown .NET language: " + project.Language); | ||
210 | } | ||
211 | |||
212 | ToolInfo toolInfo = (ToolInfo)m_Tools[project.Language]; | ||
213 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension); | ||
214 | StreamWriter ps = new StreamWriter(projectFile); | ||
215 | |||
216 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
217 | Helper.SetCurrentDir(Path.GetDirectoryName(projectFile)); | ||
218 | |||
219 | IEnumerator enumerator; | ||
220 | //ConfigurationNode scripts; | ||
221 | |||
222 | using(ps) | ||
223 | { | ||
224 | ps.WriteLine("<VisualStudioProject>"); | ||
225 | ps.WriteLine(" <{0}", toolInfo.XmlTag); | ||
226 | ps.WriteLine("\t\t\t\tProjectType = \"Local\""); | ||
227 | ps.WriteLine("\t\t\t\tProductVersion = \"{0}\"", this.ProductVersion); | ||
228 | ps.WriteLine("\t\t\t\tSchemaVersion = \"{0}\"", this.SchemaVersion); | ||
229 | ps.WriteLine("\t\t\t\tProjectGuid = \"{{{0}}}\"", project.Guid.ToString().ToUpper()); | ||
230 | ps.WriteLine("\t\t>"); | ||
231 | |||
232 | ps.WriteLine("\t\t\t\t<Build>"); | ||
233 | ps.WriteLine(" <Settings"); | ||
234 | ps.WriteLine("\t\t\t\t ApplicationIcon = \"{0}\"",project.AppIcon); | ||
235 | ps.WriteLine("\t\t\t\t AssemblyKeyContainerName = \"\""); | ||
236 | ps.WriteLine("\t\t\t\t AssemblyName = \"{0}\"", project.AssemblyName); | ||
237 | ps.WriteLine("\t\t\t\t AssemblyOriginatorKeyFile = \"\""); | ||
238 | ps.WriteLine("\t\t\t\t DefaultClientScript = \"JScript\""); | ||
239 | ps.WriteLine("\t\t\t\t DefaultHTMLPageLayout = \"Grid\""); | ||
240 | ps.WriteLine("\t\t\t\t DefaultTargetSchema = \"IE50\""); | ||
241 | ps.WriteLine("\t\t\t\t DelaySign = \"false\""); | ||
242 | |||
243 | if(this.Version == VSVersion.VS70) | ||
244 | { | ||
245 | ps.WriteLine("\t\t\t\t NoStandardLibraries = \"false\""); | ||
246 | } | ||
247 | |||
248 | ps.WriteLine("\t\t\t\t OutputType = \"{0}\"", project.Type.ToString()); | ||
249 | |||
250 | enumerator = project.Configurations.GetEnumerator(); | ||
251 | enumerator.Reset(); | ||
252 | enumerator.MoveNext(); | ||
253 | foreach(ConfigurationNode conf in project.Configurations) | ||
254 | { | ||
255 | if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0) | ||
256 | { | ||
257 | ps.WriteLine("\t\t\t\t PreBuildEvent = \"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString())); | ||
258 | } | ||
259 | else | ||
260 | { | ||
261 | ps.WriteLine("\t\t\t\t PreBuildEvent = \"{0}\"", conf.Options["PreBuildEvent"]); | ||
262 | } | ||
263 | if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0) | ||
264 | { | ||
265 | ps.WriteLine("\t\t\t\t PostBuildEvent = \"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString())); | ||
266 | } | ||
267 | else | ||
268 | { | ||
269 | ps.WriteLine("\t\t\t\t PostBuildEvent = \"{0}\"", conf.Options["PostBuildEvent"]); | ||
270 | } | ||
271 | if (conf.Options["RunPostBuildEvent"] == null) | ||
272 | { | ||
273 | ps.WriteLine("\t\t\t\t RunPostBuildEvent = \"{0}\"", "OnBuildSuccess"); | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | ps.WriteLine("\t\t\t\t RunPostBuildEvent = \"{0}\"", conf.Options["RunPostBuildEvent"]); | ||
278 | } | ||
279 | break; | ||
280 | } | ||
281 | |||
282 | ps.WriteLine("\t\t\t\t RootNamespace = \"{0}\"", project.RootNamespace); | ||
283 | ps.WriteLine("\t\t\t\t StartupObject = \"{0}\"", project.StartupObject); | ||
284 | ps.WriteLine("\t\t >"); | ||
285 | |||
286 | foreach(ConfigurationNode conf in project.Configurations) | ||
287 | { | ||
288 | ps.WriteLine("\t\t\t\t <Config"); | ||
289 | ps.WriteLine("\t\t\t\t Name = \"{0}\"", conf.Name); | ||
290 | ps.WriteLine("\t\t\t\t AllowUnsafeBlocks = \"{0}\"", conf.Options["AllowUnsafe"].ToString().ToLower()); | ||
291 | ps.WriteLine("\t\t\t\t BaseAddress = \"{0}\"", conf.Options["BaseAddress"]); | ||
292 | ps.WriteLine("\t\t\t\t CheckForOverflowUnderflow = \"{0}\"", conf.Options["CheckUnderflowOverflow"].ToString().ToLower()); | ||
293 | ps.WriteLine("\t\t\t\t ConfigurationOverrideFile = \"\""); | ||
294 | ps.WriteLine("\t\t\t\t DefineConstants = \"{0}\"", conf.Options["CompilerDefines"]); | ||
295 | ps.WriteLine("\t\t\t\t DocumentationFile = \"{0}\"", GetXmlDocFile(project, conf));//default to the assembly name | ||
296 | ps.WriteLine("\t\t\t\t DebugSymbols = \"{0}\"", conf.Options["DebugInformation"].ToString().ToLower()); | ||
297 | ps.WriteLine("\t\t\t\t FileAlignment = \"{0}\"", conf.Options["FileAlignment"]); | ||
298 | ps.WriteLine("\t\t\t\t IncrementalBuild = \"{0}\"", conf.Options["IncrementalBuild"].ToString().ToLower()); | ||
299 | |||
300 | if(this.Version == VSVersion.VS71) | ||
301 | { | ||
302 | ps.WriteLine("\t\t\t\t NoStdLib = \"{0}\"", conf.Options["NoStdLib"].ToString().ToLower()); | ||
303 | ps.WriteLine("\t\t\t\t NoWarn = \"{0}\"", conf.Options["SuppressWarnings"].ToString().ToLower()); | ||
304 | } | ||
305 | |||
306 | ps.WriteLine("\t\t\t\t Optimize = \"{0}\"", conf.Options["OptimizeCode"].ToString().ToLower()); | ||
307 | ps.WriteLine(" OutputPath = \"{0}\"", | ||
308 | Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString()))); | ||
309 | ps.WriteLine(" RegisterForComInterop = \"{0}\"", conf.Options["RegisterComInterop"].ToString().ToLower()); | ||
310 | ps.WriteLine(" RemoveIntegerChecks = \"{0}\"", conf.Options["RemoveIntegerChecks"].ToString().ToLower()); | ||
311 | ps.WriteLine(" TreatWarningsAsErrors = \"{0}\"", conf.Options["WarningsAsErrors"].ToString().ToLower()); | ||
312 | ps.WriteLine(" WarningLevel = \"{0}\"", conf.Options["WarningLevel"]); | ||
313 | ps.WriteLine(" />"); | ||
314 | } | ||
315 | |||
316 | ps.WriteLine(" </Settings>"); | ||
317 | |||
318 | ps.WriteLine(" <References>"); | ||
319 | foreach(ReferenceNode refr in project.References) | ||
320 | { | ||
321 | ps.WriteLine(" <Reference"); | ||
322 | ps.WriteLine(" Name = \"{0}\"", refr.Name); | ||
323 | ps.WriteLine(" AssemblyName = \"{0}\"", refr.Name); | ||
324 | |||
325 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
326 | { | ||
327 | ProjectNode refProject = (ProjectNode)solution.ProjectsTable[refr.Name]; | ||
328 | ps.WriteLine(" Project = \"{{{0}}}\"", refProject.Guid.ToString().ToUpper()); | ||
329 | ps.WriteLine(" Package = \"{0}\"", toolInfo.Guid.ToString().ToUpper()); | ||
330 | } | ||
331 | else | ||
332 | { | ||
333 | if(refr.Path != null) | ||
334 | { | ||
335 | ps.WriteLine(" HintPath = \"{0}\"", Helper.MakeFilePath(refr.Path, refr.Name, "dll")); | ||
336 | } | ||
337 | |||
338 | } | ||
339 | |||
340 | if(refr.LocalCopySpecified) | ||
341 | { | ||
342 | ps.WriteLine(" Private = \"{0}\"",refr.LocalCopy); | ||
343 | } | ||
344 | |||
345 | ps.WriteLine(" />"); | ||
346 | } | ||
347 | ps.WriteLine(" </References>"); | ||
348 | |||
349 | ps.WriteLine(" </Build>"); | ||
350 | ps.WriteLine(" <Files>"); | ||
351 | |||
352 | ps.WriteLine(" <Include>"); | ||
353 | |||
354 | foreach(string file in project.Files) | ||
355 | { | ||
356 | string fileName = file.Replace(".\\", ""); | ||
357 | ps.WriteLine(" <File"); | ||
358 | ps.WriteLine(" RelPath = \"{0}\"", fileName); | ||
359 | ps.WriteLine(" SubType = \"{0}\"", project.Files.GetSubType(file)); | ||
360 | ps.WriteLine(" BuildAction = \"{0}\"", project.Files.GetBuildAction(file)); | ||
361 | ps.WriteLine(" />"); | ||
362 | |||
363 | if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings) | ||
364 | { | ||
365 | ps.WriteLine(" <File"); | ||
366 | ps.WriteLine(" RelPath = \"{0}\"", fileName.Substring(0, fileName.LastIndexOf('.')) + ".resx"); | ||
367 | int slash = fileName.LastIndexOf('\\'); | ||
368 | if (slash == -1) | ||
369 | { | ||
370 | ps.WriteLine(" DependentUpon = \"{0}\"", fileName); | ||
371 | } | ||
372 | else | ||
373 | { | ||
374 | ps.WriteLine(" DependentUpon = \"{0}\"", fileName.Substring(slash + 1, fileName.Length - slash - 1)); | ||
375 | } | ||
376 | ps.WriteLine(" BuildAction = \"{0}\"", "EmbeddedResource"); | ||
377 | ps.WriteLine(" />"); | ||
378 | |||
379 | } | ||
380 | } | ||
381 | ps.WriteLine(" </Include>"); | ||
382 | |||
383 | ps.WriteLine(" </Files>"); | ||
384 | ps.WriteLine(" </{0}>", toolInfo.XmlTag); | ||
385 | ps.WriteLine("</VisualStudioProject>"); | ||
386 | } | ||
387 | |||
388 | ps = new StreamWriter(projectFile + ".user"); | ||
389 | using(ps) | ||
390 | { | ||
391 | ps.WriteLine("<VisualStudioProject>"); | ||
392 | ps.WriteLine(" <{0}>", toolInfo.XmlTag); | ||
393 | ps.WriteLine(" <Build>"); | ||
394 | |||
395 | ps.WriteLine(" <Settings ReferencePath=\"{0}\">", MakeRefPath(project)); | ||
396 | foreach(ConfigurationNode conf in project.Configurations) | ||
397 | { | ||
398 | ps.WriteLine(" <Config"); | ||
399 | ps.WriteLine(" Name = \"{0}\"", conf.Name); | ||
400 | ps.WriteLine(" />"); | ||
401 | } | ||
402 | ps.WriteLine(" </Settings>"); | ||
403 | |||
404 | ps.WriteLine(" </Build>"); | ||
405 | ps.WriteLine(" </{0}>", toolInfo.XmlTag); | ||
406 | ps.WriteLine("</VisualStudioProject>"); | ||
407 | } | ||
408 | |||
409 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
410 | } | ||
411 | |||
412 | /// <summary> | ||
413 | /// Gets the XML doc file. | ||
414 | /// </summary> | ||
415 | /// <param name="project">The project.</param> | ||
416 | /// <param name="conf">The conf.</param> | ||
417 | /// <returns></returns> | ||
418 | public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf) | ||
419 | { | ||
420 | if( conf == null ) | ||
421 | { | ||
422 | throw new ArgumentNullException("conf"); | ||
423 | } | ||
424 | if( project == null ) | ||
425 | { | ||
426 | throw new ArgumentNullException("project"); | ||
427 | } | ||
428 | // if(!(bool)conf.Options["GenerateXmlDocFile"]) //default to none, if the generate option is false | ||
429 | // { | ||
430 | // return string.Empty; | ||
431 | // } | ||
432 | |||
433 | //default to "AssemblyName.xml" | ||
434 | //string defaultValue = Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml"; | ||
435 | //return (string)conf.Options["XmlDocFile", defaultValue]; | ||
436 | |||
437 | //default to no XmlDocFile file | ||
438 | return (string)conf.Options["XmlDocFile", ""]; | ||
439 | } | ||
440 | |||
441 | private void WriteSolution(SolutionNode solution) | ||
442 | { | ||
443 | m_Kernel.Log.Write("Creating Visual Studio {0} solution and project files", this.VersionName); | ||
444 | |||
445 | foreach(ProjectNode project in solution.Projects) | ||
446 | { | ||
447 | if(m_Kernel.AllowProject(project.FilterGroups)) | ||
448 | { | ||
449 | m_Kernel.Log.Write("...Creating project: {0}", project.Name); | ||
450 | WriteProject(solution, project); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | m_Kernel.Log.Write(""); | ||
455 | string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln"); | ||
456 | StreamWriter ss = new StreamWriter(solutionFile); | ||
457 | |||
458 | m_Kernel.CurrentWorkingDirectory.Push(); | ||
459 | Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile)); | ||
460 | |||
461 | using(ss) | ||
462 | { | ||
463 | ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", this.SolutionVersion); | ||
464 | foreach(ProjectNode project in solution.Projects) | ||
465 | { | ||
466 | if(!m_Tools.ContainsKey(project.Language)) | ||
467 | { | ||
468 | throw new UnknownLanguageException("Unknown .NET language: " + project.Language); | ||
469 | } | ||
470 | |||
471 | ToolInfo toolInfo = (ToolInfo)m_Tools[project.Language]; | ||
472 | |||
473 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
474 | ss.WriteLine("Project(\"{0}\") = \"{1}\", \"{2}\", \"{{{3}}}\"", | ||
475 | toolInfo.Guid, project.Name, Helper.MakeFilePath(path, project.Name, | ||
476 | toolInfo.FileExtension), project.Guid.ToString().ToUpper()); | ||
477 | |||
478 | ss.WriteLine("\tProjectSection(ProjectDependencies) = postProject"); | ||
479 | ss.WriteLine("\tEndProjectSection"); | ||
480 | |||
481 | ss.WriteLine("EndProject"); | ||
482 | } | ||
483 | |||
484 | ss.WriteLine("Global"); | ||
485 | |||
486 | ss.WriteLine("\tGlobalSection(SolutionConfiguration) = preSolution"); | ||
487 | foreach(ConfigurationNode conf in solution.Configurations) | ||
488 | { | ||
489 | ss.WriteLine("\t\t{0} = {0}", conf.Name); | ||
490 | } | ||
491 | ss.WriteLine("\tEndGlobalSection"); | ||
492 | |||
493 | ss.WriteLine("\tGlobalSection(ProjectDependencies) = postSolution"); | ||
494 | foreach(ProjectNode project in solution.Projects) | ||
495 | { | ||
496 | for(int i = 0; i < project.References.Count; i++) | ||
497 | { | ||
498 | ReferenceNode refr = (ReferenceNode)project.References[i]; | ||
499 | if(solution.ProjectsTable.ContainsKey(refr.Name)) | ||
500 | { | ||
501 | ProjectNode refProject = (ProjectNode)solution.ProjectsTable[refr.Name]; | ||
502 | ss.WriteLine("\t\t({{{0}}}).{1} = ({{{2}}})", | ||
503 | project.Guid.ToString().ToUpper() | ||
504 | , i, | ||
505 | refProject.Guid.ToString().ToUpper() | ||
506 | ); | ||
507 | } | ||
508 | } | ||
509 | } | ||
510 | ss.WriteLine("\tEndGlobalSection"); | ||
511 | |||
512 | ss.WriteLine("\tGlobalSection(ProjectConfiguration) = postSolution"); | ||
513 | foreach(ProjectNode project in solution.Projects) | ||
514 | { | ||
515 | foreach(ConfigurationNode conf in solution.Configurations) | ||
516 | { | ||
517 | ss.WriteLine("\t\t{{{0}}}.{1}.ActiveCfg = {1}|.NET", | ||
518 | project.Guid.ToString().ToUpper(), | ||
519 | conf.Name); | ||
520 | |||
521 | ss.WriteLine("\t\t{{{0}}}.{1}.Build.0 = {1}|.NET", | ||
522 | project.Guid.ToString().ToUpper(), | ||
523 | conf.Name); | ||
524 | } | ||
525 | } | ||
526 | ss.WriteLine("\tEndGlobalSection"); | ||
527 | |||
528 | if(solution.Files != null) | ||
529 | { | ||
530 | ss.WriteLine("\tGlobalSection(SolutionItems) = postSolution"); | ||
531 | foreach(string file in solution.Files) | ||
532 | { | ||
533 | ss.WriteLine("\t\t{0} = {0}", file); | ||
534 | } | ||
535 | ss.WriteLine("\tEndGlobalSection"); | ||
536 | } | ||
537 | |||
538 | ss.WriteLine("\tGlobalSection(ExtensibilityGlobals) = postSolution"); | ||
539 | ss.WriteLine("\tEndGlobalSection"); | ||
540 | ss.WriteLine("\tGlobalSection(ExtensibilityAddIns) = postSolution"); | ||
541 | ss.WriteLine("\tEndGlobalSection"); | ||
542 | |||
543 | ss.WriteLine("EndGlobal"); | ||
544 | } | ||
545 | |||
546 | m_Kernel.CurrentWorkingDirectory.Pop(); | ||
547 | } | ||
548 | |||
549 | private void CleanProject(ProjectNode project) | ||
550 | { | ||
551 | m_Kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
552 | |||
553 | ToolInfo toolInfo = (ToolInfo)m_Tools[project.Language]; | ||
554 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension); | ||
555 | string userFile = projectFile + ".user"; | ||
556 | |||
557 | Helper.DeleteIfExists(projectFile); | ||
558 | Helper.DeleteIfExists(userFile); | ||
559 | } | ||
560 | |||
561 | private void CleanSolution(SolutionNode solution) | ||
562 | { | ||
563 | m_Kernel.Log.Write("Cleaning Visual Studio {0} solution and project files", this.VersionName, solution.Name); | ||
564 | |||
565 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln"); | ||
566 | string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo"); | ||
567 | |||
568 | Helper.DeleteIfExists(slnFile); | ||
569 | Helper.DeleteIfExists(suoFile); | ||
570 | |||
571 | foreach(ProjectNode project in solution.Projects) | ||
572 | { | ||
573 | CleanProject(project); | ||
574 | } | ||
575 | |||
576 | m_Kernel.Log.Write(""); | ||
577 | } | ||
578 | |||
579 | #endregion | ||
580 | |||
581 | #region ITarget Members | ||
582 | |||
583 | /// <summary> | ||
584 | /// Writes the specified kern. | ||
585 | /// </summary> | ||
586 | /// <param name="kern">The kern.</param> | ||
587 | public virtual void Write(Kernel kern) | ||
588 | { | ||
589 | if( kern == null ) | ||
590 | { | ||
591 | throw new ArgumentNullException("kern"); | ||
592 | } | ||
593 | m_Kernel = kern; | ||
594 | foreach(SolutionNode sol in m_Kernel.Solutions) | ||
595 | { | ||
596 | WriteSolution(sol); | ||
597 | } | ||
598 | m_Kernel = null; | ||
599 | } | ||
600 | |||
601 | /// <summary> | ||
602 | /// Cleans the specified kern. | ||
603 | /// </summary> | ||
604 | /// <param name="kern">The kern.</param> | ||
605 | public virtual void Clean(Kernel kern) | ||
606 | { | ||
607 | if( kern == null ) | ||
608 | { | ||
609 | throw new ArgumentNullException("kern"); | ||
610 | } | ||
611 | m_Kernel = kern; | ||
612 | foreach(SolutionNode sol in m_Kernel.Solutions) | ||
613 | { | ||
614 | CleanSolution(sol); | ||
615 | } | ||
616 | m_Kernel = null; | ||
617 | } | ||
618 | |||
619 | /// <summary> | ||
620 | /// Gets the name. | ||
621 | /// </summary> | ||
622 | /// <value>The name.</value> | ||
623 | public virtual string Name | ||
624 | { | ||
625 | get | ||
626 | { | ||
627 | return "vs2003"; | ||
628 | } | ||
629 | } | ||
630 | |||
631 | #endregion | ||
632 | } | ||
633 | } | ||
diff --git a/Prebuild/src/Core/Targets/VS2005Target.cs b/Prebuild/src/Core/Targets/VS2005Target.cs new file mode 100644 index 0000000..23b6116 --- /dev/null +++ b/Prebuild/src/Core/Targets/VS2005Target.cs | |||
@@ -0,0 +1,883 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: robloach $ | ||
30 | * $Date: 2007-02-27 19:52:34 +0100 (ti, 27 feb 2007) $ | ||
31 | * $Revision: 207 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.IO; | ||
39 | |||
40 | using Prebuild.Core.Attributes; | ||
41 | using Prebuild.Core.Interfaces; | ||
42 | using Prebuild.Core.Nodes; | ||
43 | using Prebuild.Core.Utilities; | ||
44 | |||
45 | namespace Prebuild.Core.Targets | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// | ||
49 | /// </summary> | ||
50 | public struct ToolInfo | ||
51 | { | ||
52 | string name; | ||
53 | string guid; | ||
54 | string fileExtension; | ||
55 | string xmlTag; | ||
56 | string importProject; | ||
57 | |||
58 | /// <summary> | ||
59 | /// Gets or sets the name. | ||
60 | /// </summary> | ||
61 | /// <value>The name.</value> | ||
62 | public string Name | ||
63 | { | ||
64 | get | ||
65 | { | ||
66 | return name; | ||
67 | } | ||
68 | set | ||
69 | { | ||
70 | name = value; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// Gets or sets the GUID. | ||
76 | /// </summary> | ||
77 | /// <value>The GUID.</value> | ||
78 | public string Guid | ||
79 | { | ||
80 | get | ||
81 | { | ||
82 | return guid; | ||
83 | } | ||
84 | set | ||
85 | { | ||
86 | guid = value; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// Gets or sets the file extension. | ||
92 | /// </summary> | ||
93 | /// <value>The file extension.</value> | ||
94 | public string FileExtension | ||
95 | { | ||
96 | get | ||
97 | { | ||
98 | return fileExtension; | ||
99 | } | ||
100 | set | ||
101 | { | ||
102 | fileExtension = value; | ||
103 | } | ||
104 | } | ||
105 | /// <summary> | ||
106 | /// Gets or sets the XML tag. | ||
107 | /// </summary> | ||
108 | /// <value>The XML tag.</value> | ||
109 | public string XmlTag | ||
110 | { | ||
111 | get | ||
112 | { | ||
113 | return xmlTag; | ||
114 | } | ||
115 | set | ||
116 | { | ||
117 | xmlTag = value; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | /// <summary> | ||
122 | /// Gets or sets the import project property. | ||
123 | /// </summary> | ||
124 | /// <value>The ImportProject tag.</value> | ||
125 | public string ImportProject | ||
126 | { | ||
127 | get | ||
128 | { | ||
129 | return importProject; | ||
130 | } | ||
131 | set | ||
132 | { | ||
133 | importProject = value; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// Initializes a new instance of the <see cref="ToolInfo"/> class. | ||
139 | /// </summary> | ||
140 | /// <param name="name">The name.</param> | ||
141 | /// <param name="guid">The GUID.</param> | ||
142 | /// <param name="fileExtension">The file extension.</param> | ||
143 | /// <param name="xml">The XML.</param> | ||
144 | /// <param name="importProject">The import project.</param> | ||
145 | public ToolInfo(string name, string guid, string fileExtension, string xml, string importProject) | ||
146 | { | ||
147 | this.name = name; | ||
148 | this.guid = guid; | ||
149 | this.fileExtension = fileExtension; | ||
150 | this.xmlTag = xml; | ||
151 | this.importProject = importProject; | ||
152 | } | ||
153 | |||
154 | /// <summary> | ||
155 | /// Initializes a new instance of the <see cref="ToolInfo"/> class. | ||
156 | /// </summary> | ||
157 | /// <param name="name">The name.</param> | ||
158 | /// <param name="guid">The GUID.</param> | ||
159 | /// <param name="fileExtension">The file extension.</param> | ||
160 | /// <param name="xml">The XML.</param> | ||
161 | public ToolInfo(string name, string guid, string fileExtension, string xml) | ||
162 | { | ||
163 | this.name = name; | ||
164 | this.guid = guid; | ||
165 | this.fileExtension = fileExtension; | ||
166 | this.xmlTag = xml; | ||
167 | this.importProject = "$(MSBuildBinPath)\\Microsoft." + xml + ".Targets"; | ||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// Equals operator | ||
172 | /// </summary> | ||
173 | /// <param name="obj">ToolInfo to compare</param> | ||
174 | /// <returns>true if toolInfos are equal</returns> | ||
175 | public override bool Equals(object obj) | ||
176 | { | ||
177 | if (obj == null) | ||
178 | { | ||
179 | throw new ArgumentNullException("obj"); | ||
180 | } | ||
181 | if (obj.GetType() != typeof(ToolInfo)) | ||
182 | return false; | ||
183 | |||
184 | ToolInfo c = (ToolInfo)obj; | ||
185 | return ((this.name == c.name) && (this.guid == c.guid) && (this.fileExtension == c.fileExtension) && (this.importProject == c.importProject)); | ||
186 | } | ||
187 | |||
188 | /// <summary> | ||
189 | /// Equals operator | ||
190 | /// </summary> | ||
191 | /// <param name="c1">ToolInfo to compare</param> | ||
192 | /// <param name="c2">ToolInfo to compare</param> | ||
193 | /// <returns>True if toolInfos are equal</returns> | ||
194 | public static bool operator ==(ToolInfo c1, ToolInfo c2) | ||
195 | { | ||
196 | return ((c1.name == c2.name) && (c1.guid == c2.guid) && (c1.fileExtension == c2.fileExtension) && (c1.importProject == c2.importProject) && (c1.xmlTag == c2.xmlTag)); | ||
197 | } | ||
198 | |||
199 | /// <summary> | ||
200 | /// Not equals operator | ||
201 | /// </summary> | ||
202 | /// <param name="c1">ToolInfo to compare</param> | ||
203 | /// <param name="c2">ToolInfo to compare</param> | ||
204 | /// <returns>True if toolInfos are not equal</returns> | ||
205 | public static bool operator !=(ToolInfo c1, ToolInfo c2) | ||
206 | { | ||
207 | return !(c1 == c2); | ||
208 | } | ||
209 | |||
210 | /// <summary> | ||
211 | /// Hash Code | ||
212 | /// </summary> | ||
213 | /// <returns>Hash code</returns> | ||
214 | public override int GetHashCode() | ||
215 | { | ||
216 | return name.GetHashCode() ^ guid.GetHashCode() ^ this.fileExtension.GetHashCode() ^ this.importProject.GetHashCode() ^ this.xmlTag.GetHashCode(); | ||
217 | |||
218 | } | ||
219 | } | ||
220 | |||
221 | /// <summary> | ||
222 | /// | ||
223 | /// </summary> | ||
224 | [Target("vs2005")] | ||
225 | public class VS2005Target : ITarget | ||
226 | { | ||
227 | #region Inner Classes | ||
228 | |||
229 | #endregion | ||
230 | |||
231 | #region Fields | ||
232 | |||
233 | string solutionVersion = "9.00"; | ||
234 | string productVersion = "8.0.50727"; | ||
235 | string schemaVersion = "2.0"; | ||
236 | string versionName = "Visual C# 2005"; | ||
237 | VSVersion version = VSVersion.VS80; | ||
238 | |||
239 | Hashtable tools; | ||
240 | Kernel kernel; | ||
241 | |||
242 | /// <summary> | ||
243 | /// Gets or sets the solution version. | ||
244 | /// </summary> | ||
245 | /// <value>The solution version.</value> | ||
246 | protected string SolutionVersion | ||
247 | { | ||
248 | get | ||
249 | { | ||
250 | return this.solutionVersion; | ||
251 | } | ||
252 | set | ||
253 | { | ||
254 | this.solutionVersion = value; | ||
255 | } | ||
256 | } | ||
257 | /// <summary> | ||
258 | /// Gets or sets the product version. | ||
259 | /// </summary> | ||
260 | /// <value>The product version.</value> | ||
261 | protected string ProductVersion | ||
262 | { | ||
263 | get | ||
264 | { | ||
265 | return this.productVersion; | ||
266 | } | ||
267 | set | ||
268 | { | ||
269 | this.productVersion = value; | ||
270 | } | ||
271 | } | ||
272 | /// <summary> | ||
273 | /// Gets or sets the schema version. | ||
274 | /// </summary> | ||
275 | /// <value>The schema version.</value> | ||
276 | protected string SchemaVersion | ||
277 | { | ||
278 | get | ||
279 | { | ||
280 | return this.schemaVersion; | ||
281 | } | ||
282 | set | ||
283 | { | ||
284 | this.schemaVersion = value; | ||
285 | } | ||
286 | } | ||
287 | /// <summary> | ||
288 | /// Gets or sets the name of the version. | ||
289 | /// </summary> | ||
290 | /// <value>The name of the version.</value> | ||
291 | protected string VersionName | ||
292 | { | ||
293 | get | ||
294 | { | ||
295 | return this.versionName; | ||
296 | } | ||
297 | set | ||
298 | { | ||
299 | this.versionName = value; | ||
300 | } | ||
301 | } | ||
302 | /// <summary> | ||
303 | /// Gets or sets the version. | ||
304 | /// </summary> | ||
305 | /// <value>The version.</value> | ||
306 | protected VSVersion Version | ||
307 | { | ||
308 | get | ||
309 | { | ||
310 | return this.version; | ||
311 | } | ||
312 | set | ||
313 | { | ||
314 | this.version = value; | ||
315 | } | ||
316 | } | ||
317 | |||
318 | #endregion | ||
319 | |||
320 | #region Constructors | ||
321 | |||
322 | /// <summary> | ||
323 | /// Initializes a new instance of the <see cref="VS2005Target"/> class. | ||
324 | /// </summary> | ||
325 | public VS2005Target() | ||
326 | { | ||
327 | this.tools = new Hashtable(); | ||
328 | |||
329 | this.tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP", "$(MSBuildBinPath)\\Microsoft.CSHARP.Targets"); | ||
330 | this.tools["Boo"] = new ToolInfo("Boo", "{45CEA7DC-C2ED-48A6-ACE0-E16144C02365}", "booproj", "Boo", "$(BooBinPath)\\Boo.Microsoft.Build.targets"); | ||
331 | this.tools["VisualBasic"] = new ToolInfo("VisualBasic", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic", "$(MSBuildBinPath)\\Microsoft.VisualBasic.Targets"); | ||
332 | } | ||
333 | |||
334 | #endregion | ||
335 | |||
336 | #region Private Methods | ||
337 | |||
338 | private string MakeRefPath(ProjectNode project) | ||
339 | { | ||
340 | string ret = ""; | ||
341 | foreach (ReferencePathNode node in project.ReferencePaths) | ||
342 | { | ||
343 | try | ||
344 | { | ||
345 | string fullPath = Helper.ResolvePath(node.Path); | ||
346 | if (ret.Length < 1) | ||
347 | { | ||
348 | ret = fullPath; | ||
349 | } | ||
350 | else | ||
351 | { | ||
352 | ret += ";" + fullPath; | ||
353 | } | ||
354 | } | ||
355 | catch (ArgumentException) | ||
356 | { | ||
357 | this.kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path); | ||
358 | } | ||
359 | } | ||
360 | |||
361 | return ret; | ||
362 | } | ||
363 | |||
364 | private void WriteProject(SolutionNode solution, ProjectNode project) | ||
365 | { | ||
366 | if (!tools.ContainsKey(project.Language)) | ||
367 | { | ||
368 | throw new UnknownLanguageException("Unknown .NET language: " + project.Language); | ||
369 | } | ||
370 | |||
371 | ToolInfo toolInfo = (ToolInfo)tools[project.Language]; | ||
372 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension); | ||
373 | StreamWriter ps = new StreamWriter(projectFile); | ||
374 | |||
375 | kernel.CurrentWorkingDirectory.Push(); | ||
376 | Helper.SetCurrentDir(Path.GetDirectoryName(projectFile)); | ||
377 | |||
378 | #region Project File | ||
379 | using (ps) | ||
380 | { | ||
381 | ps.WriteLine("<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"); | ||
382 | //ps.WriteLine(" <{0}", toolInfo.XMLTag); | ||
383 | ps.WriteLine(" <PropertyGroup>"); | ||
384 | ps.WriteLine(" <ProjectType>Local</ProjectType>"); | ||
385 | ps.WriteLine(" <ProductVersion>{0}</ProductVersion>", this.ProductVersion); | ||
386 | ps.WriteLine(" <SchemaVersion>{0}</SchemaVersion>", this.SchemaVersion); | ||
387 | ps.WriteLine(" <ProjectGuid>{{{0}}}</ProjectGuid>", project.Guid.ToString().ToUpper()); | ||
388 | |||
389 | ps.WriteLine(" <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>"); | ||
390 | ps.WriteLine(" <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>"); | ||
391 | //ps.WriteLine(" <Build>"); | ||
392 | |||
393 | //ps.WriteLine(" <Settings"); | ||
394 | ps.WriteLine(" <ApplicationIcon>{0}</ApplicationIcon>", project.AppIcon); | ||
395 | ps.WriteLine(" <AssemblyKeyContainerName>"); | ||
396 | ps.WriteLine(" </AssemblyKeyContainerName>"); | ||
397 | ps.WriteLine(" <AssemblyName>{0}</AssemblyName>", project.AssemblyName); | ||
398 | foreach (ConfigurationNode conf in project.Configurations) | ||
399 | { | ||
400 | if (conf.Options.KeyFile != "") | ||
401 | { | ||
402 | ps.WriteLine(" <AssemblyOriginatorKeyFile>{0}</AssemblyOriginatorKeyFile>", conf.Options.KeyFile); | ||
403 | ps.WriteLine(" <SignAssembly>true</SignAssembly>"); | ||
404 | break; | ||
405 | } | ||
406 | } | ||
407 | ps.WriteLine(" <DefaultClientScript>JScript</DefaultClientScript>"); | ||
408 | ps.WriteLine(" <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>"); | ||
409 | ps.WriteLine(" <DefaultTargetSchema>IE50</DefaultTargetSchema>"); | ||
410 | ps.WriteLine(" <DelaySign>false</DelaySign>"); | ||
411 | |||
412 | //if(m_Version == VSVersion.VS70) | ||
413 | // ps.WriteLine(" NoStandardLibraries = \"false\""); | ||
414 | |||
415 | ps.WriteLine(" <OutputType>{0}</OutputType>", project.Type.ToString()); | ||
416 | ps.WriteLine(" <AppDesignerFolder>{0}</AppDesignerFolder>", project.DesignerFolder); | ||
417 | ps.WriteLine(" <RootNamespace>{0}</RootNamespace>", project.RootNamespace); | ||
418 | ps.WriteLine(" <StartupObject>{0}</StartupObject>", project.StartupObject); | ||
419 | //ps.WriteLine(" >"); | ||
420 | ps.WriteLine(" <FileUpgradeFlags>"); | ||
421 | ps.WriteLine(" </FileUpgradeFlags>"); | ||
422 | |||
423 | ps.WriteLine(" </PropertyGroup>"); | ||
424 | |||
425 | foreach (ConfigurationNode conf in project.Configurations) | ||
426 | { | ||
427 | ps.Write(" <PropertyGroup "); | ||
428 | ps.WriteLine("Condition=\" '$(Configuration)|$(Platform)' == '{0}|AnyCPU' \">", conf.Name); | ||
429 | ps.WriteLine(" <AllowUnsafeBlocks>{0}</AllowUnsafeBlocks>", conf.Options["AllowUnsafe"]); | ||
430 | ps.WriteLine(" <BaseAddress>{0}</BaseAddress>", conf.Options["BaseAddress"]); | ||
431 | ps.WriteLine(" <CheckForOverflowUnderflow>{0}</CheckForOverflowUnderflow>", conf.Options["CheckUnderflowOverflow"]); | ||
432 | ps.WriteLine(" <ConfigurationOverrideFile>"); | ||
433 | ps.WriteLine(" </ConfigurationOverrideFile>"); | ||
434 | ps.WriteLine(" <DefineConstants>{0}</DefineConstants>", conf.Options["CompilerDefines"]); | ||
435 | ps.WriteLine(" <DocumentationFile>{0}</DocumentationFile>", conf.Options["XmlDocFile"]); | ||
436 | ps.WriteLine(" <DebugSymbols>{0}</DebugSymbols>", conf.Options["DebugInformation"]); | ||
437 | ps.WriteLine(" <FileAlignment>{0}</FileAlignment>", conf.Options["FileAlignment"]); | ||
438 | // ps.WriteLine(" <IncrementalBuild = \"{0}\"", conf.Options["IncrementalBuild"]); | ||
439 | |||
440 | // if(m_Version == VSVersion.VS71) | ||
441 | // { | ||
442 | // ps.WriteLine(" NoStdLib = \"{0}\"", conf.Options["NoStdLib"]); | ||
443 | // ps.WriteLine(" NoWarn = \"{0}\"", conf.Options["SuppressWarnings"]); | ||
444 | // } | ||
445 | |||
446 | ps.WriteLine(" <Optimize>{0}</Optimize>", conf.Options["OptimizeCode"]); | ||
447 | ps.WriteLine(" <OutputPath>{0}</OutputPath>", | ||
448 | Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString()))); | ||
449 | ps.WriteLine(" <RegisterForComInterop>{0}</RegisterForComInterop>", conf.Options["RegisterComInterop"]); | ||
450 | ps.WriteLine(" <RemoveIntegerChecks>{0}</RemoveIntegerChecks>", conf.Options["RemoveIntegerChecks"]); | ||
451 | ps.WriteLine(" <TreatWarningsAsErrors>{0}</TreatWarningsAsErrors>", conf.Options["WarningsAsErrors"]); | ||
452 | ps.WriteLine(" <WarningLevel>{0}</WarningLevel>", conf.Options["WarningLevel"]); | ||
453 | ps.WriteLine(" <NoWarn>{0}</NoWarn>", conf.Options["SuppressWarnings"]); | ||
454 | ps.WriteLine(" </PropertyGroup>"); | ||
455 | } | ||
456 | |||
457 | //ps.WriteLine(" </Settings>"); | ||
458 | |||
459 | // Assembly References | ||
460 | ps.WriteLine(" <ItemGroup>"); | ||
461 | string refPath = ((ReferencePathNode) project.ReferencePaths[0]).Path; | ||
462 | |||
463 | foreach (ReferenceNode refr in project.References) | ||
464 | { | ||
465 | if (!solution.ProjectsTable.ContainsKey(refr.Name)) | ||
466 | { | ||
467 | ps.Write(" <Reference"); | ||
468 | ps.Write(" Include=\""); | ||
469 | ps.Write(refr.Name); | ||
470 | |||
471 | ps.WriteLine("\" >"); | ||
472 | |||
473 | string path; | ||
474 | |||
475 | if( refr.Name.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase )) | ||
476 | { | ||
477 | path = Helper.NormalizePath(Path.Combine( refPath, refr.Name), '\\'); | ||
478 | } | ||
479 | else | ||
480 | { | ||
481 | path = refr.Name + ".dll"; | ||
482 | } | ||
483 | |||
484 | // TODO: Allow reference to *.exe files | ||
485 | ps.WriteLine(" <HintPath>{0}</HintPath>", path ); | ||
486 | ps.WriteLine(" <Private>{0}</Private>", refr.LocalCopy); | ||
487 | ps.WriteLine(" </Reference>"); | ||
488 | } | ||
489 | } | ||
490 | ps.WriteLine(" </ItemGroup>"); | ||
491 | |||
492 | //Project References | ||
493 | ps.WriteLine(" <ItemGroup>"); | ||
494 | foreach (ReferenceNode refr in project.References) | ||
495 | { | ||
496 | if (solution.ProjectsTable.ContainsKey(refr.Name)) | ||
497 | { | ||
498 | ProjectNode refProject = (ProjectNode)solution.ProjectsTable[refr.Name]; | ||
499 | // TODO: Allow reference to visual basic projects | ||
500 | string path = | ||
501 | Helper.MakePathRelativeTo(project.FullPath, | ||
502 | Helper.MakeFilePath(refProject.FullPath, refProject.Name, "csproj")); | ||
503 | ps.WriteLine(" <ProjectReference Include=\"{0}\">", path ); | ||
504 | //<ProjectReference Include="..\..\RealmForge\Utility\RealmForge.Utility.csproj"> | ||
505 | ps.WriteLine(" <Name>{0}</Name>", refProject.Name); | ||
506 | // <Name>RealmForge.Utility</Name> | ||
507 | ps.WriteLine(" <Project>{{{0}}}</Project>", refProject.Guid.ToString().ToUpper()); | ||
508 | // <Project>{6880D1D3-69EE-461B-B841-5319845B20D3}</Project> | ||
509 | ps.WriteLine(" <Package>{0}</Package>", toolInfo.Guid.ToString().ToUpper()); | ||
510 | // <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> | ||
511 | ps.WriteLine("\t\t\t<Private>{0}</Private>", refr.LocalCopy); | ||
512 | ps.WriteLine(" </ProjectReference>"); | ||
513 | //</ProjectReference> | ||
514 | } | ||
515 | else | ||
516 | { | ||
517 | } | ||
518 | } | ||
519 | ps.WriteLine(" </ItemGroup>"); | ||
520 | |||
521 | // ps.WriteLine(" </Build>"); | ||
522 | ps.WriteLine(" <ItemGroup>"); | ||
523 | |||
524 | // ps.WriteLine(" <Include>"); | ||
525 | ArrayList list = new ArrayList(); | ||
526 | foreach (string file in project.Files) | ||
527 | { | ||
528 | // if (file == "Properties\\Bind.Designer.cs") | ||
529 | // { | ||
530 | // Console.WriteLine("Wait a minute!"); | ||
531 | // Console.WriteLine(project.Files.GetSubType(file).ToString()); | ||
532 | // } | ||
533 | |||
534 | if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings && project.Files.GetSubType(file) != SubType.Designer) | ||
535 | { | ||
536 | ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx"); | ||
537 | |||
538 | int slash = file.LastIndexOf('\\'); | ||
539 | if (slash == -1) | ||
540 | { | ||
541 | ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", file); | ||
542 | } | ||
543 | else | ||
544 | { | ||
545 | ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", file.Substring(slash + 1, file.Length - slash - 1)); | ||
546 | } | ||
547 | ps.WriteLine(" <SubType>Designer</SubType>"); | ||
548 | ps.WriteLine(" </EmbeddedResource>"); | ||
549 | // | ||
550 | } | ||
551 | |||
552 | if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) == SubType.Designer) | ||
553 | { | ||
554 | ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx"); | ||
555 | ps.WriteLine(" <SubType>" + project.Files.GetSubType(file) + "</SubType>"); | ||
556 | ps.WriteLine(" <Generator>ResXFileCodeGenerator</Generator>"); | ||
557 | ps.WriteLine(" <LastGenOutput>Resources.Designer.cs</LastGenOutput>"); | ||
558 | ps.WriteLine(" </EmbeddedResource>"); | ||
559 | ps.WriteLine(" <Compile Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".Designer.cs"); | ||
560 | ps.WriteLine(" <AutoGen>True</AutoGen>"); | ||
561 | ps.WriteLine(" <DesignTime>True</DesignTime>"); | ||
562 | ps.WriteLine(" <DependentUpon>Resources.resx</DependentUpon>"); | ||
563 | ps.WriteLine(" </Compile>"); | ||
564 | list.Add(file.Substring(0, file.LastIndexOf('.')) + ".Designer.cs"); | ||
565 | } | ||
566 | if (project.Files.GetSubType(file).ToString() == "Settings") | ||
567 | { | ||
568 | //Console.WriteLine("File: " + file); | ||
569 | //Console.WriteLine("Last index: " + file.LastIndexOf('.')); | ||
570 | //Console.WriteLine("Length: " + file.Length); | ||
571 | ps.Write(" <{0} ", project.Files.GetBuildAction(file)); | ||
572 | ps.WriteLine("Include=\"{0}\">", file); | ||
573 | int slash = file.LastIndexOf('\\'); | ||
574 | string fileName = file.Substring(slash + 1, file.Length - slash - 1); | ||
575 | if (project.Files.GetBuildAction(file) == BuildAction.None) | ||
576 | { | ||
577 | ps.WriteLine(" <Generator>SettingsSingleFileGenerator</Generator>"); | ||
578 | |||
579 | //Console.WriteLine("FileName: " + fileName); | ||
580 | //Console.WriteLine("FileNameMain: " + fileName.Substring(0, fileName.LastIndexOf('.'))); | ||
581 | //Console.WriteLine("FileNameExt: " + fileName.Substring(fileName.LastIndexOf('.'), fileName.Length - fileName.LastIndexOf('.'))); | ||
582 | if (slash == -1) | ||
583 | { | ||
584 | ps.WriteLine(" <LastGenOutput>{0}</LastGenOutput>", fileName.Substring(0, fileName.LastIndexOf('.')) + ".Designer.cs"); | ||
585 | } | ||
586 | else | ||
587 | { | ||
588 | ps.WriteLine(" <LastGenOutput>{0}</LastGenOutput>", fileName.Substring(0, fileName.LastIndexOf('.')) + ".Designer.cs"); | ||
589 | } | ||
590 | } | ||
591 | else | ||
592 | { | ||
593 | ps.WriteLine(" <SubType>Code</SubType>"); | ||
594 | ps.WriteLine(" <AutoGen>True</AutoGen>"); | ||
595 | ps.WriteLine(" <DesignTimeSharedInput>True</DesignTimeSharedInput>"); | ||
596 | string fileNameShort = fileName.Substring(0, fileName.LastIndexOf('.')); | ||
597 | string fileNameShorter = fileNameShort.Substring(0, fileNameShort.LastIndexOf('.')); | ||
598 | ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", fileNameShorter + ".settings"); | ||
599 | } | ||
600 | ps.WriteLine(" </{0}>", project.Files.GetBuildAction(file)); | ||
601 | } | ||
602 | else if (project.Files.GetSubType(file) != SubType.Designer) | ||
603 | { | ||
604 | if (!list.Contains(file)) | ||
605 | { | ||
606 | ps.Write(" <{0} ", project.Files.GetBuildAction(file)); | ||
607 | ps.WriteLine("Include=\"{0}\">", file); | ||
608 | |||
609 | |||
610 | if (file.Contains("Designer.cs")) | ||
611 | { | ||
612 | ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", file.Substring(0, file.IndexOf(".Designer.cs")) + ".cs"); | ||
613 | } | ||
614 | |||
615 | if (project.Files.GetIsLink(file)) | ||
616 | { | ||
617 | ps.WriteLine(" <Link>{0}</Link>", Path.GetFileName(file)); | ||
618 | } | ||
619 | else if (project.Files.GetBuildAction(file) != BuildAction.None) | ||
620 | { | ||
621 | if (project.Files.GetBuildAction(file) != BuildAction.EmbeddedResource) | ||
622 | { | ||
623 | ps.WriteLine(" <SubType>{0}</SubType>", project.Files.GetSubType(file)); | ||
624 | } | ||
625 | } | ||
626 | if (project.Files.GetCopyToOutput(file) != CopyToOutput.Never) | ||
627 | { | ||
628 | ps.WriteLine(" <CopyToOutputDirectory>{0}</CopyToOutputDirectory>", project.Files.GetCopyToOutput(file)); | ||
629 | } | ||
630 | |||
631 | ps.WriteLine(" </{0}>", project.Files.GetBuildAction(file)); | ||
632 | } | ||
633 | } | ||
634 | } | ||
635 | // ps.WriteLine(" </Include>"); | ||
636 | |||
637 | ps.WriteLine(" </ItemGroup>"); | ||
638 | ps.WriteLine(" <Import Project=\"" + toolInfo.ImportProject + "\" />"); | ||
639 | ps.WriteLine(" <PropertyGroup>"); | ||
640 | ps.WriteLine(" <PreBuildEvent>"); | ||
641 | ps.WriteLine(" </PreBuildEvent>"); | ||
642 | ps.WriteLine(" <PostBuildEvent>"); | ||
643 | ps.WriteLine(" </PostBuildEvent>"); | ||
644 | ps.WriteLine(" </PropertyGroup>"); | ||
645 | // ps.WriteLine(" </{0}>", toolInfo.XMLTag); | ||
646 | ps.WriteLine("</Project>"); | ||
647 | } | ||
648 | #endregion | ||
649 | |||
650 | #region User File | ||
651 | |||
652 | ps = new StreamWriter(projectFile + ".user"); | ||
653 | using (ps) | ||
654 | { | ||
655 | ps.WriteLine("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"); | ||
656 | //ps.WriteLine( "<VisualStudioProject>" ); | ||
657 | //ps.WriteLine(" <{0}>", toolInfo.XMLTag); | ||
658 | //ps.WriteLine(" <Build>"); | ||
659 | ps.WriteLine(" <PropertyGroup>"); | ||
660 | //ps.WriteLine(" <Settings ReferencePath=\"{0}\">", MakeRefPath(project)); | ||
661 | |||
662 | |||
663 | ps.WriteLine(" <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>"); | ||
664 | ps.WriteLine(" <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>"); | ||
665 | |||
666 | if (projectFile.Contains( "OpenSim.csproj" )) | ||
667 | { | ||
668 | ps.WriteLine(" <StartArguments>-loginserver -sandbox -accounts</StartArguments>"); | ||
669 | } | ||
670 | |||
671 | ps.WriteLine(" <ReferencePath>{0}</ReferencePath>", MakeRefPath(project)); | ||
672 | ps.WriteLine(" <LastOpenVersion>{0}</LastOpenVersion>", this.ProductVersion); | ||
673 | ps.WriteLine(" <ProjectView>ProjectFiles</ProjectView>"); | ||
674 | ps.WriteLine(" <ProjectTrust>0</ProjectTrust>"); | ||
675 | ps.WriteLine(" </PropertyGroup>"); | ||
676 | foreach (ConfigurationNode conf in project.Configurations) | ||
677 | { | ||
678 | ps.Write(" <PropertyGroup"); | ||
679 | ps.Write(" Condition = \" '$(Configuration)|$(Platform)' == '{0}|AnyCPU' \"", conf.Name); | ||
680 | ps.WriteLine(" />"); | ||
681 | } | ||
682 | |||
683 | ps.WriteLine("</Project>"); | ||
684 | } | ||
685 | #endregion | ||
686 | |||
687 | kernel.CurrentWorkingDirectory.Pop(); | ||
688 | } | ||
689 | |||
690 | private void WriteSolution(SolutionNode solution) | ||
691 | { | ||
692 | kernel.Log.Write("Creating {0} solution and project files", this.VersionName); | ||
693 | |||
694 | foreach (ProjectNode project in solution.Projects) | ||
695 | { | ||
696 | kernel.Log.Write("...Creating project: {0}", project.Name); | ||
697 | WriteProject(solution, project); | ||
698 | } | ||
699 | |||
700 | kernel.Log.Write(""); | ||
701 | string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln"); | ||
702 | StreamWriter ss = new StreamWriter(solutionFile); | ||
703 | |||
704 | kernel.CurrentWorkingDirectory.Push(); | ||
705 | Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile)); | ||
706 | |||
707 | using (ss) | ||
708 | { | ||
709 | ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", this.SolutionVersion); | ||
710 | ss.WriteLine("# Visual Studio 2005"); | ||
711 | foreach (ProjectNode project in solution.Projects) | ||
712 | { | ||
713 | if (!tools.ContainsKey(project.Language)) | ||
714 | { | ||
715 | throw new UnknownLanguageException("Unknown .NET language: " + project.Language); | ||
716 | } | ||
717 | |||
718 | ToolInfo toolInfo = (ToolInfo)tools[project.Language]; | ||
719 | |||
720 | string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath); | ||
721 | ss.WriteLine("Project(\"{0}\") = \"{1}\", \"{2}\", \"{{{3}}}\"", | ||
722 | toolInfo.Guid, project.Name, Helper.MakeFilePath(path, project.Name, | ||
723 | toolInfo.FileExtension), project.Guid.ToString().ToUpper()); | ||
724 | |||
725 | //ss.WriteLine(" ProjectSection(ProjectDependencies) = postProject"); | ||
726 | //ss.WriteLine(" EndProjectSection"); | ||
727 | |||
728 | ss.WriteLine("EndProject"); | ||
729 | } | ||
730 | |||
731 | if (solution.Files != null) | ||
732 | { | ||
733 | ss.WriteLine("Project(\"{0}\") = \"Solution Items\", \"Solution Items\", \"{1}\"", "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", "{468F1D07-AD17-4CC3-ABD0-2CA268E4E1A6}"); | ||
734 | ss.WriteLine("\tProjectSection(SolutionItems) = preProject"); | ||
735 | foreach (string file in solution.Files) | ||
736 | ss.WriteLine("\t\t{0} = {0}", file); | ||
737 | ss.WriteLine("\tEndProjectSection"); | ||
738 | ss.WriteLine("EndProject"); | ||
739 | } | ||
740 | |||
741 | ss.WriteLine("Global"); | ||
742 | |||
743 | ss.WriteLine(" GlobalSection(SolutionConfigurationPlatforms) = preSolution"); | ||
744 | foreach (ConfigurationNode conf in solution.Configurations) | ||
745 | { | ||
746 | ss.WriteLine(" {0}|Any CPU = {0}|Any CPU", conf.Name); | ||
747 | } | ||
748 | ss.WriteLine(" EndGlobalSection"); | ||
749 | |||
750 | if (solution.Projects.Count > 1) | ||
751 | { | ||
752 | ss.WriteLine(" GlobalSection(ProjectDependencies) = postSolution"); | ||
753 | } | ||
754 | foreach (ProjectNode project in solution.Projects) | ||
755 | { | ||
756 | for (int i = 0; i < project.References.Count; i++) | ||
757 | { | ||
758 | ReferenceNode refr = (ReferenceNode)project.References[i]; | ||
759 | if (solution.ProjectsTable.ContainsKey(refr.Name)) | ||
760 | { | ||
761 | ProjectNode refProject = (ProjectNode)solution.ProjectsTable[refr.Name]; | ||
762 | ss.WriteLine(" ({{{0}}}).{1} = ({{{2}}})", | ||
763 | project.Guid.ToString().ToUpper() | ||
764 | , i, | ||
765 | refProject.Guid.ToString().ToUpper() | ||
766 | ); | ||
767 | } | ||
768 | } | ||
769 | } | ||
770 | if (solution.Projects.Count > 1) | ||
771 | { | ||
772 | ss.WriteLine(" EndGlobalSection"); | ||
773 | } | ||
774 | ss.WriteLine(" GlobalSection(ProjectConfigurationPlatforms) = postSolution"); | ||
775 | foreach (ProjectNode project in solution.Projects) | ||
776 | { | ||
777 | foreach (ConfigurationNode conf in solution.Configurations) | ||
778 | { | ||
779 | ss.WriteLine(" {{{0}}}.{1}|Any CPU.ActiveCfg = {1}|Any CPU", | ||
780 | project.Guid.ToString().ToUpper(), | ||
781 | conf.Name); | ||
782 | |||
783 | ss.WriteLine(" {{{0}}}.{1}|Any CPU.Build.0 = {1}|Any CPU", | ||
784 | project.Guid.ToString().ToUpper(), | ||
785 | conf.Name); | ||
786 | } | ||
787 | } | ||
788 | ss.WriteLine(" EndGlobalSection"); | ||
789 | ss.WriteLine(" GlobalSection(SolutionProperties) = preSolution"); | ||
790 | ss.WriteLine(" HideSolutionNode = FALSE"); | ||
791 | ss.WriteLine(" EndGlobalSection"); | ||
792 | |||
793 | ss.WriteLine("EndGlobal"); | ||
794 | } | ||
795 | |||
796 | kernel.CurrentWorkingDirectory.Pop(); | ||
797 | } | ||
798 | |||
799 | private void CleanProject(ProjectNode project) | ||
800 | { | ||
801 | kernel.Log.Write("...Cleaning project: {0}", project.Name); | ||
802 | |||
803 | ToolInfo toolInfo = (ToolInfo)tools[project.Language]; | ||
804 | string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension); | ||
805 | string userFile = projectFile + ".user"; | ||
806 | |||
807 | Helper.DeleteIfExists(projectFile); | ||
808 | Helper.DeleteIfExists(userFile); | ||
809 | } | ||
810 | |||
811 | private void CleanSolution(SolutionNode solution) | ||
812 | { | ||
813 | kernel.Log.Write("Cleaning {0} solution and project files", this.VersionName, solution.Name); | ||
814 | |||
815 | string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln"); | ||
816 | string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo"); | ||
817 | |||
818 | Helper.DeleteIfExists(slnFile); | ||
819 | Helper.DeleteIfExists(suoFile); | ||
820 | |||
821 | foreach (ProjectNode project in solution.Projects) | ||
822 | { | ||
823 | CleanProject(project); | ||
824 | } | ||
825 | |||
826 | kernel.Log.Write(""); | ||
827 | } | ||
828 | |||
829 | #endregion | ||
830 | |||
831 | #region ITarget Members | ||
832 | |||
833 | /// <summary> | ||
834 | /// Writes the specified kern. | ||
835 | /// </summary> | ||
836 | /// <param name="kern">The kern.</param> | ||
837 | public virtual void Write(Kernel kern) | ||
838 | { | ||
839 | if (kern == null) | ||
840 | { | ||
841 | throw new ArgumentNullException("kern"); | ||
842 | } | ||
843 | kernel = kern; | ||
844 | foreach (SolutionNode sol in kernel.Solutions) | ||
845 | { | ||
846 | WriteSolution(sol); | ||
847 | } | ||
848 | kernel = null; | ||
849 | } | ||
850 | |||
851 | /// <summary> | ||
852 | /// Cleans the specified kern. | ||
853 | /// </summary> | ||
854 | /// <param name="kern">The kern.</param> | ||
855 | public virtual void Clean(Kernel kern) | ||
856 | { | ||
857 | if (kern == null) | ||
858 | { | ||
859 | throw new ArgumentNullException("kern"); | ||
860 | } | ||
861 | kernel = kern; | ||
862 | foreach (SolutionNode sol in kernel.Solutions) | ||
863 | { | ||
864 | CleanSolution(sol); | ||
865 | } | ||
866 | kernel = null; | ||
867 | } | ||
868 | |||
869 | /// <summary> | ||
870 | /// Gets the name. | ||
871 | /// </summary> | ||
872 | /// <value>The name.</value> | ||
873 | public virtual string Name | ||
874 | { | ||
875 | get | ||
876 | { | ||
877 | return "vs2005"; | ||
878 | } | ||
879 | } | ||
880 | |||
881 | #endregion | ||
882 | } | ||
883 | } | ||
diff --git a/Prebuild/src/Core/UnknownLanguageException.cs b/Prebuild/src/Core/UnknownLanguageException.cs new file mode 100644 index 0000000..cbd1dc1 --- /dev/null +++ b/Prebuild/src/Core/UnknownLanguageException.cs | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | * $RCSfile$ | ||
3 | * Copyright (C) 2004, 2005 David Hudson (jendave@yahoo.com) | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2.1 of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this library; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | using System; | ||
21 | using System.Runtime.Serialization; | ||
22 | |||
23 | namespace Prebuild.Core | ||
24 | { | ||
25 | /// <summary> | ||
26 | /// </summary> | ||
27 | [Serializable()] | ||
28 | public class UnknownLanguageException : Exception | ||
29 | { | ||
30 | /// <summary> | ||
31 | /// Basic exception. | ||
32 | /// </summary> | ||
33 | public UnknownLanguageException() | ||
34 | { | ||
35 | } | ||
36 | |||
37 | /// <summary> | ||
38 | /// Exception with specified string | ||
39 | /// </summary> | ||
40 | /// <param name="message">Exception message</param> | ||
41 | public UnknownLanguageException(string message): base(message) | ||
42 | { | ||
43 | } | ||
44 | |||
45 | /// <summary> | ||
46 | /// | ||
47 | /// </summary> | ||
48 | /// <param name="message"></param> | ||
49 | /// <param name="exception"></param> | ||
50 | public UnknownLanguageException(string message, Exception exception) : base(message, exception) | ||
51 | { | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// | ||
56 | /// </summary> | ||
57 | /// <param name="info"></param> | ||
58 | /// <param name="context"></param> | ||
59 | protected UnknownLanguageException(SerializationInfo info, StreamingContext context) : base( info, context ) | ||
60 | { | ||
61 | } | ||
62 | } | ||
63 | } | ||
diff --git a/Prebuild/src/Core/Utilities/CommandLineCollection.cs b/Prebuild/src/Core/Utilities/CommandLineCollection.cs new file mode 100644 index 0000000..496731f --- /dev/null +++ b/Prebuild/src/Core/Utilities/CommandLineCollection.cs | |||
@@ -0,0 +1,162 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: robloach $ | ||
30 | * $Date: 2006-09-26 00:30:53 +0200 (ti, 26 sep 2006) $ | ||
31 | * $Revision: 165 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.Diagnostics; | ||
39 | |||
40 | namespace Prebuild.Core.Utilities | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// The CommandLine class parses and interprets the command-line arguments passed to | ||
44 | /// prebuild. | ||
45 | /// </summary> | ||
46 | public class CommandLineCollection | ||
47 | { | ||
48 | #region Fields | ||
49 | |||
50 | // The raw OS arguments | ||
51 | private string[] m_RawArgs; | ||
52 | |||
53 | // Command-line argument storage | ||
54 | private Hashtable m_Arguments; | ||
55 | |||
56 | #endregion | ||
57 | |||
58 | #region Constructors | ||
59 | |||
60 | /// <summary> | ||
61 | /// Create a new CommandLine instance and set some internal variables. | ||
62 | /// </summary> | ||
63 | public CommandLineCollection(string[] args) | ||
64 | { | ||
65 | m_RawArgs = args; | ||
66 | m_Arguments = new Hashtable(); | ||
67 | |||
68 | Parse(); | ||
69 | } | ||
70 | |||
71 | #endregion | ||
72 | |||
73 | #region Private Methods | ||
74 | |||
75 | private void Parse() | ||
76 | { | ||
77 | if(m_RawArgs.Length < 1) | ||
78 | return; | ||
79 | |||
80 | int idx = 0; | ||
81 | string arg = null, lastArg = null; | ||
82 | |||
83 | while(idx <m_RawArgs.Length) | ||
84 | { | ||
85 | arg = m_RawArgs[idx]; | ||
86 | |||
87 | if(arg.Length > 2 && arg[0] == '/') | ||
88 | { | ||
89 | arg = arg.Substring(1); | ||
90 | lastArg = arg; | ||
91 | m_Arguments[arg] = ""; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | if(lastArg != null) | ||
96 | { | ||
97 | m_Arguments[lastArg] = arg; | ||
98 | lastArg = null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | idx++; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | #endregion | ||
107 | |||
108 | #region Public Methods | ||
109 | |||
110 | /// <summary> | ||
111 | /// Wases the passed. | ||
112 | /// </summary> | ||
113 | /// <param name="arg">The arg.</param> | ||
114 | /// <returns></returns> | ||
115 | public bool WasPassed(string arg) | ||
116 | { | ||
117 | return (m_Arguments.ContainsKey(arg)); | ||
118 | } | ||
119 | |||
120 | #endregion | ||
121 | |||
122 | #region Properties | ||
123 | |||
124 | /// <summary> | ||
125 | /// Gets the parameter associated with the command line option | ||
126 | /// </summary> | ||
127 | /// <remarks>Returns null if option was not specified, | ||
128 | /// null string if no parameter was specified, and the value if a parameter was specified</remarks> | ||
129 | public string this[string index] | ||
130 | { | ||
131 | get | ||
132 | { | ||
133 | if(m_Arguments.ContainsKey(index)) | ||
134 | { | ||
135 | return (string)(m_Arguments[index]); | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | return null; | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
144 | #endregion | ||
145 | |||
146 | #region IEnumerable Members | ||
147 | |||
148 | /// <summary> | ||
149 | /// Returns an enumerator that can iterate through a collection. | ||
150 | /// </summary> | ||
151 | /// <returns> | ||
152 | /// An <see cref="T:System.Collections.IDictionaryEnumerator"/> | ||
153 | /// that can be used to iterate through the collection. | ||
154 | /// </returns> | ||
155 | public IDictionaryEnumerator GetEnumerator() | ||
156 | { | ||
157 | return m_Arguments.GetEnumerator(); | ||
158 | } | ||
159 | |||
160 | #endregion | ||
161 | } | ||
162 | } | ||
diff --git a/Prebuild/src/Core/Utilities/CurrentDirectory.cs b/Prebuild/src/Core/Utilities/CurrentDirectory.cs new file mode 100644 index 0000000..a76d844 --- /dev/null +++ b/Prebuild/src/Core/Utilities/CurrentDirectory.cs | |||
@@ -0,0 +1,89 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | |||
38 | namespace Prebuild.Core.Utilities | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | public class CurrentDirectory | ||
44 | { | ||
45 | #region Fields | ||
46 | |||
47 | private Stack m_Stack; | ||
48 | |||
49 | #endregion | ||
50 | |||
51 | #region Constructors | ||
52 | |||
53 | /// <summary> | ||
54 | /// Initializes a new instance of the <see cref="CurrentDirectory"/> class. | ||
55 | /// </summary> | ||
56 | public CurrentDirectory() | ||
57 | { | ||
58 | m_Stack = new Stack(); | ||
59 | } | ||
60 | |||
61 | #endregion | ||
62 | |||
63 | #region Public Methods | ||
64 | |||
65 | /// <summary> | ||
66 | /// Pushes this instance. | ||
67 | /// </summary> | ||
68 | public void Push() | ||
69 | { | ||
70 | m_Stack.Push(Environment.CurrentDirectory); | ||
71 | } | ||
72 | |||
73 | /// <summary> | ||
74 | /// Pops this instance. | ||
75 | /// </summary> | ||
76 | public void Pop() | ||
77 | { | ||
78 | if(m_Stack.Count < 1) | ||
79 | { | ||
80 | return; | ||
81 | } | ||
82 | |||
83 | string cwd = (string)m_Stack.Pop(); | ||
84 | Helper.SetCurrentDir(cwd); | ||
85 | } | ||
86 | |||
87 | #endregion | ||
88 | } | ||
89 | } | ||
diff --git a/Prebuild/src/Core/Utilities/Helper.cs b/Prebuild/src/Core/Utilities/Helper.cs new file mode 100644 index 0000000..33c9618 --- /dev/null +++ b/Prebuild/src/Core/Utilities/Helper.cs | |||
@@ -0,0 +1,661 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2007-02-13 21:58:03 +0100 (ti, 13 feb 2007) $ | ||
31 | * $Revision: 205 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Diagnostics; | ||
38 | using System.IO; | ||
39 | using System.Runtime.InteropServices; | ||
40 | using System.Text.RegularExpressions; | ||
41 | using System.Collections.Specialized; | ||
42 | using System.Xml; | ||
43 | using Prebuild.Core.Nodes; | ||
44 | |||
45 | namespace Prebuild.Core.Utilities | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// | ||
49 | /// </summary> | ||
50 | public class Helper | ||
51 | { | ||
52 | #region Fields | ||
53 | |||
54 | private static Stack dirStack; | ||
55 | private static Regex varRegex; | ||
56 | static bool checkForOSVariables; | ||
57 | |||
58 | /// <summary> | ||
59 | /// | ||
60 | /// </summary> | ||
61 | public static bool CheckForOSVariables | ||
62 | { | ||
63 | get | ||
64 | { | ||
65 | return checkForOSVariables; | ||
66 | } | ||
67 | set | ||
68 | { | ||
69 | checkForOSVariables = value; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | #endregion | ||
74 | |||
75 | #region Constructors | ||
76 | |||
77 | /// <summary> | ||
78 | /// Initializes the <see cref="Helper"/> class. | ||
79 | /// </summary> | ||
80 | static Helper() | ||
81 | { | ||
82 | dirStack = new Stack(); | ||
83 | //m_VarRegex = new Regex(@"\${(?<var>[\w|_]+)}"); | ||
84 | } | ||
85 | |||
86 | #endregion | ||
87 | |||
88 | #region Properties | ||
89 | |||
90 | /// <summary> | ||
91 | /// | ||
92 | /// </summary> | ||
93 | public static Stack DirStack | ||
94 | { | ||
95 | get | ||
96 | { | ||
97 | return dirStack; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// | ||
103 | /// </summary> | ||
104 | public static Regex VarRegex | ||
105 | { | ||
106 | get | ||
107 | { | ||
108 | return varRegex; | ||
109 | } | ||
110 | set | ||
111 | { | ||
112 | varRegex = value; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | #endregion | ||
117 | |||
118 | #region Public Methods | ||
119 | |||
120 | #region String Parsing | ||
121 | #region Inner Classes and Delegates | ||
122 | /// <summary> | ||
123 | /// | ||
124 | /// </summary> | ||
125 | public delegate string StringLookup(string key); | ||
126 | |||
127 | #endregion | ||
128 | |||
129 | /// <summary> | ||
130 | /// Gets a collection of StringLocationPair objects that represent the matches | ||
131 | /// </summary> | ||
132 | /// <param name="target">The target.</param> | ||
133 | /// <param name="beforeGroup">The before group.</param> | ||
134 | /// <param name="afterGroup">The after group.</param> | ||
135 | /// <param name="includeDelimitersInSubstrings">if set to <c>true</c> [include delimiters in substrings].</param> | ||
136 | /// <returns></returns> | ||
137 | public static StringCollection FindGroups(string target, string beforeGroup, string afterGroup, bool includeDelimitersInSubstrings) | ||
138 | { | ||
139 | if( beforeGroup == null ) | ||
140 | { | ||
141 | throw new ArgumentNullException("beforeGroup"); | ||
142 | } | ||
143 | if( afterGroup == null ) | ||
144 | { | ||
145 | throw new ArgumentNullException("afterGroup"); | ||
146 | } | ||
147 | StringCollection results = new StringCollection(); | ||
148 | if(target == null || target.Length == 0) | ||
149 | { | ||
150 | return results; | ||
151 | } | ||
152 | |||
153 | int beforeMod = 0; | ||
154 | int afterMod = 0; | ||
155 | if(includeDelimitersInSubstrings) | ||
156 | { | ||
157 | //be sure to not exlude the delims | ||
158 | beforeMod = beforeGroup.Length; | ||
159 | afterMod = afterGroup.Length; | ||
160 | } | ||
161 | int startIndex = 0; | ||
162 | while((startIndex = target.IndexOf(beforeGroup,startIndex)) != -1) { | ||
163 | int endIndex = target.IndexOf(afterGroup,startIndex);//the index of the char after it | ||
164 | if(endIndex == -1) | ||
165 | { | ||
166 | break; | ||
167 | } | ||
168 | int length = endIndex - startIndex - beforeGroup.Length;//move to the first char in the string | ||
169 | string substring = substring = target.Substring(startIndex + beforeGroup.Length - beforeMod, | ||
170 | length - afterMod); | ||
171 | |||
172 | results.Add(substring); | ||
173 | //results.Add(new StringLocationPair(substring,startIndex)); | ||
174 | startIndex = endIndex + 1; | ||
175 | //the Interpolate*() methods will not work if expressions are expandded inside expression due to an optimization | ||
176 | //so start after endIndex | ||
177 | |||
178 | } | ||
179 | return results; | ||
180 | } | ||
181 | |||
182 | /// <summary> | ||
183 | /// Replaces the groups. | ||
184 | /// </summary> | ||
185 | /// <param name="target">The target.</param> | ||
186 | /// <param name="beforeGroup">The before group.</param> | ||
187 | /// <param name="afterGroup">The after group.</param> | ||
188 | /// <param name="lookup">The lookup.</param> | ||
189 | /// <returns></returns> | ||
190 | public static string ReplaceGroups(string target, string beforeGroup, string afterGroup, StringLookup lookup) { | ||
191 | if( target == null ) | ||
192 | { | ||
193 | throw new ArgumentNullException("target"); | ||
194 | } | ||
195 | //int targetLength = target.Length; | ||
196 | StringCollection strings = FindGroups(target,beforeGroup,afterGroup,false); | ||
197 | if( lookup == null ) | ||
198 | { | ||
199 | throw new ArgumentNullException("lookup"); | ||
200 | } | ||
201 | foreach(string substring in strings) | ||
202 | { | ||
203 | target = target.Replace(beforeGroup + substring + afterGroup, lookup(substring) ); | ||
204 | } | ||
205 | return target; | ||
206 | } | ||
207 | |||
208 | /// <summary> | ||
209 | /// Replaces ${var} statements in a string with the corresonding values as detirmined by the lookup delegate | ||
210 | /// </summary> | ||
211 | /// <param name="target">The target.</param> | ||
212 | /// <param name="lookup">The lookup.</param> | ||
213 | /// <returns></returns> | ||
214 | public static string InterpolateForVariables(string target, StringLookup lookup) | ||
215 | { | ||
216 | return ReplaceGroups(target, "${" , "}" , lookup); | ||
217 | } | ||
218 | |||
219 | /// <summary> | ||
220 | /// Replaces ${var} statements in a string with the corresonding environment variable with name var | ||
221 | /// </summary> | ||
222 | /// <param name="target"></param> | ||
223 | /// <returns></returns> | ||
224 | public static string InterpolateForEnvironmentVariables(string target) | ||
225 | { | ||
226 | return InterpolateForVariables(target, new StringLookup(Environment.GetEnvironmentVariable)); | ||
227 | } | ||
228 | |||
229 | #endregion | ||
230 | |||
231 | /// <summary> | ||
232 | /// Translates the value. | ||
233 | /// </summary> | ||
234 | /// <param name="translateType">Type of the translate.</param> | ||
235 | /// <param name="translationItem">The translation item.</param> | ||
236 | /// <returns></returns> | ||
237 | public static object TranslateValue(Type translateType, string translationItem) | ||
238 | { | ||
239 | if(translationItem == null) | ||
240 | { | ||
241 | return null; | ||
242 | } | ||
243 | |||
244 | try | ||
245 | { | ||
246 | string lowerVal = translationItem.ToLower(); | ||
247 | if(translateType == typeof(bool)) | ||
248 | { | ||
249 | return (lowerVal == "true" || lowerVal == "1" || lowerVal == "y" || lowerVal == "yes" || lowerVal == "on"); | ||
250 | } | ||
251 | else if(translateType == typeof(int)) | ||
252 | { | ||
253 | return (Int32.Parse(translationItem)); | ||
254 | } | ||
255 | else | ||
256 | { | ||
257 | return translationItem; | ||
258 | } | ||
259 | } | ||
260 | catch(FormatException) | ||
261 | { | ||
262 | return null; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | /// <summary> | ||
267 | /// Deletes if exists. | ||
268 | /// </summary> | ||
269 | /// <param name="file">The file.</param> | ||
270 | /// <returns></returns> | ||
271 | public static bool DeleteIfExists(string file) | ||
272 | { | ||
273 | string resFile = null; | ||
274 | try | ||
275 | { | ||
276 | resFile = ResolvePath(file); | ||
277 | } | ||
278 | catch(ArgumentException) | ||
279 | { | ||
280 | return false; | ||
281 | } | ||
282 | |||
283 | if(!File.Exists(resFile)) | ||
284 | { | ||
285 | return false; | ||
286 | } | ||
287 | |||
288 | File.Delete(resFile); | ||
289 | return true; | ||
290 | } | ||
291 | |||
292 | // This little gem was taken from the NeL source, thanks guys! | ||
293 | /// <summary> | ||
294 | /// Makes a relative path | ||
295 | /// </summary> | ||
296 | /// <param name="startPath">Path to start from</param> | ||
297 | /// <param name="endPath">Path to end at</param> | ||
298 | /// <returns>Path that will get from startPath to endPath</returns> | ||
299 | public static string MakePathRelativeTo(string startPath, string endPath) | ||
300 | { | ||
301 | string tmp = NormalizePath(startPath, '/'); | ||
302 | string src = NormalizePath(endPath, '/'); | ||
303 | string prefix = ""; | ||
304 | |||
305 | while(true) | ||
306 | { | ||
307 | if((String.Compare(tmp, 0, src, 0, tmp.Length) == 0)) | ||
308 | { | ||
309 | string ret; | ||
310 | int size = tmp.Length; | ||
311 | if(size == src.Length) | ||
312 | { | ||
313 | return "./"; | ||
314 | } | ||
315 | if ((src.Length > tmp.Length) && src[tmp.Length-1] != '/' && src[tmp.Length-1] != '\\') | ||
316 | { | ||
317 | } | ||
318 | else | ||
319 | { | ||
320 | ret = prefix + endPath.Substring(size, endPath.Length - size); | ||
321 | ret = ret.Trim(); | ||
322 | if(ret[0] == '/' || ret[0] == '\\') | ||
323 | { | ||
324 | ret = "." + ret; | ||
325 | } | ||
326 | |||
327 | return NormalizePath(ret); | ||
328 | } | ||
329 | |||
330 | } | ||
331 | |||
332 | if(tmp.Length < 2) | ||
333 | { | ||
334 | break; | ||
335 | } | ||
336 | |||
337 | int lastPos = tmp.LastIndexOf('/', tmp.Length - 2); | ||
338 | int prevPos = tmp.IndexOf('/'); | ||
339 | |||
340 | if((lastPos == prevPos) || (lastPos == -1)) | ||
341 | { | ||
342 | break; | ||
343 | } | ||
344 | |||
345 | tmp = tmp.Substring(0, lastPos + 1); | ||
346 | prefix += "../"; | ||
347 | } | ||
348 | |||
349 | return endPath; | ||
350 | } | ||
351 | |||
352 | /// <summary> | ||
353 | /// Resolves the path. | ||
354 | /// </summary> | ||
355 | /// <param name="path">The path.</param> | ||
356 | /// <returns></returns> | ||
357 | public static string ResolvePath(string path) | ||
358 | { | ||
359 | string tmpPath = NormalizePath(path); | ||
360 | if(tmpPath.Length < 1) | ||
361 | { | ||
362 | tmpPath = "."; | ||
363 | } | ||
364 | |||
365 | tmpPath = Path.GetFullPath(tmpPath); | ||
366 | if(!File.Exists(tmpPath) && !Directory.Exists(tmpPath)) | ||
367 | { | ||
368 | throw new ArgumentException("Path could not be resolved: " + tmpPath); | ||
369 | } | ||
370 | |||
371 | return tmpPath; | ||
372 | } | ||
373 | |||
374 | /// <summary> | ||
375 | /// Normalizes the path. | ||
376 | /// </summary> | ||
377 | /// <param name="path">The path.</param> | ||
378 | /// <param name="separatorCharacter">The separator character.</param> | ||
379 | /// <returns></returns> | ||
380 | public static string NormalizePath(string path, char separatorCharacter) | ||
381 | { | ||
382 | if(path == null || path == "" || path.Length < 1) | ||
383 | { | ||
384 | return ""; | ||
385 | } | ||
386 | |||
387 | string tmpPath = path.Replace('\\', '/'); | ||
388 | tmpPath = tmpPath.Replace('/', separatorCharacter); | ||
389 | return tmpPath; | ||
390 | } | ||
391 | |||
392 | /// <summary> | ||
393 | /// Normalizes the path. | ||
394 | /// </summary> | ||
395 | /// <param name="path">The path.</param> | ||
396 | /// <returns></returns> | ||
397 | public static string NormalizePath(string path) | ||
398 | { | ||
399 | return NormalizePath(path, Path.DirectorySeparatorChar); | ||
400 | } | ||
401 | |||
402 | /// <summary> | ||
403 | /// Ends the path. | ||
404 | /// </summary> | ||
405 | /// <param name="path">The path.</param> | ||
406 | /// <param name="separatorCharacter">The separator character.</param> | ||
407 | /// <returns></returns> | ||
408 | public static string EndPath(string path, char separatorCharacter) | ||
409 | { | ||
410 | if(path == null || path == "" || path.Length < 1) | ||
411 | { | ||
412 | return ""; | ||
413 | } | ||
414 | |||
415 | if(!path.EndsWith(separatorCharacter.ToString())) | ||
416 | { | ||
417 | return (path + separatorCharacter); | ||
418 | } | ||
419 | |||
420 | return path; | ||
421 | } | ||
422 | |||
423 | /// <summary> | ||
424 | /// Ends the path. | ||
425 | /// </summary> | ||
426 | /// <param name="path">The path.</param> | ||
427 | /// <returns></returns> | ||
428 | public static string EndPath(string path) | ||
429 | { | ||
430 | return EndPath(path, Path.DirectorySeparatorChar); | ||
431 | } | ||
432 | |||
433 | /// <summary> | ||
434 | /// Makes the file path. | ||
435 | /// </summary> | ||
436 | /// <param name="path">The path.</param> | ||
437 | /// <param name="name">The name.</param> | ||
438 | /// <param name="ext">The ext.</param> | ||
439 | /// <returns></returns> | ||
440 | public static string MakeFilePath(string path, string name, string ext) | ||
441 | { | ||
442 | string ret = EndPath(NormalizePath(path)); | ||
443 | |||
444 | if( name == null ) | ||
445 | { | ||
446 | throw new ArgumentNullException("name"); | ||
447 | } | ||
448 | |||
449 | ret += name; | ||
450 | if(!name.EndsWith("." + ext)) | ||
451 | { | ||
452 | ret += "." + ext; | ||
453 | } | ||
454 | |||
455 | //foreach(char c in Path.GetInvalidPathChars()) | ||
456 | //{ | ||
457 | // ret = ret.Replace(c, '_'); | ||
458 | //} | ||
459 | |||
460 | return ret; | ||
461 | } | ||
462 | |||
463 | /// <summary> | ||
464 | /// Makes the file path. | ||
465 | /// </summary> | ||
466 | /// <param name="path">The path.</param> | ||
467 | /// <param name="name">The name.</param> | ||
468 | /// <returns></returns> | ||
469 | public static string MakeFilePath(string path, string name) | ||
470 | { | ||
471 | string ret = EndPath(NormalizePath(path)); | ||
472 | |||
473 | if( name == null ) | ||
474 | { | ||
475 | throw new ArgumentNullException("name"); | ||
476 | } | ||
477 | |||
478 | ret += name; | ||
479 | |||
480 | //foreach (char c in Path.GetInvalidPathChars()) | ||
481 | //{ | ||
482 | // ret = ret.Replace(c, '_'); | ||
483 | //} | ||
484 | |||
485 | return ret; | ||
486 | } | ||
487 | |||
488 | /// <summary> | ||
489 | /// | ||
490 | /// </summary> | ||
491 | /// <param name="path"></param> | ||
492 | /// <returns></returns> | ||
493 | public static string MakeReferencePath(string path) | ||
494 | { | ||
495 | string ret = EndPath(NormalizePath(path)); | ||
496 | |||
497 | //foreach (char c in Path.GetInvalidPathChars()) | ||
498 | //{ | ||
499 | // ret = ret.Replace(c, '_'); | ||
500 | //} | ||
501 | |||
502 | return ret; | ||
503 | } | ||
504 | |||
505 | /// <summary> | ||
506 | /// Sets the current dir. | ||
507 | /// </summary> | ||
508 | /// <param name="path">The path.</param> | ||
509 | public static void SetCurrentDir(string path) | ||
510 | { | ||
511 | if( path == null ) | ||
512 | { | ||
513 | throw new ArgumentNullException("path"); | ||
514 | } | ||
515 | if(path.Length < 1) | ||
516 | { | ||
517 | return; | ||
518 | } | ||
519 | |||
520 | Environment.CurrentDirectory = path; | ||
521 | } | ||
522 | |||
523 | /// <summary> | ||
524 | /// Checks the type. | ||
525 | /// </summary> | ||
526 | /// <param name="typeToCheck">The type to check.</param> | ||
527 | /// <param name="attr">The attr.</param> | ||
528 | /// <param name="inter">The inter.</param> | ||
529 | /// <returns></returns> | ||
530 | public static object CheckType(Type typeToCheck, Type attr, Type inter) | ||
531 | { | ||
532 | if(typeToCheck == null || attr == null) | ||
533 | { | ||
534 | return null; | ||
535 | } | ||
536 | |||
537 | object[] attrs = typeToCheck.GetCustomAttributes(attr, false); | ||
538 | if(attrs == null || attrs.Length < 1) | ||
539 | { | ||
540 | return null; | ||
541 | } | ||
542 | if( inter == null ) | ||
543 | { | ||
544 | throw new ArgumentNullException("inter"); | ||
545 | } | ||
546 | |||
547 | if(typeToCheck.GetInterface(inter.FullName) == null) | ||
548 | { | ||
549 | return null; | ||
550 | } | ||
551 | |||
552 | return attrs[0]; | ||
553 | } | ||
554 | |||
555 | /* A bit of overhead for simple group parsing, there are problems with Regex in Mono | ||
556 | public static string ParseValue(string val) | ||
557 | { | ||
558 | if(val == null || val.Length < 1 || !CheckForOSVariables) | ||
559 | return val; | ||
560 | |||
561 | string tmp = val; | ||
562 | Match m = m_VarRegex.Match(val); | ||
563 | while(m.Success) | ||
564 | { | ||
565 | if(m.Groups["var"] == null) | ||
566 | continue; | ||
567 | |||
568 | Capture c = m.Groups["var"].Captures[0]; | ||
569 | if(c == null) | ||
570 | continue; | ||
571 | |||
572 | string var = c.Value; | ||
573 | string envVal = Environment.GetEnvironmentVariable(var); | ||
574 | if(envVal == null) | ||
575 | envVal = ""; | ||
576 | |||
577 | tmp = tmp.Replace("${" + var + "}", envVal); | ||
578 | m = m.NextMatch(); | ||
579 | } | ||
580 | |||
581 | return tmp; | ||
582 | }*/ | ||
583 | |||
584 | /// <summary> | ||
585 | /// Attributes the value. | ||
586 | /// </summary> | ||
587 | /// <param name="node">The node.</param> | ||
588 | /// <param name="attr">The attr.</param> | ||
589 | /// <param name="def">The def.</param> | ||
590 | /// <returns></returns> | ||
591 | public static string AttributeValue(XmlNode node, string attr, string def) | ||
592 | { | ||
593 | if( node == null ) | ||
594 | { | ||
595 | throw new ArgumentNullException("node"); | ||
596 | } | ||
597 | if(node.Attributes[attr] == null) | ||
598 | { | ||
599 | return def; | ||
600 | } | ||
601 | string val = node.Attributes[attr].Value; | ||
602 | if(!CheckForOSVariables) | ||
603 | { | ||
604 | return val; | ||
605 | } | ||
606 | |||
607 | return InterpolateForEnvironmentVariables(val); | ||
608 | } | ||
609 | |||
610 | /// <summary> | ||
611 | /// Parses the boolean. | ||
612 | /// </summary> | ||
613 | /// <param name="node">The node.</param> | ||
614 | /// <param name="attr">The attr.</param> | ||
615 | /// <param name="defaultValue">if set to <c>true</c> [default value].</param> | ||
616 | /// <returns></returns> | ||
617 | public static bool ParseBoolean(XmlNode node, string attr, bool defaultValue) | ||
618 | { | ||
619 | if( node == null ) | ||
620 | { | ||
621 | throw new ArgumentNullException("node"); | ||
622 | } | ||
623 | if(node.Attributes[attr] == null) | ||
624 | { | ||
625 | return defaultValue; | ||
626 | } | ||
627 | return bool.Parse(node.Attributes[attr].Value); | ||
628 | } | ||
629 | |||
630 | /// <summary> | ||
631 | /// Enums the attribute value. | ||
632 | /// </summary> | ||
633 | /// <param name="node">The node.</param> | ||
634 | /// <param name="attr">The attr.</param> | ||
635 | /// <param name="enumType">Type of the enum.</param> | ||
636 | /// <param name="def">The def.</param> | ||
637 | /// <returns></returns> | ||
638 | public static object EnumAttributeValue(XmlNode node, string attr, Type enumType, object def) | ||
639 | { | ||
640 | if( def == null ) | ||
641 | { | ||
642 | throw new ArgumentNullException("def"); | ||
643 | } | ||
644 | string val = AttributeValue(node, attr, def.ToString()); | ||
645 | return Enum.Parse(enumType, val, true); | ||
646 | } | ||
647 | |||
648 | /// <summary> | ||
649 | /// | ||
650 | /// </summary> | ||
651 | /// <param name="assemblyName"></param> | ||
652 | /// <param name="projectType"></param> | ||
653 | /// <returns></returns> | ||
654 | public static string AssemblyFullName(string assemblyName, ProjectType projectType) | ||
655 | { | ||
656 | return assemblyName + (projectType == ProjectType.Library ? ".dll" : ".exe"); | ||
657 | } | ||
658 | |||
659 | #endregion | ||
660 | } | ||
661 | } | ||
diff --git a/Prebuild/src/Core/Utilities/Log.cs b/Prebuild/src/Core/Utilities/Log.cs new file mode 100644 index 0000000..da2cc96 --- /dev/null +++ b/Prebuild/src/Core/Utilities/Log.cs | |||
@@ -0,0 +1,279 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.IO; | ||
37 | |||
38 | namespace Prebuild.Core.Utilities | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | public enum LogType | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// | ||
47 | /// </summary> | ||
48 | None, | ||
49 | /// <summary> | ||
50 | /// | ||
51 | /// </summary> | ||
52 | Info, | ||
53 | /// <summary> | ||
54 | /// | ||
55 | /// </summary> | ||
56 | Warning, | ||
57 | /// <summary> | ||
58 | /// | ||
59 | /// </summary> | ||
60 | Error | ||
61 | } | ||
62 | |||
63 | /// <summary> | ||
64 | /// | ||
65 | /// </summary> | ||
66 | [Flags] | ||
67 | public enum LogTargets | ||
68 | { | ||
69 | /// <summary> | ||
70 | /// | ||
71 | /// </summary> | ||
72 | None = 0, | ||
73 | /// <summary> | ||
74 | /// | ||
75 | /// </summary> | ||
76 | Null = 1, | ||
77 | /// <summary> | ||
78 | /// | ||
79 | /// </summary> | ||
80 | File = 2, | ||
81 | /// <summary> | ||
82 | /// | ||
83 | /// </summary> | ||
84 | Console = 4 | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// Summary description for Log. | ||
89 | /// </summary> | ||
90 | public class Log : IDisposable | ||
91 | { | ||
92 | #region Fields | ||
93 | |||
94 | private StreamWriter m_Writer; | ||
95 | private LogTargets m_Target = LogTargets.Null; | ||
96 | bool disposed; | ||
97 | |||
98 | #endregion | ||
99 | |||
100 | #region Constructors | ||
101 | |||
102 | /// <summary> | ||
103 | /// Initializes a new instance of the <see cref="Log"/> class. | ||
104 | /// </summary> | ||
105 | /// <param name="target">The target.</param> | ||
106 | /// <param name="fileName">Name of the file.</param> | ||
107 | public Log(LogTargets target, string fileName) | ||
108 | { | ||
109 | m_Target = target; | ||
110 | |||
111 | if((m_Target & LogTargets.File) != 0) | ||
112 | { | ||
113 | m_Writer = new StreamWriter(fileName, false); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | #endregion | ||
118 | |||
119 | #region Public Methods | ||
120 | |||
121 | /// <summary> | ||
122 | /// Writes this instance. | ||
123 | /// </summary> | ||
124 | public void Write() | ||
125 | { | ||
126 | Write(string.Empty); | ||
127 | } | ||
128 | |||
129 | /// <summary> | ||
130 | /// Writes the specified MSG. | ||
131 | /// </summary> | ||
132 | /// <param name="msg">The MSG.</param> | ||
133 | public void Write(string msg) | ||
134 | { | ||
135 | if((m_Target & LogTargets.Null) != 0) | ||
136 | { | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | if((m_Target & LogTargets.Console) != 0) | ||
141 | { | ||
142 | Console.WriteLine(msg); | ||
143 | } | ||
144 | if((m_Target & LogTargets.File) != 0 && m_Writer != null) | ||
145 | { | ||
146 | m_Writer.WriteLine(msg); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | /// <summary> | ||
151 | /// Writes the specified format. | ||
152 | /// </summary> | ||
153 | /// <param name="format">The format.</param> | ||
154 | /// <param name="args">The args.</param> | ||
155 | public void Write(string format, params object[] args) | ||
156 | { | ||
157 | Write(string.Format(format,args)); | ||
158 | } | ||
159 | |||
160 | /// <summary> | ||
161 | /// Writes the specified type. | ||
162 | /// </summary> | ||
163 | /// <param name="type">The type.</param> | ||
164 | /// <param name="format">The format.</param> | ||
165 | /// <param name="args">The args.</param> | ||
166 | public void Write(LogType type, string format, params object[] args) | ||
167 | { | ||
168 | if((m_Target & LogTargets.Null) != 0) | ||
169 | { | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | string str = ""; | ||
174 | switch(type) | ||
175 | { | ||
176 | case LogType.Info: | ||
177 | str = "[I] "; | ||
178 | break; | ||
179 | case LogType.Warning: | ||
180 | str = "[!] "; | ||
181 | break; | ||
182 | case LogType.Error: | ||
183 | str = "[X] "; | ||
184 | break; | ||
185 | } | ||
186 | |||
187 | Write(str + format,args); | ||
188 | } | ||
189 | |||
190 | /// <summary> | ||
191 | /// Writes the exception. | ||
192 | /// </summary> | ||
193 | /// <param name="type">The type.</param> | ||
194 | /// <param name="ex">The ex.</param> | ||
195 | public void WriteException(LogType type, Exception ex) | ||
196 | { | ||
197 | if(ex != null) | ||
198 | { | ||
199 | Write(type, ex.Message); | ||
200 | //#if DEBUG | ||
201 | m_Writer.WriteLine("Exception @{0} stack trace [[", ex.TargetSite.Name); | ||
202 | m_Writer.WriteLine(ex.StackTrace); | ||
203 | m_Writer.WriteLine("]]"); | ||
204 | //#endif | ||
205 | } | ||
206 | } | ||
207 | |||
208 | /// <summary> | ||
209 | /// Flushes this instance. | ||
210 | /// </summary> | ||
211 | public void Flush() | ||
212 | { | ||
213 | if(m_Writer != null) | ||
214 | { | ||
215 | m_Writer.Flush(); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | #endregion | ||
220 | |||
221 | #region IDisposable Members | ||
222 | |||
223 | /// <summary> | ||
224 | /// Performs application-defined tasks associated with freeing, releasing, or | ||
225 | /// resetting unmanaged resources. | ||
226 | /// </summary> | ||
227 | public void Dispose() | ||
228 | { | ||
229 | Dispose(true); | ||
230 | GC.SuppressFinalize(this); | ||
231 | } | ||
232 | |||
233 | /// <summary> | ||
234 | /// Dispose objects | ||
235 | /// </summary> | ||
236 | /// <param name="disposing"> | ||
237 | /// If true, it will dispose close the handle | ||
238 | /// </param> | ||
239 | /// <remarks> | ||
240 | /// Will dispose managed and unmanaged resources. | ||
241 | /// </remarks> | ||
242 | protected virtual void Dispose(bool disposing) | ||
243 | { | ||
244 | if (!this.disposed) | ||
245 | { | ||
246 | if (disposing) | ||
247 | { | ||
248 | if (m_Writer != null) | ||
249 | { | ||
250 | m_Writer.Close(); | ||
251 | m_Writer = null; | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | this.disposed = true; | ||
256 | } | ||
257 | |||
258 | /// <summary> | ||
259 | /// | ||
260 | /// </summary> | ||
261 | ~Log() | ||
262 | { | ||
263 | this.Dispose(false); | ||
264 | } | ||
265 | |||
266 | /// <summary> | ||
267 | /// Closes and destroys this object | ||
268 | /// </summary> | ||
269 | /// <remarks> | ||
270 | /// Same as Dispose(true) | ||
271 | /// </remarks> | ||
272 | public void Close() | ||
273 | { | ||
274 | Dispose(); | ||
275 | } | ||
276 | |||
277 | #endregion | ||
278 | } | ||
279 | } | ||
diff --git a/Prebuild/src/Core/WarningException.cs b/Prebuild/src/Core/WarningException.cs new file mode 100644 index 0000000..a200bdc --- /dev/null +++ b/Prebuild/src/Core/WarningException.cs | |||
@@ -0,0 +1,93 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
9 | and the following disclaimer. | ||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
11 | and the following disclaimer in the documentation and/or other materials provided with the | ||
12 | distribution. | ||
13 | * The name of the author may not be used to endorse or promote products derived from this software | ||
14 | without specific prior written permission. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-01-28 01:49:58 +0100 (lö, 28 jan 2006) $ | ||
31 | * $Revision: 71 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Runtime.Serialization; | ||
37 | |||
38 | namespace Prebuild.Core | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | [Serializable()] | ||
44 | public class WarningException : Exception | ||
45 | { | ||
46 | #region Constructors | ||
47 | |||
48 | /// <summary> | ||
49 | /// | ||
50 | /// </summary> | ||
51 | public WarningException() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | /// <summary> | ||
56 | /// | ||
57 | /// </summary> | ||
58 | /// <param name="format"></param> | ||
59 | /// <param name="args"></param> | ||
60 | public WarningException(string format, params object[] args) | ||
61 | : base(String.Format(format, args)) | ||
62 | { | ||
63 | } | ||
64 | |||
65 | /// <summary> | ||
66 | /// Exception with specified string | ||
67 | /// </summary> | ||
68 | /// <param name="message">Exception message</param> | ||
69 | public WarningException(string message): base(message) | ||
70 | { | ||
71 | } | ||
72 | |||
73 | /// <summary> | ||
74 | /// | ||
75 | /// </summary> | ||
76 | /// <param name="message"></param> | ||
77 | /// <param name="exception"></param> | ||
78 | public WarningException(string message, Exception exception) : base(message, exception) | ||
79 | { | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// | ||
84 | /// </summary> | ||
85 | /// <param name="info"></param> | ||
86 | /// <param name="context"></param> | ||
87 | protected WarningException(SerializationInfo info, StreamingContext context) : base( info, context ) | ||
88 | { | ||
89 | } | ||
90 | |||
91 | #endregion | ||
92 | } | ||
93 | } | ||