forked from nant/nant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSharpProject.cs
231 lines (203 loc) · 9.11 KB
/
JSharpProject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// NAnt - A .NET build tool
// Copyright (C) 2001-2004 Gerry Shaw
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Laurent Arnal ([email protected])
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Xml;
using NAnt.Core;
using NAnt.Core.Util;
using NAnt.VSNet.Tasks;
namespace NAnt.VSNet {
public class JSharpProject : ManagedProjectBase {
#region Public Instance Constructors
public JSharpProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) {
}
#endregion Public Instance Constructors
#region Override implementation of ProjectBase
/// <summary>
/// Gets the type of the project.
/// </summary>
/// <value>
/// The type of the project.
/// </value>
public override ProjectType Type {
get { return ProjectType.JSharp; }
}
/// <summary>
/// Verifies whether the specified XML fragment represents a valid project
/// that is supported by this <see cref="ProjectBase" />.
/// </summary>
/// <param name="docElement">XML fragment representing the project file.</param>
/// <exception cref="BuildException">
/// <para>The XML fragment is not supported by this <see cref="ProjectBase" />.</para>
/// <para>-or-</para>
/// <para>The XML fragment does not represent a valid project (for this <see cref="ProjectBase" />).</para>
/// </exception>
protected override void VerifyProjectXml(XmlElement docElement) {
if (!IsSupported(docElement)) {
throw new BuildException(string.Format(CultureInfo.InvariantCulture,
"Project '{0}' is not a valid J# project.", ProjectPath),
Location.UnknownLocation);
}
}
/// <summary>
/// Returns the Visual Studio product version of the specified project
/// XML fragment.
/// </summary>
/// <param name="docElement">The document element of the project.</param>
/// <returns>
/// The Visual Studio product version of the specified project XML
/// fragment.
/// </returns>
/// <exception cref="BuildException">
/// <para>The product version could not be determined.</para>
/// <para>-or-</para>
/// <para>The product version is not supported.</para>
/// </exception>
protected override ProductVersion DetermineProductVersion(XmlElement docElement) {
return GetProductVersion(docElement.SelectSingleNode("./VISUALJSHARP"));
}
/// <summary>
/// Prepares the project for being built.
/// </summary>
/// <param name="solutionConfiguration">The solution configuration that is built.</param>
/// <remarks>
/// Ensures the configuration-level object directory exists and ensures
/// that none of the output files are marked read-only.
/// </remarks>
protected override void Prepare(Configuration solutionConfiguration) {
// Visual J#.NET uses the <project dir>\obj\<configuration>
// as working directory, so we should do the same to make
// sure relative paths are resolved correctly
// (eg. AssemblyKeyFile attribute)
// obtain project configuration (corresponding with solution configuration)
ConfigurationBase config = BuildConfigurations[solutionConfiguration];
// ensure configuration-level object directory exists
if (!config.ObjectDir.Exists) {
config.ObjectDir.Create();
config.ObjectDir.Refresh();
}
}
/// <summary>
/// Returns a <see cref="ProcessStartInfo" /> for launching the compiler
/// for this project.
/// </summary>
/// <param name="config">The configuration to build.</param>
/// <param name="responseFile">The response file for the compiler.</param>
/// <returns>
/// A <see cref="ProcessStartInfo" /> for launching the compiler for
/// this project.
/// </returns>
protected override ProcessStartInfo GetProcessStartInfo(ConfigurationBase config, string responseFile) {
ProcessStartInfo psi = new ProcessStartInfo(FileUtils.CombinePaths(SolutionTask.
Project.TargetFramework.FrameworkDirectory.FullName, "vjc.exe"),
"@\"" + responseFile + "\"");
// to resolve the path to the file specified in the AssemblyKeyFile
// attribute, the command line compilers try to resolve that relative
// path using the output directory and the current directory
//
// VS.NET compiles assembly to the intermediate output directory and
// uses the solution directory as current directory
if (SolutionTask.SolutionFile != null) {
psi.WorkingDirectory = Path.GetDirectoryName(SolutionTask.SolutionFile.FullName);
} else {
psi.WorkingDirectory = ProjectDirectory.FullName;
}
return psi;
}
#endregion Override implementation of ProjectBase
#region Override implementation of ManagedProjectBase
/// <summary>
/// Gets the default file extension of sources for this project.
/// </summary>
/// <value>
/// For J# projects, the default file extension is ".jsl".
/// </value>
protected override string FileExtension {
get { return ".jsl"; }
}
/// <summary>
/// Returns the project location from the specified project XML fragment.
/// </summary>
/// <param name="docElement">XML fragment representing the project file.</param>
/// <returns>
/// The project location of the specified project XML file.
/// </returns>
/// <exception cref="BuildException">
/// <para>The project location could not be determined.</para>
/// <para>-or-</para>
/// <para>The project location is invalid.</para>
/// </exception>
protected override ProjectLocation DetermineProjectLocation(XmlElement docElement) {
return GetProjectLocation(docElement.SelectSingleNode("./VISUALJSHARP"));
}
#endregion Override implementation of ManagedProjectBase
#region Public Static Methods
/// <summary>
/// Returns a value indicating whether the project represented by the
/// specified XML fragment is supported by <see cref="JSharpProject" />.
/// </summary>
/// <param name="docElement">XML fragment representing the project to check.</param>
/// <returns>
/// <see langword="true" /> if <see cref="CSharpProject" /> supports
/// the specified project; otherwise, <see langword="false" />.
/// </returns>
/// <remarks>
/// <para>
/// A project is identified as as J# project, if the XML fragment at
/// least has the following information:
/// </para>
/// <code>
/// <![CDATA[
/// <VisualStudioProject>
/// <JSHARP
/// ProductVersion="..."
/// ....
/// >
/// ...
/// </JSHARP>
/// </VisualStudioProject>
/// ]]>
/// </code>
/// </remarks>
public static bool IsSupported(XmlElement docElement) {
if (docElement == null) {
return false;
}
if (docElement.Name != "VisualStudioProject") {
return false;
}
XmlNode projectNode = docElement.SelectSingleNode("./VISUALJSHARP");
if (projectNode == null) {
return false;
}
try {
GetProductVersion(projectNode);
// no need to perform version check here as this is done in
// GetProductVersion
} catch {
// product version could not be determined or is not supported
return false;
}
return true;
}
#endregion Public Static Methods
}
}