-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--update-project feature work (#1593)
* Added update-project command feature (#1592) * update-project with code changes * minor fix * more updates * minor fixes * minor fixes * fixed Resources and other minor fixes * fixes and updates * added DocumentBuilder, and unit tests. * switched to using Resources. Important for localization later. * PR comment fixes. * version.props fixes. * pr comment fixes 2 * final fixes. * minor fix and preview version update. * skip stuck tests for now Co-authored-by: Deep Choudhery <[email protected]>
- Loading branch information
1 parent
2d6dbca
commit c49241c
Showing
41 changed files
with
2,546 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/MSIdentityScaffolding/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeAnalysisHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.MSBuild; | ||
|
||
namespace Microsoft.DotNet.MSIdentity.CodeReaderWriter | ||
{ | ||
//static class helper for CodeAnalysis | ||
public static class CodeAnalysisHelper | ||
{ | ||
//helps create a CodeAnalysis.Project with project files given a project path. | ||
public static async Task<CodeAnalysis.Project> LoadCodeAnalysisProjectAsync(string projectFilePath) | ||
{ | ||
var workspace = MSBuildWorkspace.Create(); | ||
var project = await workspace.OpenProjectAsync(projectFilePath); | ||
var projectWithFiles = project.WithAllSourceFiles(); | ||
project = projectWithFiles ?? project; | ||
return project; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...tityScaffolding/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeChange/CodeChangeType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Microsoft.DotNet.MSIdentity.CodeReaderWriter.CodeChange | ||
{ | ||
public class CodeChangeType | ||
{ | ||
public const string MemberAccess = nameof(MemberAccess); | ||
public const string InLambdaBlock = nameof(InLambdaBlock); | ||
public const string LambdaExpression = nameof(LambdaExpression); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...MSIdentityScaffolding/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeChange/CodeFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.DotNet.MSIdentity.CodeReaderWriter.CodeChange | ||
{ | ||
public class CodeFile | ||
{ | ||
public Dictionary<string, Method>? Methods { get; set; } | ||
public string[]? Usings { get; set; } | ||
public string? FileName { get; set; } | ||
public string[]? ClassProperties { get; set; } | ||
public string[]? ClassAttributes { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...dentityScaffolding/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeChange/CodeSnippet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Microsoft.DotNet.MSIdentity.CodeReaderWriter.CodeChange | ||
{ | ||
public class CodeSnippet | ||
{ | ||
public string? InsertAfter { get; set; } | ||
public string? Block { get; set; } | ||
public string? Parent { get; set; } | ||
public string? Type { get; set; } | ||
public bool? Append { get; set; } = false; | ||
public string? Parameter { get; set; } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/MSIdentityScaffolding/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeChange/Method.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Microsoft.DotNet.MSIdentity.CodeReaderWriter.CodeChange | ||
{ | ||
public class Method | ||
{ | ||
public string[]? Parameters { get; set; } | ||
public CodeSnippet[]? CodeChanges { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/MSIdentityScaffolding/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeModifierConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Microsoft.DotNet.MSIdentity.CodeReaderWriter.CodeChange; | ||
|
||
namespace Microsoft.DotNet.MSIdentity.CodeReaderWriter | ||
{ | ||
public class CodeModifierConfig | ||
{ | ||
public string? Identifier { get; set; } | ||
public CodeFile[]? Files { get; set; } | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ding/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeModifierConfigs/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
ach project type/scenario should have a json config file for itself. | ||
|
||
class CodeModifierConfig | ||
{ | ||
public string? Identifier { get; set; } --> identifier for project type/scenario. | ||
public File[]? Files { get; set; } --> All the files that need editing in the project. | ||
} | ||
|
||
class File | ||
{ | ||
public Dictionary<string, Method>? Methods { get; set; } --> all the methods in the file that need editing | ||
public string[]? Usings { get; set; } --> any `usings` that need to be added to a C# file. | ||
public string? FileName { get; set; } --> .cs file to edit | ||
public string[]? ClassProperties { get; set; } --> any properties that need to be added to the class' members. | ||
public string[]? ClassAttributes { get; set; } --> [Attribute] that need to added to the class. | ||
} | ||
|
||
class Method | ||
{ | ||
public string[]? Parameters { get; set; } --> parameter types for the method. Used to get the correct ParameterSyntax. | ||
public CodeChange[]? CodeChanges { get; set; } --> All the changes within a particular method. | ||
} | ||
class CodeChange | ||
{ | ||
public string? InsertAfter { get; set; } --> Insert new statement block after this statement syntax node. | ||
public string? Block { get; set; } --> C# statement that is parsed using SyntaxFactory.ParseStatement | ||
public string? Parent { get; set; } --> Add C# statement syntax node upon this parent statement syntax node based on Type | ||
public string? Type { get; set; } --> CodeChangeType (below) string. | ||
public bool? Append { get; set; } = false; --> Insert Block at the top of the method. | ||
} | ||
|
||
class CodeChangeType | ||
{ | ||
public const string MemberAccess = nameof(MemberAccess); --> Add a SimpleMemberAccess expression to the parent statement syntax. | ||
public const string InLambdaBlock = nameof(InBlock); --> Add in lambda block to the parent statement syntax. | ||
} | ||
This info is also available in CodeModifierConfig folder as well. | ||
|
||
The scenarios below need to be supported for all project types : | ||
| Scenario | Status| | ||
| --- | --- | | ||
| ASP .NET Core Web App | Config w/out layout(.cshtml) files | | ||
| ASP .NET Core Web App (w/ B2C tenant) | Config w/out layout(.cshtml) files | | ||
| ASP .NET Core Web Api | Config w/out layout(.cshtml) files | | ||
| ASP .NET Core Web Api (w/ B2C tenant) | Config w/out layout(.cshtml) files | | ||
| Blazor Server App | Need config | | ||
| Blazor Server App (w/ B2C tenant) | Need config | | ||
| Blazor WebAssembly App | Need config | | ||
| Blazor WebAssembly App (w/ B2C tenant) | Need config | | ||
| Blazor Hosted WebAssembly App | Need config | | ||
| Blazor Hosted WebAssembly App (w/ B2C tenant) | Need config | | ||
|
||
Blazor server updates- | ||
- App.razor changes | ||
+ Shared/LoginDisplay.razor | ||
- Shared/MainLayout.razor changes | ||
- Startup.cs changes | ||
- appsettings.json changes |
65 changes: 65 additions & 0 deletions
65
...rosoft.DotNet.MSIdentity/CodeReaderWriter/CodeModifierConfigs/cm_dotnet_blazorserver.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"Identifier": "dotnet-blazorserver", | ||
"Files": [ | ||
{ | ||
"FileName": "Startup.cs", | ||
"Methods": { | ||
"Configure": { | ||
"Parameters": [ "IApplicationBuilder", "IWebHostEnvironment" ], | ||
"CodeChanges": [ | ||
{ | ||
"InsertAfter": "IApplicationBuilder.UseRouting()", | ||
"Block": "IApplicationBuilder.UseAuthentication()" | ||
}, | ||
{ | ||
"InsertAfter": "IApplicationBuilder.UseAuthentication()", | ||
"Block": "IApplicationBuilder.UseAuthorization()" | ||
}, | ||
{ | ||
"Parent": "IApplicationBuilder.UseEndpoints", | ||
"Type": "InLambdaBlock", | ||
"Block": "endpoints.MapControllers()" | ||
} | ||
] | ||
}, | ||
"ConfigureServices": { | ||
"Parameters": [ "IServiceCollection" ], | ||
"CodeChanges": [ | ||
{ | ||
"Block": "IServiceCollection.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)" | ||
}, | ||
{ | ||
"Block": "IServiceCollection.AddControllersWithViews().AddMicrosoftIdentityUI()", | ||
"InsertAfter":"IApplicationBuilder.AddAuthentication()" | ||
}, | ||
{ | ||
"Parent": "IServiceCollection.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)", | ||
"Type": "MemberAccess", | ||
"Block": "AddMicrosoftIdentityWebApp(Configuration.GetSection(\"AzureAd\"))" | ||
}, | ||
{ | ||
"Block": "IServiceCollection.AddAuthorization(options => { options.FallbackPolicy = options.DefaultPolicy; })" | ||
}, | ||
{ | ||
"Block": "IServiceCollection.AddServerSideBlazor()", | ||
"InsertAfter":"IServiceCollection.AddRazorPages()" | ||
}, | ||
{ | ||
"Parent": "IServiceCollection.AddServerSideBlazor()", | ||
"Type": "MemberAccess", | ||
"Block": "AddMicrosoftIdentityConsentHandler()" | ||
} | ||
] | ||
} | ||
}, | ||
"Usings": [ | ||
"Microsoft.AspNetCore.Authentication", | ||
"Microsoft.Identity.Web", | ||
"Microsoft.Identity.Web.UI", | ||
"Microsoft.AspNetCore.Authentication.OpenIdConnect", | ||
"Microsoft.AspNetCore.Authorization", | ||
"Microsoft.AspNetCore.Mvc.Authorization" | ||
] | ||
} | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
...icrosoft.DotNet.MSIdentity/CodeReaderWriter/CodeModifierConfigs/cm_dotnet_blazorwasm.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...t.DotNet.MSIdentity/CodeReaderWriter/CodeModifierConfigs/cm_dotnet_blazorwasm_hosted.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...ng/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeModifierConfigs/cm_dotnet_webapi.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"Identifier": "dotnet-webapi", | ||
"Files": [ | ||
{ | ||
"FileName": "Startup.cs", | ||
"Methods": { | ||
"Configure": { | ||
"Parameters": [ "IApplicationBuilder", "IWebHostEnvironment" ], | ||
"CodeChanges": [ | ||
{ | ||
"InsertAfter": "IApplicationBuilder.UseRouting()", | ||
"Block": "IApplicationBuilder.UseAuthentication()" | ||
} | ||
] | ||
}, | ||
"ConfigureServices": { | ||
"Parameters": [ "IServiceCollection" ], | ||
"CodeChanges": [ | ||
{ | ||
"Block": "IServiceCollection.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)" | ||
}, | ||
{ | ||
"Parent": "IServiceCollection.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)", | ||
"Type": "MemberAccess", | ||
"Block": "AddMicrosoftIdentityWebApi(Configuration.GetSection(\"AzureAd\"));", | ||
"BlockB2C": "AddMicrosoftIdentityWebApi(Configuration.GetSection(\"AzureAdB2C\"))" | ||
} | ||
] | ||
} | ||
}, | ||
"Usings": [ | ||
"Microsoft.AspNetCore.Authentication", | ||
"Microsoft.Identity.Web", | ||
"Microsoft.AspNetCore.Authentication.JwtBearer" | ||
] | ||
}, | ||
{ | ||
"FileName": "WeatherForecastController.cs", | ||
"ClassAttributes": [ "Authorize" ], | ||
"ClassProperties": [ | ||
"static readonly string[] scopeRequiredByApi = new string[] { \"access_as_user\" }" | ||
], | ||
"Methods": { | ||
"Configure": { | ||
"Parameters": [ "IApplicationBuilder", "IWebHostEnvironment" ], | ||
"CodeChanges": [ | ||
{ | ||
"InsertAfter": "IApplicationBuilder.UseRouting()", | ||
"Block": "IApplicationBuilder.UseAuthentication()" | ||
} | ||
] | ||
}, | ||
"Get": { | ||
"Parameters": [ "IEnumerable<WeatherForecast>" ], | ||
"CodeChanges": [ | ||
{ | ||
"Append": true, | ||
"Block": "HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);" | ||
} | ||
] | ||
} | ||
}, | ||
"Usings": [ | ||
"Microsoft.AspNetCore.Authorization", | ||
"Microsoft.Identity.Web.Resource" | ||
] | ||
} | ||
] | ||
} |
66 changes: 66 additions & 0 deletions
66
...ng/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeModifierConfigs/cm_dotnet_webapp.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"Identifier": "dotnet-webapp", | ||
"Files": [ | ||
{ | ||
"FileName": "Startup.cs", | ||
"Methods": { | ||
"Configure": { | ||
"Parameters": [ "IApplicationBuilder", "IWebHostEnvironment" ], | ||
"CodeChanges": [ | ||
{ | ||
"InsertAfter": "IApplicationBuilder.UseRouting()", | ||
"Block": "IApplicationBuilder.UseAuthentication()" | ||
}, | ||
{ | ||
"Parent": "IApplicationBuilder.UseEndpoints", | ||
"Type": "InLambdaBlock", | ||
"InsertAfter": "endpoints.MapRazorPages()", | ||
"Block": "endpoints.MapControllers()" | ||
} | ||
] | ||
}, | ||
"ConfigureServices": { | ||
"Parameters": [ "IServiceCollection" ], | ||
"CodeChanges": [ | ||
{ | ||
"Block": "IServiceCollection.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)" | ||
}, | ||
{ | ||
"Parent": "IServiceCollection.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)", | ||
"Type": "MemberAccess", | ||
"Block": "AddMicrosoftIdentityWebApp(Configuration.GetSection(\"AzureAd\"));" | ||
}, | ||
{ | ||
"Parent": "IServiceCollection.AddRazorPages()", | ||
"Type": "MemberAccess", | ||
"Block": "AddMvcOptions(options => {})" | ||
}, | ||
{ | ||
"Block": "IServiceCollection.AddAuthorization", | ||
"Type": "LambdaExpression", | ||
"Parameter": "options" | ||
}, | ||
{ | ||
"Parent": "services.AddAuthorization", | ||
"Type": "InLambdaBlock", | ||
"Block": "options.FallbackPolicy = options.DefaultPolicy" | ||
}, | ||
{ | ||
"Parent": "IServiceCollection.AddRazorPages()", | ||
"Type": "MemberAccess", | ||
"Block": "AddMicrosoftIdentityUI()" | ||
} | ||
] | ||
} | ||
}, | ||
"Usings": [ | ||
"Microsoft.AspNetCore.Authentication", | ||
"Microsoft.Identity.Web", | ||
"Microsoft.Identity.Web.UI", | ||
"Microsoft.AspNetCore.Authentication.OpenIdConnect", | ||
"Microsoft.AspNetCore.Authorization", | ||
"Microsoft.AspNetCore.Mvc.Authorization" | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.