Welcome to mirror list, hosted at ThFree Co, Russian Federation.

comparereport.cs « DocStat « DocStat « tools - github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4673a1dd2766275b3cee2f9a5a8cb197d9f026ca (plain)
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Mono.Options;

namespace DocStat
{
    public class CompareReportCommand : ApiCommand
    {
        
        public override void Run(IEnumerable<string> args)
        {
            // throw new NotImplementedException();

            string updatedDir = "";
			string omitlist = "";
			string processlist = "";
			string pattern = "";

			List<string> extras = CommandUtils.ProcessFileArgs(args,
															   ref updatedDir,
															   ref omitlist,
															   ref processlist,
															   ref pattern);

            string oldFilesDir = "";
            bool typeOnly = false;
            string reportFile = "";
            bool nosigil = false;

            var options = new OptionSet {
                {"previous=", (p) => oldFilesDir = p},
                {"typeonly", (t) => typeOnly = t != null},
                {"reportfile=", (r) => reportFile = r},
                { "no-check-TBA", (t) => nosigil = t != null }
            };

            extras = options.Parse(extras);

            CommandUtils.ThrowOnFiniteExtras(extras);

			if (String.IsNullOrEmpty(oldFilesDir))
				throw new ArgumentException("You must supply a parallel directory from which to source new content with 'previous='.");

            if (String.IsNullOrEmpty(reportFile) || !reportFile.EndsWith(".csv"))
                throw new ArgumentException("'reportfile=' must be used, and its value must end with '.csv'.");

            string bareReportDir = Path.GetDirectoryName(Path.GetFullPath(reportFile));

            if (!Directory.Exists(bareReportDir))
                throw new ArgumentException(bareReportDir + " does not exist.");

            IEnumerable<string> updated = CommandUtils.GetFileList(processlist, omitlist, updatedDir, pattern);

            StreamWriter reportStream = new StreamWriter(reportFile);

            reportStream.WriteLine(String.Format(CommandUtils.CSVFormatString(5), "File Name", "Type", "Member","Need file summary", "Need member summary"));

			Func<XElement, bool> hasSigil = null;

            if (nosigil)
            {
                hasSigil = (XElement e) => true;
            }
            else
            {
                hasSigil = (XElement e) => e.Element("Docs").Element("summary").Value == "To be added.";
            }

            //Func<XElement, bool> needSummary = (XElement e) => e.Element("Docs").Element("summary").Value == "To be added.";

            Func<XElement, string> MemberLine = (XElement e) => {
				return string.Format(
                    CommandUtils.CSVFormatString(5), 
                    "",
                    "",
                    e.Attribute("MemberName").Value,
                    "",
                    hasSigil(e) ? "y" : "n");
            };



            List<string> toWrite = new List<string>();
			foreach (string updatedXMLFile in updated)
			{
                
                bool fileLineAdded = false;

                XDocument updatedXDoc = XDocument.Load(updatedXMLFile);

                Func<string> FileLine = () =>
                {
                    return string.Format(
                        CommandUtils.CSVFormatString(5),
                        updatedXMLFile,
                        updatedXDoc.Element("Type").Attribute("FullName").Value,
                        "",
                        hasSigil(updatedXDoc.Element("Type")) ? "y" : "n",
                        "");
                };

				
                string oldXMLFile = EcmaXmlHelper.GetParallelFilePathFor(updatedXMLFile, oldFilesDir, updatedDir);
                XDocument oldXDoc = File.Exists(oldXMLFile) ? XDocument.Load(oldXMLFile) : null;
                if (null == oldXDoc && hasSigil(updatedXDoc.Element("Type")))
                {
                    toWrite.Add(FileLine());
                    fileLineAdded = true;
                }

                IEnumerable<XElement> newMembers = EcmaXmlHelper.NewMembers(updatedXDoc, oldXDoc);
                if (null != newMembers && newMembers.Where((f) => hasSigil(f)).Any())
                {
                    if (!fileLineAdded)
                        toWrite.Add(FileLine());

                    foreach (XElement e in newMembers.Where((f) => hasSigil(f)))
                    {
                        toWrite.Add(MemberLine(e));
                    }
                }

                // If toWrite isn't empty, write all lines
                if (toWrite.Any())
                {
                    foreach (string s in toWrite)
                        reportStream.WriteLine(s);
                }
                toWrite.Clear();
			}
            reportStream.Flush();
            reportStream.Close();

		}

	}


}