From: Rolf Bjarne Kvinge Date: Thu, 28 Jan 2016 14:14:13 +0000 (+0100) Subject: [mono-api-html] Make it possible to hide/show non-breaking changes in the html output. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=a8c6b0d380ba283a3aad3aa61d27beee5ab7df29 [mono-api-html] Make it possible to hide/show non-breaking changes in the html output. We now add data-is-[non-]breaking attributes to the generated html elements, and then use some javascript logic to show/hide non-breaking elements (and the javascript also looks in the container elements show/hide containers that have only non-breaking descendants). Also use css classes/styles to colorize. --- diff --git a/mcs/tools/corcompare/mono-api-html/ApiChange.cs b/mcs/tools/corcompare/mono-api-html/ApiChange.cs index 72e905b8c58..1d902cacfad 100644 --- a/mcs/tools/corcompare/mono-api-html/ApiChange.cs +++ b/mcs/tools/corcompare/mono-api-html/ApiChange.cs @@ -21,15 +21,9 @@ namespace Xamarin.ApiDiff public ApiChange AppendAdded (string text, bool breaking = false) { - if (breaking) - Member.Append (""); - if (State.Colorize) - Member.Append (""); + Member.Append (""); Member.Append (text); - if (State.Colorize) - Member.Append (""); - if (breaking) - Member.Append (""); + Member.Append (""); Breaking |= breaking; AnyChange = true; return this; @@ -37,12 +31,8 @@ namespace Xamarin.ApiDiff public ApiChange AppendRemoved (string text, bool breaking = true) { - Member.Append (""); - if (State.Colorize && breaking) - Member.Append (""); + Member.Append (""); Member.Append (text); - if (State.Colorize && breaking) - Member.Append (""); Member.Append (""); Breaking |= breaking; AnyChange = true; diff --git a/mcs/tools/corcompare/mono-api-html/ApiDiff.cs b/mcs/tools/corcompare/mono-api-html/ApiDiff.cs index 69454e1184c..8fe27844852 100644 --- a/mcs/tools/corcompare/mono-api-html/ApiDiff.cs +++ b/mcs/tools/corcompare/mono-api-html/ApiDiff.cs @@ -168,12 +168,98 @@ namespace Xamarin.ApiDiff { } if (diffHtml.Length > 0) { using (var file = new StreamWriter (diff)) { + file.WriteLine ("
"); + if (State.Colorize) { + file.WriteLine (""); + } + file.WriteLine ( +@""); if (ac.SourceAssembly == ac.TargetAssembly) { file.WriteLine ("

{0}.dll

", ac.SourceAssembly); } else { file.WriteLine ("

{0}.dll vs {1}.dll

", ac.SourceAssembly, ac.TargetAssembly); } + file.WriteLine ("Hide non-breaking changes"); + file.WriteLine (""); + file.WriteLine ("
"); + file.WriteLine ("
"); file.Write (diffHtml); + file.WriteLine ("
"); + file.WriteLine ("
"); } } } else { diff --git a/mcs/tools/corcompare/mono-api-html/ClassComparer.cs b/mcs/tools/corcompare/mono-api-html/ClassComparer.cs index 761f87a5552..1e19ab4b38e 100644 --- a/mcs/tools/corcompare/mono-api-html/ClassComparer.cs +++ b/mcs/tools/corcompare/mono-api-html/ClassComparer.cs @@ -72,11 +72,13 @@ namespace Xamarin.ApiDiff { string name = target.Attribute ("name").Value; if (State.IgnoreNew.Any (re => re.IsMatch (name))) return; + Output.WriteLine ("
", name); Output.WriteLine ("

New Type {0}.{1}

", State.Namespace, name); - Output.WriteLine (State.Colorize ? "
" : "
");
+			Output.WriteLine ("
");
 			State.Indent = 0;
 			AddedInner (target);
 			Output.WriteLine ("
"); + Output.WriteLine ("
", name); } public void AddedInner (XElement target) @@ -226,17 +228,17 @@ namespace Xamarin.ApiDiff { var s = (Output as StringWriter).ToString (); State.Output = output; if (s.Length > 0) { + var tn = GetTypeName (target); + Output.WriteLine ("
", tn); Output.WriteLine ("

Type Changed: {0}.{1}

", State.Namespace, GetTypeName (target)); Output.WriteLine (s); + Output.WriteLine ("
", tn); } } public override void Removed (XElement source) { - var style = string.Empty; - if (State.Colorize) - style = "style='color: red'"; - Output.Write ("

Removed Type {1}.{2}

", style, State.Namespace, GetTypeName (source)); + Output.Write ("

Removed Type {0}.{1}

", State.Namespace, GetTypeName (source)); } public virtual string GetTypeName (XElement type) diff --git a/mcs/tools/corcompare/mono-api-html/FieldComparer.cs b/mcs/tools/corcompare/mono-api-html/FieldComparer.cs index bb4f6c6b075..a2b0225b448 100644 --- a/mcs/tools/corcompare/mono-api-html/FieldComparer.cs +++ b/mcs/tools/corcompare/mono-api-html/FieldComparer.cs @@ -189,8 +189,9 @@ namespace Xamarin.ApiDiff { { first = true; if (State.BaseType == "System.Enum") { + Output.WriteLine ("
"); Output.WriteLine ("

Added value{0}:

", list.Count () > 1 ? "s" : String.Empty); - Output.WriteLine (State.Colorize ? "
" : "
");
+				Output.WriteLine ("
");
 			} else {
 				base.BeforeAdding (list);
 			}
@@ -201,7 +202,7 @@ namespace Xamarin.ApiDiff {
 			first = true;
 			if (State.BaseType == "System.Enum") {
 				Output.WriteLine ("

Removed value{0}:

", list.Count () > 1 ? "s" : String.Empty); - Output.WriteLine (State.Colorize ? "
" : "
");
+				Output.WriteLine ("
");
 			} else {
 				base.BeforeRemoving (list);
 			}
diff --git a/mcs/tools/corcompare/mono-api-html/MemberComparer.cs b/mcs/tools/corcompare/mono-api-html/MemberComparer.cs
index dee528ebc7a..92e36e8fd79 100644
--- a/mcs/tools/corcompare/mono-api-html/MemberComparer.cs
+++ b/mcs/tools/corcompare/mono-api-html/MemberComparer.cs
@@ -41,6 +41,11 @@ namespace Xamarin.ApiDiff {
 		public abstract string GroupName { get; }
 		public abstract string ElementName { get; }
 
+		protected virtual bool IsBreakingRemoval (XElement e)
+		{
+			return true;
+		}
+
 		public void Compare (XElement source, XElement target)
 		{
 			var s = source.Element (GroupName);
@@ -136,8 +141,10 @@ namespace Xamarin.ApiDiff {
 				Output.WriteLine ("

{0}:

", changes.Key); Output.WriteLine ("
");
 				foreach (var element in changes.Value) {
+					Output.Write ("
", element.Breaking ? "data-is-breaking" : "data-is-non-breaking"); foreach (var line in element.Member.ToString ().Split ('\n')) Output.WriteLine ("\t{0}", line); + Output.Write ("
"); } Output.WriteLine ("
"); @@ -192,10 +199,10 @@ namespace Xamarin.ApiDiff { public virtual void BeforeAdding (IEnumerable list) { first = true; - Output.WriteLine ("

Added {0}:

", list.Count () > 1 ? GroupName : ElementName); - bool isInterface = list.Count () > 0 && IsInInterface (list.First ()); - Output.WriteLine (State.Colorize ? string.Format ("
", isInterface ? "red" : "green") : "
");
+			Output.WriteLine ("
"); + Output.WriteLine ("

Added {0}:

", list.Count () > 1 ? GroupName : ElementName); + Output.WriteLine ("
");
 		}
 
 		public override void Added (XElement target)
@@ -203,13 +210,18 @@ namespace Xamarin.ApiDiff {
 			var o = GetObsoleteMessage (target);
 			if (!first && (o.Length > 0))
 				Output.WriteLine ();
-			Indent ().WriteLine ("\t{0}{1}", o, GetDescription (target));
+			Indent ();
+			bool isInterface = IsInInterface (target);
+			Output.Write ("\t", ElementName, isInterface ? "breaking" : string.Empty, isInterface ? "data-is-breaking" : "data-is-non-breaking");
+			Output.Write ("{0}{1}", o, GetDescription (target));
+			Output.WriteLine ("");
 			first = false;
 		}
 
 		public virtual void AfterAdding ()
 		{
-			Output.WriteLine ("
");; + Output.WriteLine ("
"); + Output.WriteLine ("
"); } public override void Modified (XElement source, XElement target, ApiChanges change) @@ -220,7 +232,7 @@ namespace Xamarin.ApiDiff { { first = true; Output.WriteLine ("

Removed {0}:

\n", list.Count () > 1 ? GroupName : ElementName); - Output.WriteLine (State.Colorize ? "
" : "
");
+			Output.WriteLine ("
");
 		}
 
 		public override void Removed (XElement source)
@@ -228,7 +240,13 @@ namespace Xamarin.ApiDiff {
 			var o = GetObsoleteMessage (source);
 			if (!first && (o.Length > 0))
 				Output.WriteLine ();
-			Indent ().WriteLine ("\t{0}{1}", o, GetDescription (source));
+
+			bool is_breaking = IsBreakingRemoval (source);
+
+			Indent ();
+			Output.Write ("\t", ElementName, is_breaking ? "data-is-breaking" : "data-is-non-breaking", is_breaking ? "breaking" : string.Empty);
+			Output.Write ("{0}{1}", o, GetDescription (source));
+			Output.WriteLine ("");
 			first = false;
 		}
 
@@ -558,15 +576,13 @@ namespace Xamarin.ApiDiff {
 					return; // neither is obsolete
 				var change = new ApiChange ();
 				change.Header = "Obsoleted " + GroupName;
-				if (State.Colorize)
-					change.Append ("");
+				change.Append (string.Format ("", ElementName));
 				change.Append ("[Obsolete (");
 				if (tgtObsolete != string.Empty)
 					change.Append ("\"").Append (tgtObsolete).Append ("\"");
 				change.Append (")]\n");
 				change.Append (GetDescription (target));
-				if (State.Colorize)
-					change.Append ("");
+				change.Append ("");
 				change.AnyChange = true;
 				changes.Add (source, target, change);
 			} else if (tgtObsolete == null) {
diff --git a/mcs/tools/corcompare/mono-api-html/MethodComparer.cs b/mcs/tools/corcompare/mono-api-html/MethodComparer.cs
index 1dffa17dfcc..4c893e757ec 100644
--- a/mcs/tools/corcompare/mono-api-html/MethodComparer.cs
+++ b/mcs/tools/corcompare/mono-api-html/MethodComparer.cs
@@ -26,6 +26,7 @@
 
 using System;
 using System.Linq;
+using System.Reflection;
 using System.Xml.Linq;
 
 namespace Xamarin.ApiDiff {
@@ -62,5 +63,15 @@ namespace Xamarin.ApiDiff {
 				return eGPs.Count () == sGPs.Count ();
 			}
 		}
+
+		protected override bool IsBreakingRemoval (XElement e)
+		{
+			// Removing virtual methods that override another method is not a breaking change.
+			var is_override = e.Attribute ("is-override");
+			if (is_override != null)
+				return is_override.Value != "true";
+			
+			return true; // all other removals are breaking changes
+		}
 	}
 }
\ No newline at end of file
diff --git a/mcs/tools/corcompare/mono-api-html/NamespaceComparer.cs b/mcs/tools/corcompare/mono-api-html/NamespaceComparer.cs
index 258374c6b9d..746166e0a64 100644
--- a/mcs/tools/corcompare/mono-api-html/NamespaceComparer.cs
+++ b/mcs/tools/corcompare/mono-api-html/NamespaceComparer.cs
@@ -61,11 +61,13 @@ namespace Xamarin.ApiDiff {
 			if (State.IgnoreNew.Any (re => re.IsMatch (name)))
 				return;
 
+			Output.WriteLine (" 
", name); Output.WriteLine ("

New Namespace {0}

", name); Output.WriteLine (); // list all new types foreach (var addedType in target.Element ("classes").Elements ("class")) comparer.Added (addedType); + Output.WriteLine ("
", name); Output.WriteLine (); } @@ -78,18 +80,24 @@ namespace Xamarin.ApiDiff { var s = Output.ToString (); State.Output = output; if (s.Length > 0) { - Output.WriteLine ("

Namespace {0}

", target.Attribute ("name").Value); + var name = target.Attribute ("name").Value; + Output.WriteLine ("
", name); + Output.WriteLine ("

Namespace {0}

", name); Output.WriteLine (s); + Output.WriteLine ("
", name); } } public override void Removed (XElement source) { - Output.WriteLine ("

Removed Namespace {0}

", source.Attribute ("name").Value); + var name = source.Attribute ("name").Value; + Output.WriteLine ("
", name); + Output.WriteLine ("

Removed Namespace {0}

", name); Output.WriteLine (); // list all removed types foreach (var removedType in source.Element ("classes").Elements ("class")) comparer.Removed (removedType); + Output.WriteLine ("
", name); Output.WriteLine (); } } diff --git a/mcs/tools/corcompare/mono-api-html/mono-api-html.csproj b/mcs/tools/corcompare/mono-api-html/mono-api-html.csproj index 286a4d0192a..6ac0f241ade 100644 --- a/mcs/tools/corcompare/mono-api-html/mono-api-html.csproj +++ b/mcs/tools/corcompare/mono-api-html/mono-api-html.csproj @@ -19,7 +19,6 @@ prompt 4 false - /Developer/MonoTouch/Source/monotouch/tools/apidiff/references/compat/monotouch.xml /Developer/MonoTouch/Source/monotouch/tools/apidiff/temp/compat/monotouch.xml -i INSObjectProtocol /tmp/diff.html full