diff --git a/bootstrap/prebuild.dll b/bootstrap/prebuild.dll index 45d3fbc..3ef9a44 100644 Binary files a/bootstrap/prebuild.dll and b/bootstrap/prebuild.dll differ diff --git a/source/Prebuild/Core/Kernel.cs b/source/Prebuild/Core/Kernel.cs index af9de07..b1b6ad1 100644 --- a/source/Prebuild/Core/Kernel.cs +++ b/source/Prebuild/Core/Kernel.cs @@ -42,10 +42,12 @@ POSSIBILITY OF SUCH DAMAGE. using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Reflection; using System.Xml; using System.Xml.Schema; +using System.Xml.Serialization; using Prebuild.Core.Attributes; using Prebuild.Core.Interfaces; using Prebuild.Core.Nodes; @@ -94,10 +96,10 @@ public class Kernel : IDisposable private readonly Dictionary m_Nodes = new(); - private string m_Target; + private string m_Target = "vs2022"; private bool cmdlineTargetFramework; private FrameworkVersion m_TargetFramework; //Overrides all project settings - public string ForcedConditionals { get; private set; } + public string ForcedConditionals { get; internal set; } private string m_Clean; private string[] m_RemoveDirectories; @@ -113,7 +115,7 @@ public class Kernel : IDisposable /// Gets a value indicating whether [pause after finish]. /// /// true if [pause after finish]; otherwise, false. - public bool PauseAfterFinish { get; private set; } + public bool PauseAfterFinish { get; internal set; } /// /// Gets the instance. @@ -132,7 +134,7 @@ public class Kernel : IDisposable /// Gets the command line. /// /// The command line. - public CommandLineCollection CommandLine { get; private set; } + public CommandLineCollection CommandLine { get; internal set; } /// /// Gets the targets. @@ -144,13 +146,13 @@ public class Kernel : IDisposable /// Gets the log. /// /// The log. - public Log Log { get; private set; } + public Log Log { get; internal set; } /// /// Gets the current working directory. /// /// The current working directory. - public CurrentDirectory CurrentWorkingDirectory { get; private set; } + public CurrentDirectory CurrentWorkingDirectory { get; internal set; } /// /// Gets the solutions. @@ -163,7 +165,7 @@ public class Kernel : IDisposable /// being processed /// /// The XmlDocument object - public XmlDocument CurrentDoc { get; private set; } + public XmlDocument CurrentDoc { get; internal set; } #endregion @@ -270,7 +272,8 @@ public class Kernel : IDisposable Log.Write("John Hurliman (john.hurliman@intel.com),"); Log.Write("WhiteCore build 2015 (greythane@gmail.com),"); Log.Write("OpenSimulator build 2017 Ubit Umarov,"); - Log.Write(""); + Log.Write("Aria's Creations 2023 - Tara Piccari"); + Log.Write(); Log.Write("See 'prebuild /usage' for help"); Log.Write(); } @@ -646,6 +649,63 @@ public class Kernel : IDisposable var file = "./prebuild.xml"; if (CommandLine.WasPassed("file")) file = CommandLine["file"]; + if(CommandLine.WasPassed("init")) + { + Log.Write("Initializing a skeleton Prebuild.xml file"); + // Initialize a new Prebuild file + // Write out a dummy file with a Solution that consists of a dummy project. + + XmlDocument doc = new XmlDocument(); + XmlElement elem = doc.CreateElement("Prebuild"); + + var ver = doc.CreateAttribute("version"); + ver.InnerText = "1.10"; + elem.Attributes.Append(ver); + + var ns = doc.CreateAttribute("xmlns"); + ns.InnerText = "http://dnpb.sourceforge.net/schemas/prebuild-1.10.xsd"; + elem.Attributes.Append(ns); + + doc.AppendChild(elem); + + SolutionNode sol = new SolutionNode(); + sol.Name = "Example"; + sol.Version = "1.0"; + sol.DefaultFramework = FrameworkVersion.net7_0; + + ProjectNode proj = new ProjectNode(); + proj.Name = "Hello World"; + proj.Path = "source/example"; + var Opts = new OptionsNode(); + Opts.OutputPath = "../../bin/"; + + ConfigurationNode debug = new ConfigurationNode(); + debug.Name = "Debug"; + debug.Options = Opts; + + ConfigurationNode release = new ConfigurationNode(); + release.Name = "Release"; + release.Options = Opts; + + proj.ConfigurationsTable.Add("Debug", debug); + proj.ConfigurationsTable.Add("Release", release); + + + + sol.ProjectsTable.Add(proj.Name, proj); + + sol.Write(doc, elem); + + + using (FileStream fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + doc.Save(fs); + } + + Log.Write("Initialization completed"); + return; + } + ProcessFile(file); var target = m_Target != null ? m_Target.ToLower() : m_Clean.ToLower(); diff --git a/source/Prebuild/Core/Nodes/AuthorNode.cs b/source/Prebuild/Core/Nodes/AuthorNode.cs index 5fc8ca3..7739c10 100644 --- a/source/Prebuild/Core/Nodes/AuthorNode.cs +++ b/source/Prebuild/Core/Nodes/AuthorNode.cs @@ -27,6 +27,7 @@ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY O using System; using System.Xml; +using System.Xml.Linq; using Prebuild.Core.Attributes; using Prebuild.Core.Utilities; @@ -47,7 +48,7 @@ public class AuthorNode : DataNode /// Gets the signature. /// /// The signature. - public string Signature { get; private set; } + public string Signature { get; internal set; } #endregion @@ -67,5 +68,13 @@ public class AuthorNode : DataNode Signature = Signature.Trim(); } + public override void Write(XmlDocument doc, XmlElement current) + { + + XmlElement elem = doc.CreateElement("Author"); + elem.InnerText = Signature; + current.AppendChild(elem); + } + #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/CleanFilesNode.cs b/source/Prebuild/Core/Nodes/CleanFilesNode.cs index 6e3100b..e84bf9b 100644 --- a/source/Prebuild/Core/Nodes/CleanFilesNode.cs +++ b/source/Prebuild/Core/Nodes/CleanFilesNode.cs @@ -45,7 +45,7 @@ public class CleanFilesNode : DataNode /// Gets the signature. /// /// The signature. - public string Pattern { get; private set; } + public string Pattern { get; internal set; } #endregion @@ -60,9 +60,18 @@ public class CleanFilesNode : DataNode if (node == null) throw new ArgumentNullException("node"); Pattern = Helper.AttributeValue(node, "pattern", string.Empty); - ; + Pattern = Pattern.Trim(); } + + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement Clean = doc.CreateElement("CleanFiles"); + Clean.InnerText = Pattern; + + current.AppendChild (Clean); + } + #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/CleanupNode.cs b/source/Prebuild/Core/Nodes/CleanupNode.cs index 294dfe1..676cae2 100644 --- a/source/Prebuild/Core/Nodes/CleanupNode.cs +++ b/source/Prebuild/Core/Nodes/CleanupNode.cs @@ -66,5 +66,15 @@ public class CleanupNode : DataNode } } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("Cleanup"); + foreach(CleanFilesNode n in CleanFiles) + { + n.Write(doc, main); + } + current.AppendChild(main); + } + #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/ConfigurationNode.cs b/source/Prebuild/Core/Nodes/ConfigurationNode.cs index b6753c7..5c2390d 100644 --- a/source/Prebuild/Core/Nodes/ConfigurationNode.cs +++ b/source/Prebuild/Core/Nodes/ConfigurationNode.cs @@ -133,7 +133,7 @@ public class ConfigurationNode : DataNode, ICloneable, IComparable /// Gets the name. /// /// The name. - public string Name { get; private set; } = "unknown"; + public string Name { get; internal set; } = "unknown"; /// /// Gets the name and platform for the configuration. @@ -187,5 +187,17 @@ public class ConfigurationNode : DataNode, ICloneable, IComparable Options.CopyTo(conf.Options); } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("Configuration"); + main.SetAttribute("name", Name); + main.SetAttribute("platform", Platform); + + + Options.Write(doc, main); + + current.AppendChild(main); + } + #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/DataNode.cs b/source/Prebuild/Core/Nodes/DataNode.cs index e4d16fc..b97d2f6 100644 --- a/source/Prebuild/Core/Nodes/DataNode.cs +++ b/source/Prebuild/Core/Nodes/DataNode.cs @@ -27,6 +27,7 @@ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY O using System.IO; using System.Xml; +using System.Xml.Serialization; using Prebuild.Core.Interfaces; namespace Prebuild.Core.Nodes; @@ -57,6 +58,16 @@ public abstract class DataNode : IDataNode { } + /// + /// Serializes to the specified node + /// + /// The document + /// The current node + public virtual void Write(XmlDocument doc, XmlElement current) { + + } + + public BuildAction GetBuildActionByFileName(string fileName) { var extension = Path.GetExtension(fileName).ToLower(); diff --git a/source/Prebuild/Core/Nodes/DatabaseProjectNode.cs b/source/Prebuild/Core/Nodes/DatabaseProjectNode.cs index 7ae6a01..f7d889a 100644 --- a/source/Prebuild/Core/Nodes/DatabaseProjectNode.cs +++ b/source/Prebuild/Core/Nodes/DatabaseProjectNode.cs @@ -14,11 +14,11 @@ public class DatabaseProjectNode : DataNode public Guid Guid { get; } = Guid.NewGuid(); - public string Name { get; private set; } + public string Name { get; internal set; } - public string Path { get; private set; } + public string Path { get; internal set; } - public string FullPath { get; private set; } + public string FullPath { get; internal set; } public IEnumerable References => references; @@ -64,4 +64,24 @@ public class DatabaseProjectNode : DataNode base.Parse(node); } + + public override void Write(XmlDocument doc, XmlElement current) + { + + XmlElement main = doc.CreateElement("DatabaseProject"); + main.SetAttribute("name", Name); + main.SetAttribute("path", Path); + + + foreach(AuthorNode author in authors) + { + author.Write(doc, main); + } + foreach(DatabaseReferenceNode databaseReference in references) + { + databaseReference.Write(doc, main); + } + + current.AppendChild(main); + } } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/DatabaseReferenceNode.cs b/source/Prebuild/Core/Nodes/DatabaseReferenceNode.cs index a61c0db..9a823a2 100644 --- a/source/Prebuild/Core/Nodes/DatabaseReferenceNode.cs +++ b/source/Prebuild/Core/Nodes/DatabaseReferenceNode.cs @@ -8,11 +8,11 @@ namespace Prebuild.Core.Nodes; [DataNode("DatabaseReference")] public class DatabaseReferenceNode : DataNode { - public string Name { get; private set; } + public string Name { get; internal set; } - public Guid ProviderId { get; private set; } + public Guid ProviderId { get; internal set; } - public string ConnectionString { get; private set; } + public string ConnectionString { get; internal set; } public override void Parse(XmlNode node) { @@ -25,19 +25,19 @@ public class DatabaseReferenceNode : DataNode // digitaljeebus: pulled from HKLM\SOFTWARE\Microsoft\VisualStudio\9.0\DataProviders\* // Not sure if these will help other operating systems, or if there's a better way. case "Microsoft.SqlServerCe.Client.3.5": - ProviderId = new Guid("7C602B5B-ACCB-4acd-9DC0-CA66388C1533"); + ProviderId = new Guid(DatabaseProviders.SqlServerCe35); break; case "System.Data.OleDb": - ProviderId = new Guid("7F041D59-D76A-44ed-9AA2-FBF6B0548B80"); + ProviderId = new Guid(DatabaseProviders.OleDb); break; case "System.Data.OracleClient": - ProviderId = new Guid("8F5C5018-AE09-42cf-B2CC-2CCCC7CFC2BB"); + ProviderId = new Guid(DatabaseProviders.OracleClient); break; case "System.Data.SqlClient": - ProviderId = new Guid("91510608-8809-4020-8897-FBA057E22D54"); + ProviderId = new Guid(DatabaseProviders.SqlClient); break; case "System.Data.Odbc": - ProviderId = new Guid("C3D4F4CE-2C48-4381-B4D6-34FA50C51C86"); + ProviderId = new Guid(DatabaseProviders.Odbc); break; default: @@ -51,4 +51,70 @@ public class DatabaseReferenceNode : DataNode base.Parse(node); } + + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("DatabaseReference"); + main.SetAttribute("name", Name); + + string provider = ""; + string providerId = ""; + + + switch (ProviderId.ToString()) + { + case DatabaseProviders.Odbc: + { + provider = "System.Data.Odbc"; + break; + } + case DatabaseProviders.OracleClient: + { + provider = "System.Data.OracleClient"; + break; + } + case DatabaseProviders.SqlClient: + { + provider = "System.Data.SqlClient"; + break; + } + case DatabaseProviders.OleDb: + { + provider = "System.Data.OleDb"; + break; + } + case DatabaseProviders.SqlServerCe35: + { + provider = "Microsoft.SqlServerCe.Client.3.5"; + break; + } + default: + { + providerId = ProviderId.ToString(); + provider = null; + break; + } + } + if(provider!= null) + main.SetAttribute("providerName", provider); + else + { + main.SetAttribute("providerId", providerId); + } + + var conn = doc.CreateAttribute("connectionString"); + conn.InnerText = ConnectionString; + main.Attributes.Append(conn); + + current.AppendChild(main); + } +} + +public class DatabaseProviders +{ + public const string SqlServerCe35 = ("7C602B5B-ACCB-4acd-9DC0-CA66388C1533"); + public const string OleDb = ("7F041D59-D76A-44ed-9AA2-FBF6B0548B80"); + public const string OracleClient = ("8F5C5018-AE09-42cf-B2CC-2CCCC7CFC2BB"); + public const string SqlClient = ("91510608-8809-4020-8897-FBA057E22D54"); + public const string Odbc = ("C3D4F4CE-2C48-4381-B4D6-34FA50C51C86"); } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/DescriptionNode.cs b/source/Prebuild/Core/Nodes/DescriptionNode.cs index 616beb1..66d6a8e 100644 --- a/source/Prebuild/Core/Nodes/DescriptionNode.cs +++ b/source/Prebuild/Core/Nodes/DescriptionNode.cs @@ -48,7 +48,7 @@ public class DescriptionNode : DataNode /// Gets the description Value. /// /// The description Value. - public string Value { get; private set; } + public string Value { get; internal set; } #endregion @@ -68,5 +68,13 @@ public class DescriptionNode : DataNode Value = Value.Trim(); } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("Description"); + main.InnerText = Value; + + current.AppendChild(main); + } + #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/ExcludeNode.cs b/source/Prebuild/Core/Nodes/ExcludeNode.cs index 0a27214..90d5f54 100644 --- a/source/Prebuild/Core/Nodes/ExcludeNode.cs +++ b/source/Prebuild/Core/Nodes/ExcludeNode.cs @@ -49,7 +49,18 @@ public class ExcludeNode : DataNode public override void Parse(XmlNode node) { Name = Helper.AttributeValue(node, "name", Name); - Name = Helper.AttributeValue(node, "pattern", Name); + Pattern = Helper.AttributeValue(node, "pattern", Pattern); + } + + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("Exclude"); + if(Name != null && Name!= "") + main.SetAttribute("name", Name); + else + main.SetAttribute("pattern", Pattern); + + current.AppendChild(main); } #endregion @@ -60,13 +71,14 @@ public class ExcludeNode : DataNode /// Gets the name. /// /// The name. - public string Name { get; private set; } = ""; + public string Name { get; internal set; } = ""; /// /// Gets the pattern. /// /// The pattern. - public string Pattern => Name; + public string Pattern { get; internal set; } = ""; + #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/FileNode.cs b/source/Prebuild/Core/Nodes/FileNode.cs index b761b78..0f98a8d 100644 --- a/source/Prebuild/Core/Nodes/FileNode.cs +++ b/source/Prebuild/Core/Nodes/FileNode.cs @@ -155,6 +155,21 @@ public class FileNode : DataNode } } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("File"); + main.SetAttribute("buildAction", BuildAction.ToString()); + main.SetAttribute("subType", SubType.ToString()); + main.SetAttribute("resourceName", ResourceName); + main.SetAttribute("link", IsLink ? bool.TrueString : bool.FalseString); + main.SetAttribute("linkPath", LinkPath); + main.SetAttribute("copyToOutput", CopyToOutput.ToString()); + main.SetAttribute("preservePath", PreservePath ? bool.TrueString : bool.FalseString); + main.InnerText = Path; + + current.AppendChild(main); + } + #endregion #region Fields @@ -168,11 +183,11 @@ public class FileNode : DataNode /// /// - public string Path { get; private set; } + public string Path { get; internal set; } /// /// - public string ResourceName { get; private set; } = ""; + public string ResourceName { get; internal set; } = ""; /// /// @@ -186,11 +201,11 @@ public class FileNode : DataNode } } - public CopyToOutput CopyToOutput { get; private set; } = CopyToOutput.Never; + public CopyToOutput CopyToOutput { get; internal set; } = CopyToOutput.Never; - public bool IsLink { get; private set; } + public bool IsLink { get; internal set; } - public string LinkPath { get; private set; } = string.Empty; + public string LinkPath { get; internal set; } = string.Empty; /// /// @@ -206,13 +221,13 @@ public class FileNode : DataNode /// /// - public bool IsValid { get; private set; } + public bool IsValid { get; internal set; } /// /// /// /// - public bool PreservePath { get; private set; } + public bool PreservePath { get; internal set; } #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/FilesNode.cs b/source/Prebuild/Core/Nodes/FilesNode.cs index 5176bf2..456a33c 100644 --- a/source/Prebuild/Core/Nodes/FilesNode.cs +++ b/source/Prebuild/Core/Nodes/FilesNode.cs @@ -40,16 +40,9 @@ public class FilesNode : DataNode { #region Fields - private readonly List m_Files = new(); - private readonly Dictionary m_BuildActions = new(); - private readonly Dictionary m_SubTypes = new(); - private readonly Dictionary m_ResourceNames = new(); - private readonly Dictionary m_CopyToOutputs = new(); - private readonly Dictionary m_Links = new(); - private readonly Dictionary m_LinkPaths = new(); - private readonly Dictionary m_PreservePaths = new(); - private readonly Dictionary m_DestinationPath = new(); - private readonly NameValueCollection m_CopyFiles = new(); + + private readonly Dictionary m_Files = new(); + private readonly Dictionary m_Matches = new(); #endregion @@ -57,9 +50,37 @@ public class FilesNode : DataNode public int Count => m_Files.Count; - public string[] Destinations => m_CopyFiles.AllKeys; + public int CopyFiles + { + get + { + int cur = 0; + foreach (var item in m_Files) + { + if(item.Value.BuildAction == BuildAction.Copy) cur++; + } + foreach(var item in m_Matches) + { + if(item.Value.BuildAction == BuildAction.Copy) cur++; + } - public int CopyFiles => m_CopyFiles.Count; + return cur; + } + } + + public string[] Destinations + { + get + { + List dests = new(); + foreach(var item in m_Matches) + { + dests.Add(item.Value.DestinationPath); + } + + return dests.ToArray(); + } + } #endregion @@ -67,64 +88,84 @@ public class FilesNode : DataNode public BuildAction GetBuildAction(string file) { - if (!m_BuildActions.ContainsKey(file)) return BuildAction.Compile; - - return m_BuildActions[file]; + if(m_Files.ContainsKey(file)) + { + return m_Files[file].BuildAction; + } + if(m_Matches.ContainsKey(file)) + { + return (BuildAction)m_Matches[file].BuildAction; + } + return BuildAction.Compile; } public string GetDestinationPath(string file) { - if (!m_DestinationPath.ContainsKey(file)) return null; - return m_DestinationPath[file]; + if (!m_Matches.ContainsKey(file)) return null; + return m_Matches[file].DestinationPath; } public string[] SourceFiles(string dest) { - return m_CopyFiles.GetValues(dest); + List files = new(); + foreach(MatchNode node in m_Matches.Values) + { + if (node.DestinationPath.Equals(dest)) + { + files.AddRange(node.Files); + } + } + return files.ToArray(); } public CopyToOutput GetCopyToOutput(string file) { - if (!m_CopyToOutputs.ContainsKey(file)) return CopyToOutput.Never; - return m_CopyToOutputs[file]; + if (m_Files.ContainsKey(file)) return m_Files[file].CopyToOutput; + if(m_Matches.ContainsKey(file))return m_Matches[file].CopyToOutput; + return CopyToOutput.Never; } public bool GetIsLink(string file) { - if (!m_Links.ContainsKey(file)) return false; - return m_Links[file]; + if (m_Files.ContainsKey(file)) return m_Files[file].IsLink; + if (m_Matches.ContainsKey(file)) return m_Matches[file].IsLink; + return false; } public bool Contains(string file) { - return m_Files.Contains(file); + return m_Files.ContainsKey(file) || m_Matches.ContainsKey(file); } public string GetLinkPath(string file) { - if (!m_LinkPaths.ContainsKey(file)) return string.Empty; - return m_LinkPaths[file]; + if (m_Files.ContainsKey(file)) return m_Files[file].LinkPath; + if (m_Matches.ContainsKey(file)) return m_Matches[file].LinkPath; + return string.Empty; } public SubType GetSubType(string file) { - if (!m_SubTypes.ContainsKey(file)) return SubType.Code; + if (m_Files.ContainsKey(file)) return m_Files[file].SubType; + if (m_Matches.ContainsKey(file)) return (SubType)m_Matches[file].SubType; - return m_SubTypes[file]; + return SubType.Code; } public string GetResourceName(string file) { - if (!m_ResourceNames.ContainsKey(file)) return string.Empty; + if (m_Files.ContainsKey(file)) return m_Files[file].ResourceName; + if (m_Matches.ContainsKey(file)) return m_Matches[file].ResourceName; - return m_ResourceNames[file]; + return string.Empty; } public bool GetPreservePath(string file) { - if (!m_PreservePaths.ContainsKey(file)) return false; + if (m_Files.ContainsKey(file)) return m_Files[file].PreservePath; + if (m_Matches.ContainsKey(file)) return m_Matches[file].PreservePath; - return m_PreservePaths[file]; + return false; } public override void Parse(XmlNode node) @@ -133,60 +174,51 @@ public class FilesNode : DataNode foreach (XmlNode child in node.ChildNodes) { var dataNode = Kernel.Instance.ParseNode(child, this); - if (dataNode is FileNode) + if (dataNode is FileNode fn) { - var fileNode = (FileNode)dataNode; - if (fileNode.IsValid) - if (!m_Files.Contains(fileNode.Path)) + if (fn.IsValid) + if (!m_Files.ContainsKey(fn.Path)) { - m_Files.Add(fileNode.Path); - m_BuildActions[fileNode.Path] = fileNode.BuildAction; - m_SubTypes[fileNode.Path] = fileNode.SubType; - m_ResourceNames[fileNode.Path] = fileNode.ResourceName; - m_PreservePaths[fileNode.Path] = fileNode.PreservePath; - m_Links[fileNode.Path] = fileNode.IsLink; - m_LinkPaths[fileNode.Path] = fileNode.LinkPath; - m_CopyToOutputs[fileNode.Path] = fileNode.CopyToOutput; + m_Files.Add(fn.Path, fn); } } - else if (dataNode is MatchNode) + else if (dataNode is MatchNode mn) { - foreach (var file in ((MatchNode)dataNode).Files) + foreach (var file in mn.Files) { - var matchNode = (MatchNode)dataNode; - if (!m_Files.Contains(file)) - { - m_Files.Add(file); - if (matchNode.BuildAction == null) - m_BuildActions[file] = GetBuildActionByFileName(file); - else - m_BuildActions[file] = matchNode.BuildAction.Value; - - if (matchNode.BuildAction == BuildAction.Copy) - { - m_CopyFiles.Add(matchNode.DestinationPath, file); - m_DestinationPath[file] = matchNode.DestinationPath; - } - - m_SubTypes[file] = matchNode.SubType == null - ? GetSubTypeByFileName(file) - : matchNode.SubType.Value; - m_ResourceNames[file] = matchNode.ResourceName; - m_PreservePaths[file] = matchNode.PreservePath; - m_Links[file] = matchNode.IsLink; - m_LinkPaths[file] = matchNode.LinkPath; - m_CopyToOutputs[file] = matchNode.CopyToOutput; - } + m_Matches.Add(file, mn); + } } } } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("Files"); + foreach(FileNode fi in m_Files.Values) + { + fi.Write(doc, main); + } + + foreach(MatchNode mn in m_Matches.Values) + { + mn.Write(doc, main); + } + + + current.AppendChild(main); + } + // TODO: Check in to why StringCollection's enumerator doesn't implement // IEnumerator? public IEnumerator GetEnumerator() { - return m_Files.GetEnumerator(); + List concat = new(); + concat.AddRange(m_Files.Keys); + concat.AddRange(m_Matches.Keys); + + return concat.GetEnumerator(); } #endregion diff --git a/source/Prebuild/Core/Nodes/InternalsNode.cs b/source/Prebuild/Core/Nodes/InternalsNode.cs index 530d978..0d21cf7 100644 --- a/source/Prebuild/Core/Nodes/InternalsNode.cs +++ b/source/Prebuild/Core/Nodes/InternalsNode.cs @@ -12,7 +12,7 @@ namespace Prebuild.Core.Nodes [DataNode("InternalsVisibleTo")] public class InternalsNode : DataNode { - public string Name { get; private set; } + public string Name { get; internal set; } #region Methods public override void Parse(XmlNode node) @@ -20,6 +20,14 @@ namespace Prebuild.Core.Nodes base.Parse(node); Name = Helper.AttributeValue(node, "name", ""); } + + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("InternalsVisibleTo"); + main.SetAttribute("name", Name); + + current.AppendChild(main); + } #endregion } } diff --git a/source/Prebuild/Core/Nodes/MatchNode.cs b/source/Prebuild/Core/Nodes/MatchNode.cs index 6020c36..46a82f5 100644 --- a/source/Prebuild/Core/Nodes/MatchNode.cs +++ b/source/Prebuild/Core/Nodes/MatchNode.cs @@ -171,12 +171,12 @@ public class MatchNode : DataNode public override void Parse(XmlNode node) { if (node == null) throw new ArgumentNullException("node"); - var path = Helper.AttributeValue(node, "path", "."); - var pattern = Helper.AttributeValue(node, "pattern", "*"); - var destination = Helper.AttributeValue(node, "destination", string.Empty); - var recurse = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false")); - var useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false")); - var buildAction = Helper.AttributeValue(node, "buildAction", string.Empty); + path = Helper.AttributeValue(node, "path", "."); + pattern = Helper.AttributeValue(node, "pattern", "*"); + destination = Helper.AttributeValue(node, "destination", string.Empty); + recurse = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "recurse", "false")); + useRegex = (bool)Helper.TranslateValue(typeof(bool), Helper.AttributeValue(node, "useRegex", "false")); + buildAction = Helper.AttributeValue(node, "buildAction", string.Empty); if (buildAction != string.Empty) BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction); @@ -242,6 +242,33 @@ public class MatchNode : DataNode m_Regex = null; } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("Match"); + + main.SetAttribute("path", path); + main.SetAttribute("pattern", pattern); + main.SetAttribute("destination", destination); + main.SetAttribute("recurse", recurse ? bool.TrueString : bool.FalseString); + main.SetAttribute("useRegex", useRegex ? bool.TrueString : bool.FalseString); + main.SetAttribute("buildAction", buildAction); + main.SetAttribute("resourceName", ResourceName); + main.SetAttribute("copyToOutput", CopyToOutput.ToString()); + main.SetAttribute("link", IsLink ? bool.TrueString : bool.FalseString); + main.SetAttribute("linkPath", LinkPath); + main.SetAttribute("preservePath", PreservePath ? bool.TrueString : bool.FalseString); + + + foreach(ExcludeNode exclude in m_Exclusions) + { + exclude.Write(doc, main); + } + + + + current.AppendChild(main); + } + #endregion #region Fields @@ -250,6 +277,13 @@ public class MatchNode : DataNode private Regex m_Regex; private readonly List m_Exclusions = new(); + private string path; + private string pattern; + private string destination; + private bool recurse; + private bool useRegex; + private string buildAction; + #endregion #region Properties @@ -260,25 +294,25 @@ public class MatchNode : DataNode /// /// - public BuildAction? BuildAction { get; private set; } + public BuildAction? BuildAction { get; internal set; } - public string DestinationPath { get; private set; } = ""; + public string DestinationPath { get; internal set; } = ""; /// /// public SubType? SubType { get; } - public CopyToOutput CopyToOutput { get; private set; } + public CopyToOutput CopyToOutput { get; internal set; } - public bool IsLink { get; private set; } + public bool IsLink { get; internal set; } - public string LinkPath { get; private set; } + public string LinkPath { get; internal set; } /// /// - public string ResourceName { get; private set; } = ""; + public string ResourceName { get; internal set; } = ""; - public bool PreservePath { get; private set; } + public bool PreservePath { get; internal set; } #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/MauiNode.cs b/source/Prebuild/Core/Nodes/MauiNode.cs index bf82e8d..39a2968 100644 --- a/source/Prebuild/Core/Nodes/MauiNode.cs +++ b/source/Prebuild/Core/Nodes/MauiNode.cs @@ -11,7 +11,7 @@ namespace Prebuild.Core.Nodes [DataNode("Maui")] public class MauiNode : DataNode { - public MauiTitle applicationTitle { get; private set; } = null; + public MauiTitle applicationTitle { get; internal set; } = null; public override void Parse(XmlNode node) { @@ -25,6 +25,14 @@ namespace Prebuild.Core.Nodes } } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement maui = doc.CreateElement("Maui"); + applicationTitle.Write(doc, maui); + + current.AppendChild(maui); + } + public override string ToString() { string ret = "true\n"; diff --git a/source/Prebuild/Core/Nodes/MauiTitle.cs b/source/Prebuild/Core/Nodes/MauiTitle.cs index f285b2b..198d7b3 100644 --- a/source/Prebuild/Core/Nodes/MauiTitle.cs +++ b/source/Prebuild/Core/Nodes/MauiTitle.cs @@ -11,12 +11,19 @@ namespace Prebuild.Core.Nodes [DataNode("Title")] public class MauiTitle : DataNode { - public string value { get; private set; } = string.Empty; + public string value { get; internal set; } = string.Empty; public override void Parse(XmlNode node) { value = node.InnerText; } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement main = doc.CreateElement("Title"); + main.InnerText = value; + current.AppendChild(main); + } + public override string ToString() { return $"{value}"; diff --git a/source/Prebuild/Core/Nodes/NullableNode.cs b/source/Prebuild/Core/Nodes/NullableNode.cs index cb80ced..80ee877 100644 --- a/source/Prebuild/Core/Nodes/NullableNode.cs +++ b/source/Prebuild/Core/Nodes/NullableNode.cs @@ -16,5 +16,11 @@ namespace Prebuild.Core.Nodes { base.Parse(node); } + + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement nullable = doc.CreateElement("Nullable"); + current.AppendChild(nullable); + } } } diff --git a/source/Prebuild/Core/Nodes/OptionsNode.cs b/source/Prebuild/Core/Nodes/OptionsNode.cs index 9867d4c..4ec9bc4 100644 --- a/source/Prebuild/Core/Nodes/OptionsNode.cs +++ b/source/Prebuild/Core/Nodes/OptionsNode.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Reflection; using System.Text; using System.Xml; +using System.Xml.Serialization; using Prebuild.Core.Attributes; using Prebuild.Core.Utilities; @@ -73,47 +74,48 @@ public class OptionsNode : DataNode /// /// [field: OptionNode("OptimizeCode")] - public bool OptimizeCode { get; set; } + public bool OptimizeCode { get; set; } = true; /// /// [field: OptionNode("CheckUnderflowOverflow")] - public bool CheckUnderflowOverflow { get; set; } + public bool CheckUnderflowOverflow { get; set; } = true; /// /// [field: OptionNode("AllowUnsafe")] - public bool AllowUnsafe { get; set; } + public bool AllowUnsafe { get; set; } = true; /// /// [field: OptionNode("PreBuildEvent")] - public string PreBuildEvent { get; set; } + public string PreBuildEvent { get; set; } = ""; + /// /// [field: OptionNode("PostBuildEvent")] - public string PostBuildEvent { get; set; } + public string PostBuildEvent { get; set; } = ""; /// /// [field: OptionNode("PreBuildEventArgs")] - public string PreBuildEventArgs { get; set; } + public string PreBuildEventArgs { get; set; } = ""; /// /// [field: OptionNode("PostBuildEventArgs")] - public string PostBuildEventArgs { get; set; } + public string PostBuildEventArgs { get; set; } = ""; /// /// [field: OptionNode("RunPostBuildEvent")] - public string RunPostBuildEvent { get; set; } + public string RunPostBuildEvent { get; set; } = ""; /// /// [field: OptionNode("RunScript")] - public string RunScript { get; set; } + public string RunScript { get; set; } = ""; /// /// @@ -123,7 +125,7 @@ public class OptionsNode : DataNode /// /// [field: OptionNode("WarningsAsErrors")] - public bool WarningsAsErrors { get; set; } + public bool WarningsAsErrors { get; set; } = false; /// /// @@ -133,7 +135,7 @@ public class OptionsNode : DataNode /// /// [field: OptionNode("Prefer32Bit")] - public bool Prefer32Bit { get; set; } + public bool Prefer32Bit { get; set; } = false; /// /// @@ -171,12 +173,12 @@ public class OptionsNode : DataNode /// /// [field: OptionNode("GenerateDocumentation")] - public bool GenerateDocumentation { get; set; } + public bool GenerateDocumentation { get; set; } = true; /// /// [field: OptionNode("GenerateXmlDocFile")] - public bool GenerateXmlDocFile { get; set; } + public bool GenerateXmlDocFile { get; set; } = false; /// /// @@ -191,22 +193,22 @@ public class OptionsNode : DataNode /// /// [field: OptionNode("DebugInformation")] - public bool DebugInformation { get; set; } + public bool DebugInformation { get; set; } = true; /// /// [field: OptionNode("RegisterComInterop")] - public bool RegisterComInterop { get; set; } + public bool RegisterComInterop { get; set; } = true; /// /// [field: OptionNode("RemoveIntegerChecks")] - public bool RemoveIntegerChecks { get; set; } + public bool RemoveIntegerChecks { get; set; } = false; /// /// [field: OptionNode("IncrementalBuild")] - public bool IncrementalBuild { get; set; } + public bool IncrementalBuild { get; set; } = true; /// /// @@ -221,15 +223,17 @@ public class OptionsNode : DataNode /// /// [field: OptionNode("NoStdLib")] - public bool NoStdLib { get; set; } + public bool NoStdLib { get; set; } = false; [field: OptionNode("UseDependencyFile")] - public bool UseDepsFile { get; } + public bool UseDepsFile { get; } = true; - [field: OptionNode("SelfContained")] public bool SelfContained { get; } + + [field: OptionNode("SelfContained")] + public bool SelfContained { get; } = true; [field: OptionNode("UseRuntimeIdentifier")] - public bool UseRuntimeIdentifier { get; } + public bool UseRuntimeIdentifier { get; } = false; private readonly List m_FieldsDefined = new(); @@ -303,6 +307,21 @@ public class OptionsNode : DataNode SetOption(child.Name, Helper.InterpolateForEnvironmentVariables(child.InnerText)); } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement options = doc.CreateElement("Options"); + foreach(var def in m_OptionFields.Keys) + { + var E = doc.CreateElement(def); + E.InnerText = m_OptionFields[def].GetValue(this).ToString(); + + options.AppendChild(E); + } + + current.AppendChild(options); + + } + /// /// Return 'true' if the option symbol has had a value set /// diff --git a/source/Prebuild/Core/Nodes/PackageReferenceNode.cs b/source/Prebuild/Core/Nodes/PackageReferenceNode.cs index 0de442c..ce96c7d 100644 --- a/source/Prebuild/Core/Nodes/PackageReferenceNode.cs +++ b/source/Prebuild/Core/Nodes/PackageReferenceNode.cs @@ -60,6 +60,16 @@ public class PackageReferenceNode : DataNode, IComparable PrivateAssets = Helper.AttributeValue(node, "private", PrivateAssets); } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement reference = doc.CreateElement("PackageReference"); + reference.SetAttribute("name", Name); + reference.SetAttribute("version", Version); + reference.SetAttribute("private", PrivateAssets); + + current.AppendChild(reference); + } + #endregion #region Fields @@ -72,15 +82,15 @@ public class PackageReferenceNode : DataNode, IComparable /// Gets the name. /// /// The name. - public string Name { get; private set; } = "unknown"; + public string Name { get; internal set; } = "unknown"; /// /// Gets the version. /// /// The version. - public string Version { get; private set; } + public string Version { get; internal set; } - public string PrivateAssets { get; private set; } + public string PrivateAssets { get; internal set; } #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/ProcessNode.cs b/source/Prebuild/Core/Nodes/ProcessNode.cs index 4a36c2f..1e72064 100644 --- a/source/Prebuild/Core/Nodes/ProcessNode.cs +++ b/source/Prebuild/Core/Nodes/ProcessNode.cs @@ -61,6 +61,14 @@ public class ProcessNode : DataNode } } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement proc = doc.CreateElement("Process"); + proc.InnerText = Path; + + current.AppendChild(proc); + } + #endregion #region Fields @@ -73,13 +81,13 @@ public class ProcessNode : DataNode /// Gets the path. /// /// The path. - public string Path { get; private set; } + public string Path { get; internal set; } /// /// Gets a value indicating whether this instance is valid. /// /// true if this instance is valid; otherwise, false. - public bool IsValid { get; private set; } = true; + public bool IsValid { get; internal set; } = true; #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/ProjectNode.cs b/source/Prebuild/Core/Nodes/ProjectNode.cs index 52e6cc2..23090d2 100644 --- a/source/Prebuild/Core/Nodes/ProjectNode.cs +++ b/source/Prebuild/Core/Nodes/ProjectNode.cs @@ -261,6 +261,85 @@ public class ProjectNode : DataNode, IComparable } } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement proj = doc.CreateElement("Project"); + + proj.SetAttribute("name", Name); + proj.SetAttribute("path", Path); + proj.SetAttribute("filterGroups", FilterGroups); + proj.SetAttribute("version", Version); + proj.SetAttribute("icon", AppIcon); + proj.SetAttribute("appmanifest", ApplicationManifest); + proj.SetAttribute("configFile", ConfigFile); + proj.SetAttribute("designerFolder", DesignerFolder); + proj.SetAttribute("assemblyName", AssemblyName); + proj.SetAttribute("scanFiles", ScanFiles ? bool.TrueString : bool.FalseString); + proj.SetAttribute("language", Language); + proj.SetAttribute("type", Type.ToString()); + proj.SetAttribute("runtime", Runtime.ToString()); + proj.SetAttribute("frameworkVersion", m_Framework.ToString()); + proj.SetAttribute("startupObject", StartupObject); + proj.SetAttribute("rootNamespace", RootNamespace); + proj.SetAttribute("copyDependencies", CopyLocalLockFileAssemblies ? bool.TrueString : bool.FalseString); + proj.SetAttribute("guid", Guid.ToString()); + proj.SetAttribute("generateAssemblyInfoFile", GenerateAssemblyInfoFile ? bool.TrueString : bool.FalseString); + proj.SetAttribute("winforms", UseWindowsForms ? bool.TrueString : bool.FalseString); + proj.SetAttribute("debugStartParameters", DebugStartParameters); + + foreach(ConfigurationNode conf in Configurations) + { + conf.Write(doc, proj); + } + + foreach(ReferencePathNode rpn in ReferencePaths) + { + rpn.Write(doc, proj); + } + + foreach(ReferenceNode refer in References) + { + refer.Write(doc, proj); + } + + foreach(PackageReferenceNode pkg in PackageReferences) + { + pkg.Write(doc, proj); + } + + foreach(ProjectReferenceNode prj in ProjectReferences) + { + prj.Write(doc, proj); + } + + foreach(AuthorNode auth in Authors) + { + auth.Write(doc, proj); + } + + Files.Write(doc, proj); + foreach(TextGenNode gen in TextGenNodes) + { + gen.Write(doc, proj); + } + + if(MauiSettings!=null) + MauiSettings.Write(doc, proj); + if (Nullable) + { + XmlElement nu = doc.CreateElement("Nullable"); + proj.AppendChild(nu); + } + + if(InternalsVisible!=null) + InternalsVisible.Write(doc, proj); + + + + + current.AppendChild(proj); + } + #endregion #region Fields @@ -303,28 +382,28 @@ public class ProjectNode : DataNode, IComparable /// Gets the name. /// /// The name. - public string Name { get; private set; } = "unknown"; + public string Name { get; internal set; } = "unknown"; /// /// Contains settings for DotNet Maui (7.0+) /// Default is null, which indicates not to include any Maui content in the project file. /// - public MauiNode MauiSettings { get; private set; } = null; + public MauiNode MauiSettings { get; internal set; } = null; /// /// Marks the visibility for internals /// - public InternalsNode InternalsVisible { get; private set; } + public InternalsNode InternalsVisible { get; internal set; } /// /// Enables Windows forms on a dotnet project. /// - public bool UseWindowsForms { get; private set; } = false; + public bool UseWindowsForms { get; internal set; } = false; /// /// Scans the directory for files /// - public bool ScanFiles {get;private set;} = true; + public bool ScanFiles {get;internal set;} = true; /// /// The version of the .NET Framework to compile under @@ -353,18 +432,18 @@ public class ProjectNode : DataNode, IComparable /// Gets the path. /// /// The path. - public string Path { get; private set; } = ""; + public string Path { get; internal set; } = ""; /// /// Gets the filter groups. /// /// The filter groups. - public string FilterGroups { get; private set; } = ""; + public string FilterGroups { get; internal set; } = ""; /// /// Indicates project nullable attribute /// - public bool Nullable { get; private set; } = false; + public bool Nullable { get; internal set; } = false; public string NullableStr { get @@ -377,65 +456,65 @@ public class ProjectNode : DataNode, IComparable /// Gets the project's version /// /// The project's version. - public string Version { get; private set; } = ""; + public string Version { get; internal set; } = ""; /// /// Gets the full path. /// /// The full path. - public string FullPath { get; private set; } = ""; + public string FullPath { get; internal set; } = ""; /// /// Gets the name of the assembly. /// /// The name of the assembly. - public string AssemblyName { get; private set; } + public string AssemblyName { get; internal set; } /// /// Copies the local dependencies to the output on build. /// This is the same behavior as publish. /// - public bool CopyLocalLockFileAssemblies { get; private set; } + public bool CopyLocalLockFileAssemblies { get; internal set; } /// /// Gets the app icon. /// /// The app icon. - public string AppIcon { get; private set; } = ""; + public string AppIcon { get; internal set; } = ""; /// /// Gets the Application Manifest. /// /// The Application Manifest. - public string ApplicationManifest { get; private set; } = ""; + public string ApplicationManifest { get; internal set; } = ""; /// /// Gets the app icon. /// /// The app icon. - public string ConfigFile { get; private set; } = ""; + public string ConfigFile { get; internal set; } = ""; /// /// - public string DesignerFolder { get; private set; } = ""; + public string DesignerFolder { get; internal set; } = ""; /// /// Gets the language. /// /// The language. - public string Language { get; private set; } = "C#"; + public string Language { get; internal set; } = "C#"; /// /// Gets the type. /// /// The type. - public ProjectType Type { get; private set; } = ProjectType.Exe; + public ProjectType Type { get; internal set; } = ProjectType.Exe; /// /// Gets the runtime. /// /// The runtime. - public ClrRuntime Runtime { get; private set; } = ClrRuntime.Microsoft; + public ClrRuntime Runtime { get; internal set; } = ClrRuntime.Microsoft; /// /// @@ -445,13 +524,13 @@ public class ProjectNode : DataNode, IComparable /// Gets the startup object. /// /// The startup object. - public string StartupObject { get; private set; } = ""; + public string StartupObject { get; internal set; } = ""; /// /// Gets the root namespace. /// /// The root namespace. - public string RootNamespace { get; private set; } + public string RootNamespace { get; internal set; } /// /// Gets the configurations. @@ -470,7 +549,7 @@ public class ProjectNode : DataNode, IComparable /// /// Gets the text generator nodes /// - public List TextGenNodes { get; private set; } = new(); + public List TextGenNodes { get; internal set; } = new(); /// @@ -545,7 +624,7 @@ public class ProjectNode : DataNode, IComparable /// Gets the files. /// /// The files. - public FilesNode Files { get; private set; } = new(); + public FilesNode Files { get; internal set; } = new(); /// /// Gets or sets the parent. @@ -584,9 +663,9 @@ public class ProjectNode : DataNode, IComparable /// Gets the GUID. /// /// The GUID. - public Guid Guid { get; private set; } + public Guid Guid { get; internal set; } - public string DebugStartParameters { get; private set; } + public string DebugStartParameters { get; internal set; } #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/ProjectReferenceNode.cs b/source/Prebuild/Core/Nodes/ProjectReferenceNode.cs index 8722213..769fcaf 100644 --- a/source/Prebuild/Core/Nodes/ProjectReferenceNode.cs +++ b/source/Prebuild/Core/Nodes/ProjectReferenceNode.cs @@ -59,6 +59,15 @@ public class ProjectReferenceNode : DataNode, IComparable Include = Helper.AttributeValue(node, "include", Include); } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement cur = doc.CreateElement("ProjectReference"); + cur.SetAttribute("name", Name); + cur.SetAttribute("include", Include); + + current.AppendChild(cur); + } + #endregion #region Fields @@ -71,13 +80,13 @@ public class ProjectReferenceNode : DataNode, IComparable /// Gets the name. /// /// The name. - public string Name { get; private set; } = "unknown"; + public string Name { get; internal set; } = "unknown"; /// /// Gets the path. /// /// The path. - public string Include { get; private set; } + public string Include { get; internal set; } #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/ReferenceNode.cs b/source/Prebuild/Core/Nodes/ReferenceNode.cs index dd1917d..0199294 100644 --- a/source/Prebuild/Core/Nodes/ReferenceNode.cs +++ b/source/Prebuild/Core/Nodes/ReferenceNode.cs @@ -61,6 +61,18 @@ public class ReferenceNode : DataNode, IComparable Version = Helper.AttributeValue(node, "version", Version); } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement cur = doc.CreateElement("Reference"); + cur.SetAttribute("name", Name); + cur.SetAttribute("path", Path); + cur.SetAttribute("version", Version); + cur.SetAttribute("localCopy", m_LocalCopy); + + + current.AppendChild(cur); + } + #endregion #region Fields @@ -75,13 +87,13 @@ public class ReferenceNode : DataNode, IComparable /// Gets the name. /// /// The name. - public string Name { get; private set; } = "unknown"; + public string Name { get; internal set; } = "unknown"; /// /// Gets the path. /// /// The path. - public string Path { get; private set; } + public string Path { get; internal set; } /// /// Gets a value indicating whether [local copy specified]. @@ -106,7 +118,7 @@ public class ReferenceNode : DataNode, IComparable /// Gets the version. /// /// The version. - public string Version { get; private set; } + public string Version { get; internal set; } #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/ReferencePathNode.cs b/source/Prebuild/Core/Nodes/ReferencePathNode.cs index dd3c0a9..d96f997 100644 --- a/source/Prebuild/Core/Nodes/ReferencePathNode.cs +++ b/source/Prebuild/Core/Nodes/ReferencePathNode.cs @@ -47,7 +47,7 @@ public class ReferencePathNode : DataNode, IComparable /// Gets the path. /// /// The path. - public string Path { get; private set; } + public string Path { get; internal set; } #endregion @@ -77,5 +77,13 @@ public class ReferencePathNode : DataNode, IComparable Path = Path.Trim(); } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement cur = doc.CreateElement("ReferencePath"); + cur.InnerText = Path; + + current.AppendChild(cur); + } + #endregion } \ No newline at end of file diff --git a/source/Prebuild/Core/Nodes/SolutionNode.cs b/source/Prebuild/Core/Nodes/SolutionNode.cs index 590ff3b..0498a9c 100644 --- a/source/Prebuild/Core/Nodes/SolutionNode.cs +++ b/source/Prebuild/Core/Nodes/SolutionNode.cs @@ -29,6 +29,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Xml; +using System.Xml.Serialization; using Prebuild.Core.Attributes; using Prebuild.Core.Interfaces; using Prebuild.Core.Utilities; @@ -136,6 +137,46 @@ public class SolutionNode : DataNode } } + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement sol = doc.CreateElement("Solution"); + sol.SetAttribute("name", Name); + sol.SetAttribute("activeConfig", ActiveConfig); + sol.SetAttribute("path", Path); + sol.SetAttribute("version", Version); + sol.SetAttribute("frameworkVersion", DefaultFramework.ToString()); + if(Options != null) + Options.Write(doc, sol); + + if (Files != null) Files.Write(doc, sol); + + if(Configurations != null) + foreach(ConfigurationNode conf in Configurations) + { + conf.Write(doc, sol); + } + + foreach(ProjectNode proj in Projects) + { + proj.Write(doc, sol); + } + + foreach(SolutionNode solX in Solutions) + { + solX.Write(doc, sol); + } + + foreach(DatabaseProjectNode db in DatabaseProjects) + { + db.Write(doc, sol); + } + + if(Cleanup != null) + Cleanup.Write(doc, sol); + + current.AppendChild(sol); + } + #endregion #region Fields @@ -179,37 +220,37 @@ public class SolutionNode : DataNode /// Gets the name. /// /// The name. - public string Name { get; private set; } = "unknown"; + public string Name { get; internal set; } = "unknown"; /// /// Gets the path. /// /// The path. - public string Path { get; private set; } = ""; + public string Path { get; internal set; } = ""; /// /// Gets the full path. /// /// The full path. - public string FullPath { get; private set; } = ""; + public string FullPath { get; internal set; } = ""; /// /// Gets the version. /// /// The version. - public string Version { get; private set; } = "1.0.0"; + public string Version { get; internal set; } = "1.0.0"; /// /// Gets the options. /// /// The options. - public OptionsNode Options { get; private set; } + public OptionsNode Options { get; internal set; } /// /// Gets the files. /// /// The files. - public FilesNode Files { get; private set; } + public FilesNode Files { get; internal set; } /// /// Gets the configurations. diff --git a/source/Prebuild/Core/Nodes/TextGenNode.cs b/source/Prebuild/Core/Nodes/TextGenNode.cs index be98331..4756f7b 100644 --- a/source/Prebuild/Core/Nodes/TextGenNode.cs +++ b/source/Prebuild/Core/Nodes/TextGenNode.cs @@ -16,7 +16,7 @@ namespace Prebuild.Core.Nodes #region Values private string m_Name; private string m_OutputName; - private List m_Libs = new(); + private List m_Libs = new(); private string m_Tool; @@ -32,9 +32,9 @@ namespace Prebuild.Core.Nodes foreach (XmlNode childNode in node.ChildNodes) { var data = Kernel.Instance.ParseNode(childNode, this); - if(data is ReferenceNode) + if(data is ReferenceNode rn) { - m_Libs.Add(((ReferenceNode)data).Name); + m_Libs.Add(rn); } } @@ -53,6 +53,22 @@ namespace Prebuild.Core.Nodes else m_OutputName = Path.ChangeExtension(m_OutputName, ".SnapWrap.cs"); } + + public override void Write(XmlDocument doc, XmlElement current) + { + XmlElement cur = doc.CreateElement("TextGen"); + cur.SetAttribute("name", m_Name); + cur.SetAttribute("output", m_OutputName); + cur.SetAttribute("tool", m_Tool); + + foreach(var reference in m_Libs) + { + reference.Write(doc, cur); + } + cur.SetAttribute("sourceInSolution", SourceInSolution ? bool.TrueString : bool.FalseString); + + current.AppendChild(cur); + } #endregion #region Fields @@ -76,11 +92,17 @@ namespace Prebuild.Core.Nodes { get { - return String.Join("..", m_Libs); + List tmp = new(); + foreach(var rn in m_Libs) + { + tmp.Add(rn.Name); + } + + return String.Join("..", tmp); } } - public bool SourceInSolution { get; private set; } = false; + public bool SourceInSolution { get; internal set; } = false; public string SourceDirectory { diff --git a/source/Prebuild/Core/Parse/IfContext.cs b/source/Prebuild/Core/Parse/IfContext.cs index c1a2745..4918a29 100644 --- a/source/Prebuild/Core/Parse/IfContext.cs +++ b/source/Prebuild/Core/Parse/IfContext.cs @@ -104,7 +104,7 @@ public class IfContext /// Gets a value indicating whether [ever kept]. /// /// true if [ever kept]; otherwise, false. - public bool EverKept { get; private set; } + public bool EverKept { get; internal set; } /// /// Gets or sets the state. diff --git a/source/Prebuild/Core/Targets/AutotoolsTarget.cs b/source/Prebuild/Core/Targets/AutotoolsTarget.cs index abc8181..af33552 100644 --- a/source/Prebuild/Core/Targets/AutotoolsTarget.cs +++ b/source/Prebuild/Core/Targets/AutotoolsTarget.cs @@ -95,22 +95,22 @@ public enum ClrVersion public class SystemPackage { - public string Name { get; private set; } + public string Name { get; internal set; } - public string Version { get; private set; } + public string Version { get; internal set; } - public string Description { get; private set; } + public string Description { get; internal set; } - public ClrVersion TargetVersion { get; private set; } + public ClrVersion TargetVersion { get; internal set; } // The package is part of the mono SDK public bool IsCorePackage => Name == "mono"; // The package has been registered by an add-in, and is not installed // in the system. - public bool IsInternalPackage { get; private set; } + public bool IsInternalPackage { get; internal set; } - public string[] Assemblies { get; private set; } + public string[] Assemblies { get; internal set; } public void Initialize(string name, string version, diff --git a/source/Prebuild/Prebuild.cs b/source/Prebuild/Prebuild.cs index 409c0d7..1153ebb 100644 --- a/source/Prebuild/Prebuild.cs +++ b/source/Prebuild/Prebuild.cs @@ -105,6 +105,7 @@ internal class Prebuild Console.WriteLine("/ppo Pre-process the file, but perform no other processing"); Console.WriteLine("/pause Pauses the application after execution to view the output"); Console.WriteLine("/yes Default to yes to any questions asked"); + Console.WriteLine("/init Initializes a skeleton Prebuild file"); Console.WriteLine(); Console.WriteLine("See 'prebuild /showtargets for a list of available targets"); Console.WriteLine("See readme.txt or check out http://dnpb.sourceforge.net for more information");