コード例 #1
0
        private static async Task Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
#if DEBUG
                args = new[] { @"..\..\..\..\.." };
#else
                args = new string[] { Environment.CurrentDirectory };
#endif
            }

            string rootPath = args[0];

            StringComparer comparer = StringComparer.InvariantCulture;

            var metadata = new RoslynatorMetadata(rootPath);

            ImmutableArray <AnalyzerMetadata>           analyzers             = metadata.Analyzers;
            ImmutableArray <AnalyzerMetadata>           codeAnalysisAnalyzers = metadata.CodeAnalysisAnalyzers;
            ImmutableArray <AnalyzerMetadata>           formattingAnalyzers   = metadata.FormattingAnalyzers;
            ImmutableArray <RefactoringMetadata>        refactorings          = metadata.Refactorings;
            ImmutableArray <CodeFixMetadata>            codeFixes             = metadata.CodeFixes;
            ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics   = metadata.CompilerDiagnostics;

            WriteAnalyzersReadMe(@"Analyzers\README.md", analyzers, "Roslynator.Analyzers");

            WriteAnalyzersReadMe(@"CodeAnalysis.Analyzers\README.md", codeAnalysisAnalyzers, "Roslynator.CodeAnalysis.Analyzers");

            WriteAnalyzersReadMe(@"Formatting.Analyzers\README.md", formattingAnalyzers, "Roslynator.Formatting.Analyzers");
#if !DEBUG
            VisualStudioInstance instance = MSBuildLocator.QueryVisualStudioInstances().First(f => f.Version.Major == 16);

            MSBuildLocator.RegisterInstance(instance);

            using (MSBuildWorkspace workspace = MSBuildWorkspace.Create())
            {
                workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message);

                string solutionPath = Path.Combine(rootPath, "Roslynator.sln");

                Console.WriteLine($"Loading solution '{solutionPath}'");

                Solution solution = await workspace.OpenSolutionAsync(solutionPath).ConfigureAwait(false);

                Console.WriteLine($"Finished loading solution '{solutionPath}'");

                RoslynatorInfo roslynatorInfo = await RoslynatorInfo.Create(solution).ConfigureAwait(false);

                IOrderedEnumerable <SourceFile> sourceFiles = analyzers
                                                              .Concat(codeAnalysisAnalyzers)
                                                              .Concat(formattingAnalyzers)
                                                              .Select(f => new SourceFile(f.Id, roslynatorInfo.GetAnalyzerFilesAsync(f.Identifier).Result))
                                                              .Concat(refactorings
                                                                      .Select(f => new SourceFile(f.Id, roslynatorInfo.GetRefactoringFilesAsync(f.Identifier).Result)))
                                                              .OrderBy(f => f.Id);

                MetadataFile.SaveSourceFiles(sourceFiles, @"..\SourceFiles.xml");
            }
#endif
            WriteAnalyzerMarkdowns(codeAnalysisAnalyzers, new (string, string)[] { ("Roslynator.CodeAnalysis.Analyzers", "https://www.nuget.org/packages/Roslynator.CodeAnalysis.Analyzers") });
コード例 #2
0
        private static async Task Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
#if DEBUG
                args = new string[] { @"..\..\..\..\.." };
#else
                args = new string[] { Environment.CurrentDirectory };
#endif
            }

            string rootPath = args[0];

            StringComparer comparer = StringComparer.InvariantCulture;

            var metadata = new RoslynatorMetadata(rootPath);

            ImmutableArray <AnalyzerMetadata>           analyzers           = metadata.Analyzers;
            ImmutableArray <RefactoringMetadata>        refactorings        = metadata.Refactorings;
            ImmutableArray <CodeFixMetadata>            codeFixes           = metadata.CodeFixes;
            ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics = metadata.CompilerDiagnostics;

            WriteAnalyzersReadMe(@"Analyzers\README.md", analyzers);

            WriteAnalyzersByCategory(@"Analyzers\AnalyzersByCategory.md", analyzers);
#if !DEBUG
            VisualStudioInstance instance = MSBuildLocator.QueryVisualStudioInstances().First(f => f.Version.Major == 15);

            MSBuildLocator.RegisterInstance(instance);

            using (MSBuildWorkspace workspace = MSBuildWorkspace.Create())
            {
                workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message);

                string solutionPath = Path.Combine(rootPath, "Roslynator.sln");

                Console.WriteLine($"Loading solution '{solutionPath}'");

                Solution solution = await workspace.OpenSolutionAsync(solutionPath).ConfigureAwait(false);

                Console.WriteLine($"Finished loading solution '{solutionPath}'");

                RoslynatorInfo roslynatorInfo = await RoslynatorInfo.Create(solution).ConfigureAwait(false);

                IOrderedEnumerable <SourceFile> sourceFiles = analyzers
                                                              .Select(f => new SourceFile(f.Id, roslynatorInfo.GetAnalyzerFilesAsync(f.Identifier).Result))
                                                              .Concat(refactorings
                                                                      .Select(f => new SourceFile(f.Id, roslynatorInfo.GetRefactoringFilesAsync(f.Identifier).Result)))
                                                              .OrderBy(f => f.Id);

                MetadataFile.SaveSourceFiles(sourceFiles, @"..\SourceFiles.xml");
            }
#endif
            foreach (AnalyzerMetadata analyzer in analyzers)
            {
                WriteAllText(
                    $@"..\docs\analyzers\{analyzer.Id}.md",
                    MarkdownGenerator.CreateAnalyzerMarkdown(analyzer, Array.Empty <string>()),
                    fileMustExists: false);
            }

            foreach (RefactoringMetadata refactoring in refactorings)
            {
                WriteAllText(
                    $@"..\docs\refactorings\{refactoring.Id}.md",
                    MarkdownGenerator.CreateRefactoringMarkdown(refactoring, Array.Empty <string>()),
                    fileMustExists: false);
            }

            foreach (CompilerDiagnosticMetadata diagnostic in compilerDiagnostics)
            {
                WriteAllText(
                    $@"..\docs\cs\{diagnostic.Id}.md",
                    MarkdownGenerator.CreateCompilerDiagnosticMarkdown(diagnostic, codeFixes, comparer, Array.Empty <string>()),
                    fileMustExists: false);
            }

            WriteAllText(
                @"..\docs\refactorings\Refactorings.md",
                MarkdownGenerator.CreateRefactoringsMarkdown(refactorings, comparer));

            WriteAllText(
                @"Refactorings\README.md",
                MarkdownGenerator.CreateRefactoringsReadMe(refactorings.Where(f => !f.IsObsolete), comparer));

            WriteAllText(
                @"CodeFixes\README.md",
                MarkdownGenerator.CreateCodeFixesReadMe(compilerDiagnostics, comparer));

            WriteAllText(
                "DefaultConfigFile.xml",
                XmlGenerator.CreateDefaultConfigFile(refactorings, codeFixes));

            WriteAllText(
                "default.ruleset",
                XmlGenerator.CreateDefaultRuleSet(analyzers));

            // find files to delete
            foreach (string path in Directory.EnumerateFiles(GetPath(@"..\docs\refactorings")))
            {
                if (Path.GetFileName(path) != "Refactorings.md" &&
                    !refactorings.Any(f => f.Id == Path.GetFileNameWithoutExtension(path)))
                {
                    Console.WriteLine($"FILE TO DELETE: {path}");
                }
            }

            // find missing samples
            foreach (RefactoringMetadata refactoring in refactorings)
            {
                if (refactoring.Samples.Count == 0)
                {
                    foreach (ImageMetadata image in refactoring.ImagesOrDefaultImage())
                    {
                        string imagePath = Path.Combine(GetPath(@"..\images\refactorings"), image.Name + ".png");

                        if (!File.Exists(imagePath))
                        {
                            Console.WriteLine($"MISSING SAMPLE: {imagePath}");
                        }
                    }
                }
            }

            void WriteAnalyzersReadMe(string path, ImmutableArray <AnalyzerMetadata> descriptors)
            {
                WriteAllText(
                    path,
                    MarkdownGenerator.CreateAnalyzersReadMe(descriptors.Where(f => !f.IsObsolete), comparer));
            }

            void WriteAnalyzersByCategory(string path, ImmutableArray <AnalyzerMetadata> descriptors)
            {
                WriteAllText(
                    path,
                    MarkdownGenerator.CreateAnalyzersByCategoryMarkdown(descriptors.Where(f => !f.IsObsolete), comparer));
            }

            void WriteAllText(string relativePath, string content, bool onlyIfChanges = true, bool fileMustExists = true)
            {
                string path = GetPath(relativePath);

                Encoding encoding = (Path.GetExtension(path) == ".md") ? _utf8NoBom : Encoding.UTF8;

                FileHelper.WriteAllText(path, content, encoding, onlyIfChanges, fileMustExists);
            }

            string GetPath(string path)
            {
                return(Path.Combine(rootPath, path));
            }
        }
コード例 #3
0
        public async Task GenerateAsync()
        {
            WriteAllText(
                @"Analyzers\README.md",
                MarkdownGenerator.CreateAnalyzersReadMe(Analyzers.Where(f => !f.IsObsolete), Comparer));

            WriteAllText(
                @"Analyzers\AnalyzersByCategory.md",
                MarkdownGenerator.CreateAnalyzersByCategoryMarkdown(Analyzers.Where(f => !f.IsObsolete), Comparer));

            VisualStudioInstance instance = MSBuildLocator.QueryVisualStudioInstances().Single();

            MSBuildLocator.RegisterInstance(instance);

            using (MSBuildWorkspace workspace = MSBuildWorkspace.Create())
            {
                workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message);

                string solutionPath = Path.Combine(RootPath, "Roslynator.sln");

                Console.WriteLine($"Loading solution '{solutionPath}'");

                Solution solution = await workspace.OpenSolutionAsync(solutionPath).ConfigureAwait(false);

                Console.WriteLine($"Finished loading solution '{solutionPath}'");

                RoslynatorInfo roslynatorInfo = await RoslynatorInfo.Create(solution).ConfigureAwait(false);

                IOrderedEnumerable <SourceFile> sourceFiles = Analyzers
                                                              .Select(f => new SourceFile(f.Id, roslynatorInfo.GetAnalyzerFilesAsync(f.Identifier).Result))
                                                              .Concat(Refactorings
                                                                      .Select(f => new SourceFile(f.Id, roslynatorInfo.GetRefactoringFilesAsync(f.Identifier).Result)))
                                                              .OrderBy(f => f.Id);

                MetadataFile.SaveSourceFiles(sourceFiles, @"..\SourceFiles.xml");

                foreach (AnalyzerDescriptor analyzer in Analyzers)
                {
                    //IEnumerable<string> filePaths = await roslynatorInfo.GetAnalyzerFilesAsync(analyzer.Identifier).ConfigureAwait(false);

                    WriteAllText(
                        $@"..\docs\analyzers\{analyzer.Id}.md",
                        MarkdownGenerator.CreateAnalyzerMarkdown(analyzer, Array.Empty <string>()),
                        fileMustExists: false);
                }

                foreach (RefactoringDescriptor refactoring in Refactorings)
                {
                    //IEnumerable<string> filePaths = await roslynatorInfo.GetRefactoringFilesAsync(refactoring.Identifier).ConfigureAwait(false);

                    WriteAllText(
                        $@"..\docs\refactorings\{refactoring.Id}.md",
                        MarkdownGenerator.CreateRefactoringMarkdown(refactoring, Array.Empty <string>()),
                        fileMustExists: false);
                }

                foreach (CompilerDiagnosticDescriptor diagnostic in CompilerDiagnostics)
                {
                    //IEnumerable<string> filePaths = await roslynatorInfo.GetCompilerDiagnosticFilesAsync(diagnostic.Identifier).ConfigureAwait(false);

                    WriteAllText(
                        $@"..\docs\cs\{diagnostic.Id}.md",
                        MarkdownGenerator.CreateCompilerDiagnosticMarkdown(diagnostic, CodeFixes, Comparer, Array.Empty <string>()),
                        fileMustExists: false);
                }
            }

            WriteAllText(
                @"..\docs\refactorings\Refactorings.md",
                MarkdownGenerator.CreateRefactoringsMarkdown(Refactorings, Comparer));

            WriteAllText(
                @"Refactorings\README.md",
                MarkdownGenerator.CreateRefactoringsReadMe(Refactorings.Where(f => !f.IsObsolete), Comparer));

            WriteAllText(
                @"CodeFixes\README.md",
                MarkdownGenerator.CreateCodeFixesReadMe(CompilerDiagnostics, Comparer));

            WriteAllText(
                "DefaultConfigFile.xml",
                XmlGenerator.CreateDefaultConfigFile(Refactorings, CodeFixes));

            WriteAllText(
                "DefaultRuleSet.ruleset",
                XmlGenerator.CreateDefaultRuleSet(Analyzers));
        }