Permalink
Please sign in to comment.
Showing
with
328 additions
and 731 deletions.
- +2 −0 .gitattributes
- +3 −1 .gitignore
- +2 −1 .travis.yml
- +1 −8 KestrelHttpServer.sln
- +3 −1 appveyor.yml
- +32 −32 build.cmd
- +21 −19 build.sh
- +8 −1 makefile.shade
- +2 −0 samples/LargeResponseApp/Startup.cs
- +6 −4 samples/LargeResponseApp/project.json
- +1 −0 samples/SampleApp/Startup.cs
- +3 −5 samples/SampleApp/project.json
- +2 −1 src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json
- +10 −19 src/Microsoft.AspNetCore.Server.Kestrel/project.json
- +12 −9 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs
- +32 −31 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs
- +17 −0 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs
- +16 −12 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs
- +9 −6 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs
- +3 −2 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs
- +15 −4 test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json
- +6 −6 test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs
- +3 −3 test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs
- +35 −33 test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs
- +6 −7 test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs
- +12 −9 test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs
- +0 −37 test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs
- +4 −4 test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs
- +15 −4 test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs
- +18 −8 test/Microsoft.AspNetCore.Server.KestrelTests/project.json
- +1 −12 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs
- +2 −10 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs
- +1 −1 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs
- +8 −12 tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json
- +10 −5 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs
- +7 −19 tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json
- +0 −20 tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj
- +0 −49 tools/Microsoft.StandardsPolice/Program.cs
- +0 −292 tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs
- +0 −44 tools/Microsoft.StandardsPolice/project.json
2
.gitattributes
4
.gitignore
3
.travis.yml
9
KestrelHttpServer.sln
4
appveyor.yml
64
build.cmd
| @@ -1,40 +1,40 @@ | ||
| -@echo off | ||
| -cd %~dp0 | ||
| - | ||
| +@ECHO off | ||
| SETLOCAL | ||
| + | ||
| +SET REPO_FOLDER=%~dp0 | ||
| +CD %REPO_FOLDER% | ||
| + | ||
| +SET BUILD_FOLDER=.build | ||
| +SET KOREBUILD_FOLDER=%BUILD_FOLDER%\KoreBuild-dotnet | ||
| +SET KOREBUILD_VERSION= | ||
| + | ||
| +SET NUGET_PATH=%BUILD_FOLDER%\NuGet.exe | ||
| SET NUGET_VERSION=latest | ||
| SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe | ||
| -SET BUILDCMD_KOREBUILD_VERSION= | ||
| -SET BUILDCMD_DNX_VERSION= | ||
| - | ||
| -IF EXIST %CACHED_NUGET% goto copynuget | ||
| -echo Downloading latest version of NuGet.exe... | ||
| -IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet | ||
| -@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" | ||
| - | ||
| -:copynuget | ||
| -IF EXIST .nuget\nuget.exe goto restore | ||
| -md .nuget | ||
| -copy %CACHED_NUGET% .nuget\nuget.exe > nul | ||
| - | ||
| -:restore | ||
| -IF EXIST packages\Sake goto getdnx | ||
| -IF "%BUILDCMD_KOREBUILD_VERSION%"=="" ( | ||
| - .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre | ||
| -) ELSE ( | ||
| - .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre | ||
| + | ||
| +IF NOT EXIST %BUILD_FOLDER% ( | ||
| + md %BUILD_FOLDER% | ||
| ) | ||
| -.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages | ||
| -:getdnx | ||
| -IF "%BUILDCMD_DNX_VERSION%"=="" ( | ||
| - SET BUILDCMD_DNX_VERSION=latest | ||
| +IF NOT EXIST %NUGET_PATH% ( | ||
| + IF NOT EXIST %CACHED_NUGET% ( | ||
| + echo Downloading latest version of NuGet.exe... | ||
| + IF NOT EXIST %LocalAppData%\NuGet ( | ||
| + md %LocalAppData%\NuGet | ||
| + ) | ||
| + @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" | ||
| + ) | ||
| + | ||
| + copy %CACHED_NUGET% %NUGET_PATH% > nul | ||
| ) | ||
| -IF "%SKIP_DNX_INSTALL%"=="" ( | ||
| - CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default | ||
| - CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default | ||
| -) ELSE ( | ||
| - CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86 | ||
| + | ||
| +IF NOT EXIST %KOREBUILD_FOLDER% ( | ||
| + SET KOREBUILD_DOWNLOAD_ARGS= | ||
| + IF NOT "%KOREBUILD_VERSION%"=="" ( | ||
| + SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION% | ||
| + ) | ||
| + | ||
| + %BUILD_FOLDER%\nuget.exe install KoreBuild-dotnet -ExcludeVersion -o %BUILD_FOLDER% -nocache -pre %KOREBUILD_DOWNLOAD_ARGS% | ||
| ) | ||
| -packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %* | ||
| +"%KOREBUILD_FOLDER%\build\KoreBuild.cmd" %* |
40
build.sh
9
makefile.shade
| @@ -1,8 +1,15 @@ | ||
| - | ||
| var VERSION='0.1' | ||
| var FULL_VERSION='0.1' | ||
| var AUTHORS='Microsoft' | ||
| +var kestrelSrcDir='${Path.Combine(Directory.GetCurrentDirectory(), "src/Microsoft.AspNetCore.Server.Kestrel")}' | ||
| use-standard-lifecycle | ||
| k-standard-goals | ||
| custom-goals | ||
| + | ||
| +exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode' workingdir='${kestrelSrcDir}' | ||
| +exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode Http/FrameHeaders.Generated.cs Http/Frame.Generated.cs' workingdir='${kestrelSrcDir}' | ||
| + | ||
| +exec program='dotnet' commandline='restore' workingdir='${kestrelSrcDir}' | ||
| +exec program='dotnet' commandline='restore ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' | ||
| +exec program='dotnet' commandline='run -p ../../tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier' workingdir='${kestrelSrcDir}' |
2
samples/LargeResponseApp/Startup.cs
10
samples/LargeResponseApp/project.json
1
samples/SampleApp/Startup.cs
8
samples/SampleApp/project.json
3
src/Microsoft.AspNetCore.Server.Kestrel.Https/project.json
29
src/Microsoft.AspNetCore.Server.Kestrel/project.json
21
test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs
63
test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PathBaseTests.cs
17
test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/PortManager.cs
| @@ -0,0 +1,17 @@ | ||
| +// Copyright (c) .NET Foundation. All rights reserved. | ||
| +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| + | ||
| +using System.Threading; | ||
| + | ||
| +namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests | ||
| +{ | ||
| + public static class PortManager | ||
| + { | ||
| + private static int _nextPort = 8001; | ||
| + | ||
| + public static int GetPort() | ||
| + { | ||
| + return Interlocked.Increment(ref _nextPort); | ||
| + } | ||
| + } | ||
| +} |
28
test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs
15
test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs
5
test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ThreadCountTests.cs
19
test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json
12
test/Microsoft.AspNetCore.Server.KestrelTests/ChunkedResponseTests.cs
6
test/Microsoft.AspNetCore.Server.KestrelTests/ConnectionFilterTests.cs
68
test/Microsoft.AspNetCore.Server.KestrelTests/EngineTests.cs
13
test/Microsoft.AspNetCore.Server.KestrelTests/HttpsConnectionFilterTests.cs
21
test/Microsoft.AspNetCore.Server.KestrelTests/NetworkingTests.cs
37
test/Microsoft.AspNetCore.Server.KestrelTests/Program.cs
| @@ -1,37 +0,0 @@ | ||
| -// Copyright (c) .NET Foundation. All rights reserved. | ||
| -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| - | ||
| -using System; | ||
| -using Microsoft.Extensions.PlatformAbstractions; | ||
| - | ||
| -namespace Microsoft.AspNetCore.Server.KestrelTests | ||
| -{ | ||
| - /// <summary> | ||
| - /// Summary description for Program | ||
| - /// </summary> | ||
| - public class Program | ||
| - { | ||
| - private readonly IApplicationEnvironment env; | ||
| - private readonly IServiceProvider sp; | ||
| - private readonly ILibraryManager _libraryManager; | ||
| - | ||
| - public Program( | ||
| - IApplicationEnvironment env, | ||
| - IServiceProvider sp, | ||
| - ILibraryManager libraryManager) | ||
| - { | ||
| - this.env = env; | ||
| - this.sp = sp; | ||
| - _libraryManager = libraryManager; | ||
| - } | ||
| - | ||
| - public int Main() | ||
| - { | ||
| - return Xunit.Runner.Dnx.Program.Main(new string[] | ||
| - { | ||
| - "-class", | ||
| - typeof(MultipleLoopTests).FullName | ||
| - }); | ||
| - } | ||
| - } | ||
| -} |
8
test/Microsoft.AspNetCore.Server.KestrelTests/TestConnection.cs
19
test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs
26
test/Microsoft.AspNetCore.Server.KestrelTests/project.json
| @@ -1,31 +1,41 @@ | ||
| { | ||
| "version": "1.0.0-*", | ||
| "dependencies": { | ||
| - "xunit.runner.aspnet": "2.0.0-aspnet-*", | ||
| "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", | ||
| "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0-*", | ||
| "Microsoft.AspNetCore.Testing": "1.0.0-*", | ||
| - "System.Net.Http": "4.0.1-*" | ||
| + "Microsoft.NETCore.Platforms": "1.0.1-*", | ||
| + "System.Net.Http": "4.0.1-*", | ||
| + "xunit": "2.1.0" | ||
| }, | ||
| "frameworks": { | ||
| - "dnx451": { }, | ||
| + "dnx451": { | ||
| + "dependencies": { | ||
| + "xunit.runner.console": "2.1.0" | ||
| + } | ||
| + }, | ||
| "dnxcore50": { | ||
| "dependencies": { | ||
| "System.Diagnostics.TraceSource": "4.0.0-*", | ||
| "System.Globalization.Extensions": "4.0.1-*", | ||
| "System.IO": "4.1.0-*", | ||
| "System.Net.Http.WinHttpHandler": "4.0.0-*", | ||
| "System.Net.Sockets": "4.1.0-*", | ||
| - "System.Runtime.Handles": "4.0.1-*" | ||
| - } | ||
| + "System.Runtime.Handles": "4.0.1-*", | ||
| + "xunit.runner.aspnet": "2.0.0-aspnet-*" | ||
| + }, | ||
| + "imports": "portable-net45+win8" | ||
| } | ||
| }, | ||
| "compilationOptions": { | ||
| "allowUnsafe": true, | ||
| "keyFile": "../../tools/Key.snk" | ||
| }, | ||
| + "testRunner": "xunit", | ||
| "commands": { | ||
| - "run": "Microsoft.AspNetCore.Server.KestrelTests", | ||
| - "test": "xunit.runner.aspnet -parallel none" | ||
| - } | ||
| + "test": "xunit.runner.aspnet" | ||
| + }, | ||
| + "content": [ | ||
| + "TestResources/testCert.pfx" | ||
| + ] | ||
| } |
13
tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs
12
tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs
2
tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/Program.cs
20
tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/project.json
| @@ -1,28 +1,24 @@ | ||
| { | ||
| "version": "1.0.0-*", | ||
| - | ||
| + "compilationOptions": { | ||
| + "emitEntryPoint": true | ||
| + }, | ||
| "dependencies": { | ||
| - "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*", | ||
| "Microsoft.AspNetCore.Http.Features": "1.0.0-*", | ||
| "Microsoft.AspNetCore.Hosting": "1.0.0-*" | ||
| }, | ||
| - | ||
| - "commands": { | ||
| - "run": "Microsoft.AspNetCore.Server.Kestrel.GeneratedCode" | ||
| - }, | ||
| - | ||
| "frameworks": { | ||
| + "dnxcore50": { | ||
| + "dependencies": { | ||
| + "NETStandard.Library": "1.0.0-*" | ||
| + } | ||
| + }, | ||
| "dnx451": { | ||
| "frameworkAssemblies": { | ||
| "System.Runtime": "", | ||
| "System.Text.Encoding": "", | ||
| "System.Threading.Tasks": "" | ||
| } | ||
| - }, | ||
| - "dnxcore50": { | ||
| - "dependencies": { | ||
| - "System.Console": "4.0.0-*" | ||
| - } | ||
| } | ||
| } | ||
| } |
15
tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/Program.cs
26
tools/Microsoft.AspNetCore.Server.Kestrel.LibuvCopier/project.json
| @@ -1,31 +1,19 @@ | ||
| { | ||
| "version": "1.0.0-*", | ||
| - "description": "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier Console Application", | ||
| - "authors": [ "pawelka" ], | ||
| - "tags": [ "" ], | ||
| - "projectUrl": "", | ||
| - "licenseUrl": "", | ||
| - | ||
| + "compilationOptions": { | ||
| + "emitEntryPoint": true | ||
| + }, | ||
| "dependencies": { | ||
| "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", | ||
| "Newtonsoft.Json": "7.0.1" | ||
| }, | ||
| - | ||
| - "commands": { | ||
| - "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier": "Microsoft.AspNetCore.Server.Kestrel.LibuvCopier" | ||
| - }, | ||
| - | ||
| "frameworks": { | ||
| - "dnx451": { }, | ||
| "dnxcore50": { | ||
| "dependencies": { | ||
| - "Microsoft.CSharp": "4.0.1-*", | ||
| - "System.Collections": "4.0.11-*", | ||
| - "System.Console": "4.0.0-*", | ||
| - "System.Linq": "4.0.1-*", | ||
| - "System.Threading": "4.0.11-*", | ||
| - "System.IO.FileSystem": "4.0.1-*" | ||
| + "NETStandard.Library": "1.0.0-*", | ||
| + "System.Dynamic.Runtime": "4.0.11-*" | ||
| } | ||
| - } | ||
| + }, | ||
| + "dnx451": { } | ||
| } | ||
| } |
20
tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj
| @@ -1,20 +0,0 @@ | ||
| -<?xml version="1.0" encoding="utf-8"?> | ||
| -<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| - <PropertyGroup> | ||
| - <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
| - <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
| - </PropertyGroup> | ||
| - | ||
| - <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
| - <PropertyGroup Label="Globals"> | ||
| - <ProjectGuid>82295647-7c1c-4671-bab6-0fef58f949ec</ProjectGuid> | ||
| - <RootNamespace>Microsoft.StandardsPolice</RootNamespace> | ||
| - <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
| - <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||
| - </PropertyGroup> | ||
| - | ||
| - <PropertyGroup> | ||
| - <SchemaVersion>2.0</SchemaVersion> | ||
| - </PropertyGroup> | ||
| - <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
| -</Project> |
49
tools/Microsoft.StandardsPolice/Program.cs
| @@ -1,49 +0,0 @@ | ||
| -using Microsoft.CodeAnalysis; | ||
| -using Microsoft.CodeAnalysis.CSharp; | ||
| -using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
| -using System; | ||
| -using System.Collections.Generic; | ||
| -using System.Linq; | ||
| - | ||
| -namespace Microsoft.StandardsPolice | ||
| -{ | ||
| - public class Program | ||
| - { | ||
| - public int Main(string[] args) | ||
| - { | ||
| - var tree = CSharpSyntaxTree.ParseText(@" | ||
| -public class Hello { public Hello(int foo){}; protected int _foo; int _bar; } | ||
| -public class World { public World(int foo){}; protected int _foo; int _bar; static int _quux = 4; enum Blah{} class Clazz{} } | ||
| -"); | ||
| - var diags = new List<Diagnostic>(); | ||
| - | ||
| - var comp = CSharpCompilation.Create("Comp", new[] { tree }); | ||
| - | ||
| - StandardsPoliceCompileModule.ScanCompilation(diags, comp); | ||
| - | ||
| - var hello = comp.GetTypeByMetadataName("Hello"); | ||
| - foreach (var f in hello.GetMembers().OfType<IFieldSymbol>()) | ||
| - { | ||
| - var syntax = f.DeclaringSyntaxReferences.Single().GetSyntax(); | ||
| - Console.WriteLine($"{syntax.ToFullString()}"); | ||
| - | ||
| - var fds = syntax.Parent.Parent as FieldDeclarationSyntax; | ||
| - var toks = syntax.DescendantTokens().ToArray(); | ||
| - var nods = syntax.DescendantNodesAndSelf().ToArray(); | ||
| - var mods = fds.Modifiers; | ||
| - | ||
| - foreach (var mod in fds.Modifiers) | ||
| - { | ||
| - Console.WriteLine($"{mod.Kind()} {mod.ToFullString()}"); | ||
| - } | ||
| - var locs = f.Locations.ToArray(); | ||
| - } | ||
| - | ||
| - foreach(var d in diags) | ||
| - { | ||
| - Console.WriteLine(d); | ||
| - } | ||
| - return 0; | ||
| - } | ||
| - } | ||
| -} |
292
tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs
| @@ -1,292 +0,0 @@ | ||
| -using Microsoft.Dnx.Compilation.CSharp; | ||
| -using System.Collections.Generic; | ||
| -using System.Linq; | ||
| -using Microsoft.CodeAnalysis; | ||
| -using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
| -using Microsoft.CodeAnalysis.CSharp; | ||
| -using System; | ||
| - | ||
| -namespace Microsoft.StandardsPolice | ||
| -{ | ||
| - public class StandardsPoliceCompileModule : ICompileModule | ||
| - { | ||
| - public void BeforeCompile(BeforeCompileContext context) | ||
| - { | ||
| - ScanCompilation(context.Diagnostics, context.Compilation); | ||
| - } | ||
| - | ||
| - internal static void ScanCompilation(IList<Diagnostic> diagnostics, CSharpCompilation compilation) | ||
| - { | ||
| - ScanNamespace(diagnostics, compilation.GlobalNamespace); | ||
| - | ||
| - foreach (var st in compilation.SyntaxTrees) | ||
| - { | ||
| - if (!st.FilePath.EndsWith(".Generated.cs")) | ||
| - { | ||
| - ScanSyntaxTree(diagnostics, st); | ||
| - } | ||
| - } | ||
| - } | ||
| - | ||
| - internal static void ScanSyntaxTree(IList<Diagnostic> diagnostics, SyntaxTree syntaxTree) | ||
| - { | ||
| - var root = syntaxTree.GetRoot(); | ||
| - | ||
| - var typeDeclarations = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax)) | ||
| - .OfType<TypeDeclarationSyntax>() | ||
| - .ToArray(); | ||
| - | ||
| - if (typeDeclarations.Length > 1) | ||
| - { | ||
| - foreach (var typeDeclaration in typeDeclarations) | ||
| - { | ||
| - diagnostics.Add(Diagnostic.Create( | ||
| - "SP1002", "StandardsPolice", "more than one type per file", | ||
| - DiagnosticSeverity.Warning, | ||
| - DiagnosticSeverity.Warning, | ||
| - false, | ||
| - 3, | ||
| - location: typeDeclaration.GetLocation())); | ||
| - } | ||
| - } | ||
| - | ||
| - var usingDirectives = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax)) | ||
| - .OfType<UsingDirectiveSyntax>() | ||
| - .ToArray(); | ||
| - | ||
| - var priorUsingDirective = default(UsingDirectiveSyntax); | ||
| - foreach (var usingDirective in usingDirectives) | ||
| - { | ||
| - var acceptableOrder = false; | ||
| - if (!acceptableOrder && priorUsingDirective == null) | ||
| - { | ||
| - acceptableOrder = true; | ||
| - } | ||
| - if (!acceptableOrder && string.Compare(priorUsingDirective.Name.ToString(), usingDirective.Name.ToString(), StringComparison.OrdinalIgnoreCase) < 0) | ||
| - { | ||
| - acceptableOrder = true; | ||
| - } | ||
| - if (!acceptableOrder && priorUsingDirective.Name.ToString() == "System") | ||
| - { | ||
| - acceptableOrder = true; | ||
| - } | ||
| - if (!acceptableOrder && | ||
| - priorUsingDirective.Name.ToString().StartsWith("System") && | ||
| - !usingDirective.Name.ToString().StartsWith("System")) | ||
| - { | ||
| - acceptableOrder = true; | ||
| - } | ||
| - if (!acceptableOrder) | ||
| - { | ||
| - diagnostics.Add(Diagnostic.Create( | ||
| - "SP1004", "StandardsPolice", "namespaces not alphabetized", | ||
| - DiagnosticSeverity.Warning, | ||
| - DiagnosticSeverity.Warning, | ||
| - false, | ||
| - 3, | ||
| - location: usingDirective.GetLocation())); | ||
| - } | ||
| - priorUsingDirective = usingDirective; | ||
| - } | ||
| - } | ||
| - | ||
| - private static void ScanNamespace(IList<Diagnostic> diagnostics, INamespaceSymbol namespaceSymbol) | ||
| - { | ||
| - foreach (var member in namespaceSymbol.GetNamespaceMembers()) | ||
| - { | ||
| - ScanNamespace(diagnostics, member); | ||
| - } | ||
| - foreach (var member in namespaceSymbol.GetTypeMembers()) | ||
| - { | ||
| - ScanType(diagnostics, member); | ||
| - } | ||
| - } | ||
| - | ||
| - private static void ScanType(IList<Diagnostic> diagnostics, INamedTypeSymbol typeSymbol) | ||
| - { | ||
| - if (typeSymbol.Locations.Any(location => location.IsInSource)) | ||
| - { | ||
| - RuleFieldPrivateKeyword(diagnostics, typeSymbol); | ||
| - RuleMembersAreInCorrectOrder(diagnostics, typeSymbol, MapClassMembers); | ||
| - } | ||
| - | ||
| - foreach (var member in typeSymbol.GetTypeMembers()) | ||
| - { | ||
| - ScanType(diagnostics, member); | ||
| - } | ||
| - } | ||
| - | ||
| - | ||
| - private static void RuleFieldPrivateKeyword(IList<Diagnostic> diagnostics, INamedTypeSymbol typeSymbol) | ||
| - { | ||
| - foreach (var member in typeSymbol.GetMembers().OfType<IFieldSymbol>()) | ||
| - { | ||
| - if (member.DeclaredAccessibility != Accessibility.Private) | ||
| - { | ||
| - continue; | ||
| - } | ||
| - | ||
| - foreach (var syntaxReference in member.DeclaringSyntaxReferences) | ||
| - { | ||
| - var fieldHasPrivateKeyword = false; | ||
| - var syntax = syntaxReference.GetSyntax(); | ||
| - var fds = syntax?.Parent?.Parent as FieldDeclarationSyntax; | ||
| - if (fds == null) | ||
| - { | ||
| - continue; | ||
| - } | ||
| - foreach (var mod in fds.Modifiers) | ||
| - { | ||
| - if (mod.IsKind(CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword)) | ||
| - { | ||
| - fieldHasPrivateKeyword = true; | ||
| - } | ||
| - } | ||
| - if (!fieldHasPrivateKeyword) | ||
| - { | ||
| - diagnostics.Add(Diagnostic.Create( | ||
| - "SP1001", "StandardsPolice", "private keyword missing", | ||
| - DiagnosticSeverity.Warning, | ||
| - DiagnosticSeverity.Warning, | ||
| - false, | ||
| - 3, | ||
| - location: member.Locations.SingleOrDefault())); | ||
| - } | ||
| - } | ||
| - } | ||
| - } | ||
| - | ||
| - private static void RuleMembersAreInCorrectOrder(IList<Diagnostic> diagnostics, INamedTypeSymbol typeSymbol, Func<ISymbol, ClassZone> mapZone) | ||
| - { | ||
| - if (typeSymbol.Locations.Length >= 2 || typeSymbol.Name == "Libuv") | ||
| - { | ||
| - // Don't apply to partial classes. All members are enumerated, but are not merged by zone order. | ||
| - return; | ||
| - } | ||
| - | ||
| - var currentZone = ClassZone.BeforeStart; | ||
| - var currentZoneExample = default(ISymbol); | ||
| - foreach (var member in typeSymbol.GetMembers()) | ||
| - { | ||
| - var memberZone = mapZone(member); | ||
| - if (memberZone == ClassZone.Ignored) | ||
| - { | ||
| - continue; | ||
| - } | ||
| - if (currentZone <= memberZone) | ||
| - { | ||
| - currentZone = memberZone; | ||
| - currentZoneExample = member; | ||
| - } | ||
| - if (memberZone >= ClassZone.OtherThings) | ||
| - { | ||
| - continue; | ||
| - } | ||
| - if (memberZone < currentZone) | ||
| - { | ||
| - if (member.Locations.Count() == 1) | ||
| - { | ||
| - diagnostics.Add(Diagnostic.Create( | ||
| - "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be after {currentZone} like {currentZoneExample.Name}", | ||
| - DiagnosticSeverity.Warning, | ||
| - DiagnosticSeverity.Warning, | ||
| - false, | ||
| - 3, | ||
| - location: member.Locations.Single(), | ||
| - additionalLocations: currentZoneExample.Locations)); | ||
| - } | ||
| - } | ||
| - } | ||
| - currentZone = ClassZone.AfterEnd; | ||
| - currentZoneExample = null; | ||
| - foreach (var member in typeSymbol.GetMembers().Reverse()) | ||
| - { | ||
| - var memberZone = mapZone(member); | ||
| - if (memberZone == ClassZone.Ignored) | ||
| - { | ||
| - continue; | ||
| - } | ||
| - if (currentZone >= memberZone) | ||
| - { | ||
| - currentZone = memberZone; | ||
| - currentZoneExample = member; | ||
| - } | ||
| - if (memberZone <= ClassZone.OtherThings) | ||
| - { | ||
| - continue; | ||
| - } | ||
| - if (memberZone > currentZone) | ||
| - { | ||
| - if (member.Locations.Count() == 1) | ||
| - { | ||
| - diagnostics.Add(Diagnostic.Create( | ||
| - "SP1003", "StandardsPolice", $"{memberZone} like {typeSymbol.Name}::{member.Name} shouldn't be before {currentZone} like {currentZoneExample.Name}", | ||
| - DiagnosticSeverity.Warning, | ||
| - DiagnosticSeverity.Warning, | ||
| - false, | ||
| - 3, | ||
| - location: member.Locations.Single(), | ||
| - additionalLocations: currentZoneExample.Locations)); | ||
| - } | ||
| - } | ||
| - } | ||
| - } | ||
| - | ||
| - private static ClassZone MapClassMembers(ISymbol member) | ||
| - { | ||
| - if (member.IsImplicitlyDeclared) | ||
| - { | ||
| - return ClassZone.Ignored; | ||
| - } | ||
| - if (member.Kind == SymbolKind.Field) | ||
| - { | ||
| - return ClassZone.Fields; | ||
| - } | ||
| - if (member.Kind == SymbolKind.Method) | ||
| - { | ||
| - var method = (IMethodSymbol)member; | ||
| - if (method.MethodKind == MethodKind.Constructor || | ||
| - method.MethodKind == MethodKind.StaticConstructor) | ||
| - { | ||
| - return ClassZone.Constructors; | ||
| - } | ||
| - if (method.MethodKind == MethodKind.PropertyGet || | ||
| - method.MethodKind == MethodKind.PropertySet) | ||
| - { | ||
| - return ClassZone.Properties; | ||
| - } | ||
| - } | ||
| - if (member.Kind == SymbolKind.Property) | ||
| - { | ||
| - return ClassZone.Properties; | ||
| - } | ||
| - if (member.Kind == SymbolKind.NamedType) | ||
| - { | ||
| - var namedType = (INamedTypeSymbol)member; | ||
| - if (namedType.TypeKind == TypeKind.Class || | ||
| - namedType.TypeKind == TypeKind.Enum || | ||
| - namedType.TypeKind == TypeKind.Struct) | ||
| - { | ||
| - return ClassZone.NestedTypes; | ||
| - } | ||
| - } | ||
| - return ClassZone.OtherThings; | ||
| - } | ||
| - | ||
| - public void AfterCompile(AfterCompileContext context) | ||
| - { | ||
| - } | ||
| - | ||
| - private enum ClassZone | ||
| - { | ||
| - Ignored, | ||
| - BeforeStart, | ||
| - Fields, | ||
| - Constructors, | ||
| - Properties, | ||
| - OtherThings, | ||
| - NestedTypes, | ||
| - AfterEnd | ||
| - } | ||
| - } | ||
| -} |
44
tools/Microsoft.StandardsPolice/project.json
| @@ -1,44 +0,0 @@ | ||
| -{ | ||
| - "version": "1.0.0-*", | ||
| - | ||
| - "compilationOptions": { | ||
| - "keyFile": "../../tools/Key.snk" | ||
| - }, | ||
| - | ||
| - "description": "Microsoft.StandardsPolice Class Library", | ||
| - | ||
| - "dependencies": { | ||
| - "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-*" | ||
| - }, | ||
| - | ||
| - "commands": { | ||
| - "Microsoft.StandardsPolice": "Microsoft.StandardsPolice" | ||
| - }, | ||
| - | ||
| - "frameworks": { | ||
| - "net451": { | ||
| - "frameworkAssemblies": { | ||
| - "System.Runtime": "", | ||
| - "System.Text.Encoding": "", | ||
| - "System.Threading.Tasks": "" | ||
| - } | ||
| - }, | ||
| - "dnx451": { | ||
| - "frameworkAssemblies": { | ||
| - "System.Runtime": "", | ||
| - "System.Text.Encoding": "", | ||
| - "System.Threading.Tasks": "" | ||
| - } | ||
| - }, | ||
| - "dotnet5.4": { | ||
| - "dependencies": { | ||
| - "System.Console": "4.0.0-*" | ||
| - } | ||
| - }, | ||
| - "dnxcore50": { | ||
| - "dependencies": { | ||
| - "System.Console": "4.0.0-*" | ||
| - } | ||
| - } | ||
| - } | ||
| -} |
0 comments on commit
6757a31