33using System . Text ;
44using BenchmarkDotNet . Build . Helpers ;
55using BenchmarkDotNet . Build . Meta ;
6+ using BenchmarkDotNet . Build . Options ;
67using BenchmarkDotNet . Build . Runners . Changelog ;
78using Cake . Common . Diagnostics ;
89using Cake . Common . IO ;
@@ -21,6 +22,9 @@ public class DocumentationRunner
2122 private readonly FilePath redirectFile ;
2223 private readonly FilePath readmeFile ;
2324 private readonly FilePath rootIndexFile ;
25+ private readonly FilePath analyzersShippedFile ;
26+ private readonly FilePath analyzersUnshippedFile ;
27+ private readonly FilePath analyzersPageFile ;
2428
2529 public DirectoryPath ChangelogSrcDirectory => changelogBuilder . SrcDirectory ;
2630
@@ -35,6 +39,33 @@ public DocumentationRunner(BuildContext context)
3539 docfxJsonFile = docsDirectory . CombineWithFilePath ( "docfx.json" ) ;
3640 readmeFile = context . RootDirectory . CombineWithFilePath ( "README.md" ) ;
3741 rootIndexFile = docsDirectory . CombineWithFilePath ( "index.md" ) ;
42+
43+ var analyzersDirectory = context . RootDirectory . Combine ( "src" ) . Combine ( "BenchmarkDotNet.Analyzers" ) ;
44+ analyzersShippedFile = analyzersDirectory . CombineWithFilePath ( "AnalyzerReleases.Shipped.md" ) ;
45+ analyzersUnshippedFile = analyzersDirectory . CombineWithFilePath ( "AnalyzerReleases.Unshipped.md" ) ;
46+ analyzersPageFile = docsGeneratedDirectory . Combine ( "articles" ) . CombineWithFilePath ( "analyzers.md" ) ;
47+ }
48+
49+ public void MoveAnalyzerRules ( )
50+ {
51+ if ( new FileInfo ( analyzersUnshippedFile . FullPath ) . Length == 0 )
52+ {
53+ return ;
54+ }
55+
56+ string tempFile = System . IO . Path . GetTempFileName ( ) ;
57+ using ( var writer = new StreamWriter ( tempFile ) )
58+ {
59+ writer . WriteLine ( $ "## { KnownOptions . CurrentVersion . Resolve ( context ) } ") ;
60+ CopyLines ( writer , analyzersUnshippedFile ) ;
61+ writer . WriteLine ( ) ;
62+ writer . WriteLine ( ) ;
63+ CopyLines ( writer , analyzersShippedFile ) ;
64+ }
65+
66+ File . Delete ( analyzersShippedFile . FullPath ) ;
67+ File . Move ( tempFile , analyzersShippedFile . FullPath ) ;
68+ File . WriteAllText ( analyzersUnshippedFile . FullPath , string . Empty ) ;
3869 }
3970
4071 public void Fetch ( )
@@ -49,6 +80,7 @@ public void Generate()
4980
5081 UpdateReadme ( ) ;
5182 GenerateIndexMd ( ) ;
83+ GenerateAnalyzersPage ( ) ;
5284 }
5385
5486 public void Build ( )
@@ -91,6 +123,24 @@ private void GenerateIndexMd()
91123 context . GenerateFile ( rootIndexFile , content ) ;
92124 }
93125
126+ private void GenerateAnalyzersPage ( )
127+ {
128+ using var writer = new StreamWriter ( analyzersPageFile . FullPath ) ;
129+ writer . WriteLine ( $ "# Roslyn Analyzers for C#") ;
130+ writer . WriteLine ( ) ;
131+ CopyLines ( writer , analyzersShippedFile ) ;
132+ }
133+
134+ private static void CopyLines ( StreamWriter writer , FilePath filePath )
135+ {
136+ using var reader = new StreamReader ( filePath . FullPath ) ;
137+ while ( reader . ReadLine ( ) is { } line )
138+ {
139+ writer . WriteLine ( ) ;
140+ writer . Write ( line ) ;
141+ }
142+ }
143+
94144 private void GenerateRedirects ( )
95145 {
96146 if ( ! context . FileExists ( redirectFile ) )
0 commit comments