[mono-api-html] Output C# 'char' instead of 'System.Char'
[mono.git] / mcs / tools / corcompare / mono-api-html / ApiDiff.cs
1 //
2 // The main differences with mono-api-diff are:
3 // * this tool directly produce HTML similar to gdiff.sh used for Xamarin.iOS
4 // * this tool reports changes in an "evolutionary" way, not in a breaking way,
5 //   i.e. it does not assume the source assembly is right (but simply older)
6 // * the diff .xml output was not easy to convert back into the HTML format
7 //   that gdiff.sh produced
8 // 
9 // Authors
10 //    Sebastien Pouliot  <sebastien@xamarin.com>
11 //
12 // Copyright 2013 Xamarin Inc. http://www.xamarin.com
13 // 
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System;
35 using System.IO;
36
37 namespace Xamarin.ApiDiff {
38
39         public static class State {
40                 static TextWriter output;
41
42                 public static TextWriter Output { 
43                         get {
44                                 if (output == null)
45                                         output = Console.Out;
46                                 return output;
47                         }
48                         set { output = value; } 
49                 }
50
51                 public static string Assembly { get; set; }
52                 public static string Namespace { get; set; }
53                 public static string Type { get; set; }
54                 public static string BaseType { get; set; }
55
56                 public static int Indent { get; set; }
57         }
58
59         class Program {
60
61                 public static int Main (string[] args)
62                 {
63                         if (args.Length < 2) {
64                                 Console.WriteLine ("mono-api-html reference.xml assembly.xml [diff.html]");
65                                 return 1;
66                         }
67
68                         try {
69                                 string input = args [0];
70                                 string output = args [1];
71                                 var ac = new AssemblyComparer (input, output);
72                                 if (args.Length > 2) {
73                                         string diff = String.Empty;
74                                         using (var writer = new StringWriter ()) {
75                                                 State.Output = writer;
76                                                 ac.Compare ();
77                                                 diff = State.Output.ToString ();
78                                         }
79                                         if (diff.Length > 0) {
80                                                 using (var file = new StreamWriter (args [2])) {
81                                                         if (ac.SourceAssembly == ac.TargetAssembly) {
82                                                                 file.WriteLine ("<h1>{0}.dll</h1>", ac.SourceAssembly);
83                                                         } else {
84                                                                 file.WriteLine ("<h1>{0}.dll vs {1}.dll</h1>", ac.SourceAssembly, ac.TargetAssembly);
85                                                         }
86                                                         file.Write (diff);
87                                                 }
88                                         }
89                                 } else {
90                                         State.Output = Console.Out;
91                                         ac.Compare ();
92                                 }
93                         }
94                         catch (Exception e) {
95                                 Console.WriteLine (e);
96                                 return 1;
97                         }
98                         return 0;
99                 }
100         }
101 }