// 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 (laurent@clae.net) using System; 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 /// /// Gets the type of the project. /// /// /// The type of the project. /// public override ProjectType Type { get { return ProjectType.JSharp; } } /// /// Verifies whether the specified XML fragment represents a valid project /// that is supported by this . /// /// XML fragment representing the project file. /// /// The XML fragment is not supported by this . /// -or- /// The XML fragment does not represent a valid project (for this ). /// 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); } } /// /// Returns the Visual Studio product version of the specified project /// XML fragment. /// /// The document element of the project. /// /// The Visual Studio product version of the specified project XML /// fragment. /// /// /// The product version could not be determined. /// -or- /// The product version is not supported. /// protected override ProductVersion DetermineProductVersion(XmlElement docElement) { return GetProductVersion(docElement.SelectSingleNode("./VISUALJSHARP")); } /// /// Prepares the project for being built. /// /// The solution configuration that is built. /// /// Ensures the configuration-level object directory exists and ensures /// that none of the output files are marked read-only. /// protected override void Prepare(string solutionConfiguration) { // Visual J#.NET uses the \obj\ // 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 = (ConfigurationBase) BuildConfigurations[solutionConfiguration]; // ensure configuration-level object directory exists if (!config.ObjectDir.Exists) { config.ObjectDir.Create(); config.ObjectDir.Refresh(); } } /// /// Returns a for launching the compiler /// for this project. /// /// The configuration to build. /// The response file for the compiler. /// /// A for launching the compiler for /// this project. /// 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 /// /// Gets the default file extension of sources for this project. /// /// /// For J# projects, the default file extension is ".jsl". /// protected override string FileExtension { get { return ".jsl"; } } /// /// Returns the project location from the specified project XML fragment. /// /// XML fragment representing the project file. /// /// The project location of the specified project XML file. /// /// /// The project location could not be determined. /// -or- /// The project location is invalid. /// protected override ProjectLocation DetermineProjectLocation(XmlElement docElement) { return GetProjectLocation(docElement.SelectSingleNode("./VISUALJSHARP")); } #endregion Override implementation of ManagedProjectBase #region Public Static Methods /// /// Returns a value indicating whether the project represented by the /// specified XML fragment is supported by . /// /// XML fragment representing the project to check. /// /// if supports /// the specified project; otherwise, . /// /// /// /// A project is identified as as J# project, if the XML fragment at /// least has the following information: /// /// /// /// /// ... /// /// /// ]]> /// /// 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 } }