From 8540228a1d296a2c0d00fe00442ff8766bd8410f Mon Sep 17 00:00:00 2001 From: Josh Varty Date: Sun, 31 Jan 2016 23:02:43 -0500 Subject: [PATCH 1/6] Ignore .vs/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a77a4fc..c0d82f1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.sln.docstates *.ide/ *.ide +*.vs/ SB_Files/ GithubStaging/ From dd09c3e1c396324dfcb066df936226b605ad03b4 Mon Sep 17 00:00:00 2001 From: Josh Varty Date: Sun, 31 Jan 2016 23:02:59 -0500 Subject: [PATCH 2/6] Get the paths for omnisharp.json & project.json --- .../Controllers/UploadController.cs | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/SourceBrowser.Site/Controllers/UploadController.cs b/src/SourceBrowser.Site/Controllers/UploadController.cs index 7612414..cb76302 100644 --- a/src/SourceBrowser.Site/Controllers/UploadController.cs +++ b/src/SourceBrowser.Site/Controllers/UploadController.cs @@ -53,17 +53,15 @@ public ActionResult Submit(string githubUrl) return View("Index"); } - // Generate the source browser files for this solution - var solutionPaths = GetSolutionPaths(repoRootPath); - if (solutionPaths.Length == 0) - { - ViewBag.Error = "No C# solution was found. Ensure that a valid .sln file exists within your repository."; - return View("Index"); - } - var organizationPath = System.Web.Hosting.HostingEnvironment.MapPath("~/") + "SB_Files\\" + retriever.UserName; var repoPath = Path.Combine(organizationPath, retriever.RepoName); + + // Generate the source browser files for this solution + var solutionPaths = Directory.GetFiles(repoRootPath, "*.sln", SearchOption.AllDirectories); + var omnisharpPaths = Directory.GetFiles(repoRootPath, "omnisharp.json", SearchOption.AllDirectories); + var projectJsonPaths= Directory.GetFiles(repoRootPath, "project.json", SearchOption.AllDirectories); + // TODO: Use parallel for. // TODO: Process all solutions. // For now, we're assuming the shallowest and shortest .sln file is the one we're interested in @@ -121,19 +119,5 @@ public ActionResult Submit(string githubUrl) } } } - - /// - /// Simply searches for the solution files and returns their paths. - /// - /// - /// The root Directory. - /// - /// - /// The solution paths. - /// - private string[] GetSolutionPaths(string rootDirectory) - { - return Directory.GetFiles(rootDirectory, "*.sln", SearchOption.AllDirectories); - } } } \ No newline at end of file From f545f6b9f6151c224feb8c73b6de2725330276e6 Mon Sep 17 00:00:00 2001 From: Josh Varty Date: Sun, 31 Jan 2016 23:46:12 -0500 Subject: [PATCH 3/6] Layout for ProjectJson support --- .../SolutionAnalyzer.cs | 2 + .../Controllers/UploadController.cs | 66 +++++++++---------- .../Repositories/UploadRepository.cs | 22 ++++++- 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/SourceBrowser.Generator/SolutionAnalyzer.cs b/src/SourceBrowser.Generator/SolutionAnalyzer.cs index 16369a1..ee25f0d 100644 --- a/src/SourceBrowser.Generator/SolutionAnalyzer.cs +++ b/src/SourceBrowser.Generator/SolutionAnalyzer.cs @@ -21,6 +21,7 @@ namespace SourceBrowser.Generator { public class SolutionAnalayzer { + public bool WorkspaceFailed { get; set; } MSBuildWorkspace _workspace; Solution _solution; private ReferencesourceLinkProvider _refsourceLinkProvider = new ReferencesourceLinkProvider(); @@ -35,6 +36,7 @@ public SolutionAnalayzer(string solutionPath) private void _workspace_WorkspaceFailed(object sender, WorkspaceDiagnosticEventArgs e) { + WorkspaceFailed = true; try { var logDirectory = System.Web.Hosting.HostingEnvironment.MapPath("/WorkspaceLogs/"); diff --git a/src/SourceBrowser.Site/Controllers/UploadController.cs b/src/SourceBrowser.Site/Controllers/UploadController.cs index cb76302..0777e96 100644 --- a/src/SourceBrowser.Site/Controllers/UploadController.cs +++ b/src/SourceBrowser.Site/Controllers/UploadController.cs @@ -7,7 +7,7 @@ using SourceBrowser.Site.Repositories; using System; using System.Linq; - + using Generator.Model; public class UploadController : Controller { // GET: Upload @@ -62,49 +62,45 @@ public ActionResult Submit(string githubUrl) var omnisharpPaths = Directory.GetFiles(repoRootPath, "omnisharp.json", SearchOption.AllDirectories); var projectJsonPaths= Directory.GetFiles(repoRootPath, "project.json", SearchOption.AllDirectories); - // TODO: Use parallel for. - // TODO: Process all solutions. - // For now, we're assuming the shallowest and shortest .sln file is the one we're interested in - foreach (var solutionPath in solutionPaths.OrderBy(n => n.Length).Take(1)) - { - try - { - var workspaceModel = UploadRepository.ProcessSolution(solutionPath, repoRootPath); - - //One pass to lookup all declarations - var typeTransformer = new TokenLookupTransformer(); - typeTransformer.Visit(workspaceModel); - var tokenLookup = typeTransformer.TokenLookup; - - //Another pass to generate HTMLs - var htmlTransformer = new HtmlTransformer(tokenLookup, repoPath); - htmlTransformer.Visit(workspaceModel); + string solutionPath = solutionPaths.OrderBy(n => n.Length).FirstOrDefault(); + string omnisharpPath = omnisharpPaths.OrderBy(n => n.Length).FirstOrDefault(); - var searchTransformer = new SearchIndexTransformer(retriever.UserName, retriever.RepoName); - searchTransformer.Visit(workspaceModel); + WorkspaceModel workspaceModel = null; + if(solutionPath != null) + { + workspaceModel = UploadRepository.ProcessSolution(solutionPath, repoRootPath); + } - // Generate HTML of the tree view - var treeViewTransformer = new TreeViewTransformer(repoPath, retriever.UserName, retriever.RepoName); - treeViewTransformer.Visit(workspaceModel); - } - catch (Exception ex) - { - // TODO: Log this - ViewBag.Error = "There was an error processing solution " + Path.GetFileName(solutionPath); - return View("Index"); - } + if(workspaceModel == null && omnisharpPath != null) + { + workspaceModel = UploadRepository.ProcessOmnisharp(omnisharpPath, repoRootPath); } - try + if(workspaceModel == null && projectJsonPaths.Count() > 0) { - UploadRepository.SaveReadme(repoPath, retriever.ProvideParsedReadme()); + workspaceModel = UploadRepository.ProcessProjectJson(projectJsonPaths, repoRootPath); } - catch (Exception ex) + + if (workspaceModel != null) { - // TODO: Log and swallow - readme is not essential. + //One pass to lookup all declarations + var typeTransformer = new TokenLookupTransformer(); + typeTransformer.Visit(workspaceModel); + var tokenLookup = typeTransformer.TokenLookup; + + //Another pass to generate HTMLs + var htmlTransformer = new HtmlTransformer(tokenLookup, repoPath); + htmlTransformer.Visit(workspaceModel); + + var searchTransformer = new SearchIndexTransformer(retriever.UserName, retriever.RepoName); + searchTransformer.Visit(workspaceModel); + + // Generate HTML of the tree view + var treeViewTransformer = new TreeViewTransformer(repoPath, retriever.UserName, retriever.RepoName); + treeViewTransformer.Visit(workspaceModel); + processingSuccessful = true; } - processingSuccessful = true; return Redirect("/Browse/" + retriever.UserName + "/" + retriever.RepoName); } finally diff --git a/src/SourceBrowser.Site/Repositories/UploadRepository.cs b/src/SourceBrowser.Site/Repositories/UploadRepository.cs index 8e878c5..09eaef2 100644 --- a/src/SourceBrowser.Site/Repositories/UploadRepository.cs +++ b/src/SourceBrowser.Site/Repositories/UploadRepository.cs @@ -7,6 +7,7 @@ using System.Security; using System.IO; using System.Configuration; +using SourceBrowser.Generator.Model; namespace SourceBrowser.Site.Repositories { @@ -18,7 +19,7 @@ public class UploadRepository [DllImport("kernel32.dll", CharSet = CharSet.Auto)] private extern static bool CloseHandle(IntPtr handle); - internal static Generator.Model.WorkspaceModel ProcessSolution(string solutionPath, string repoRootPath) + internal static WorkspaceModel ProcessSolution(string solutionPath, string repoRootPath) { SafeTokenHandle safeTokenHandle; string safeUserName = ConfigurationManager.AppSettings["safeUserName"]; @@ -28,6 +29,11 @@ internal static Generator.Model.WorkspaceModel ProcessSolution(string solutionPa if (String.IsNullOrEmpty(safeUserName)) { var sourceGenerator = new Generator.SolutionAnalayzer(solutionPath); + if(sourceGenerator.WorkspaceFailed) + { + return null; + } + var workspaceModel = sourceGenerator.BuildWorkspaceModel(repoRootPath); return workspaceModel; } @@ -54,6 +60,10 @@ internal static Generator.Model.WorkspaceModel ProcessSolution(string solutionPa using (WindowsImpersonationContext impersonatedUser = WindowsIdentity.Impersonate(safeTokenHandle.DangerousGetHandle())) { var sourceGenerator = new Generator.SolutionAnalayzer(solutionPath); + if (sourceGenerator.WorkspaceFailed) + { + return null; + } var workspaceModel = sourceGenerator.BuildWorkspaceModel(repoRootPath); return workspaceModel; } @@ -61,6 +71,16 @@ internal static Generator.Model.WorkspaceModel ProcessSolution(string solutionPa } } + internal static WorkspaceModel ProcessOmnisharp(string omnisharpPath, string repoRootPath) + { + throw new NotImplementedException(); + } + + internal static WorkspaceModel ProcessProjectJson(string[] projectJsonPaths, string repoRootPath) + { + throw new NotImplementedException(); + } + internal static void SaveReadme(string repoPath, string readmeInHtml) { string readmePath = Path.Combine(repoPath, "readme.html"); From b34b7d29459fe58b06979616d0538229d4abed61 Mon Sep 17 00:00:00 2001 From: Josh Varty Date: Mon, 1 Feb 2016 01:16:09 -0500 Subject: [PATCH 4/6] Update to latest version of Roslyn --- src/SourceBrowser.Generator/App.config | 26 ++++- .../DocumentWalkers/CSWalkerUtils.cs | 6 +- .../DocumentWalkers/DocumentWalker.cs | 5 +- .../DocumentWalkers/VBWalkerUtils.cs | 6 +- .../SourceBrowser.Generator.csproj | 98 +++++++++++-------- src/SourceBrowser.Generator/packages.config | 35 +++++-- .../SourceBrowser.Samples.csproj | 58 ++--------- src/SourceBrowser.Samples/packages.config | 34 +++++-- .../SourceBrowser.Site.csproj | 58 ++--------- src/SourceBrowser.Site/packages.config | 34 +++++-- .../SourceBrowser.Tests.csproj | 60 ++---------- src/SourceBrowser.Tests/app.config | 16 +-- src/SourceBrowser.Tests/packages.config | 34 +++++-- 13 files changed, 218 insertions(+), 252 deletions(-) diff --git a/src/SourceBrowser.Generator/App.config b/src/SourceBrowser.Generator/App.config index 8e15646..c8cc771 100644 --- a/src/SourceBrowser.Generator/App.config +++ b/src/SourceBrowser.Generator/App.config @@ -1,6 +1,26 @@ - + - + - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SourceBrowser.Generator/DocumentWalkers/CSWalkerUtils.cs b/src/SourceBrowser.Generator/DocumentWalkers/CSWalkerUtils.cs index e8c76ae..704571f 100644 --- a/src/SourceBrowser.Generator/DocumentWalkers/CSWalkerUtils.cs +++ b/src/SourceBrowser.Generator/DocumentWalkers/CSWalkerUtils.cs @@ -29,13 +29,13 @@ internal CSWalkerUtils(DocumentWalker walker) public string LocalVariableDelimiter { get; } = CSharpDelimiters.LOCAL_VARIABLE; - public string GetFullName(SyntaxToken token) => token.CSharpKind().ToString(); + public string GetFullName(SyntaxToken token) => token.Kind().ToString(); - public bool IsIdentifier(SyntaxToken token) => token.CSharpKind() == SyntaxKind.IdentifierToken; + public bool IsIdentifier(SyntaxToken token) => token.Kind() == SyntaxKind.IdentifierToken; public bool IsKeyword(SyntaxToken token) => token.IsKeyword(); - public bool IsLiteral(SyntaxToken token) => token.CSharpKind() == SyntaxKind.StringLiteralToken; + public bool IsLiteral(SyntaxToken token) => token.Kind() == SyntaxKind.StringLiteralToken; public override void VisitToken(SyntaxToken token) => _walker.VisitToken(token); } diff --git a/src/SourceBrowser.Generator/DocumentWalkers/DocumentWalker.cs b/src/SourceBrowser.Generator/DocumentWalkers/DocumentWalker.cs index a44fe93..09a2e8d 100644 --- a/src/SourceBrowser.Generator/DocumentWalkers/DocumentWalker.cs +++ b/src/SourceBrowser.Generator/DocumentWalkers/DocumentWalker.cs @@ -5,6 +5,7 @@ using SourceBrowser.Generator.Model; using SourceBrowser.Generator.Extensions; using Microsoft.CodeAnalysis.FindSymbols; +using Microsoft.CodeAnalysis.CSharp; namespace SourceBrowser.Generator.DocumentWalkers { @@ -81,7 +82,7 @@ private ICollection ProcessTrivia(SyntaxTriviaList triviaList) { var triviaModelList = triviaList.Select(n => new Trivia( value: n.ToFullString(), - type: n.CSharpKind().ToString() + type: n.Kind().ToString() )).ToList(); return triviaModelList; @@ -92,7 +93,7 @@ private ICollection ProcessTrivia(SyntaxTriviaList triviaList) /// private Token ProcessOtherToken(SyntaxToken token) { - string fullName = token.CSharpKind().ToString(); + string fullName = token.Kind().ToString(); string value = token.ToString(); string type = _walkerUtils.OtherTokenTypeName; int lineNumber = token.GetLocation().GetLineSpan().StartLinePosition.Line + 1; diff --git a/src/SourceBrowser.Generator/DocumentWalkers/VBWalkerUtils.cs b/src/SourceBrowser.Generator/DocumentWalkers/VBWalkerUtils.cs index 4f2a6cf..68c9011 100644 --- a/src/SourceBrowser.Generator/DocumentWalkers/VBWalkerUtils.cs +++ b/src/SourceBrowser.Generator/DocumentWalkers/VBWalkerUtils.cs @@ -29,13 +29,13 @@ internal VBWalkerUtils(DocumentWalker walker) public string LocalVariableDelimiter { get; } = VBDelimiters.LOCAL_VARIABLE; - public string GetFullName(SyntaxToken token) => token.CSharpKind().ToString(); + public string GetFullName(SyntaxToken token) => token.Kind().ToString(); - public bool IsIdentifier(SyntaxToken token) => token.VBKind() == SyntaxKind.IdentifierToken; + public bool IsIdentifier(SyntaxToken token) => token.Kind() == SyntaxKind.IdentifierToken; public bool IsKeyword(SyntaxToken token) => token.IsKeyword(); - public bool IsLiteral(SyntaxToken token) => token.VBKind() == SyntaxKind.StringLiteralToken; + public bool IsLiteral(SyntaxToken token) => token.Kind() == SyntaxKind.StringLiteralToken; public override void VisitToken(SyntaxToken token) => _walker.VisitToken(token); } diff --git a/src/SourceBrowser.Generator/SourceBrowser.Generator.csproj b/src/SourceBrowser.Generator/SourceBrowser.Generator.csproj index e614bf7..f0edf7c 100644 --- a/src/SourceBrowser.Generator/SourceBrowser.Generator.csproj +++ b/src/SourceBrowser.Generator/SourceBrowser.Generator.csproj @@ -9,8 +9,9 @@ Properties SourceBrowser.Generator SourceBrowser.Generator - v4.5 + v4.6.1 512 + AnyCPU @@ -35,50 +36,39 @@ - - False - ..\packages\Microsoft.CodeAnalysis.Common.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.dll - - - False - ..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.CSharp.dll - - - False - ..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll - - - False - ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll + + ..\packages\Microsoft.CodeAnalysis.Common.1.1.1\lib\net45\Microsoft.CodeAnalysis.dll + True - - ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop.dll + + ..\packages\Microsoft.CodeAnalysis.CSharp.1.1.1\lib\net45\Microsoft.CodeAnalysis.CSharp.dll + True - - False - ..\packages\Microsoft.CodeAnalysis.Common.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.Desktop.dll + + ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.1.1\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll + True - - False - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.1.1\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll + True - - False - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Desktop.dll + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.1.1\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll + True - - False - ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll + + ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.1.1\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll + True - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.Desktop.dll + + ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.1.1\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll + True - - False - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll + + ..\lib\Microsoft.DotNet.ProjectModel.dll - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-beta1-20141031-01\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll + + ..\lib\Microsoft.DotNet.ProjectModel.Workspaces.dll False @@ -86,15 +76,35 @@ - + + ..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\System.Collections.Immutable.dll + True + + + ..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll + True + + + ..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll + True + + + ..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll + True + + + ..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll + True + + + ..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll True - ..\packages\System.Collections.Immutable.1.1.32-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - - False - ..\packages\System.Reflection.Metadata.1.0.17-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll + + ..\packages\System.Reflection.Metadata.1.1.0\lib\dotnet5.2\System.Reflection.Metadata.dll + True @@ -148,6 +158,10 @@ SourceBrowser.Search + + + +