private static Task <IProjectAnalyzationResult> AnalyzeProject(ProjectData projectData, ILoggerFactory loggerFactory, CancellationToken cancellationToken = default(CancellationToken)) { var analyzer = new ProjectAnalyzer(projectData, loggerFactory); return(analyzer.Analyze(cancellationToken)); }
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings) { var projectsToAnalyze = PathUtility.GetProjectPaths(settings.ProjectOrSolutionPath, out var entry); // Remove all projects that we want to skip. projectsToAnalyze.RemoveAll(p => { var projectName = Path.GetFileNameWithoutExtension(p); return(settings.Skip?.Contains(projectName, StringComparer.OrdinalIgnoreCase) ?? false); }); var targetFramework = settings.TargetFramework; var analyzerResults = new List <ProjectAnalyzerResult>(); var projectCache = new HashSet <Project>(new ProjectComparer()); _console.WriteLine(); return(_console.Status().Start($"Analyzing...", ctx => { ctx.Refresh(); _console.MarkupLine($"Analyzing [yellow]{Path.GetFileName(entry)}[/]"); foreach (var projectToAnalyze in projectsToAnalyze) { // Perform a design time build of the project. var buildResult = _builder.Build( projectToAnalyze, targetFramework, settings.Skip, projectCache); // Update the cache of built projects. projectCache.Add(buildResult.Project); foreach (var item in buildResult.Dependencies) { projectCache.Add(item); } // Analyze the project. var analyzeResult = _analyzer.Analyze(buildResult.Project); if (settings.Exclude?.Length > 0) { // Filter packages that should be excluded. analyzeResult = analyzeResult.Filter(settings.Exclude); } analyzerResults.Add(analyzeResult); } // Write the rport to the console _reporter.WriteToConsole(analyzerResults); // Return the correct exit code. return GetExitCode(settings, analyzerResults); })); }
public override int Execute(CommandContext context, Settings settings) { var projectsToAnalyze = PathUtility.GetProjectPaths(settings.ProjectOrSolutionPath, out var entry); // Remove all projects that we want to skip. projectsToAnalyze.RemoveAll(p => { var projectName = Path.GetFileNameWithoutExtension(p); return(settings.Skip?.Contains(projectName, StringComparer.OrdinalIgnoreCase) ?? false); }); _console.WriteLine(); _console.Write("Processing "); _console.ForegroundColor = ConsoleColor.Yellow; _console.Write(Path.GetFileName(entry)); _console.ResetColor(); _console.WriteLine("..."); var targetFramework = settings.TargetFramework; var analyzerResults = new List <ProjectAnalyzerResult>(); var projectCache = new HashSet <Project>(new ProjectComparer()); foreach (var projectToAnalyze in projectsToAnalyze) { // Perform a design time build of the project. var buildResult = _builder.Build( projectToAnalyze, targetFramework, settings.Skip, projectCache); // Update the cache of built projects. projectCache.Add(buildResult.Project); foreach (var item in buildResult.Dependencies) { projectCache.Add(item); } // Analyze the project. var analyzeResult = _analyzer.Analyze(buildResult.Project); if (settings.Exclude?.Length > 0) { // Filter packages that should be excluded. analyzeResult = analyzeResult.Filter(settings.Exclude); } analyzerResults.Add(analyzeResult); } _reporter.WriteToConsole(analyzerResults); return(GetExitCode(settings, analyzerResults)); }
public override int Execute(CommandContext context, Settings settings) { settings.ProjectPath = PathUtility.GetProjectPath(settings.ProjectPath); // Analyze the project. var project = _builder.Build(settings.ProjectPath, settings.TargetFramework); var result = _analyzer.Analyze(project); if (settings.Ignore?.Length > 0) { // Filter packages that should be excluded. result = result.Filter(settings.Ignore); } _reporter.WriteToConsole(result); return(GetExitCode(settings, result)); }
private void AnalyzeSyntax(SemanticModelAnalysisContext context) { var compilation = (CSharpCompilation)context.SemanticModel.Compilation; var options = new ProjectAnalyzer.Options() { breakOnError = false, writeSyntaxSuffix = false, scanChilderen = false }; var analyzer = new ProjectAnalyzer(compilation, options); analyzer.SyntaxErrorCallback += Analyzer_SyntaxErrorCallback; void Analyzer_SyntaxErrorCallback(SyntaxError error) { var location = error.node.GetLocation(); if (!location.IsInSource || Location.None.Equals(location)) { return; } var diagnostic = Diagnostic.Create(ErrorRule, location, error.message); context.ReportDiagnostic(diagnostic); } try { analyzer.Analyze(context.SemanticModel.SyntaxTree); } catch (Exception e) { var diagnostic = Diagnostic.Create(WarningRule, Location.None, "CS2X: Analyzer error: " + e.Message); context.ReportDiagnostic(diagnostic); } }
public override async Task <ApplicationBundleInfo> Build() { OnBundlingStart(); BuildStopWatch.Reset(); BuildStopWatch.Start(); var bundleInfo = new ApplicationBundleInfo(); bundleInfo.OutputFilePath = Path.Combine(Settings.OutputCssDirectory, "bundle.css"); if (_fileManager.TempCssFileExists()) { await _fileManager.ClearTmpCssFileAsync(); } else { await _fileManager.CreateTmpCssFileAsync(); } ProjectAnalyzingResult projAnalyzeRes = _projAnalyzer.Analyze(Settings.ProjectFilePath); foreach (var pckgRef in projAnalyzeRes.PackageReferences.Where(x => !x.Name.StartsWith("System") && !x.Name.StartsWith("Microsoft"))) { /* Extract styles from assembly */ string mainAsmPath = NugetHelper.MakeAssemblyPath(pckgRef.Name, pckgRef.Version, "netstandard2.0"); var mainStylesheet = CssParser.Parse(BundleHelper.GetStylesFromAssembly(mainAsmPath)); if (BundleHelper.HasIsolatedCss(mainAsmPath)) { BundleHelper.AppendStylesToFile(_fileManager.TempStylesFilePath, mainStylesheet); } /* Extract styles from assembly references */ AssemblyAnalyzingResult asmAnalyzeRes = _asmAnalyzer.Analyze(mainAsmPath); foreach (string asmPath in asmAnalyzeRes.AssemblyPaths) { if (BundleHelper.HasIsolatedCss(asmPath)) { var stylesheet = CssParser.Parse(BundleHelper.GetStylesFromAssembly(asmPath)); BundleHelper.AppendStylesToFile(_fileManager.TempStylesFilePath, stylesheet); } } } foreach (var @ref in projAnalyzeRes.References) { string mainAsmPath = @ref.HintPath; if (@ref.HintPath.StartsWith("..\\")) { mainAsmPath = Path.Combine(Settings.ProjectDirectory, mainAsmPath); } /* Extract styles from assembly */ if (BundleHelper.HasIsolatedCss(mainAsmPath)) { var mainStylesheet = CssParser.Parse(BundleHelper.GetStylesFromAssembly(mainAsmPath)); BundleHelper.AppendStylesToFile(_fileManager.TempStylesFilePath, mainStylesheet); } /* Extract styles from assembly references */ AssemblyAnalyzingResult asmAnalyzeRes = _asmAnalyzer.Analyze(mainAsmPath); foreach (string asmPath in asmAnalyzeRes.AssemblyPaths) { Stylesheet stylesheet = CssParser.Parse(BundleHelper.GetStylesFromAssembly(asmPath)); if (BundleHelper.HasIsolatedCss(asmPath)) { BundleHelper.AppendStylesToFile(_fileManager.TempStylesFilePath, stylesheet); } } } string pagesDirPath = Path.Combine(Settings.ProjectDirectory, "Pages"); string sharedDirPath = Path.Combine(Settings.ProjectDirectory, "Shared"); BuildByDirectory(pagesDirPath, bundleInfo); BuildByDirectory(sharedDirPath, bundleInfo); File.WriteAllText(bundleInfo.OutputFilePath, File.ReadAllText(_fileManager.TempStylesFilePath)); // generating css bundle BuildStopWatch.Stop(); bundleInfo.BundlingTime = BuildStopWatch.Elapsed; if (bundleInfo.Succeed) { OnBundlingEnd(bundleInfo); } else { OnBundlingError(bundleInfo); } return(bundleInfo); }
internal async Task Parse() { if (isParsed) { return; } isParsed = true; // get compilation compilation = (CSharpCompilation)await roslynProject.GetCompilationAsync(); // validate syntax rules var options = new ProjectAnalyzer.Options() { breakOnError = false, writeSyntaxSuffix = true, scanChilderen = true }; var analyzer = new ProjectAnalyzer(compilation, options); if (!await analyzer.Analyze(roslynProject)) { throw new Exception("Failed to Analyze project: " + roslynProject.FilePath); } // gather references var references = new List <Project>(); var sln = roslynProject.Solution; foreach (var reference in roslynProject.AllProjectReferences) { var project = solution.projects.FirstOrDefault(x => x.roslynProject.Id == reference.ProjectId); if (project == null) { throw new Exception("Project reference not found in solution: " + reference.ProjectId); } references.Add(project); await project.Parse(); } this.references = references; // init main objects classTypes = new List <INamedTypeSymbol>(); structTypes = new List <INamedTypeSymbol>(); interfaceTypes = new List <INamedTypeSymbol>(); enumTypes = new List <INamedTypeSymbol>(); delegateTypes = new List <INamedTypeSymbol>(); // parse normal members ParseNamespace(compilation.Assembly.GlobalNamespace); // merge all types in one list var allTypesList = new List <INamedTypeSymbol>(); allTypesList.AddRange(classTypes); allTypesList.AddRange(structTypes); allTypesList.AddRange(interfaceTypes); allTypesList.AddRange(enumTypes); allTypesList.AddRange(delegateTypes); // dependency sort all types allTypes = DependencySortTypes(allTypesList); }
private Task <IProjectAnalyzationResult> AnalyzeProject(ProjectData projectData) { var analyzer = new ProjectAnalyzer(projectData); return(analyzer.Analyze()); }