フィルターxmlにコメントがあると例外で停止するバグを修正
ソースコード整理
-v オプションでバージョン出力
@@ -1,15 +1,22 @@ | ||
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | 2 | <CCCC_Project> |
3 | -<module_summary> | |
4 | -<lines_of_code value="value <= 120" /> | |
5 | -</module_summary> | |
6 | -<procedural_detail> | |
7 | -<member_function> | |
8 | -<lines_of_code value="value <= 30"/> | |
9 | -<McCabes_cyclomatic_complexity value="value <= 30" /> | |
10 | -<lines_of_comment /> | |
11 | -<lines_of_code_per_line_of_comment value="value <= 5" /> | |
12 | -<McCabes_cyclomatic_complexity_per_line_of_comment value="value <= 30" /> | |
13 | -</member_function> | |
14 | -</procedural_detail> | |
3 | + <!-- モジュール --> | |
4 | + <module_summary> | |
5 | + <!-- コード数 --> | |
6 | + <lines_of_code value="value <= 120" /> | |
7 | + </module_summary> | |
8 | + <procedural_detail> | |
9 | + <member_function> | |
10 | + <!-- コード数 --> | |
11 | + <lines_of_code value="value <= 30"/> | |
12 | + <!-- 複雑度 --> | |
13 | + <McCabes_cyclomatic_complexity value="value <= 30" /> | |
14 | + <!-- コメント行数 --> | |
15 | + <lines_of_comment /> | |
16 | + <!-- コード数 / コメント行数 --> | |
17 | + <lines_of_code_per_line_of_comment value="value <= 5" /> | |
18 | + <!-- 複雑度 / コメント行数 --> | |
19 | + <McCabes_cyclomatic_complexity_per_line_of_comment value="value <= 30" /> | |
20 | + </member_function> | |
21 | + </procedural_detail> | |
15 | 22 | </CCCC_Project> |
@@ -5,25 +5,11 @@ | ||
5 | 5 | using System.Xml; |
6 | 6 | using System.IO; |
7 | 7 | using System.Diagnostics; |
8 | +using System.Reflection; | |
8 | 9 | using junit; |
9 | 10 | |
10 | 11 | namespace c4ju |
11 | 12 | { |
12 | - #region フィルター | |
13 | - class FilterAttribute | |
14 | - { | |
15 | - public string Name; | |
16 | - public string Value; | |
17 | - public CSharpEval Eval; | |
18 | - }; | |
19 | - class Filter | |
20 | - { | |
21 | - public string TestName; | |
22 | - public string strXPath; | |
23 | - public List<FilterAttribute> list; | |
24 | - }; | |
25 | - #endregion | |
26 | - | |
27 | 13 | class Program |
28 | 14 | { |
29 | 15 | static int Main(string[] args) |
@@ -32,7 +18,6 @@ | ||
32 | 18 | List<string> files = new List<string>(); |
33 | 19 | string outfile = "test_default.xml"; |
34 | 20 | string filter_xmlpath = "filter_default.xml"; |
35 | - XmlDocument doc_filter = new XmlDocument(); | |
36 | 21 | |
37 | 22 | #region コマンドライン解析 |
38 | 23 | // コマンドライン引数の解析 |
@@ -101,12 +86,26 @@ | ||
101 | 86 | } |
102 | 87 | #endregion |
103 | 88 | } |
104 | - #region 標準入力ファイル | |
105 | - else if (i == args.Length - 1 && argv.Length == 1 && argv[0] == '-') | |
89 | + else if( argv[0] == '-' ) | |
106 | 90 | { |
107 | - input_stdin = true; | |
91 | + #region バージョン | |
92 | + if (argv == "-v") | |
93 | + { | |
94 | + AssemblyName asmName = Assembly.GetEntryAssembly().GetName(); | |
95 | + Version ver = asmName.Version; | |
96 | + Console.Write(asmName.Name); | |
97 | + Console.Write(" v"); | |
98 | + Console.WriteLine(ver); | |
99 | + return 0; | |
100 | + } | |
101 | + #endregion | |
102 | + #region 標準入力ファイル | |
103 | + else if (i == args.Length - 1 && argv.Length == 1) | |
104 | + { | |
105 | + input_stdin = true; | |
106 | + } | |
107 | + #endregion | |
108 | 108 | } |
109 | - #endregion | |
110 | 109 | #region 入力ファイル |
111 | 110 | else |
112 | 111 | { |
@@ -117,50 +116,8 @@ | ||
117 | 116 | #endregion |
118 | 117 | |
119 | 118 | #region フィルター用意 |
120 | - try | |
121 | - { | |
122 | - doc_filter.Load(filter_xmlpath); | |
123 | - } | |
124 | - catch (Exception e) | |
125 | - { | |
126 | - Console.WriteLine(e.Message); | |
127 | - return 1; | |
128 | - } | |
129 | - | |
130 | - if (doc_filter.ChildNodes.Count == 0) | |
131 | - { | |
132 | - Console.WriteLine("not found filter."); | |
133 | - return 1; | |
134 | - } | |
135 | - List<string> filter_xpaths = XmlToXPathList.Convert(doc_filter.SelectSingleNode("//CCCC_Project")); | |
136 | - if (filter_xpaths.Count == 0) | |
137 | - { | |
138 | - Console.WriteLine("not found CCCC_Project node"); | |
139 | - return 1; | |
140 | - } | |
141 | - List<Filter> filter_list = new List<Filter>(); | |
142 | - foreach (string xpath in filter_xpaths) | |
143 | - { | |
144 | - Filter f = new Filter(); | |
145 | - XmlNode filter_node = doc_filter.SelectSingleNode(xpath); | |
146 | - f.TestName = filter_node.ParentNode.Name + "/" + filter_node.Name + " : "; | |
147 | - f.strXPath = xpath; | |
148 | - f.list = new List<FilterAttribute>(); | |
149 | - foreach (XmlAttribute attr in filter_node.Attributes) | |
150 | - { | |
151 | - FilterAttribute a = new FilterAttribute(); | |
152 | - a.Name = attr.Name; | |
153 | - a.Value = attr.Value; | |
154 | - a.Eval = new CSharpEval(); | |
155 | - if (!a.Eval.Init(attr.Value)) | |
156 | - { | |
157 | - Console.WriteLine("Evaluation of the filter expression is invalid xml."); | |
158 | - return 1; | |
159 | - } | |
160 | - f.list.Add(a); | |
161 | - } | |
162 | - filter_list.Add(f); | |
163 | - } | |
119 | + List<Filter> filter_list = FilterBuilder.Build(filter_xmlpath); | |
120 | + if (filter_list == null) return 1; | |
164 | 121 | #endregion |
165 | 122 | |
166 | 123 | #region 標準入力からのファイルパス取得 |
@@ -341,40 +298,3 @@ | ||
341 | 298 | } |
342 | 299 | } |
343 | 300 | |
344 | -#region XmlToXPathList | |
345 | -class XmlToXPathList | |
346 | -{ | |
347 | - public static List<string> Convert(XmlNode node) | |
348 | - { | |
349 | - List<string> list = new List<string>(); | |
350 | - if (node.ChildNodes.Count == 0) | |
351 | - { | |
352 | - string path = node.Name; | |
353 | - XmlNode p = node.ParentNode; | |
354 | - while (p != null && p.ParentNode != null) | |
355 | - { | |
356 | - path = p.Name + "/" + path; | |
357 | - p = p.ParentNode; | |
358 | - } | |
359 | - path = "//" + path; | |
360 | - list.Add(path); | |
361 | - } | |
362 | - foreach (XmlNode n in node.ChildNodes) | |
363 | - { | |
364 | - list.AddRange(Convert(n)); | |
365 | - } | |
366 | - return list; | |
367 | - } | |
368 | - public static List<string> Convert(XmlDocument doc) | |
369 | - { | |
370 | - List<string> list = new List<string>(); | |
371 | - | |
372 | - foreach (XmlNode n in doc.ChildNodes) | |
373 | - { | |
374 | - list.AddRange(Convert(n)); | |
375 | - } | |
376 | - return list; | |
377 | - } | |
378 | -} | |
379 | - | |
380 | -#endregion |
@@ -32,5 +32,5 @@ | ||
32 | 32 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を |
33 | 33 | // 既定値にすることができます: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.0.0.0")] | |
36 | -[assembly: AssemblyFileVersion("1.0.0.0")] | |
35 | +[assembly: AssemblyVersion("1.0.0.1")] | |
36 | +[assembly: AssemblyFileVersion("1.0.0.1")] |