From 3a1f13340e2875d0619fc19cd894a8391bc053dc Mon Sep 17 00:00:00 2001 From: akarnokd Date: Thu, 14 Jun 2018 11:36:06 +0200 Subject: [PATCH 1/2] 4.x: Check for license header and add them --- .../Source/facades/GlobalAssemblyVersion.cs | 6 +- .../TypeForwarders.Core.cs | 4 + .../TypeForwarders.Experimental.cs | 4 + .../TypeForwarders.Interfaces.cs | 4 + .../TypeForwarders.Linq.cs | 4 + .../TypeForwarders.PlatformServices.cs | 4 + .../TypeForwarders.Providers.cs | 4 + .../TypeForwarders.Remoting.cs | 4 + .../TypeForwarders.Forms.cs | 4 + .../TypeForwarders.Threading.cs | 4 + .../TypeForwarders.WindowsRuntime.cs | 4 + .../src/System.Reactive/Linq/QueryDebugger.cs | 6 +- .../Tests/ImmutableListTest.cs | 6 +- .../Tests/Internal/PriorityQueueTest.cs | 6 +- .../Tests/LicenseHeaderTest.cs | 98 +++++++++++++++++++ 15 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 Rx.NET/Source/tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs diff --git a/Rx.NET/Source/facades/GlobalAssemblyVersion.cs b/Rx.NET/Source/facades/GlobalAssemblyVersion.cs index 862e953c3e..4b3206acf4 100644 --- a/Rx.NET/Source/facades/GlobalAssemblyVersion.cs +++ b/Rx.NET/Source/facades/GlobalAssemblyVersion.cs @@ -1,4 +1,8 @@ - +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + + using System.Reflection; diff --git a/Rx.NET/Source/facades/System.Reactive.Core/TypeForwarders.Core.cs b/Rx.NET/Source/facades/System.Reactive.Core/TypeForwarders.Core.cs index 5b6734c279..630acd7250 100644 --- a/Rx.NET/Source/facades/System.Reactive.Core/TypeForwarders.Core.cs +++ b/Rx.NET/Source/facades/System.Reactive.Core/TypeForwarders.Core.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.ObservableExtensions))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.AnonymousObservable<>))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.AnonymousObserver<>))] diff --git a/Rx.NET/Source/facades/System.Reactive.Experimental/TypeForwarders.Experimental.cs b/Rx.NET/Source/facades/System.Reactive.Experimental/TypeForwarders.Experimental.cs index 2c0cd1f191..3f0cc7a27e 100644 --- a/Rx.NET/Source/facades/System.Reactive.Experimental/TypeForwarders.Experimental.cs +++ b/Rx.NET/Source/facades/System.Reactive.Experimental/TypeForwarders.Experimental.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.ExperimentalAttribute))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.ListObservable<>))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Linq.ObservableEx))] diff --git a/Rx.NET/Source/facades/System.Reactive.Interfaces/TypeForwarders.Interfaces.cs b/Rx.NET/Source/facades/System.Reactive.Interfaces/TypeForwarders.Interfaces.cs index 8c7d881a0f..40d06d2130 100644 --- a/Rx.NET/Source/facades/System.Reactive.Interfaces/TypeForwarders.Interfaces.cs +++ b/Rx.NET/Source/facades/System.Reactive.Interfaces/TypeForwarders.Interfaces.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.IEventPatternSource<>))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.IEventPattern<,>))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.IEventSource<>))] diff --git a/Rx.NET/Source/facades/System.Reactive.Linq/TypeForwarders.Linq.cs b/Rx.NET/Source/facades/System.Reactive.Linq/TypeForwarders.Linq.cs index 247a8365f4..e1007c5a19 100644 --- a/Rx.NET/Source/facades/System.Reactive.Linq/TypeForwarders.Linq.cs +++ b/Rx.NET/Source/facades/System.Reactive.Linq/TypeForwarders.Linq.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.EventPatternSourceBase<,>))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.EventPattern<>))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.EventPattern<,>))] diff --git a/Rx.NET/Source/facades/System.Reactive.PlatformServices/TypeForwarders.PlatformServices.cs b/Rx.NET/Source/facades/System.Reactive.PlatformServices/TypeForwarders.PlatformServices.cs index 62cd6baf98..0667135f95 100644 --- a/Rx.NET/Source/facades/System.Reactive.PlatformServices/TypeForwarders.PlatformServices.cs +++ b/Rx.NET/Source/facades/System.Reactive.PlatformServices/TypeForwarders.PlatformServices.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Concurrency.EventLoopScheduler))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Concurrency.NewThreadScheduler))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Concurrency.TaskPoolScheduler))] diff --git a/Rx.NET/Source/facades/System.Reactive.Providers/TypeForwarders.Providers.cs b/Rx.NET/Source/facades/System.Reactive.Providers/TypeForwarders.Providers.cs index aa787f6352..95c943a034 100644 --- a/Rx.NET/Source/facades/System.Reactive.Providers/TypeForwarders.Providers.cs +++ b/Rx.NET/Source/facades/System.Reactive.Providers/TypeForwarders.Providers.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Joins.QueryablePattern))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Joins.QueryablePattern<,,,,,,,,,>))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Joins.QueryablePattern<,,,,,,,,,,>))] diff --git a/Rx.NET/Source/facades/System.Reactive.Runtime.Remoting/TypeForwarders.Remoting.cs b/Rx.NET/Source/facades/System.Reactive.Runtime.Remoting/TypeForwarders.Remoting.cs index ebe04a3c08..8dfb1532e5 100644 --- a/Rx.NET/Source/facades/System.Reactive.Runtime.Remoting/TypeForwarders.Remoting.cs +++ b/Rx.NET/Source/facades/System.Reactive.Runtime.Remoting/TypeForwarders.Remoting.cs @@ -1 +1,5 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Linq.RemotingObservable))] diff --git a/Rx.NET/Source/facades/System.Reactive.Windows.Forms/TypeForwarders.Forms.cs b/Rx.NET/Source/facades/System.Reactive.Windows.Forms/TypeForwarders.Forms.cs index 64d80cdf9b..e7b7daf64e 100644 --- a/Rx.NET/Source/facades/System.Reactive.Windows.Forms/TypeForwarders.Forms.cs +++ b/Rx.NET/Source/facades/System.Reactive.Windows.Forms/TypeForwarders.Forms.cs @@ -1,2 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Concurrency.ControlScheduler))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Linq.ControlObservable))] diff --git a/Rx.NET/Source/facades/System.Reactive.Windows.Threading/TypeForwarders.Threading.cs b/Rx.NET/Source/facades/System.Reactive.Windows.Threading/TypeForwarders.Threading.cs index e8205272e6..912867a53a 100644 --- a/Rx.NET/Source/facades/System.Reactive.Windows.Threading/TypeForwarders.Threading.cs +++ b/Rx.NET/Source/facades/System.Reactive.Windows.Threading/TypeForwarders.Threading.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + #if WINDOWS [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Concurrency.CoreDispatcherScheduler))] #else diff --git a/Rx.NET/Source/facades/System.Reactive.WindowsRuntime/TypeForwarders.WindowsRuntime.cs b/Rx.NET/Source/facades/System.Reactive.WindowsRuntime/TypeForwarders.WindowsRuntime.cs index 69bbf41518..2809f08410 100644 --- a/Rx.NET/Source/facades/System.Reactive.WindowsRuntime/TypeForwarders.WindowsRuntime.cs +++ b/Rx.NET/Source/facades/System.Reactive.WindowsRuntime/TypeForwarders.WindowsRuntime.cs @@ -1,3 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.IEventPatternSource<,>))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Linq.AsyncInfoObservable))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Reactive.Linq.WindowsObservable))] diff --git a/Rx.NET/Source/src/System.Reactive/Linq/QueryDebugger.cs b/Rx.NET/Source/src/System.Reactive/Linq/QueryDebugger.cs index 75e9a5a684..a4b4161029 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/QueryDebugger.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/QueryDebugger.cs @@ -1,4 +1,8 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. // // This file acts as a placeholder for future extension with a debugger service diff --git a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/ImmutableListTest.cs b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/ImmutableListTest.cs index 3e3c4f3e33..5cd5b8b75c 100644 --- a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/ImmutableListTest.cs +++ b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/ImmutableListTest.cs @@ -1,4 +1,8 @@ -using Xunit; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using Xunit; using System.Linq; using System.Reactive; diff --git a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/Internal/PriorityQueueTest.cs b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/Internal/PriorityQueueTest.cs index 235c0baede..c96e9fda90 100644 --- a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/Internal/PriorityQueueTest.cs +++ b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/Internal/PriorityQueueTest.cs @@ -1,4 +1,8 @@ -using System.Reactive; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System.Reactive; using Xunit; namespace ReactiveTests.Tests diff --git a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs new file mode 100644 index 0000000000..0679ec7b78 --- /dev/null +++ b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs @@ -0,0 +1,98 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace Tests.System.Reactive.Tests +{ + /// + /// Verify that main classes and unit tests have a license header + /// in the source files. + /// + public class LicenseHeaderTest + { + static readonly bool fixHeaders = true; + + static readonly string[] lines = { + "// Licensed to the .NET Foundation under one or more agreements.", + "// The .NET Foundation licenses this file to you under the Apache 2.0 License.", + "// See the LICENSE file in the project root for more information.", + "" + }; + + [Fact] + public void ScanFiles() + { + var dir = Directory.GetCurrentDirectory(); + var idx = dir.IndexOf("Rx.NET"); + if (idx < 0) + { + Console.WriteLine($"Could not locate sources directory: {dir}"); + } + else + { + var newDir = dir.Substring(0, idx) + "Rx.NET/Source"; + + var error = new StringBuilder(); + + var count = ScanPath(newDir, error); + + if (error.Length != 0) + { + + Assert.False(true, $"Files with no license header: {count}\r\n{error.ToString()}"); + } + } + } + + int ScanPath(string path, StringBuilder error) + { + var count = 0; + foreach (var file in Directory.EnumerateFiles(path, "*.cs", SearchOption.AllDirectories)) + { + // exclusions + if (file.Contains("obj/Debug") + || file.Contains(@"obj\Debug") + || file.Contains("AssemblyInfo.cs") + || file.Contains(".Designer.cs") + || file.Contains(".Generated.cs") + || file.Contains("Uwp.DeviceRunner") + ) + { + continue; + } + + // analysis + string content = File.ReadAllText(file); + + if (!content.StartsWith(lines[0])) + { + count++; + error.Append(file).Append("\r\n"); + + if (fixHeaders) + { + StringBuilder newContent = new StringBuilder(); + string separator = content.Contains("\r\n") ? "\r\n" : "\n"; + + foreach (var s in lines) + { + newContent.Append(s).Append(separator); + } + newContent.Append(content); + + File.WriteAllText(file, newContent.ToString()); + } + } + } + return count; + } + } +} From ea986e299c48db0acbab9c21d3e51d618567f280 Mon Sep 17 00:00:00 2001 From: akarnokd Date: Thu, 14 Jun 2018 11:58:31 +0200 Subject: [PATCH 2/2] Ignore obj/Release --- .../tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs index 0679ec7b78..6f19705807 100644 --- a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs +++ b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/LicenseHeaderTest.cs @@ -64,6 +64,8 @@ int ScanPath(string path, StringBuilder error) || file.Contains(".Designer.cs") || file.Contains(".Generated.cs") || file.Contains("Uwp.DeviceRunner") + || file.Contains(@"obj\Release") + || file.Contains("obj/Release") ) { continue;